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

Commit ca660ce3 authored by William Leshner's avatar William Leshner Committed by Android (Google) Code Review
Browse files

Merge changes from topic "power_button_gh" into main

* changes:
  Return to dream on power button press when occluded by glanceable hub.
  Track dream focus in order to know when dreams are occluded.
parents 3b9dbb08 8de5068c
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;
@@ -457,6 +458,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} */
@@ -1152,6 +1162,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
@@ -1608,6 +1631,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