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

Commit 5cc04a86 authored by Bryce Lee's avatar Bryce Lee
Browse files

Dream Wake Redirection Introduction.

This changelist provides the ability to redirect wakeup calls from the
dream to the overlay. This is useful in the case where alternative
behavior is desired at wakeup.

Test: atest DreamServiceTest#testRedirect
Flag: aconfig android.service.dreams.Flags.dream_exit_redirect disabled
Bug: 334083490
Change-Id: I7d44b2ca3131f35a9e4c140ca019d233093b484e
parent 62ad2da3
Loading
Loading
Loading
Loading
+46 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.dreams;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
@@ -84,7 +85,14 @@ public abstract class DreamOverlayService extends Service {
            mService.comeToFront(this);
        }

        private void onExitRequested() {
        @Override
        public void onWakeRequested() {
            if (Flags.dreamWakeRedirect()) {
                mService.onWakeRequested();
            }
        }

        private void requestExit() {
            try {
                mDreamOverlayCallback.onExitRequested();
            } catch (RemoteException e) {
@@ -92,6 +100,14 @@ public abstract class DreamOverlayService extends Service {
            }
        }

        private void redirectWake(boolean redirect) {
            try {
                mDreamOverlayCallback.onRedirectWake(redirect);
            } catch (RemoteException e) {
                Log.e(TAG, "could not request redirect wake", e);
            }
        }

        private boolean shouldShowComplications() {
            return mShowComplications;
        }
@@ -229,7 +245,35 @@ public abstract class DreamOverlayService extends Service {
            throw new IllegalStateException("requested exit with no dream present");
        }

        mCurrentClient.onExitRequested();
        mCurrentClient.requestExit();
    }

    /**
     * Called to inform the dream to redirect waking to this overlay rather than exiting.
     * @param redirect {@code true} if waking up should be redirected. {@code false} otherwise.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_DREAM_WAKE_REDIRECT)
    public final void redirectWake(boolean redirect) {
        if (!Flags.dreamWakeRedirect()) {
            return;
        }

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

        mCurrentClient.redirectWake(redirect);
    }

    /**
     * Invoked when the dream has requested to exit. This is only called if the dream overlay
     * has explicitly requested exits to be redirected via {@link #redirectWake(boolean)}.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_DREAM_WAKE_REDIRECT)
    public void onWakeRequested() {
    }

    /**
+19 −0
Original line number Diff line number Diff line
@@ -281,6 +281,8 @@ public class DreamService extends Service implements Window.Callback {

    private Integer mTrackingConfirmKey = null;

    private boolean mRedirectWake;

    private final Injector mInjector;

    /**
@@ -1117,6 +1119,11 @@ public class DreamService extends Service implements Window.Callback {
                // Simply finish dream when exit is requested.
                mHandler.post(() -> finish());
            }

            @Override
            public void onRedirectWake(boolean redirect) {
                mRedirectWake = redirect;
            }
        };

        super.onCreate();
@@ -1283,6 +1290,18 @@ public class DreamService extends Service implements Window.Callback {
                    + ", mFinished=" + mFinished);
        }

        if (!fromSystem && mOverlayConnection != null && mRedirectWake) {
            mOverlayConnection.addConsumer(overlay -> {
                try {
                    overlay.onWakeRequested();
                } catch (RemoteException e) {
                    Log.e(mTag, "could not inform overlay of dream wakeup:" + e);
                }
            });

            return;
        }

        if (!mWaking && !mFinished) {
            mWaking = true;

+6 −1
Original line number Diff line number Diff line
@@ -23,9 +23,14 @@ package android.service.dreams;
*
* @hide
*/
interface IDreamOverlayCallback {
oneway interface IDreamOverlayCallback {
    /**
    * Invoked to request the dream exit.
    */
    void onExitRequested();

    /**
    * Invoked to redirect wake requests to overlay instead.
    */
    void onRedirectWake(boolean redirect);
}
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ interface IDreamOverlayClient {
    /** Called when the dream has ended. */
    void endDream();

    /** Called when wake up has been redirected to the overlay. */
    void onWakeRequested();

    /** Called when the dream is coming to the front. */
    void comeToFront();
}
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,14 @@ flag {
  }
}

flag {
  name: "dream_wake_redirect"
  namespace: "systemui"
  description: "This flag enables using a host to handle displaying a dream's overlay rather than "
      "relying on the dream's window"
  bug: "334083490"
}

flag {
  name: "dream_tracks_focus"
  namespace: "communal"
Loading