Search in sources :

Example 71 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class PermissionMonitor method onAppAdded.

private synchronized void onAppAdded(String appName, int appUid) {
    if (TextUtils.isEmpty(appName) || appUid < 0) {
        loge("Invalid app in onAppAdded: " + appName + " | " + appUid);
        return;
    }
    try {
        PackageInfo app = mPackageManager.getPackageInfo(appName, GET_PERMISSIONS);
        boolean isNetwork = hasNetworkPermission(app);
        boolean hasRestrictedPermission = hasRestrictedNetworkPermission(app);
        if (isNetwork || hasRestrictedPermission) {
            Boolean permission = mApps.get(appUid);
            // permissions, don't downgrade (i.e., if it's already SYSTEM, leave it as is).
            if (permission == null || permission == NETWORK) {
                mApps.put(appUid, hasRestrictedPermission);
                Map<Integer, Boolean> apps = new HashMap<>();
                apps.put(appUid, hasRestrictedPermission);
                update(mUsers, apps, true);
            }
        }
    } catch (NameNotFoundException e) {
        loge("NameNotFoundException in onAppAdded: " + e);
    }
}
Also used : HashMap(java.util.HashMap) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 72 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class AppSecurityPermissions method extractPerms.

private void extractPerms(PackageInfo info, Set<MyPermissionInfo> permSet, PackageInfo installedPkgInfo) {
    String[] strList = info.requestedPermissions;
    int[] flagsList = info.requestedPermissionsFlags;
    if ((strList == null) || (strList.length == 0)) {
        return;
    }
    for (int i = 0; i < strList.length; i++) {
        String permName = strList[i];
        try {
            PermissionInfo tmpPermInfo = mPm.getPermissionInfo(permName, 0);
            if (tmpPermInfo == null) {
                continue;
            }
            int existingIndex = -1;
            if (installedPkgInfo != null && installedPkgInfo.requestedPermissions != null) {
                for (int j = 0; j < installedPkgInfo.requestedPermissions.length; j++) {
                    if (permName.equals(installedPkgInfo.requestedPermissions[j])) {
                        existingIndex = j;
                        break;
                    }
                }
            }
            final int existingFlags = existingIndex >= 0 ? installedPkgInfo.requestedPermissionsFlags[existingIndex] : 0;
            if (!isDisplayablePermission(tmpPermInfo, flagsList[i], existingFlags)) {
                // to see, so skip it.
                continue;
            }
            final String origGroupName = tmpPermInfo.group;
            String groupName = origGroupName;
            if (groupName == null) {
                groupName = tmpPermInfo.packageName;
                tmpPermInfo.group = groupName;
            }
            MyPermissionGroupInfo group = mPermGroups.get(groupName);
            if (group == null) {
                PermissionGroupInfo grp = null;
                if (origGroupName != null) {
                    grp = mPm.getPermissionGroupInfo(origGroupName, 0);
                }
                if (grp != null) {
                    group = new MyPermissionGroupInfo(grp);
                } else {
                    // We could be here either because the permission
                    // didn't originally specify a group or the group it
                    // gave couldn't be found.  In either case, we consider
                    // its group to be the permission's package name.
                    tmpPermInfo.group = tmpPermInfo.packageName;
                    group = mPermGroups.get(tmpPermInfo.group);
                    if (group == null) {
                        group = new MyPermissionGroupInfo(tmpPermInfo);
                    }
                    group = new MyPermissionGroupInfo(tmpPermInfo);
                }
                mPermGroups.put(tmpPermInfo.group, group);
            }
            final boolean newPerm = installedPkgInfo != null && (existingFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0;
            MyPermissionInfo myPerm = new MyPermissionInfo(tmpPermInfo);
            myPerm.mNewReqFlags = flagsList[i];
            myPerm.mExistingReqFlags = existingFlags;
            // This is a new permission if the app is already installed and
            // doesn't currently hold this permission.
            myPerm.mNew = newPerm;
            permSet.add(myPerm);
        } catch (NameNotFoundException e) {
            Log.i(TAG, "Ignoring unknown permission:" + permName);
        }
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PermissionGroupInfo(android.content.pm.PermissionGroupInfo)

Example 73 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class PackageHelper method resolveInstallVolume.

/**
     * Given a requested {@link PackageInfo#installLocation} and calculated
     * install size, pick the actual volume to install the app. Only considers
     * internal and private volumes, and prefers to keep an existing package on
     * its current volume.
     *
     * @return the {@link VolumeInfo#fsUuid} to install onto, or {@code null}
     *         for internal storage.
     */
public static String resolveInstallVolume(Context context, String packageName, int installLocation, long sizeBytes) throws IOException {
    final boolean forceAllowOnExternal = Settings.Global.getInt(context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
    // TODO: handle existing apps installed in ASEC; currently assumes
    // they'll end up back on internal storage
    ApplicationInfo existingInfo = null;
    try {
        existingInfo = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (NameNotFoundException ignored) {
    }
    final StorageManager storageManager = context.getSystemService(StorageManager.class);
    final boolean fitsOnInternal = fitsOnInternal(context, sizeBytes);
    final ArraySet<String> allCandidates = new ArraySet<>();
    VolumeInfo bestCandidate = null;
    long bestCandidateAvailBytes = Long.MIN_VALUE;
    for (VolumeInfo vol : storageManager.getVolumes()) {
        if (vol.type == VolumeInfo.TYPE_PRIVATE && vol.isMountedWritable()) {
            final long availBytes = storageManager.getStorageBytesUntilLow(new File(vol.path));
            if (availBytes >= sizeBytes) {
                allCandidates.add(vol.fsUuid);
            }
            if (availBytes >= bestCandidateAvailBytes) {
                bestCandidate = vol;
                bestCandidateAvailBytes = availBytes;
            }
        }
    }
    // System apps always forced to internal storage
    if (existingInfo != null && existingInfo.isSystemApp()) {
        installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
    }
    // If app expresses strong desire for internal storage, honor it
    if (!forceAllowOnExternal && installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
        if (existingInfo != null && !Objects.equals(existingInfo.volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL)) {
            throw new IOException("Cannot automatically move " + packageName + " from " + existingInfo.volumeUuid + " to internal storage");
        }
        if (fitsOnInternal) {
            return StorageManager.UUID_PRIVATE_INTERNAL;
        } else {
            throw new IOException("Requested internal only, but not enough space");
        }
    }
    // If app already exists somewhere, we must stay on that volume
    if (existingInfo != null) {
        if (Objects.equals(existingInfo.volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL) && fitsOnInternal) {
            return StorageManager.UUID_PRIVATE_INTERNAL;
        } else if (allCandidates.contains(existingInfo.volumeUuid)) {
            return existingInfo.volumeUuid;
        } else {
            throw new IOException("Not enough space on existing volume " + existingInfo.volumeUuid + " for " + packageName + " upgrade");
        }
    }
    // volume with most space
    if (bestCandidate != null) {
        return bestCandidate.fsUuid;
    } else if (fitsOnInternal) {
        return StorageManager.UUID_PRIVATE_INTERNAL;
    } else {
        throw new IOException("No special requests, but no room anywhere");
    }
}
Also used : ArraySet(android.util.ArraySet) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 74 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageAccountsSettings method isSafeIntent.

/**
     * Determines if the supplied Intent is safe. A safe intent is one that is
     * will launch a exported=true activity or owned by the same uid as the
     * authenticator supplying the intent.
     */
private boolean isSafeIntent(PackageManager pm, Intent intent) {
    AuthenticatorDescription authDesc = mAuthenticatorHelper.getAccountTypeDescription(mAccountType);
    ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
    if (resolveInfo == null) {
        return false;
    }
    ActivityInfo resolvedActivityInfo = resolveInfo.activityInfo;
    ApplicationInfo resolvedAppInfo = resolvedActivityInfo.applicationInfo;
    try {
        ApplicationInfo authenticatorAppInf = pm.getApplicationInfo(authDesc.packageName, 0);
        return resolvedActivityInfo.exported || resolvedAppInfo.uid == authenticatorAppInf.uid;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Intent considered unsafe due to exception.", e);
        return false;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AuthenticatorDescription(android.accounts.AuthenticatorDescription) ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 75 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppListPreference method setPackageNames.

public void setPackageNames(CharSequence[] packageNames, CharSequence defaultPackageName, CharSequence systemPackageName) {
    // Look up all package names in PackageManager. Skip ones we can't find.
    PackageManager pm = getContext().getPackageManager();
    final int entryCount = packageNames.length + (mShowItemNone ? 1 : 0);
    List<CharSequence> applicationNames = new ArrayList<>(entryCount);
    List<CharSequence> validatedPackageNames = new ArrayList<>(entryCount);
    List<Drawable> entryDrawables = new ArrayList<>(entryCount);
    int selectedIndex = -1;
    mSystemAppIndex = -1;
    for (int i = 0; i < packageNames.length; i++) {
        try {
            ApplicationInfo appInfo = pm.getApplicationInfoAsUser(packageNames[i].toString(), 0, mUserId);
            applicationNames.add(appInfo.loadLabel(pm));
            validatedPackageNames.add(appInfo.packageName);
            entryDrawables.add(appInfo.loadIcon(pm));
            if (defaultPackageName != null && appInfo.packageName.contentEquals(defaultPackageName)) {
                selectedIndex = i;
            }
            if (appInfo.packageName != null && systemPackageName != null && appInfo.packageName.contentEquals(systemPackageName)) {
                mSystemAppIndex = i;
            }
        } catch (NameNotFoundException e) {
        // Skip unknown packages.
        }
    }
    if (mShowItemNone) {
        applicationNames.add(getContext().getResources().getText(R.string.app_list_preference_none));
        validatedPackageNames.add(ITEM_NONE_VALUE);
        entryDrawables.add(getContext().getDrawable(R.drawable.ic_remove_circle));
    }
    setEntries(applicationNames.toArray(new CharSequence[applicationNames.size()]));
    setEntryValues(validatedPackageNames.toArray(new CharSequence[validatedPackageNames.size()]));
    mEntryDrawables = entryDrawables.toArray(new Drawable[entryDrawables.size()]);
    if (selectedIndex != -1) {
        setValueIndex(selectedIndex);
    } else {
        setValue(null);
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1012 PackageManager (android.content.pm.PackageManager)358 PackageInfo (android.content.pm.PackageInfo)291 ApplicationInfo (android.content.pm.ApplicationInfo)235 Intent (android.content.Intent)141 ComponentName (android.content.ComponentName)133 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)103 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)90 UserHandle (android.os.UserHandle)79 ResolveInfo (android.content.pm.ResolveInfo)72 ArrayList (java.util.ArrayList)68 RemoteException (android.os.RemoteException)63 File (java.io.File)57 TextView (android.widget.TextView)52 View (android.view.View)47 FileNotFoundException (java.io.FileNotFoundException)44