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

Commit 83eedb46 authored by William Xiao's avatar William Xiao
Browse files

Add null check to DreamService.comeToFront

Dreams like doze may not have an overlay connection, which causes a
crash when invoked. This can also prevent crashes if called during
dream exit.

Bug: 359622028
Fix: 359622028
Test: atest DreamServiceTest
Flag: EXEMPT bugfix
Change-Id: I5ef49777c872a944d9247eef4eaf29acdfc035bf
parent c54f721a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1363,6 +1363,9 @@ public class DreamService extends Service implements Window.Callback {
     * Tells the dream to come to the front (which in turn tells the overlay to come to the front).
     */
    private void comeToFront() {
        if (mOverlayConnection == null) {
            return;
        }
        mOverlayConnection.addConsumer(overlay -> {
            try {
                overlay.comeToFront();
+36 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -215,4 +216,39 @@ public class DreamServiceTest {
        // Ensure service does not crash from only receiving up event.
        environment.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE));
    }

    @Test
    @EnableFlags(Flags.FLAG_DREAM_HANDLES_BEING_OBSCURED)
    public void testComeToFront() throws Exception {
        TestDreamEnvironment environment = new TestDreamEnvironment.Builder(mTestableLooper)
                .setDreamOverlayPresent(true)
                .build();
        environment.advance(TestDreamEnvironment.DREAM_STATE_STARTED);

        // Call comeToFront through binder.
        environment.resetClientInvocations();
        environment.comeToFront();
        mTestableLooper.processAllMessages();

        // Overlay client receives call.
        verify(environment.getDreamOverlayClient()).comeToFront();
    }

    @Test
    @EnableFlags(Flags.FLAG_DREAM_HANDLES_BEING_OBSCURED)
    public void testComeToFront_noOverlay() throws Exception {
        // Dream environment with no overlay present
        TestDreamEnvironment environment = new TestDreamEnvironment.Builder(mTestableLooper)
                .setDreamOverlayPresent(false)
                .build();
        environment.advance(TestDreamEnvironment.DREAM_STATE_STARTED);

        // Call comeToFront through binder.
        environment.resetClientInvocations();
        environment.comeToFront();
        mTestableLooper.processAllMessages();

        // Overlay client receives call.
        verify(environment.getDreamOverlayClient(), never()).comeToFront();
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -398,10 +398,14 @@ public class TestDreamEnvironment {
        mService.dispatchKeyEvent(event);
    }

    private void wakeDream() throws RemoteException {
    private void wakeDream() {
        mService.wakeUp();
    }

    void comeToFront() throws RemoteException {
        mDreamServiceWrapper.comeToFront();
    }

    /**
     * Retrieves the dream overlay callback.
     */