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

Commit 94718619 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Update logic for adjusting standby buckets for restored apps." into...

Merge "Update logic for adjusting standby buckets for restored apps." into tm-qpr-dev am: 9960d8b5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20693151



Change-Id: Iee9be08f64d1840ba2a0d2ac9cded754c3dd347d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents bcce2028 9960d8b5
Loading
Loading
Loading
Loading
+34 −9
Original line number Original line Diff line number Diff line
@@ -109,6 +109,7 @@ import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseBooleanArray;
import android.util.SparseLongArray;
import android.util.SparseLongArray;
import android.util.SparseSetArray;
import android.util.TimeUtils;
import android.util.TimeUtils;
import android.view.Display;
import android.view.Display;
import android.widget.Toast;
import android.widget.Toast;
@@ -451,6 +452,12 @@ public class AppStandbyController
     */
     */
    private final Map<String, String> mAppStandbyProperties = new ArrayMap<>();
    private final Map<String, String> mAppStandbyProperties = new ArrayMap<>();


    /**
     * Set of apps that were restored via backup & restore, per user, that need their
     * standby buckets to be adjusted when installed.
     */
    private final SparseSetArray<String> mAppsToRestoreToRare = new SparseSetArray<>();

    /**
    /**
     * List of app-ids of system packages, populated on boot, when system services are ready.
     * List of app-ids of system packages, populated on boot, when system services are ready.
     */
     */
@@ -1610,18 +1617,29 @@ public class AppStandbyController
        final int reason = REASON_MAIN_DEFAULT | REASON_SUB_DEFAULT_APP_RESTORED;
        final int reason = REASON_MAIN_DEFAULT | REASON_SUB_DEFAULT_APP_RESTORED;
        final long nowElapsed = mInjector.elapsedRealtime();
        final long nowElapsed = mInjector.elapsedRealtime();
        for (String packageName : restoredApps) {
        for (String packageName : restoredApps) {
            // If the package is not installed, don't allow the bucket to be set.
            // If the package is not installed, don't allow the bucket to be set. Instead, add it
            // to a list of all packages whose buckets need to be adjusted when installed.
            if (!mInjector.isPackageInstalled(packageName, 0, userId)) {
            if (!mInjector.isPackageInstalled(packageName, 0, userId)) {
                Slog.e(TAG, "Tried to restore bucket for uninstalled app: " + packageName);
                Slog.i(TAG, "Tried to restore bucket for uninstalled app: " + packageName);
                mAppsToRestoreToRare.add(userId, packageName);
                continue;
                continue;
            }
            }


            final int standbyBucket = getAppStandbyBucket(packageName, userId, nowElapsed, false);
            restoreAppToRare(packageName, userId, nowElapsed, reason);
        }
        // Clear out the list of restored apps that need to have their standby buckets adjusted
        // if they still haven't been installed eight hours after restore.
        // Note: if the device reboots within these first 8 hours, this list will be lost since it's
        // not persisted - this is the expected behavior for now and may be updated in the future.
        mHandler.postDelayed(() -> mAppsToRestoreToRare.remove(userId), 8 * ONE_HOUR);
    }

    /** Adjust the standby bucket of the given package for the user to RARE. */
    private void restoreAppToRare(String pkgName, int userId, long nowElapsed, int reason) {
        final int standbyBucket = getAppStandbyBucket(pkgName, userId, nowElapsed, false);
        // Only update the standby bucket to RARE if the app is still in the NEVER bucket.
        // Only update the standby bucket to RARE if the app is still in the NEVER bucket.
        if (standbyBucket == STANDBY_BUCKET_NEVER) {
        if (standbyBucket == STANDBY_BUCKET_NEVER) {
                setAppStandbyBucket(packageName, userId, STANDBY_BUCKET_RARE, reason,
            setAppStandbyBucket(pkgName, userId, STANDBY_BUCKET_RARE, reason, nowElapsed, false);
                        nowElapsed, false);
            }
        }
        }
    }
    }


@@ -2123,8 +2141,15 @@ public class AppStandbyController
                    Intent.ACTION_PACKAGE_ADDED.equals(action))) {
                    Intent.ACTION_PACKAGE_ADDED.equals(action))) {
                if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                    maybeUnrestrictBuggyApp(pkgName, userId);
                    maybeUnrestrictBuggyApp(pkgName, userId);
                } else {
                } else if (!Intent.ACTION_PACKAGE_ADDED.equals(action)) {
                    clearAppIdleForPackage(pkgName, userId);
                    clearAppIdleForPackage(pkgName, userId);
                } else {
                    // Package was just added and it's not being replaced.
                    if (mAppsToRestoreToRare.contains(userId, pkgName)) {
                        restoreAppToRare(pkgName, userId, mInjector.elapsedRealtime(),
                                REASON_MAIN_DEFAULT | REASON_SUB_DEFAULT_APP_RESTORED);
                        mAppsToRestoreToRare.remove(userId, pkgName);
                    }
                }
                }
            }
            }
        }
        }