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

Commit 453b7019 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9410359 from e78c205d to tm-qpr2-release

Change-Id: I0d0975c055515ea02d82ed983f82c8aeb9f0d7e8
parents dfceb9ed e78c205d
Loading
Loading
Loading
Loading
+48 −17
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseLongArray;
import android.util.SparseSetArray;
import android.util.TimeUtils;
import android.view.Display;
import android.widget.Toast;
@@ -451,6 +452,12 @@ public class AppStandbyController
     */
    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.
     */
@@ -968,8 +975,11 @@ public class AppStandbyController
                                    + standbyBucketToString(newBucket));
                        }
                    } else {
                        newBucket = getBucketForLocked(packageName, userId,
                                elapsedRealtime);
                        // Don't update the standby state for apps that were restored
                        if (!(oldMainReason == REASON_MAIN_DEFAULT
                                && (app.bucketingReason & REASON_SUB_MASK)
                                        == REASON_SUB_DEFAULT_APP_RESTORED)) {
                            newBucket = getBucketForLocked(packageName, userId, elapsedRealtime);
                            if (DEBUG) {
                                Slog.d(TAG, "Evaluated AOSP newBucket = "
                                        + standbyBucketToString(newBucket));
@@ -977,6 +987,7 @@ public class AppStandbyController
                            reason = REASON_MAIN_TIMEOUT;
                        }
                    }
                }

                // Check if the app is within one of the expiry times for forced bucket elevation
                final long elapsedTimeAdjusted = mAppIdleHistory.getElapsedTime(elapsedRealtime);
@@ -1610,18 +1621,29 @@ public class AppStandbyController
        final int reason = REASON_MAIN_DEFAULT | REASON_SUB_DEFAULT_APP_RESTORED;
        final long nowElapsed = mInjector.elapsedRealtime();
        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)) {
                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;
            }

            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.
        if (standbyBucket == STANDBY_BUCKET_NEVER) {
                setAppStandbyBucket(packageName, userId, STANDBY_BUCKET_RARE, reason,
                        nowElapsed, false);
            }
            setAppStandbyBucket(pkgName, userId, STANDBY_BUCKET_RARE, reason, nowElapsed, false);
        }
    }

@@ -2116,15 +2138,24 @@ public class AppStandbyController
                }
                // component-level enable/disable can affect bucketing, so we always
                // reevaluate that for any PACKAGE_CHANGED
                if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
                    mHandler.obtainMessage(MSG_CHECK_PACKAGE_IDLE_STATE, userId, -1, pkgName)
                            .sendToTarget();
                }
            }
            if ((Intent.ACTION_PACKAGE_REMOVED.equals(action) ||
                    Intent.ACTION_PACKAGE_ADDED.equals(action))) {
                if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                    maybeUnrestrictBuggyApp(pkgName, userId);
                } else {
                } else if (!Intent.ACTION_PACKAGE_ADDED.equals(action)) {
                    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);
                    }
                }
            }
        }
+40 −35
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@ package android.animation;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.view.Choreographer;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

