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

Commit f4b9de1d authored by Sean Stout's avatar Sean Stout Committed by Automerger Merge Worker
Browse files

Merge "Ensure Wakelock display group is still valid." into sc-dev am: b7cc3ac4

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

Change-Id: I511ff11c101bb95f7511799b0d80fab92cd363de
parents 0b3f413e b7cc3ac4
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -2329,10 +2329,14 @@ public final class PowerManagerService extends SystemService
            final int numWakeLocks = mWakeLocks.size();
            for (int i = 0; i < numWakeLocks; i++) {
                final WakeLock wakeLock = mWakeLocks.get(i);
                final Integer groupId = wakeLock.getDisplayGroupId();
                if (groupId == null) {
                    continue;
                }

                final int wakeLockFlags = getWakeLockSummaryFlags(wakeLock);
                mWakeLockSummary |= wakeLockFlags;

                final int groupId = wakeLock.getDisplayGroupId();
                if (groupId != Display.INVALID_DISPLAY_GROUP) {
                    int wakeLockSummary = mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(
                            groupId);
@@ -4876,13 +4880,19 @@ public final class PowerManagerService extends SystemService
            mWorkSource = copyWorkSource(workSource);
        }

        public int getDisplayGroupId() {
        /** Returns the DisplayGroup Id of this wakeLock or {@code null} if no longer valid. */
        public Integer getDisplayGroupId() {
            if (!mSystemReady || mDisplayId == Display.INVALID_DISPLAY) {
                return Display.INVALID_DISPLAY_GROUP;
            }

            final int[] ids = mDisplayGroupPowerStateMapper.getDisplayGroupIdsLocked();
            final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId);
            return displayInfo == null ? Display.INVALID_DISPLAY_GROUP : displayInfo.displayGroupId;
            if (displayInfo != null && ArrayUtils.contains(ids, displayInfo.displayGroupId)) {
                return displayInfo.displayGroupId;
            }

            return null;
        }

        @Override
+41 −0
Original line number Diff line number Diff line
@@ -922,6 +922,47 @@ public class PowerManagerServiceTest {
                WAKEFULNESS_AWAKE);
    }

    @Test
    public void testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups() throws Exception {
        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);

        final String pkg = mContextSpy.getOpPackageName();
        final Binder token = new Binder();
        final String tag = "testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups";

        setMinimumScreenOffTimeoutConfig(5);
        createService();
        startSystem();
        listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId);

        mService.getBinderServiceInstance().acquireWakeLock(token,
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
                null /* workSource */, null /* historyTag */, nonDefaultDisplay);

        assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
                WAKEFULNESS_AWAKE);
        assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
                WAKEFULNESS_AWAKE);
        assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);

        listener.get().onDisplayGroupRemoved(nonDefaultDisplayGroupId);

        advanceTime(15000);
        assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
                WAKEFULNESS_DOZING);
        assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_DOZING);
    }

    @Test
    public void testBoot_ShouldBeAwake() throws Exception {
        createService();