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

Commit 8a19c01a authored by Oleg Blinnikov's avatar Oleg Blinnikov Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE in FoldableDeviceStateProvider" into main

parents 520233ad d170ec5f
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(