/**
@@ -40,7 +40,7 @@ import java.util.ArrayList;
public class AnimationHandler {

    private static final String TAG = "AnimationHandler";
    private static final boolean LOCAL_LOGV = true;
    private static final boolean LOCAL_LOGV = false;

    /**
     * Internal per-thread collections used to avoid set collisions as animations start and end
@@ -78,7 +78,7 @@ public class AnimationHandler {
     * store visible (foreground) requestors; if the set size reaches zero, there are no
     * objects in the foreground and it is time to pause animators.
     */
    private final ArraySet<Object> mAnimatorRequestors = new ArraySet<>();
    private final ArrayList<WeakReference<Object>> mAnimatorRequestors = new ArrayList<>();

    private final Choreographer.FrameCallback mFrameCallback = new Choreographer.FrameCallback() {
        @Override
@@ -141,24 +141,9 @@ public class AnimationHandler {
     * tracking obsolete+enabled requestors.
     */
    public static void removeRequestor(Object requestor) {
        getInstance().removeRequestorImpl(requestor);
    }

    private void removeRequestorImpl(Object requestor) {
        // Also request disablement, in case that requestor was the sole object keeping
        // animators un-paused
        long startTime = System.nanoTime();
        requestAnimatorsEnabled(false, requestor);
        Log.d(TAG, "removeRequestorImpl called requestAnimatorsEnabled after " + 
              (System.nanoTime() - startTime));
        mAnimatorRequestors.remove(requestor);
        Log.d(TAG, "removeRequestorImpl removed requestor after " + 
              (System.nanoTime() - startTime));
        getInstance().requestAnimatorsEnabledImpl(false, requestor);
        if (LOCAL_LOGV) {
            Log.v(TAG, "removeRequestorImpl for " + requestor);
            for (int i = 0; i < mAnimatorRequestors.size(); ++i) {
                Log.v(TAG, "animatorRequesters " + i + " = " + mAnimatorRequestors.valueAt(i));
            }
            Log.v(TAG, "removeRequestor for " + requestor);
        }
    }

@@ -176,25 +161,44 @@ public class AnimationHandler {
    }

    private void requestAnimatorsEnabledImpl(boolean enable, Object requestor) {
        long startTime = System.nanoTime();
        boolean wasEmpty = mAnimatorRequestors.isEmpty();
        setAnimatorPausingEnabled(isPauseBgAnimationsEnabledInSystemProperties());
        Log.d(TAG, "requestAnimatorsEnabledImpl called setAnimatorPausingEnabled after " + 
              (System.nanoTime() - startTime));
        synchronized (mAnimatorRequestors) {
            // Only store WeakRef objects to avoid leaks
            if (enable) {
            mAnimatorRequestors.add(requestor);
                // First, check whether such a reference is already on the list
                WeakReference<Object> weakRef = null;
                for (int i = mAnimatorRequestors.size() - 1; i >= 0; --i) {
                    WeakReference<Object> ref = mAnimatorRequestors.get(i);
                    Object referent = ref.get();
                    if (referent == requestor) {
                        weakRef = ref;
                    } else if (referent == null) {
                        // Remove any reference that has been cleared
                        mAnimatorRequestors.remove(i);
                    }
                }
                if (weakRef == null) {
                    weakRef = new WeakReference<>(requestor);
                    mAnimatorRequestors.add(weakRef);
                }
            } else {
            mAnimatorRequestors.remove(requestor);
                for (int i = mAnimatorRequestors.size() - 1; i >= 0; --i) {
                    WeakReference<Object> ref = mAnimatorRequestors.get(i);
                    Object referent = ref.get();
                    if (referent == requestor || referent == null) {
                        // remove requested item or item that has been cleared
                        mAnimatorRequestors.remove(i);
                    }
                }
                // If a reference to the requestor wasn't in the list, nothing to remove
            }
        }
        Log.d(TAG, "requestAnimatorsEnabledImpl added/removed after " + 
              (System.nanoTime() - startTime));
        if (!sAnimatorPausingEnabled) {
            // Resume any animators that have been paused in the meantime, otherwise noop
            // Leave logic above so that if pausing gets re-enabled, the state of the requestors
            // list is valid
            resumeAnimators();
            Log.d(TAG, "requestAnimatorsEnabledImpl resumed, returning after " + 
                  (System.nanoTime() - startTime));
            return;
        }
        boolean isEmpty = mAnimatorRequestors.isEmpty();
@@ -209,12 +213,13 @@ public class AnimationHandler {
                        Animator.getBackgroundPauseDelay());
            }
        }
        Log.d(TAG, "requestAnimatorsEnabledImpl post was/is check after " + 
              (System.nanoTime() - startTime));
        if (LOCAL_LOGV) {
            Log.v(TAG, enable ? "enable" : "disable" + " animators for " + requestor);
            Log.v(TAG, (enable ? "enable" : "disable") + " animators for " + requestor
                    + " with pauseDelay of " + Animator.getBackgroundPauseDelay());
            for (int i = 0; i < mAnimatorRequestors.size(); ++i) {
                Log.v(TAG, "animatorRequesters " + i + " = " + mAnimatorRequestors.valueAt(i));
                Log.v(TAG, "animatorRequestors " + i + " = "
                        + mAnimatorRequestors.get(i) + " with referent "
                        + mAnimatorRequestors.get(i).get());
            }
        }
    }
