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

Commit af4120d0 authored by Jimmy Shiu's avatar Jimmy Shiu Committed by Android (Google) Code Review
Browse files

Merge changes from topic "main_add_DISPLAY_CHANGE_mode" into main

* changes:
  Use separated power mode for display change
  Add a new power mode
parents a1bfd75d 942d112c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -314,6 +314,13 @@ public abstract class PowerManagerInternal {
     */
    public static final int MODE_DISPLAY_INACTIVE = 9;

    /**
     * Mode: It indicates that display is changing layout due to rotation or fold
     * unfold behavior.
     * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
     */
    public static final int MODE_DISPLAY_CHANGE = 17;

    /**
     * SetPowerMode() is called to enable/disable specific hint mode, which
     * may result in adjustment of power/performance parameters of the
+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;
@@ -711,11 +710,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({
@@ -4657,11 +4660,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);
@@ -4671,27 +4672,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);
        }
    }

@@ -5751,7 +5781,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
@@ -2009,7 +2009,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
@@ -3484,7 +3484,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;
        }

Loading