Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf45006b authored by Adam Bookatz's avatar Adam Bookatz
Browse files

PMS caches DPM

Repeatedly fetching DPM is a significant source of slowness,
so we cache it.

Test: treehugger and `atest CtsSuspendAppsTestCases`
Bug: 177255383
Change-Id: Ic9999827d5500d0c18a9160719c1a6d0d85e0136
parent 249a37c5
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -1494,6 +1494,9 @@ public class PackageManagerService extends IPackageManager.Stub
    // List of packages names to keep cached, even if they are uninstalled for all users
    private List<String> mKeepUninstalledPackages;
    // Cached reference to IDevicePolicyManager.
    private IDevicePolicyManager mDevicePolicyManager = null;
    private File mCacheDir;
    private Future<?> mPrepareAppDataFuture;
@@ -20827,8 +20830,7 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    private boolean isPackageDeviceAdmin(String packageName, int userId) {
        IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface(
                ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
        final IDevicePolicyManager dpm = getDevicePolicyManager();
        try {
            if (dpm != null) {
                final ComponentName deviceOwnerComponentName = dpm.getDeviceOwnerComponent(
@@ -20860,6 +20862,16 @@ public class PackageManagerService extends IPackageManager.Stub
        return false;
    }
    /** Returns the device policy manager interface. */
    private IDevicePolicyManager getDevicePolicyManager() {
        if (mDevicePolicyManager == null) {
            // No need to synchronize; worst-case scenario it will be fetched twice.
            mDevicePolicyManager = IDevicePolicyManager.Stub.asInterface(
                            ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
        }
        return mDevicePolicyManager;
    }
    private boolean shouldKeepUninstalledPackageLPr(String packageName) {
        return mKeepUninstalledPackages != null && mKeepUninstalledPackages.contains(packageName);
    }