+16 −0
Original line number Diff line number Diff line
@@ -511,10 +511,26 @@ public class StatusBarManager {
    @SystemApi
    public static final int MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER = 1;

    /**
     * State indicating that media transfer to this receiver device is succeeded.
     *
     * @hide
     */
    public static final int MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED = 2;

    /**
     * State indicating that media transfer to this receiver device is failed.
     *
     * @hide
     */
    public static final int MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_FAILED = 3;

    /** @hide */
    @IntDef(prefix = {"MEDIA_TRANSFER_RECEIVER_STATE_"}, value = {
            MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER,
            MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER,
            MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED,
            MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_FAILED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface MediaTransferReceiverState {}
+0 −7
Original line number Diff line number Diff line
@@ -427,9 +427,6 @@ public abstract class DisplayManagerInternal {
        // 1 (brighter). Set to Float.NaN if there's no override.
        public float screenAutoBrightnessAdjustmentOverride;

        // If true, enables automatic brightness control.
        public boolean useAutoBrightness;

        // If true, scales the brightness to a fraction of desired (as defined by
        // screenLowPowerBrightnessFactor).
        public boolean lowPowerMode;
@@ -459,7 +456,6 @@ public abstract class DisplayManagerInternal {
            policy = POLICY_BRIGHT;
            useProximitySensor = false;
            screenBrightnessOverride = PowerManager.BRIGHTNESS_INVALID_FLOAT;
            useAutoBrightness = false;
            screenAutoBrightnessAdjustmentOverride = Float.NaN;
            screenLowPowerBrightnessFactor = 0.5f;
            blockScreenOn = false;
@@ -483,7 +479,6 @@ public abstract class DisplayManagerInternal {
            policy = other.policy;
            useProximitySensor = other.useProximitySensor;
            screenBrightnessOverride = other.screenBrightnessOverride;
            useAutoBrightness = other.useAutoBrightness;
            screenAutoBrightnessAdjustmentOverride = other.screenAutoBrightnessAdjustmentOverride;
            screenLowPowerBrightnessFactor = other.screenLowPowerBrightnessFactor;
            blockScreenOn = other.blockScreenOn;
@@ -505,7 +500,6 @@ public abstract class DisplayManagerInternal {
                    && useProximitySensor == other.useProximitySensor
                    && floatEquals(screenBrightnessOverride,
                            other.screenBrightnessOverride)
                    && useAutoBrightness == other.useAutoBrightness
                    && floatEquals(screenAutoBrightnessAdjustmentOverride,
                            other.screenAutoBrightnessAdjustmentOverride)
                    && screenLowPowerBrightnessFactor
@@ -531,7 +525,6 @@ public abstract class DisplayManagerInternal {
            return "policy=" + policyToString(policy)
                    + ", useProximitySensor=" + useProximitySensor
                    + ", screenBrightnessOverride=" + screenBrightnessOverride
                    + ", useAutoBrightness=" + useAutoBrightness
                    + ", screenAutoBrightnessAdjustmentOverride="
                    + screenAutoBrightnessAdjustmentOverride
                    + ", screenLowPowerBrightnessFactor=" + screenLowPowerBrightnessFactor
+7 −0
Original line number Diff line number Diff line
@@ -522,6 +522,13 @@ public final class PowerManager {
     */
    public static final int GO_TO_SLEEP_FLAG_NO_DOZE = 1 << 0;

    /**
     * Go to sleep flag: Sleep softly, go to sleep only if there's no wakelock explicitly keeping
     * the device awake.
     * @hide
     */
    public static final int GO_TO_SLEEP_FLAG_SOFT_SLEEP = 1 << 1;

    /**
     * @hide
     */
Loading