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

Commit 28a2bf80 authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Separately timing out different power groups

An issue was observed that even though the power groups timeout was
configured differntly, they would lock/unlock together. This was
primarily because PhoneWindowManager invoked KeyguardDelegate only when
the default display was sleeping/waking up. This condition has now been
updated to instead check on the global interactivity.

We also noticed issues that the system would block the migration of the
display from sleeping to dozing state, this has now been relaxed for the
cases where there are more than one power groups and all of them are
sleeping

The system will now sleep the default display when it times out if there
is another active power group. This will then transition to doze when
all the non-default power groups migrate to sleep

This CL was originally reverted because of b/419803718. This is because
once the display transitions from Dream to Off, we wouldnt notify the
DozeService to activate the TriggerSensor, which impacted the tap to
wakeup gesture in certain cases.

Bug: 414444200
Test: Manual
Test: atest com.android.server.power
Flag: com.android.server.display.feature.flags.separate_timeouts
Change-Id: Ic6b1f4c60e12bd510e3629aee7d5edb7d67af10e
parent 6dbefde9
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -208,12 +208,22 @@ public abstract class PowerManagerInternal {

    public abstract void uidIdle(int uid);

    /**
     * Checks if the wakefulness of the supplied group is interactive.
     */
    public abstract boolean isGroupInteractive(int groupId);

    /** Returns if any of the default adjacent group is interactive. */
    public abstract boolean isAnyDefaultAdjacentGroupInteractive();

    /** Returns if the supplied group is adjacent to the default group. */
    public abstract boolean isDefaultGroupAdjacent(int groupId);

    /**
     * Used to notify the power manager that wakelocks should be disabled.
     *
     * @param force {@code true} to activate force disable wakelocks, {@code false} to turn it off.
     */

    public abstract void setForceDisableWakelocks(boolean force);

    /**
+4 −5
Original line number Diff line number Diff line
@@ -1100,14 +1100,12 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
            decidedGroupId = calculateGroupId(requiredGroupType, mDisplayGroups);
            groupName = requiredGroupType;
        }

        // Get the new display group if a change is needed, if display group name is empty and
        // {@code DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP} is not set, and required group type
        // has not been decided, the display is assigned to the default display group.
        final boolean needsOwnDisplayGroup =
                (displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP) != 0
                        || !TextUtils.isEmpty(groupName);

        final boolean hasOwnDisplayGroup = groupId != Display.DEFAULT_DISPLAY_GROUP;
        final boolean needsDeviceDisplayGroup =
                !needsOwnDisplayGroup && linkedDeviceUniqueId != null;
@@ -1118,7 +1116,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                || hasDeviceDisplayGroup != needsDeviceDisplayGroup
                || decidedGroupId != Display.INVALID_DISPLAY_GROUP) {
            groupId =
                    assignDisplayGroupIdLocked(needsOwnDisplayGroup,
                    assignDisplayGroupIdLocked(needsDeviceDisplayGroup, needsOwnDisplayGroup,
                            display.getLayoutGroupNameLocked(), needsDeviceDisplayGroup,
                            linkedDeviceUniqueId, decidedGroupId);
        }
@@ -1351,9 +1349,10 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        }
    }

    private int assignDisplayGroupIdLocked(boolean isOwnDisplayGroup, String displayGroupName,
    private int assignDisplayGroupIdLocked(boolean needsDeviceDisplayGroup,
            boolean isOwnDisplayGroup, String displayGroupName,
            boolean isDeviceDisplayGroup, Integer linkedDeviceUniqueId, int decidedGroupId) {
        if (decidedGroupId != Display.INVALID_DISPLAY_GROUP) {
        if (decidedGroupId != Display.INVALID_DISPLAY_GROUP && !needsDeviceDisplayGroup) {
            return decidedGroupId;
        }
        if (isDeviceDisplayGroup && linkedDeviceUniqueId != null) {
+54 −10
Original line number Diff line number Diff line
@@ -1327,11 +1327,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        }

        sleepDefaultDisplay(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, flags);
        goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, flags);
        return true;
    }

    private void sleepDefaultDisplay(long eventTime, int reason, int flags) {
    private void goToSleep(long eventTime, int reason, int flags) {
        mRequestedOrSleepingDefaultDisplay = true;
        mPowerManager.goToSleep(eventTime, reason, flags);
    }
@@ -1369,7 +1369,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            Settings.Global.THEATER_MODE_ON, 1);

                    if (mGoToSleepOnButtonPressTheaterMode && interactive) {
                        sleepDefaultDisplay(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
                        goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
                                0);
                    }
                }
@@ -1542,7 +1542,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
            case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
                Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
                sleepDefaultDisplay(eventTime, PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
                goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
                break;
        }
    }
@@ -4623,7 +4623,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            }
                            if ((mEndcallBehavior
                                    & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
                                sleepDefaultDisplay(event.getEventTime(),
                                goToSleep(event.getEventTime(),
                                        PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
                                isWakeKey = false;
                            }
@@ -5274,6 +5274,45 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mDeviceGoingToSleep = false;
    }

    // Both the default and default adjacent groups should be non interactive
    private boolean isReadyToSignalSleep(int displayGroupId) {
        if (!com.android.server.display.feature.flags.Flags.separateTimeouts()) {
            return displayGroupId == Display.DEFAULT_DISPLAY_GROUP;
        }

        // We only care about default and default-adjacent groups
        if (displayGroupId != Display.DEFAULT_DISPLAY_GROUP
                && !mPowerManagerInternal.isDefaultGroupAdjacent(displayGroupId)) {
            return false;
        }

        boolean areAllDefaultAdjacentGroupsNonInteractive =
                !mPowerManagerInternal.isAnyDefaultAdjacentGroupInteractive();
        boolean isDefaultGroupNonInteractive =
                !mPowerManagerInternal.isGroupInteractive(DEFAULT_DISPLAY);
        return areAllDefaultAdjacentGroupsNonInteractive && isDefaultGroupNonInteractive;
    }

    // Either of the default or default adjacent groups should be interactive
    private boolean isReadyToSignalWakeup(int displayGroupId) {
        if (!com.android.server.display.feature.flags.Flags.separateTimeouts()) {
            return displayGroupId == Display.DEFAULT_DISPLAY_GROUP;
        }

        // We only care about default and default-adjacent groups
        if (displayGroupId != Display.DEFAULT_DISPLAY_GROUP
                && !mPowerManagerInternal.isDefaultGroupAdjacent(displayGroupId)) {
            return false;
        }

        boolean isAnyDefaultAdjacentGroupInteractive =
                mPowerManagerInternal.isAnyDefaultAdjacentGroupInteractive();
        boolean isDefaultGroupInteractive = mPowerManagerInternal
                .isGroupInteractive(DEFAULT_DISPLAY);

        return isAnyDefaultAdjacentGroupInteractive || isDefaultGroupInteractive;
    }

    // Called on the PowerManager's Notifier thread.
    @Override
    public void startedGoingToSleep(int displayGroupId,
@@ -5284,7 +5323,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            WindowManagerPolicyConstants.translateSleepReasonToOffReason(
                                    pmSleepReason)) + ")");
        }
        if (displayGroupId != Display.DEFAULT_DISPLAY_GROUP) {

        if (!isReadyToSignalSleep(displayGroupId)) {
            return;
        }

@@ -5300,9 +5340,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    @Override
    public void finishedGoingToSleep(int displayGroupId,
            @PowerManager.GoToSleepReason int pmSleepReason) {
        if (displayGroupId != Display.DEFAULT_DISPLAY_GROUP) {
        if (!isReadyToSignalSleep(displayGroupId)) {
            return;
        }

        EventLogTags.writeScreenToggled(0);
        if (DEBUG_WAKEUP) {
            Slog.i(TAG, "Finished going to sleep... (groupId=" + displayGroupId + " why="
@@ -5344,9 +5385,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    WindowManagerPolicyConstants.translateWakeReasonToOnReason(
                            pmWakeReason)) + ")");
        }
        if (displayGroupId != Display.DEFAULT_DISPLAY_GROUP) {

        if (!isReadyToSignalWakeup(displayGroupId)) {
            return;
        }

        EventLogTags.writeScreenToggled(1);

        mIsGoingToSleepDefaultDisplay = false;
@@ -5378,7 +5421,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            WindowManagerPolicyConstants.translateWakeReasonToOnReason(
                                    pmWakeReason)) + ")");
        }
        if (displayGroupId != Display.DEFAULT_DISPLAY_GROUP) {

        if (!isReadyToSignalWakeup(displayGroupId)) {
            return;
        }

@@ -6043,7 +6087,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    mWindowManagerFuncs.lockDeviceNow();
                    break;
                case LID_BEHAVIOR_SLEEP:
                    sleepDefaultDisplay(SystemClock.uptimeMillis(),
                    goToSleep(SystemClock.uptimeMillis(),
                            PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
                            PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
                    break;
+58 −3
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ public class PowerGroup {
    private final long mDimDuration;
    private final long mScreenOffTimeout;

    private boolean mDreamManagerAttemptedDozing;

    PowerGroup(int groupId, PowerGroupListener wakefulnessListener, Notifier notifier,
            DisplayManagerInternal displayManagerInternal, int wakefulness, boolean ready,
            boolean supportsSandman, long eventTime, PowerManagerFlags featureFlags,
@@ -211,6 +213,12 @@ public class PowerGroup {
                    mLastSleepReason = reason;
                }
            }

            // Since the group is transitioning to interactive wakefulness, we should reset the
            // previous attempt of doze made by DreamManager
            if (isInteractive(newWakefulness)) {
                setDreamManagerAttemptedDozingLocked(/* dreamManagerAttemptedDozing */ false);
            }
            mWakefulness = newWakefulness;
            mWakefulnessListener.onWakefulnessChangedLocked(mGroupId, mWakefulness, eventTime,
                    reason, uid, opUid, opPackageName, details);
