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

Commit 942d112c authored by Riddle Hsu's avatar Riddle Hsu Committed by Jimmy Shiu
Browse files

Use separated power mode for display change

To distinguish whether it is actual launching apps.

Bug: 298150450
Test: atest ActivityTaskManagerServiceTests#testSetPowerMode
Change-Id: Ib058a6924eadb4c329b5fd74acd83472debdf332
parent 33b539cb
Loading
Loading
Loading
Loading
+47 −17
Original line number Diff line number Diff line
@@ -187,7 +187,6 @@ 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;
@@ -709,11 +708,15 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    static final int POWER_MODE_REASON_CHANGE_DISPLAY = 1 << 1;
    /** @see UnknownAppVisibilityController */
    static final int POWER_MODE_REASON_UNKNOWN_VISIBILITY = 1 << 2;
    /** This can only be used by {@link #endLaunchPowerMode(int)}.*/
    /**
     * This can only be used by {@link #endPowerMode(int)}. Excluding UNKNOWN_VISIBILITY because
     * that is guarded by a timeout while keyguard is locked.
     */
    static final int POWER_MODE_REASON_ALL = (1 << 2) - 1;

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

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
@@ -4629,11 +4632,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    void startLaunchPowerMode(@PowerModeReason int reason) {
        if (mPowerManagerInternal != null) {
            mPowerManagerInternal.setPowerMode(Mode.LAUNCH, true);
        }
        mLaunchPowerModeReasons |= reason;
    void startPowerMode(@PowerModeReason int reason) {
        final int prevReasons = mPowerModeReasons;
        mPowerModeReasons |= reason;
        if ((reason & POWER_MODE_REASON_UNKNOWN_VISIBILITY) != 0) {
            if (mRetainPowerModeAndTopProcessState) {
                mH.removeMessages(H.END_POWER_MODE_UNKNOWN_VISIBILITY_MSG);
@@ -4643,27 +4644,56 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    POWER_MODE_UNKNOWN_VISIBILITY_TIMEOUT_MS);
            Slog.d(TAG, "Temporarily retain top process state for launching app");
        }
        if (mPowerManagerInternal == null) {
            return;
        }

        // START_ACTIVITY can be used with UNKNOWN_VISIBILITY. CHANGE_DISPLAY should be used alone.
        if ((reason & POWER_MODE_REASON_START_ACTIVITY) != 0
                && (prevReasons & POWER_MODE_REASON_START_ACTIVITY) == 0) {
            Trace.instant(Trace.TRACE_TAG_WINDOW_MANAGER, "StartModeLaunch");
            mPowerManagerInternal.setPowerMode(PowerManagerInternal.MODE_LAUNCH, true);
        } else if (reason == POWER_MODE_REASON_CHANGE_DISPLAY
                && (prevReasons & POWER_MODE_REASON_CHANGE_DISPLAY) == 0) {
            Trace.instant(Trace.TRACE_TAG_WINDOW_MANAGER, "StartModeDisplayChange");
            mPowerManagerInternal.setPowerMode(PowerManagerInternal.MODE_DISPLAY_CHANGE, true);
        }
    }

    void endLaunchPowerMode(@PowerModeReason int reason) {
        if (mLaunchPowerModeReasons == 0) return;
        mLaunchPowerModeReasons &= ~reason;
    void endPowerMode(@PowerModeReason int reason) {
        if (mPowerModeReasons == 0) return;
        final int prevReasons = mPowerModeReasons;
        mPowerModeReasons &= ~reason;

        if ((mLaunchPowerModeReasons & POWER_MODE_REASON_UNKNOWN_VISIBILITY) != 0) {
        if ((mPowerModeReasons & POWER_MODE_REASON_UNKNOWN_VISIBILITY) != 0) {
            boolean allResolved = true;
            for (int i = mRootWindowContainer.getChildCount() - 1; i >= 0; i--) {
                allResolved &= mRootWindowContainer.getChildAt(i).mUnknownAppVisibilityController
                        .allResolved();
            }
            if (allResolved) {
                mLaunchPowerModeReasons &= ~POWER_MODE_REASON_UNKNOWN_VISIBILITY;
                mPowerModeReasons &= ~POWER_MODE_REASON_UNKNOWN_VISIBILITY;
                mRetainPowerModeAndTopProcessState = false;
                mH.removeMessages(H.END_POWER_MODE_UNKNOWN_VISIBILITY_MSG);
            }
        }
        if (mPowerManagerInternal == null) {
            return;
        }

        if (mLaunchPowerModeReasons == 0 && mPowerManagerInternal != null) {
            mPowerManagerInternal.setPowerMode(Mode.LAUNCH, false);
        // If the launching apps have unknown visibility, only end launch power mode until the
        // states are resolved.
        final int endLaunchModeReasons = POWER_MODE_REASON_START_ACTIVITY
                | POWER_MODE_REASON_UNKNOWN_VISIBILITY;
        if ((prevReasons & endLaunchModeReasons) != 0
                && (mPowerModeReasons & endLaunchModeReasons) == 0) {
            Trace.instant(Trace.TRACE_TAG_WINDOW_MANAGER, "EndModeLaunch");
            mPowerManagerInternal.setPowerMode(PowerManagerInternal.MODE_LAUNCH, false);
        }
        if ((prevReasons & POWER_MODE_REASON_CHANGE_DISPLAY) != 0
                && (mPowerModeReasons & POWER_MODE_REASON_CHANGE_DISPLAY) == 0) {
            Trace.instant(Trace.TRACE_TAG_WINDOW_MANAGER, "EndModeDisplayChange");
            mPowerManagerInternal.setPowerMode(PowerManagerInternal.MODE_DISPLAY_CHANGE, false);
        }
    }

@@ -5723,7 +5753,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                case END_POWER_MODE_UNKNOWN_VISIBILITY_MSG: {
                    synchronized (mGlobalLock) {
                        mRetainPowerModeAndTopProcessState = false;
                        endLaunchPowerMode(POWER_MODE_REASON_UNKNOWN_VISIBILITY);
                        endPowerMode(POWER_MODE_REASON_UNKNOWN_VISIBILITY);
                        if (mTopApp != null
                                && mTopProcessState == ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
                            // Restore the scheduling group for sleeping.
+1 −1
Original line number Diff line number Diff line
@@ -2004,7 +2004,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        }

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

        // Rank task layers to make sure the {@link Task#mLayerRank} is updated.
        mRootWindowContainer.rankTaskLayers();
+1 −1
Original line number Diff line number Diff line
@@ -3474,7 +3474,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        final Transition t = controller.requestTransitionIfNeeded(TRANSIT_CHANGE, 0 /* flags */,
                this, this, null /* remoteTransition */, displayChange);
        if (t != null) {
            mAtmService.startLaunchPowerMode(POWER_MODE_REASON_CHANGE_DISPLAY);
            mAtmService.startPowerMode(POWER_MODE_REASON_CHANGE_DISPLAY);
            if (mAsyncRotationController != null) {
                // Give a chance to update the transform if the current rotation is changed when
                // some windows haven't finished previous rotation.
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class PhysicalDisplaySwitchTransitionLauncher {
                displayChange);

        if (t != null) {
            mDisplayContent.mAtmService.startLaunchPowerMode(POWER_MODE_REASON_CHANGE_DISPLAY);
            mDisplayContent.mAtmService.startPowerMode(POWER_MODE_REASON_CHANGE_DISPLAY);
            mTransition = t;
        }

+1 −2
Original line number Diff line number Diff line
@@ -293,8 +293,7 @@ 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.endLaunchPowerMode(
                        ActivityTaskManagerService.POWER_MODE_REASON_START_ACTIVITY);
                mService.endPowerMode(ActivityTaskManagerService.POWER_MODE_REASON_START_ACTIVITY);
            }

            // Once the target is shown, prevent spurious background app switches
Loading