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

Commit d170ec5f authored by Oleg Blinnikov's avatar Oleg Blinnikov
Browse files

Fix NPE in FoldableDeviceStateProvider

Change-Id: Ib0903e41e98fd59ba4aa5a54a26225334bebf63c
Bug: 318307530
Test: atest FoldableDeviceStateProviderTest
parent 85b6e55c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -367,8 +367,11 @@ public final class FoldableDeviceStateProvider implements DeviceStateProvider,
        // TODO(b/312397262): consider virtual displays cases
        synchronized (mLock) {
            if (mIsDualDisplayBlockingEnabled
                    && !mExternalDisplaysConnected.get(displayId, false)
                    && mDisplayManager.getDisplay(displayId).getType() == TYPE_EXTERNAL) {
                    && !mExternalDisplaysConnected.get(displayId, false)) {
                var display = mDisplayManager.getDisplay(displayId);
                if (display == null || display.getType() != TYPE_EXTERNAL) {
                    return;
                }
                mExternalDisplaysConnected.put(displayId, true);

                // Only update the supported state when going from 0 external display to 1
+14 −0
Original line number Diff line number Diff line
@@ -590,6 +590,20 @@ public final class FoldableDeviceStateProviderTest {
        assertThat(mProvider.hasNoConnectedExternalDisplay()).isFalse();
    }

    @Test
    public void testOnDisplayAddedWithNullDisplayDoesNotThrowNPE() {
        createProvider(
                createConfig(
                        /* identifier= */ 1, /* name= */ "ONE",
                        /* flags= */0, (c) -> true,
                        FoldableDeviceStateProvider::hasNoConnectedExternalDisplay)
        );

        when(mDisplayManager.getDisplay(1)).thenReturn(null);
        // This call should not throw NPE.
        mProvider.onDisplayAdded(1);
    }

    @Test
    public void hasNoConnectedDisplay_afterExternalDisplayAddedAndRemoved_returnsTrue() {
        createProvider(