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

Commit b193131c authored by Will Leshner's avatar Will Leshner
Browse files

Track dream focus in order to know when dreams are occluded.

One of the changes needed to return to a dream on power button press if
the dream is occluded by something like the notification shade or the
bouncer.

Bug: 331798001
Test: atest DreamServiceTests
Flag: ACONFIG android.service.dreams.dream_tracks_focus STAGING

Change-Id: Iebb5470b7bdda869d46cdb7ffb6bedb580810ae5
parent b0a3ee31
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -79,6 +79,11 @@ public abstract class DreamOverlayService extends Service {
            mService.endDream(this);
        }

        @Override
        public void comeToFront() {
            mService.comeToFront(this);
        }

        private void onExitRequested() {
            try {
                mDreamOverlayCallback.onExitRequested();
@@ -130,6 +135,16 @@ public abstract class DreamOverlayService extends Service {
        });
    }

    private void comeToFront(OverlayClient client) {
        mExecutor.execute(() -> {
            if (mCurrentClient != client) {
                return;
            }

            onComeToFront();
        });
    }

    private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
        @Override
        public void getClient(IDreamOverlayClientCallback callback) {
@@ -189,6 +204,13 @@ public abstract class DreamOverlayService extends Service {
     */
    public void onWakeUp() {}

    /**
     * This method is overridden by implementations to handle when the dream is coming to the front
     * (after having lost focus to something on top of it).
     * @hide
     */
    public void onComeToFront() {}

    /**
     * This method is overridden by implementations to handle when the dream has ended. There may
     * be earlier signals leading up to this step, such as @{@link #onWakeUp(Runnable)}.
+32 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.service.dreams;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.service.dreams.Flags.dreamHandlesConfirmKeys;
import static android.service.dreams.Flags.dreamTracksFocus;

import android.annotation.FlaggedApi;
import android.annotation.IdRes;
@@ -455,6 +456,15 @@ public class DreamService extends Service implements Window.Callback {
    /** {@inheritDoc} */
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if (!dreamTracksFocus()) {
            return;
        }

        try {
            mDreamManager.onDreamFocusChanged(hasFocus);
        } catch (RemoteException ex) {
            // system server died
        }
    }

    /** {@inheritDoc} */
@@ -1149,6 +1159,19 @@ public class DreamService extends Service implements Window.Callback {
        wakeUp(false);
    }

    /**
     * Tells the dream to come to the front (which in turn tells the overlay to come to the front).
     */
    private void comeToFront() {
        mOverlayConnection.addConsumer(overlay -> {
            try {
                overlay.comeToFront();
            } catch (RemoteException e) {
                Log.e(mTag, "could not tell overlay to come to front:" + e);
            }
        });
    }

    private void wakeUp(boolean fromSystem) {
        if (mDebug) {
            Slog.v(mTag, "wakeUp(): fromSystem=" + fromSystem + ", mWaking=" + mWaking
@@ -1596,6 +1619,15 @@ public class DreamService extends Service implements Window.Callback {
        public void wakeUp() {
            mHandler.post(() -> DreamService.this.wakeUp(true /*fromSystem*/));
        }

        @Override
        public void comeToFront() {
            if (!dreamTracksFocus()) {
                return;
            }

            mHandler.post(DreamService.this::comeToFront);
        }
    }

    /** @hide */
+1 −0
Original line number Diff line number Diff line
@@ -48,4 +48,5 @@ interface IDreamManager {
    void setSystemDreamComponent(in ComponentName componentName);
    void registerDreamOverlayService(in ComponentName componentName);
    void startDreamActivity(in Intent intent);
    void onDreamFocusChanged(in boolean hasFocus);
}
+3 −0
Original line number Diff line number Diff line
@@ -42,4 +42,7 @@ interface IDreamOverlayClient {

    /** Called when the dream has ended. */
    void endDream();

    /** Called when the dream is coming to the front. */
    void comeToFront();
}
+1 −0
Original line number Diff line number Diff line
@@ -25,4 +25,5 @@ oneway interface IDreamService {
    void attach(IBinder windowToken, boolean canDoze, boolean isPreviewMode, IRemoteCallback started);
    void detach();
    void wakeUp();
    void comeToFront();
}
Loading