use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class DeviceIdleController method addSystemPowerSaveWhitelistAppInternal.
public boolean addSystemPowerSaveWhitelistAppInternal(String name) {
synchronized (this) {
try {
ApplicationInfo ai = getContext().getPackageManager().getApplicationInfo(name, PackageManager.MATCH_UNINSTALLED_PACKAGES);
if (mPowerSaveWhitelistApps.put(name, UserHandle.getAppId(ai.uid)) == null) {
reportPowerSaveWhitelistChangedLocked();
updateWhitelistAppIdsLocked();
writeConfigFileLocked();
}
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class DeviceIdleController method addPowerSaveWhitelistAppInternal.
public boolean addPowerSaveWhitelistAppInternal(String name) {
synchronized (this) {
try {
ApplicationInfo ai = getContext().getPackageManager().getApplicationInfo(name, PackageManager.MATCH_UNINSTALLED_PACKAGES);
if (mPowerSaveWhitelistUserApps.put(name, UserHandle.getAppId(ai.uid)) == null) {
reportPowerSaveWhitelistChangedLocked();
updateWhitelistAppIdsLocked();
writeConfigFileLocked();
}
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class DevicePolicyManagerTest method testApplicationRestrictionsManagingApp.
public void testApplicationRestrictionsManagingApp() throws Exception {
setAsProfileOwner(admin1);
final String nonExistAppRestrictionsManagerPackage = "com.google.app.restrictions.manager2";
final String appRestrictionsManagerPackage = "com.google.app.restrictions.manager";
final int appRestrictionsManagerAppId = 20987;
final int appRestrictionsManagerUid = UserHandle.getUid(DpmMockContext.CALLER_USER_HANDLE, appRestrictionsManagerAppId);
doReturn(appRestrictionsManagerUid).when(mContext.packageManager).getPackageUidAsUser(eq(appRestrictionsManagerPackage), eq(DpmMockContext.CALLER_USER_HANDLE));
mContext.binder.callingUid = appRestrictionsManagerUid;
final PackageInfo pi = new PackageInfo();
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.flags = ApplicationInfo.FLAG_HAS_CODE;
doReturn(pi).when(mContext.ipackageManager).getPackageInfo(eq(appRestrictionsManagerPackage), anyInt(), eq(DpmMockContext.CALLER_USER_HANDLE));
// appRestrictionsManager package shouldn't be able to manage restrictions as the PO hasn't
// delegated that permission yet.
assertFalse(dpm.isCallerApplicationRestrictionsManagingPackage());
Bundle rest = new Bundle();
rest.putString("KEY_STRING", "Foo1");
try {
dpm.setApplicationRestrictions(null, "pkg1", rest);
fail("Didn't throw expected SecurityException");
} catch (SecurityException expected) {
MoreAsserts.assertContainsRegex("caller cannot manage application restrictions", expected.getMessage());
}
try {
dpm.getApplicationRestrictions(null, "pkg1");
fail("Didn't throw expected SecurityException");
} catch (SecurityException expected) {
MoreAsserts.assertContainsRegex("caller cannot manage application restrictions", expected.getMessage());
}
// Check via the profile owner that no restrictions were set.
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
assertEquals(0, dpm.getApplicationRestrictions(admin1, "pkg1").size());
// Check the API does not allow setting a non-existent package
try {
dpm.setApplicationRestrictionsManagingPackage(admin1, nonExistAppRestrictionsManagerPackage);
fail("Non-existent app set as app restriction manager.");
} catch (PackageManager.NameNotFoundException expected) {
MoreAsserts.assertContainsRegex(nonExistAppRestrictionsManagerPackage, expected.getMessage());
}
// Let appRestrictionsManagerPackage manage app restrictions
dpm.setApplicationRestrictionsManagingPackage(admin1, appRestrictionsManagerPackage);
assertEquals(appRestrictionsManagerPackage, dpm.getApplicationRestrictionsManagingPackage(admin1));
// Now that package should be able to set and retrieve app restrictions.
mContext.binder.callingUid = appRestrictionsManagerUid;
assertTrue(dpm.isCallerApplicationRestrictionsManagingPackage());
dpm.setApplicationRestrictions(null, "pkg1", rest);
Bundle returned = dpm.getApplicationRestrictions(null, "pkg1");
assertEquals(1, returned.size(), 1);
assertEquals("Foo1", returned.get("KEY_STRING"));
// The same app running on a separate user shouldn't be able to manage app restrictions.
mContext.binder.callingUid = UserHandle.getUid(UserHandle.USER_SYSTEM, appRestrictionsManagerAppId);
assertFalse(dpm.isCallerApplicationRestrictionsManagingPackage());
try {
dpm.setApplicationRestrictions(null, "pkg1", rest);
fail("Didn't throw expected SecurityException");
} catch (SecurityException expected) {
MoreAsserts.assertContainsRegex("caller cannot manage application restrictions", expected.getMessage());
}
// The DPM is still able to manage app restrictions, even if it allowed another app to do it
// too.
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
assertEquals(returned, dpm.getApplicationRestrictions(admin1, "pkg1"));
dpm.setApplicationRestrictions(admin1, "pkg1", null);
assertEquals(0, dpm.getApplicationRestrictions(admin1, "pkg1").size());
// Removing the ability for the package to manage app restrictions.
dpm.setApplicationRestrictionsManagingPackage(admin1, null);
assertNull(dpm.getApplicationRestrictionsManagingPackage(admin1));
mContext.binder.callingUid = appRestrictionsManagerUid;
assertFalse(dpm.isCallerApplicationRestrictionsManagingPackage());
try {
dpm.setApplicationRestrictions(null, "pkg1", null);
fail("Didn't throw expected SecurityException");
} catch (SecurityException expected) {
MoreAsserts.assertContainsRegex("caller cannot manage application restrictions", expected.getMessage());
}
}
use of android.content.pm.ApplicationInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccountSettings method getWorkGroupSummary.
private String getWorkGroupSummary(Context context, UserInfo userInfo) {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo adminApplicationInfo = Utils.getAdminApplicationInfo(context, userInfo.id);
if (adminApplicationInfo == null) {
return null;
}
CharSequence appLabel = packageManager.getApplicationLabel(adminApplicationInfo);
return getString(R.string.managing_admin, appLabel);
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class ActivityThread method getPackageInfo.
public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, int flags, int userId) {
final boolean differentUser = (UserHandle.myUserId() != userId);
synchronized (mResourcesManager) {
WeakReference<LoadedApk> ref;
if (differentUser) {
// Caching not supported across users
ref = null;
} else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) {
ref = mPackages.get(packageName);
} else {
ref = mResourcePackages.get(packageName);
}
LoadedApk packageInfo = ref != null ? ref.get() : null;
// + ": " + packageInfo.mResources.getAssets().isUpToDate());
if (packageInfo != null && (packageInfo.mResources == null || packageInfo.mResources.getAssets().isUpToDate())) {
if (packageInfo.isSecurityViolation() && (flags & Context.CONTEXT_IGNORE_SECURITY) == 0) {
throw new SecurityException("Requesting code from " + packageName + " to be run in process " + mBoundApplication.processName + "/" + mBoundApplication.appInfo.uid);
}
return packageInfo;
}
}
ApplicationInfo ai = null;
try {
ai = getPackageManager().getApplicationInfo(packageName, PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
if (ai != null) {
return getPackageInfo(ai, compatInfo, flags);
}
return null;
}
Aggregations