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

Commit 0b440afc authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix possible NPE in DisplayPowerController" into main

parents 52988051 dceb5963
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
@@ -2471,6 +2471,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}.
     */