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

Commit fa3b77ad authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge "Reapply "Manage redirectToWake state in DreamOverlayService."" into main

parents 129457f0 14116cce
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ public abstract class DreamOverlayService extends Service {
     */
    private Executor mExecutor;

    private Boolean mCurrentRedirectToWake;

    // An {@link IDreamOverlayClient} implementation that identifies itself when forwarding
    // requests to the {@link DreamOverlayService}
    private static class OverlayClient extends IDreamOverlayClient.Stub {
@@ -132,6 +134,10 @@ public abstract class DreamOverlayService extends Service {
        mExecutor.execute(() -> {
            endDreamInternal(mCurrentClient);
            mCurrentClient = client;
            if (Flags.dreamWakeRedirect() && mCurrentRedirectToWake != null) {
                mCurrentClient.redirectWake(mCurrentRedirectToWake);
            }

            onStartDream(params);
        });
    }
@@ -282,8 +288,10 @@ public abstract class DreamOverlayService extends Service {
            return;
        }

        mCurrentRedirectToWake = redirect;

        if (mCurrentClient == null) {
            throw new IllegalStateException("redirected wake with no dream present");
            return;
        }

        mCurrentClient.redirectWake(redirect);
+45 −0
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package com.android.server.dreams;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -27,7 +29,9 @@ import android.content.ComponentName;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.platform.test.annotations.EnableFlags;
import android.service.dreams.DreamOverlayService;
import android.service.dreams.Flags;
import android.service.dreams.IDreamOverlay;
import android.service.dreams.IDreamOverlayCallback;
import android.service.dreams.IDreamOverlayClient;
@@ -221,6 +225,47 @@ public class DreamOverlayServiceTest {
        verify(monitor, never()).onWakeUp();
    }

    /**
     * Verifies that only the currently started dream is able to affect the overlay.
     */
    @Test
    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT)
    public void testRedirectToWakeAcrossClients() throws RemoteException {
        doAnswer(invocation -> {
            ((Runnable) invocation.getArgument(0)).run();
            return null;
        }).when(mExecutor).execute(any());

        final TestDreamOverlayService.Monitor monitor = Mockito.mock(
                TestDreamOverlayService.Monitor.class);
        final TestDreamOverlayService service = new TestDreamOverlayService(monitor, mExecutor);
        final IBinder binder = service.onBind(new Intent());
        final IDreamOverlay overlay = IDreamOverlay.Stub.asInterface(binder);

        service.redirectWake(true);

        final IDreamOverlayClient client = getClient(overlay);

        // Start the dream.
        client.startDream(mLayoutParams, mOverlayCallback,
                FIRST_DREAM_COMPONENT.flattenToString(), false);
        // Make sure redirect state is set on dream.
        verify(mOverlayCallback).onRedirectWake(eq(true));

        // Make sure new changes are propagated.
        clearInvocations(mOverlayCallback);
        service.redirectWake(false);
        verify(mOverlayCallback).onRedirectWake(eq(false));


        // Start another dream, make sure new dream is informed of current state.
        service.redirectWake(true);
        clearInvocations(mOverlayCallback);
        client.startDream(mLayoutParams, mOverlayCallback,
                FIRST_DREAM_COMPONENT.flattenToString(), false);
        verify(mOverlayCallback).onRedirectWake(eq(true));
    }

    private static IDreamOverlayClient getClient(IDreamOverlay overlay) throws RemoteException {
        final OverlayClientCallback callback = new OverlayClientCallback();
        overlay.getClient(callback);