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

Commit 52b52a60 authored by Kweku Adams's avatar Kweku Adams
Browse files

Fix app standby bugs.

1. Don't set app standby buckets when app idle is disabled. When the
bucket is set when app idle is disabled, AppStandbyController notifies
listeners, which then puts the listeners in an invalid state where
they think some apps are exempted from things like battery saver.

2. Remove uninstalled packages from AppStateTracker's exempted package
cache.

Bug: 156868557
Test: make cts -j 64 && cts-tradefed run commandAndExit cts -m CtsBatterySavingTestCases -t android.os.cts.batterysaving.BatterySaverAlarmTest
Test: make cts -j 64 && cts-tradefed run commandAndExit cts-on-gsi -m CtsBatterySavingTestCases -t android.os.cts.batterysaving.BatterySaverAlarmTest
Change-Id: If62c75eff0bc56ef1750e109335ba7e47832c128
Merged-In: 2a94051c
parent 57e977a5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1322,6 +1322,8 @@ public class AppStandbyController implements AppStandbyInternal {

    private void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket,
            int reason, long elapsedRealtime, boolean resetTimeout) {
        if (!mAppIdleEnabled) return;

        synchronized (mAppIdleLock) {
            // If the package is not installed, don't allow the bucket to be set.
            if (!mInjector.isPackageInstalled(packageName, 0, userId)) {
+8 −0
Original line number Diff line number Diff line
@@ -448,6 +448,7 @@ public class AppStateTracker {
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_USER_REMOVED);
            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            mContext.registerReceiver(new MyReceiver(), filter);

            refreshForcedAppStandbyUidPackagesLocked();
@@ -688,6 +689,13 @@ public class AppStateTracker {
                    mIsPluggedIn = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0);
                }
                updateForceAllAppStandbyState();
            } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())
                    && !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                final String pkgName = intent.getData().getSchemeSpecificPart();
                if (mExemptedPackages.remove(userId, pkgName)) {
                    mHandler.notifyExemptChanged();
                }
            }
        }
    }