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

Commit 0bdc6903 authored by William Xiao's avatar William Xiao Committed by Android (Google) Code Review
Browse files

Merge "Add null check to DreamService.comeToFront" into main

parents 87336a98 83eedb46
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.
     */