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

Commit 319c0b83 authored by William Leshner's avatar William Leshner Committed by Automerger Merge Worker
Browse files

Merge "Keep dreaming when undocked when configured to." into tm-qpr-dev am: 01f14d68

parents 3c15a2eb 01f14d68
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -467,6 +467,9 @@ public final class PowerManagerService extends SystemService
    // True if the device should wake up when plugged or unplugged.
    private boolean mWakeUpWhenPluggedOrUnpluggedConfig;

    // True if the device should keep dreaming when undocked.
    private boolean mKeepDreamingWhenUndockingConfig;

    // True if the device should wake up when plugged or unplugged in theater mode.
    private boolean mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig;

@@ -1374,6 +1377,8 @@ public final class PowerManagerService extends SystemService
                com.android.internal.R.bool.config_powerDecoupleInteractiveModeFromDisplay);
        mWakeUpWhenPluggedOrUnpluggedConfig = resources.getBoolean(
                com.android.internal.R.bool.config_unplugTurnsOnScreen);
        mKeepDreamingWhenUndockingConfig = resources.getBoolean(
                com.android.internal.R.bool.config_keepDreamingWhenUndocking);
        mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig = resources.getBoolean(
                com.android.internal.R.bool.config_allowTheaterModeWakeFromUnplug);
        mSuspendWhenScreenOffDueToProximityConfig = resources.getBoolean(
@@ -2487,6 +2492,14 @@ public final class PowerManagerService extends SystemService
            return false;
        }

        // Don't wake when undocking while dreaming if configured not to.
        if (mKeepDreamingWhenUndockingConfig
                && getGlobalWakefulnessLocked() == WAKEFULNESS_DREAMING
                && wasPowered && !mIsPowered
                && oldPlugType == BatteryManager.BATTERY_PLUGGED_DOCK) {
            return false;
        }

        // Don't wake when undocked from wireless charger.
        // See WirelessChargerDetector for justification.
        if (wasPowered && !mIsPowered
@@ -4408,6 +4421,8 @@ public final class PowerManagerService extends SystemService
                    + mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig);
            pw.println("  mTheaterModeEnabled="
                    + mTheaterModeEnabled);
            pw.println("  mKeepDreamingWhenUndockingConfig="
                    + mKeepDreamingWhenUndockingConfig);
            pw.println("  mSuspendWhenScreenOffDueToProximityConfig="
                    + mSuspendWhenScreenOffDueToProximityConfig);
            pw.println("  mDreamsSupportedConfig=" + mDreamsSupportedConfig);
+25 −0
Original line number Diff line number Diff line
@@ -612,6 +612,31 @@ public class PowerManagerServiceTest {
        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
    }

    /**
     * Tests that dreaming continues when undocking and configured to do so.
     */
    @Test
    public void testWakefulnessDream_shouldKeepDreamingWhenUndocked() {
        createService();
        startSystem();

        when(mResourcesSpy.getBoolean(
                com.android.internal.R.bool.config_keepDreamingWhenUndocking))
                .thenReturn(true);
        mService.readConfigurationLocked();

        when(mBatteryManagerInternalMock.getPlugType())
                .thenReturn(BatteryManager.BATTERY_PLUGGED_DOCK);
        setPluggedIn(true);

        forceAwake();  // Needs to be awake first before it can dream.
        forceDream();
        when(mBatteryManagerInternalMock.getPlugType()).thenReturn(0);
        setPluggedIn(false);

        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DREAMING);
    }

    @Test
    public void testWakefulnessDoze_goToSleep() {
        createService();