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

Commit c86da5f7 authored by Kweku Adams's avatar Kweku Adams
Browse files

Load headless system app cache on boot.

AppStandbyController.initializeDefaultsForSystemApps() is only called
when there's a system update. The headless system app cache needs to be
loaded on every boot, so this moves the loading to the on-boot path.

Bug: 155761007
Test: reboot device multiple times
Change-Id: I94fd6a85b791388f937e208448c6b38d9639005e
parent 9f2c4366
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -447,6 +447,8 @@ public class AppStandbyController implements AppStandbyInternal {
                userFileExists = mAppIdleHistory.userFileExists(UserHandle.USER_SYSTEM);
            }

            loadHeadlessSystemAppCache();

            if (mPendingInitializeDefaults || !userFileExists) {
                initializeDefaultsForSystemApps(UserHandle.USER_SYSTEM);
            }
@@ -1670,6 +1672,8 @@ public class AppStandbyController implements AppStandbyInternal {
                clearCarrierPrivilegedApps();
                // ACTION_PACKAGE_ADDED is called even for system app downgrades.
                evaluateSystemAppException(pkgName, userId);
                mHandler.obtainMessage(MSG_CHECK_PACKAGE_IDLE_STATE, userId, -1, pkgName)
                    .sendToTarget();
            }
            if ((Intent.ACTION_PACKAGE_REMOVED.equals(action) ||
                    Intent.ACTION_PACKAGE_ADDED.equals(action))) {
@@ -1684,7 +1688,7 @@ public class AppStandbyController implements AppStandbyInternal {

    private void evaluateSystemAppException(String packageName, int userId) {
        if (!mSystemServicesReady) {
            // The app will be evaluated in initializeDefaultsForSystemApps() when possible.
            // The app will be evaluated in when services are ready.
            return;
        }
        try {
@@ -1710,6 +1714,7 @@ public class AppStandbyController implements AppStandbyInternal {
        }
    }

    /** Call on a system version update to temporarily reset system app buckets. */
    @Override
    public void initializeDefaultsForSystemApps(int userId) {
        if (!mSystemServicesReady) {
@@ -1721,7 +1726,7 @@ public class AppStandbyController implements AppStandbyInternal {
                + "appIdleEnabled=" + mAppIdleEnabled);
        final long elapsedRealtime = mInjector.elapsedRealtime();
        List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser(
                PackageManager.GET_ACTIVITIES | PackageManager.MATCH_DISABLED_COMPONENTS,
                PackageManager.MATCH_DISABLED_COMPONENTS,
                userId);
        final int packageCount = packages.size();
        synchronized (mAppIdleLock) {
@@ -1734,8 +1739,6 @@ public class AppStandbyController implements AppStandbyInternal {
                    mAppIdleHistory.reportUsage(packageName, userId, STANDBY_BUCKET_ACTIVE,
                            REASON_SUB_USAGE_SYSTEM_UPDATE, 0,
                            elapsedRealtime + mSystemUpdateUsageTimeoutMillis);

                    evaluateSystemAppException(pi);
                }
            }
            // Immediately persist defaults to disk
@@ -1743,6 +1746,18 @@ public class AppStandbyController implements AppStandbyInternal {
        }
    }

    /** Call on a system update to temporarily reset system app buckets. */
    private void loadHeadlessSystemAppCache() {
        Slog.d(TAG, "Loading headless system app cache. appIdleEnabled=" + mAppIdleEnabled);
        final List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser(
                PackageManager.GET_ACTIVITIES | PackageManager.MATCH_DISABLED_COMPONENTS,
                UserHandle.USER_SYSTEM);
        final int packageCount = packages.size();
        for (int i = 0; i < packageCount; i++) {
            evaluateSystemAppException(packages.get(i));
        }
    }

    @Override
    public void postReportContentProviderUsage(String name, String packageName, int userId) {
        SomeArgs args = SomeArgs.obtain();
@@ -1835,6 +1850,14 @@ public class AppStandbyController implements AppStandbyInternal {
        pw.print("mScreenThresholds="); pw.println(Arrays.toString(mAppStandbyScreenThresholds));
        pw.print("mElapsedThresholds="); pw.println(Arrays.toString(mAppStandbyElapsedThresholds));
        pw.println();

        pw.println("mHeadlessSystemApps=[");
        for (int i = mHeadlessSystemApps.size() - 1; i >= 0; --i) {
            pw.print(mHeadlessSystemApps.keyAt(i));
            pw.println(",");
        }
        pw.println("]");
        pw.println();
    }

    /**