Search in sources :

Example 51 with NameNotFoundException

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

the class AccountManagerService method calculatePackageSignatureDigest.

private byte[] calculatePackageSignatureDigest(String callerPkg) {
    MessageDigest digester;
    try {
        digester = MessageDigest.getInstance("SHA-256");
        PackageInfo pkgInfo = mPackageManager.getPackageInfo(callerPkg, PackageManager.GET_SIGNATURES);
        for (Signature sig : pkgInfo.signatures) {
            digester.update(sig.toByteArray());
        }
    } catch (NoSuchAlgorithmException x) {
        Log.wtf(TAG, "SHA-256 should be available", x);
        digester = null;
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Could not find packageinfo for: " + callerPkg);
        digester = null;
    }
    return (digester == null) ? null : digester.digest();
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 52 with NameNotFoundException

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

the class AccountManagerService method filterSharedAccounts.

private Account[] filterSharedAccounts(UserAccounts userAccounts, Account[] unfiltered, int callingUid, String callingPackage) {
    if (getUserManager() == null || userAccounts == null || userAccounts.userId < 0 || callingUid == Process.myUid()) {
        return unfiltered;
    }
    UserInfo user = getUserManager().getUserInfo(userAccounts.userId);
    if (user != null && user.isRestricted()) {
        String[] packages = mPackageManager.getPackagesForUid(callingUid);
        // If any of the packages is a white listed package, return the full set,
        // otherwise return non-shared accounts only.
        // This might be a temporary way to specify a whitelist
        String whiteList = mContext.getResources().getString(com.android.internal.R.string.config_appsAuthorizedForSharedAccounts);
        for (String packageName : packages) {
            if (whiteList.contains(";" + packageName + ";")) {
                return unfiltered;
            }
        }
        ArrayList<Account> allowed = new ArrayList<Account>();
        Account[] sharedAccounts = getSharedAccountsAsUser(userAccounts.userId);
        if (sharedAccounts == null || sharedAccounts.length == 0)
            return unfiltered;
        String requiredAccountType = "";
        try {
            // opted in to see restricted accounts.
            if (callingPackage != null) {
                PackageInfo pi = mPackageManager.getPackageInfo(callingPackage, 0);
                if (pi != null && pi.restrictedAccountType != null) {
                    requiredAccountType = pi.restrictedAccountType;
                }
            } else {
                // Otherwise check if the callingUid has a package that has opted in
                for (String packageName : packages) {
                    PackageInfo pi = mPackageManager.getPackageInfo(packageName, 0);
                    if (pi != null && pi.restrictedAccountType != null) {
                        requiredAccountType = pi.restrictedAccountType;
                        break;
                    }
                }
            }
        } catch (NameNotFoundException nnfe) {
        }
        for (Account account : unfiltered) {
            if (account.type.equals(requiredAccountType)) {
                allowed.add(account);
            } else {
                boolean found = false;
                for (Account shared : sharedAccounts) {
                    if (shared.equals(account)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    allowed.add(account);
                }
            }
        }
        Account[] filtered = new Account[allowed.size()];
        allowed.toArray(filtered);
        return filtered;
    } else {
        return unfiltered;
    }
}
Also used : Account(android.accounts.Account) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo)

Example 53 with NameNotFoundException

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

the class AccountManagerService method isPrivileged.

private boolean isPrivileged(int callingUid) {
    final int callingUserId = UserHandle.getUserId(callingUid);
    final PackageManager userPackageManager;
    try {
        userPackageManager = mContext.createPackageContextAsUser("android", 0, new UserHandle(callingUserId)).getPackageManager();
    } catch (NameNotFoundException e) {
        return false;
    }
    String[] packages = userPackageManager.getPackagesForUid(callingUid);
    for (String name : packages) {
        try {
            PackageInfo packageInfo = userPackageManager.getPackageInfo(name, 0);
            if (packageInfo != null && (packageInfo.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) {
                return true;
            }
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) UserHandle(android.os.UserHandle)

Example 54 with NameNotFoundException

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

the class Vpn method getAppUid.

private int getAppUid(String app, int userHandle) {
    if (VpnConfig.LEGACY_VPN.equals(app)) {
        return Process.myUid();
    }
    PackageManager pm = mContext.getPackageManager();
    int result;
    try {
        result = pm.getPackageUidAsUser(app, userHandle);
    } catch (NameNotFoundException e) {
        result = -1;
    }
    return result;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 55 with NameNotFoundException

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

the class PowerUsageDetail method fillPackagesSection.

private void fillPackagesSection(int uid) {
    if (uid < 1) {
        removePackagesSection();
        return;
    }
    if (mPackages == null || mPackages.length < 2) {
        removePackagesSection();
        return;
    }
    PackageManager pm = getPackageManager();
    // Convert package names to user-facing labels where possible
    for (int i = 0; i < mPackages.length; i++) {
        try {
            ApplicationInfo ai = pm.getApplicationInfo(mPackages[i], 0);
            CharSequence label = ai.loadLabel(pm);
            if (label != null) {
                mPackages[i] = label.toString();
            }
            addHorizontalPreference(mPackagesParent, mPackages[i], null);
        } catch (NameNotFoundException e) {
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) 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