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

Commit 286a29ba authored by Eric Jeong's avatar Eric Jeong
Browse files

Add test cases for multiple power group initialization

- At boot, power groups are created per display group.
- This rule is effective even for multiple display groups.
- This CL adds test cases to test the rule.

Bug: 254542024
Test: atest PowerManagerServiceTest
Change-Id: I3d638f31c8fc59b3af9d709805adc7e163281ed6
parent 27761dab
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -6639,6 +6639,13 @@ public final class PowerManagerService extends SystemService
        }
    }

    @VisibleForTesting
    int getPowerGroupSize() {
        synchronized (mLock) {
            return mPowerGroups.size();
        }
    }

    @GoToSleepReason
    private int getLastSleepReasonInternal() {
        synchronized (mLock) {
+26 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import android.provider.Settings;
import android.service.dreams.DreamManagerInternal;
import android.sysprop.PowerProperties;
import android.test.mock.MockContentResolver;
import android.util.IntArray;
import android.view.Display;
import android.view.DisplayInfo;

@@ -2337,6 +2338,31 @@ public class PowerManagerServiceTest {
        verify(mLowPowerStandbyControllerMock).setActiveDuringMaintenance(false);
    }

    @Test
    public void testPowerGroupInitialization_multipleDisplayGroups() {
        IntArray displayGroupIds = IntArray.wrap(new int[]{1, 2, 3});
        when(mDisplayManagerInternalMock.getDisplayGroupIds()).thenReturn(displayGroupIds);

        createService();
        startSystem();

        // Power group for DEFAULT_DISPLAY_GROUP is added by default.
        assertThat(mService.getPowerGroupSize()).isEqualTo(4);
    }

    @Test
    public void testPowerGroupInitialization_multipleDisplayGroupsWithDefaultGroup() {
        IntArray displayGroupIds = IntArray.wrap(new int[]{Display.DEFAULT_DISPLAY_GROUP, 1, 2, 3});
        when(mDisplayManagerInternalMock.getDisplayGroupIds()).thenReturn(displayGroupIds);

        createService();
        startSystem();

        // Power group for DEFAULT_DISPLAY_GROUP is added once even if getDisplayGroupIds() return
        // an array including DEFAULT_DESIPLAY_GROUP.
        assertThat(mService.getPowerGroupSize()).isEqualTo(4);
    }

    private WakeLock acquireWakeLock(String tag, int flags) {
        IBinder token = new Binder();
        String packageName = "pkg.name";