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

Commit dceb5963 authored by Santos Cordon's avatar Santos Cordon
Browse files

Fix possible NPE in DisplayPowerController

Bug: 380423455
Test: atest DisplayPowerControllerTest
Flag: EXEMPT bugfix
Change-Id: Id0f72b9617b6dba0e51cbcea30dd9c43e565cf49
parent 46f5297a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -906,6 +906,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mLogicalDisplay.getPowerThrottlingDataIdLocked();

        mHandler.postAtTime(() -> {
            if (mStopped) {
                // DPC has already stopped, don't execute any more.
                return;
            }

            boolean changed = false;

            if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) {
+20 −0
Original line number Diff line number Diff line
@@ -2468,6 +2468,26 @@ public final class DisplayPowerControllerTest {
                eq(false));
    }

    @Test
    public void onDisplayChange_canceledAfterStop() {
        mHolder = createDisplayPowerController(DISPLAY_ID, UNIQUE_ID);

        // stop the dpc (turn it down)
        mHolder.dpc.stop();
        advanceTime(1);

        // To trigger all the changes that can happen, we will completely change the underlying
        // display device.
        setUpDisplay(DISPLAY_ID, "new_unique_id", mHolder.display, mock(DisplayDevice.class),
                mock(DisplayDeviceConfig.class), /* isEnabled= */ true);

        // Call onDisplayChange after we stopped DPC and make sure it doesn't crash
        mHolder.dpc.onDisplayChanged(mHolder.hbmMetadata, Layout.NO_LEAD_DISPLAY);
        advanceTime(1);

        // No crash = success
    }

    /**
     * Creates a mock and registers it to {@link LocalServices}.
     */