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

Commit ad71a3cd authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Apply launch power mode during freezing screen am: 4bc0e4eb

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I8f285ba3377fb1392b01467530b207372ae10a38
parents 2eb7f844 4bc0e4eb
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -176,6 +176,7 @@ import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.power.Mode;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -343,7 +344,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    private StatusBarManagerInternal mStatusBarManagerInternal;
    @VisibleForTesting
    final ActivityTaskManagerInternal mInternal;
    PowerManagerInternal mPowerManagerInternal;
    private PowerManagerInternal mPowerManagerInternal;
    private UsageStatsManagerInternal mUsageStatsInternal;

    PendingIntentController mPendingIntentController;
@@ -589,6 +590,22 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     */
    volatile int mTopProcessState = ActivityManager.PROCESS_STATE_TOP;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            POWER_MODE_REASON_START_ACTIVITY,
            POWER_MODE_REASON_FREEZE_DISPLAY,
            POWER_MODE_REASON_ALL,
    })
    @interface PowerModeReason {}

    static final int POWER_MODE_REASON_START_ACTIVITY = 1 << 0;
    static final int POWER_MODE_REASON_FREEZE_DISPLAY = 1 << 1;
    /** This can only be used by {@link #endLaunchPowerMode(int)}.*/
    static final int POWER_MODE_REASON_ALL = (1 << 2) - 1;

    /** The reasons to use {@link Mode#LAUNCH} power mode. */
    private @PowerModeReason int mLaunchPowerModeReasons;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            LAYOUT_REASON_CONFIG_CHANGED,
@@ -4095,6 +4112,20 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        return changes;
    }

    void startLaunchPowerMode(@PowerModeReason int reason) {
        if (mPowerManagerInternal == null) return;
        mPowerManagerInternal.setPowerMode(Mode.LAUNCH, true);
        mLaunchPowerModeReasons |= reason;
    }

    void endLaunchPowerMode(@PowerModeReason int reason) {
        if (mPowerManagerInternal == null || mLaunchPowerModeReasons == 0) return;
        mLaunchPowerModeReasons &= ~reason;
        if (mLaunchPowerModeReasons == 0) {
            mPowerManagerInternal.setPowerMode(Mode.LAUNCH, false);
        }
    }

    /** @see WindowSurfacePlacer#deferLayout */
    void deferWindowLayout() {
        if (!mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) {
+1 −1
Original line number Diff line number Diff line
@@ -1755,7 +1755,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        }

        // End power mode launch before going sleep
        mRootWindowContainer.endPowerModeLaunchIfNeeded();
        mService.endLaunchPowerMode(ActivityTaskManagerService.POWER_MODE_REASON_ALL);

        removeSleepTimeouts();

+2 −1
Original line number Diff line number Diff line
@@ -284,7 +284,8 @@ class RecentsAnimation implements RecentsAnimationCallbacks, OnRootTaskOrderChan
            // Just to be sure end the launch hint in case the target activity was never launched.
            // However, if we're keeping the activity and making it visible, we can leave it on.
            if (reorderMode != REORDER_KEEP_IN_PLACE) {
                mService.mRootWindowContainer.endPowerModeLaunchIfNeeded();
                mService.endLaunchPowerMode(
                        ActivityTaskManagerService.POWER_MODE_REASON_START_ACTIVITY);
            }

            // Once the target is shown, prevent spurious background app switches
+4 −15
Original line number Diff line number Diff line
@@ -267,9 +267,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
     */
    final SparseArray<SleepToken> mSleepTokens = new SparseArray<>();

    /** Set when a power mode launch has started, but not ended. */
    private boolean mPowerModeLaunchStarted;

    // The default minimal size that will be used if the activity doesn't specify its minimal size.
    // It will be calculated when the default display gets added.
    int mDefaultMinSizeOfResizeableTaskDp = -1;
@@ -3327,7 +3324,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            }
        }
        // End power mode launch when idle.
        endPowerModeLaunchIfNeeded();
        mService.endLaunchPowerMode(ActivityTaskManagerService.POWER_MODE_REASON_START_ACTIVITY);
        return true;
    }

@@ -3540,17 +3537,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            sendPowerModeLaunch = noResumedActivities[0] || allFocusedProcessesDiffer[0];
        }

        if (sendPowerModeLaunch && mService.mPowerManagerInternal != null) {
            mService.mPowerManagerInternal.setPowerMode(Mode.LAUNCH, true);
            mPowerModeLaunchStarted = true;
        }
    }

    void endPowerModeLaunchIfNeeded() {
        // Trigger launch power mode off if activity is launched
        if (mPowerModeLaunchStarted && mService.mPowerManagerInternal != null) {
            mService.mPowerManagerInternal.setPowerMode(Mode.LAUNCH, false);
            mPowerModeLaunchStarted = false;
        if (sendPowerModeLaunch) {
            mService.startLaunchPowerMode(
                    ActivityTaskManagerService.POWER_MODE_REASON_START_ACTIVITY);
        }
    }

+5 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ import static com.android.internal.util.LatencyTracker.ACTION_ROTATE_SCREEN;
import static com.android.server.LockGuard.INDEX_WINDOW;
import static com.android.server.LockGuard.installLock;
import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
import static com.android.server.wm.ActivityTaskManagerService.POWER_MODE_REASON_FREEZE_DISPLAY;
import static com.android.server.wm.DisplayContent.IME_TARGET_CONTROL;
import static com.android.server.wm.DisplayContent.IME_TARGET_INPUT;
import static com.android.server.wm.DisplayContent.IME_TARGET_LAYERING;
@@ -5841,6 +5842,9 @@ public class WindowManagerService extends IWindowManager.Stub
                            "startFreezingDisplayLocked: exitAnim=%d enterAnim=%d called by %s",
                            exitAnim, enterAnim, Debug.getCallers(8));
        mScreenFrozenLock.acquire();
        // Apply launch power mode to reduce screen frozen time because orientation change may
        // relaunch activity and redraw windows. This may also help speed up user switching.
        mAtmService.startLaunchPowerMode(POWER_MODE_REASON_FREEZE_DISPLAY);

        mDisplayFrozen = true;
        mDisplayFreezeTime = SystemClock.elapsedRealtime();
@@ -5984,6 +5988,7 @@ public class WindowManagerService extends IWindowManager.Stub
        if (configChanged) {
            displayContent.sendNewConfiguration();
        }
        mAtmService.endLaunchPowerMode(POWER_MODE_REASON_FREEZE_DISPLAY);
        mLatencyTracker.onActionEnd(ACTION_ROTATE_SCREEN);
    }