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

Commit 9c551e6d authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille Committed by Android Build Coastguard Worker
Browse files

Prevent uses of all dual display states with an external display

Some time ago, DEVICE_STATE_REAR_DISPLAY_OUTER_DEFAULT was introduced
with is also a dual display state. First, performance wise, most phones
don't support that many local displays. Second, a lot of code assume
this isn't possible.

Fix: 445146126
Test: atest BookStyleDeviceStatePolicyTest
Test: manual with Google Camera
Flag: EXEMPT BUGFIX
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:a90d0f0e7b029134b602880ccd163440ab634737
Merged-In: Ib520b8e62bcff31ae2352d4b6421969158b46ccc
Change-Id: Ib520b8e62bcff31ae2352d4b6421969158b46ccc
parent fc503984
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -141,7 +141,9 @@ public class BookStyleDeviceStatePolicy extends DeviceStatePolicy implements
                        /* availabilityPredicate= */ provider -> !mIsDualDisplayBlockingEnabled
                                || provider.hasNoConnectedExternalDisplay()),
                createConfig(getRearDisplayOuterDefaultState(),
                        /* activeStatePredicate= */ NOT_ALLOWED)
                        /* activeStatePredicate= */ NOT_ALLOWED,
                        /* availabilityPredicate= */ provider -> !mIsDualDisplayBlockingEnabled
                                || provider.hasNoConnectedExternalDisplay())
        };
    }

+33 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.devicestate.DeviceState;
import android.hardware.display.DisplayManager;
import android.hardware.input.InputSensorInfo;
import android.os.Handler;
@@ -71,6 +72,7 @@ import org.mockito.MockitoAnnotations;
import org.mockito.internal.util.reflection.FieldSetter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -86,6 +88,9 @@ public final class BookStyleDeviceStatePolicyTest {
    private static final int DEVICE_STATE_CLOSED = 0;
    private static final int DEVICE_STATE_HALF_OPENED = 1;
    private static final int DEVICE_STATE_OPENED = 2;
    private static final int EXTERNAL_DISPLAY_ID = 17;
    private static final int DEVICE_STATE_CONCURRENT_INNER_DEFAULT = 4;
    private static final int DEVICE_STATE_REAR_DISPLAY_OUTER_DEFAULT = 5;

    @Captor
    private ArgumentCaptor<Integer> mDeviceStateCaptor;
@@ -760,6 +765,34 @@ public final class BookStyleDeviceStatePolicyTest {
        assertNoListenersForSensor(mOrientationSensor);
    }

    @Test
    public void test_externalDisplay_noDualDisplayModes() {
        List<Integer> lastStatesIdentifiers = new ArrayList<>();
        Listener captureStates = new Listener() {
            @Override
            public void onSupportedDeviceStatesChanged(DeviceState[] newDeviceStates, int reason) {
                lastStatesIdentifiers.clear();
                Arrays.stream(newDeviceStates)
                        .map(DeviceState::getIdentifier)
                        .forEach(lastStatesIdentifiers::add);
            }

            @Override
            public void onStateChanged(int identifier) {
            }
        };
        mProvider.setListener(captureStates);
        Display display = mock(Display.class);
        when(display.getType()).thenReturn(Display.TYPE_EXTERNAL);
        when(mDisplayManager.getDisplay(EXTERNAL_DISPLAY_ID)).thenReturn(display);
        DisplayManager.DisplayListener displayListener = (DisplayManager.DisplayListener) mProvider;

        displayListener.onDisplayAdded(EXTERNAL_DISPLAY_ID);

        assertThat(lastStatesIdentifiers).containsNoneOf(DEVICE_STATE_CONCURRENT_INNER_DEFAULT,
                DEVICE_STATE_REAR_DISPLAY_OUTER_DEFAULT);
    }

    @Test
    public void test_deviceClosed_screenIsOn_doesNotListenForOneAccelerometer() {
        mProvider.setListener(mListener);