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

Commit a8365cda 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:...

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

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

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

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


                final int groupId = wakeLock.getDisplayGroupId();
                if (groupId != Display.INVALID_DISPLAY_GROUP) {
                if (groupId != Display.INVALID_DISPLAY_GROUP) {
                    int wakeLockSummary = mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(
                    int wakeLockSummary = mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(
                            groupId);
                            groupId);
@@ -4876,13 +4880,19 @@ public final class PowerManagerService extends SystemService
            mWorkSource = copyWorkSource(workSource);
            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) {
            if (!mSystemReady || mDisplayId == Display.INVALID_DISPLAY) {
                return Display.INVALID_DISPLAY_GROUP;
                return Display.INVALID_DISPLAY_GROUP;
            }
            }


            final int[] ids = mDisplayGroupPowerStateMapper.getDisplayGroupIdsLocked();
            final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId);
            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
        @Override
+41 −0
Original line number Original line Diff line number Diff line
@@ -922,6 +922,47 @@ public class PowerManagerServiceTest {
                WAKEFULNESS_AWAKE);
                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
    @Test
    public void testBoot_ShouldBeAwake() throws Exception {
    public void testBoot_ShouldBeAwake() throws Exception {
        createService();
        createService();