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();
}
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;
}
}
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;
}
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;
}
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) {
}
}
}
Aggregations