@@ -219,6 +227,33 @@ public class PowerGroup {
        return false;
    }

    /**
     * Sets the dreamManagerAttemptedDozing status, indicating if the DreamManager attempted to
     * put the group to doze. This being true doesn't necessarily mean that the group is dozing
     * as it can fail in that attempt
     */
    public void setDreamManagerAttemptedDozingLocked(boolean dreamManagerAttemptedDozing) {
        Slog.i(TAG, "dreamManagerAttemptedDozing status changed to "
                + dreamManagerAttemptedDozing + " for group " + mGroupId);
        mDreamManagerAttemptedDozing = dreamManagerAttemptedDozing;
    }

    public boolean isDefaultOrAdjacentGroup() {
        return isDefaultGroupAdjacent() || getGroupId() == Display.DEFAULT_DISPLAY_GROUP;
    }

    /**
     * A group can transition from sleep to doze
     * 1. It is a default display
     * 2. com.android.server.display.feature.flags.Flags.separateTimeouts() is enabled
     * 3. Is non interactive
     */
    public boolean canTransitionBetweenNonInteractiveStates() {
        return (com.android.server.display.feature.flags.Flags.separateTimeouts())
                && (getGroupId() == Display.DEFAULT_DISPLAY_GROUP)
                && !isInteractive(getWakefulnessLocked());
    }

    /**
     * Returns {@code true} if every display in this group has its requested state matching
     * its actual state.
@@ -258,8 +293,7 @@ public class PowerGroup {
        return mPoweringOn;
    }

    @VisibleForTesting
    boolean isDefaultGroupAdjacent() {
    public boolean isDefaultGroupAdjacent() {
        return mIsDefaultGroupAdjacent;
    }

@@ -324,9 +358,27 @@ public class PowerGroup {
    }

    boolean dozeLocked(long eventTime, int uid, @PowerManager.GoToSleepReason int reason) {
        if (eventTime < getLastWakeTimeLocked() || !isInteractive(mWakefulness)) {
        return dozeLocked(eventTime, uid, reason, false);
    }

    boolean dozeLocked(long eventTime, int uid, @PowerManager.GoToSleepReason int reason,
            boolean allowSleepToDozeTransition) {
        if (!com.android.server.display.feature.flags.Flags.separateTimeouts()) {
            allowSleepToDozeTransition = false;
        }

        if (eventTime < getLastWakeTimeLocked() || mWakefulness == WAKEFULNESS_DOZING) {
            return false;
        }
        if (mWakefulness == WAKEFULNESS_ASLEEP) {
            if (!allowSleepToDozeTransition) {
                return false;
            }

            if (mDreamManagerAttemptedDozing) {
                return false;
            }
        }

        Trace.traceBegin(Trace.TRACE_TAG_POWER, "powerOffDisplay");
        try {
@@ -586,6 +638,9 @@ public class PowerGroup {
                + "\nmDimDuration=" + mDimDuration
                + "\nmWakefulness=" + mWakefulness
                + "\nmIsDefaultGroupAdjacent=" + mIsDefaultGroupAdjacent
                + "\nmSupportsSandman=" + mSupportsSandman
                + "\nmDreamManagerAttemptedDozing="
                + mDreamManagerAttemptedDozing
                + "\nmScreenOffTimeout=" + mScreenOffTimeout;
    }

+134 −20

File changed.

Preview size limit exceeded, changes collapsed.

Loading