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

Commit 15a39748 authored by Antony Sargent's avatar Antony Sargent Committed by Automerger Merge Worker
Browse files

Merge "Lock default display when it sleeps independent of global wakefulness"...

Merge "Lock default display when it sleeps independent of global wakefulness" into tm-dev am: 68eab3f1

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



Change-Id: I8f92b68b7df8db04194f2d16c60e6e25358d31f3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 63a299ec 68eab3f1
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -4524,6 +4524,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mCameraGestureTriggered = false;
    }

    // Called on the PowerManager's Notifier thread.
    @Override
    public void onPowerGroupWakefulnessChanged(int groupId, int wakefulness,
            @PowerManager.GoToSleepReason int pmSleepReason, int globalWakefulness) {
        if (wakefulness != globalWakefulness
                && wakefulness != PowerManagerInternal.WAKEFULNESS_AWAKE
                && groupId == Display.DEFAULT_DISPLAY_GROUP
                && mKeyguardDelegate != null) {
            mKeyguardDelegate.doKeyguardTimeout(null);
        }
    }

    // Called on the PowerManager's Notifier thread.
    @Override
    public void startedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
+14 −0
Original line number Diff line number Diff line
@@ -772,6 +772,20 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
     */
    public void finishedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason);

    /**
     * Called when a particular PowerGroup has changed wakefulness.
     *
     * @param groupId The id of the PowerGroup.
     * @param wakefulness One of PowerManagerInternal.WAKEFULNESS_* indicating the wake state for
     * the group
     * @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the reason this
     * group is going to sleep.
     * @param globalWakefulness The global wakefulness, which may or may not match that of this
     * group. One of PowerManagerInternal.WAKEFULNESS_*
     */
    void onPowerGroupWakefulnessChanged(int groupId, int wakefulness,
            @PowerManager.GoToSleepReason int pmSleepReason, int globalWakefulness);

    /**
     * Called when the display is about to turn on to show content.
     * When waking up, this method will be called once after the call to wakingUp().
+9 −0
Original line number Diff line number Diff line
@@ -552,6 +552,15 @@ public class Notifier {
        }
    }

    /**
     * Called when an individual PowerGroup changes wakefulness.
     */
    public void onPowerGroupWakefulnessChanged(int groupId, int groupWakefulness, int changeReason,
            int globalWakefulness) {
        mHandler.post(() -> mPolicy.onPowerGroupWakefulnessChanged(groupId, groupWakefulness,
                changeReason, globalWakefulness));
    }

    /**
     * Called when there has been user activity.
     */
+2 −0
Original line number Diff line number Diff line
@@ -674,6 +674,8 @@ public final class PowerManagerService extends SystemService
            }
            mDirty |= DIRTY_DISPLAY_GROUP_WAKEFULNESS;
            updateGlobalWakefulnessLocked(eventTime, reason, uid, opUid, opPackageName, details);
            mNotifier.onPowerGroupWakefulnessChanged(groupId, wakefulness, reason,
                    getGlobalWakefulnessLocked());
            updatePowerStateLocked();
        }
    }
+93 −0
Original line number Diff line number Diff line
@@ -1696,6 +1696,99 @@ public class PowerManagerServiceTest {
        assertThat(mService.getLocalServiceInstance().getLastWakeup()).isEqualTo(initialWakeData);
    }

    @Test
    public void testMultiDisplay_onlyOneDisplaySleeps_onWakefulnessChangedEventFires() {
        createService();
        startSystem();
        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
        forceSleep();
        assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
                WAKEFULNESS_ASLEEP);

        verify(mNotifierMock).onPowerGroupWakefulnessChanged(eq(Display.DEFAULT_DISPLAY_GROUP),
                eq(WAKEFULNESS_ASLEEP), anyInt(), eq(WAKEFULNESS_ASLEEP));
    }

    @Test
    public void testMultiDisplay_bothDisplaysSleep_onWakefulnessChangedEventFiresCorrectly() {
        final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
        final int nonDefaultDisplay = Display.DEFAULT_DISPLAY + 1;
        final AtomicReference<DisplayManagerInternal.DisplayGroupListener> listener =
                new AtomicReference<>();
        doAnswer((Answer<Void>) invocation -> {
            listener.set(invocation.getArgument(0));
            return null;
        }).when(mDisplayManagerInternalMock).registerDisplayGroupListener(any());
        final DisplayInfo info = new DisplayInfo();
        info.displayGroupId = nonDefaultDisplayGroupId;
        when(mDisplayManagerInternalMock.getDisplayInfo(nonDefaultDisplay)).thenReturn(info);

        createService();
        startSystem();

        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
        listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId);

        mService.setWakefulnessLocked(nonDefaultDisplayGroupId, WAKEFULNESS_ASLEEP, 0, 0, 0, 0,
                null, null);
        mService.setWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP, WAKEFULNESS_ASLEEP, 0, 0, 0, 0,
                null, null);

        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
        assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
                WAKEFULNESS_ASLEEP);
        assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
                WAKEFULNESS_ASLEEP);

        verify(mNotifierMock).onPowerGroupWakefulnessChanged(eq(nonDefaultDisplayGroupId),
                eq(WAKEFULNESS_ASLEEP), anyInt(), eq(WAKEFULNESS_AWAKE));
        verify(mNotifierMock).onPowerGroupWakefulnessChanged(eq(Display.DEFAULT_DISPLAY_GROUP),
                eq(WAKEFULNESS_ASLEEP), anyInt(), eq(WAKEFULNESS_ASLEEP));
    }

    @Test
    public void testMultiDisplay_separateWakeStates_onWakefulnessChangedEventFiresCorrectly() {
        final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
        final int nonDefaultDisplay = Display.DEFAULT_DISPLAY + 1;
        final AtomicReference<DisplayManagerInternal.DisplayGroupListener> listener =
                new AtomicReference<>();
        doAnswer((Answer<Void>) invocation -> {
            listener.set(invocation.getArgument(0));
            return null;
        }).when(mDisplayManagerInternalMock).registerDisplayGroupListener(any());
        final DisplayInfo info = new DisplayInfo();
        info.displayGroupId = nonDefaultDisplayGroupId;
        when(mDisplayManagerInternalMock.getDisplayInfo(nonDefaultDisplay)).thenReturn(info);

        createService();
        startSystem();

        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
        listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId);

        final String pkg = mContextSpy.getOpPackageName();
        final Binder token = new Binder();
        final String tag =
                "testMultiDisplay_separateWakeStates_onWakefulnessChangedEventFiresCorrectly";
        mService.getBinderServiceInstance().acquireWakeLock(token,
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
                null /* workSource */, null /* historyTag */, nonDefaultDisplay, null);

        forceSleep();

        // The wakelock should have kept the second display awake, and we should notify that the
        // default display went to sleep.
        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
        assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
                WAKEFULNESS_ASLEEP);
        assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
                WAKEFULNESS_AWAKE);
        verify(mNotifierMock).onPowerGroupWakefulnessChanged(eq(Display.DEFAULT_DISPLAY_GROUP),
                eq(WAKEFULNESS_ASLEEP), anyInt(), eq(WAKEFULNESS_AWAKE));
        verify(mNotifierMock, never()).onPowerGroupWakefulnessChanged(
                eq(nonDefaultDisplayGroupId), anyInt(), anyInt(), anyInt());
    }

    @Test
    public void testGetFullPowerSavePolicy_returnsStateMachineResult() {
        createService();
Loading