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

Commit d31d7a4e authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Do not wake device when going from emulated -> non-emulated state

Fixes: 362914724
Test: atest LogicalDisplayMapperTest
Test: Modify sample to show on lockscreen, enter concurrent mode,
      press power button. Repeat 10+ times, device no longer
      re-wakes itself
Flag: EXEMPT bugfix

Change-Id: If6158a8064d709b386f0bfe82d586bc3f4ac8f1f
parent de6e85d0
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.display;

import static android.hardware.devicestate.DeviceState.PROPERTY_EMULATED_ONLY;
import static android.hardware.devicestate.DeviceState.PROPERTY_POWER_CONFIGURATION_TRIGGER_SLEEP;
import static android.hardware.devicestate.DeviceState.PROPERTY_POWER_CONFIGURATION_TRIGGER_WAKE;
import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE;
@@ -576,6 +577,13 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
    boolean shouldDeviceBeWoken(DeviceState pendingState, DeviceState currentState,
            boolean isInteractive, boolean isBootCompleted) {
        if (mDeviceStateManagerFlags.deviceStatePropertyMigration()) {
            if (currentState.hasProperties(PROPERTY_EMULATED_ONLY)
                    && !pendingState.hasProperties(PROPERTY_EMULATED_ONLY)) {
                // Do not wake the device, since this transition may occur due to the user pressing
                // the power button to exit an emulated state.
                return false;
            }

            return pendingState.hasProperty(PROPERTY_POWER_CONFIGURATION_TRIGGER_WAKE)
                    && !currentState.equals(INVALID_DEVICE_STATE)
                    && !currentState.hasProperty(PROPERTY_POWER_CONFIGURATION_TRIGGER_WAKE)
+10 −0
Original line number Diff line number Diff line
@@ -121,6 +121,8 @@ public class LogicalDisplayMapperTest {
            Set.of(DeviceState.PROPERTY_POWER_CONFIGURATION_TRIGGER_WAKE), Collections.emptySet());
    private static final DeviceState DEVICE_STATE_OPEN = createDeviceState(2, "Two",
            Set.of(DeviceState.PROPERTY_POWER_CONFIGURATION_TRIGGER_WAKE), Collections.emptySet());
    private static final DeviceState DEVICE_STATE_EMULATED = createDeviceState(3, "Three",
            Set.of(DeviceState.PROPERTY_EMULATED_ONLY), Collections.emptySet());
    private static final int FLAG_GO_TO_SLEEP_ON_FOLD = 0;
    private static final int FLAG_GO_TO_SLEEP_FLAG_SOFT_SLEEP = 2;
    private static int sNextNonDefaultDisplayId = DEFAULT_DISPLAY + 1;
@@ -685,6 +687,14 @@ public class LogicalDisplayMapperTest {
                /* isBootCompleted= */true));
    }

    @Test
    public void testDeviceShouldNotBeWokenWhenExitingEmulatedState() {
        assertFalse(mLogicalDisplayMapper.shouldDeviceBeWoken(DEVICE_STATE_OPEN,
                DEVICE_STATE_EMULATED,
                /* isInteractive= */false,
                /* isBootCompleted= */true));
    }

    @Test
    public void testDeviceShouldBePutToSleep() {
        assertTrue(mLogicalDisplayMapper.shouldDeviceBePutToSleep(DEVICE_STATE_CLOSED,