Search in sources :

Example 76 with ApplicationInfo

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;
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 77 with ApplicationInfo

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;
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 78 with ApplicationInfo

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());
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) Matchers.anyString(org.mockito.Matchers.anyString)

Example 79 with ApplicationInfo

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);
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 80 with ApplicationInfo

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;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1914 PackageManager (android.content.pm.PackageManager)682 Test (org.junit.Test)366 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)363 ArrayList (java.util.ArrayList)258 Intent (android.content.Intent)231 RemoteException (android.os.RemoteException)229 PackageInfo (android.content.pm.PackageInfo)214 ResolveInfo (android.content.pm.ResolveInfo)177 IOException (java.io.IOException)122 ActivityInfo (android.content.pm.ActivityInfo)114 IPackageManager (android.content.pm.IPackageManager)109 UserHandle (android.os.UserHandle)108 Context (android.content.Context)103 Bundle (android.os.Bundle)103 File (java.io.File)100 Drawable (android.graphics.drawable.Drawable)91 UserInfo (android.content.pm.UserInfo)89 ComponentName (android.content.ComponentName)69 SmallTest (android.support.test.filters.SmallTest)66