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

Commit 52f63245 authored by Lucas Silva's avatar Lucas Silva
Browse files

Pipe the preview boolean to the dream overlay service.

This will allow us to change which complications are shown based on if
we are in preview mode.

Test: atest DreamOverlayServiceTest
Test: locally on device
Bug: 219747041
Change-Id: I4ec34b990fec5e09114a71719c0271da7758aac7
parent d8dd4b41
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -2347,6 +2347,7 @@ package android.service.dreams {


  public abstract class DreamOverlayService extends android.app.Service {
  public abstract class DreamOverlayService extends android.app.Service {
    ctor public DreamOverlayService();
    ctor public DreamOverlayService();
    method public final boolean isPreviewMode();
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
    method public abstract void onStartDream(@NonNull android.view.WindowManager.LayoutParams);
    method public abstract void onStartDream(@NonNull android.view.WindowManager.LayoutParams);
    method public final void requestExit();
    method public final void requestExit();
+9 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ public abstract class DreamOverlayService extends Service {
    private static final String TAG = "DreamOverlayService";
    private static final String TAG = "DreamOverlayService";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;
    private boolean mShowComplications;
    private boolean mShowComplications;
    private boolean mIsPreviewMode;


    private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
    private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
        @Override
        @Override
@@ -56,6 +57,7 @@ public abstract class DreamOverlayService extends Service {
    public final IBinder onBind(@NonNull Intent intent) {
    public final IBinder onBind(@NonNull Intent intent) {
        mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
        mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
                DreamService.DEFAULT_SHOW_COMPLICATIONS);
                DreamService.DEFAULT_SHOW_COMPLICATIONS);
        mIsPreviewMode = intent.getBooleanExtra(DreamService.EXTRA_IS_PREVIEW, false);
        return mDreamOverlay.asBinder();
        return mDreamOverlay.asBinder();
    }
    }


@@ -84,4 +86,11 @@ public abstract class DreamOverlayService extends Service {
    public final boolean shouldShowComplications() {
    public final boolean shouldShowComplications() {
        return mShowComplications;
        return mShowComplications;
    }
    }

    /**
     * Returns whether the dream is running in preview mode.
     */
    public final boolean isPreviewMode() {
        return mIsPreviewMode;
    }
}
}
+13 −3
Original line number Original line Diff line number Diff line
@@ -215,6 +215,12 @@ public class DreamService extends Service implements Window.Callback {
    public static final String EXTRA_SHOW_COMPLICATIONS =
    public static final String EXTRA_SHOW_COMPLICATIONS =
            "android.service.dreams.SHOW_COMPLICATIONS";
            "android.service.dreams.SHOW_COMPLICATIONS";


    /**
     * Extra containing a boolean for whether we are showing this dream in preview mode.
     * @hide
     */
    public static final String EXTRA_IS_PREVIEW = "android.service.dreams.IS_PREVIEW";

    /**
    /**
     * The default value for whether to show complications on the overlay.
     * The default value for whether to show complications on the overlay.
     * @hide
     * @hide
@@ -258,7 +264,7 @@ public class DreamService extends Service implements Window.Callback {
        }
        }


        public void bind(Context context, @Nullable ComponentName overlayService,
        public void bind(Context context, @Nullable ComponentName overlayService,
                ComponentName dreamService) {
                ComponentName dreamService, boolean isPreviewMode) {
            if (overlayService == null) {
            if (overlayService == null) {
                return;
                return;
            }
            }
@@ -267,6 +273,7 @@ public class DreamService extends Service implements Window.Callback {
            overlayIntent.setComponent(overlayService);
            overlayIntent.setComponent(overlayService);
            overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
            overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
                    fetchShouldShowComplications(context, dreamService));
                    fetchShouldShowComplications(context, dreamService));
            overlayIntent.putExtra(EXTRA_IS_PREVIEW, isPreviewMode);


            context.bindService(overlayIntent,
            context.bindService(overlayIntent,
                    this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
                    this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
@@ -988,8 +995,11 @@ public class DreamService extends Service implements Window.Callback {


        // Connect to the overlay service if present.
        // Connect to the overlay service if present.
        if (!mWindowless) {
        if (!mWindowless) {
            mOverlayConnection.bind(this, intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
            mOverlayConnection.bind(
                    new ComponentName(this, getClass()));
                    /* context= */ this,
                    intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
                    new ComponentName(this, getClass()),
                    intent.getBooleanExtra(EXTRA_IS_PREVIEW, /* defaultValue= */ false));
        }
        }


        return mDreamServiceWrapper;
        return mDreamServiceWrapper;
+16 −0
Original line number Original line Diff line number Diff line
@@ -162,6 +162,22 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
        assertThat(mService.shouldShowComplications()).isFalse();
        assertThat(mService.shouldShowComplications()).isFalse();
    }
    }


    @Test
    public void testPreviewModeFalseByDefault() {
        mService.onBind(new Intent());

        assertThat(mService.isPreviewMode()).isFalse();
    }

    @Test
    public void testPreviewModeSetByIntentExtra() {
        final Intent intent = new Intent();
        intent.putExtra(DreamService.EXTRA_IS_PREVIEW, true);
        mService.onBind(intent);

        assertThat(mService.isPreviewMode()).isTrue();
    }

    @Test
    @Test
    public void testDestroy() {
    public void testDestroy() {
        mService.onDestroy();
        mService.onDestroy();
+12 −10
Original line number Original line Diff line number Diff line
@@ -104,7 +104,7 @@ final class DreamController {
            pw.println("  mCurrentDream:");
            pw.println("  mCurrentDream:");
            pw.println("    mToken=" + mCurrentDream.mToken);
            pw.println("    mToken=" + mCurrentDream.mToken);
            pw.println("    mName=" + mCurrentDream.mName);
            pw.println("    mName=" + mCurrentDream.mName);
            pw.println("    mIsTest=" + mCurrentDream.mIsTest);
            pw.println("    mIsPreviewMode=" + mCurrentDream.mIsPreviewMode);
            pw.println("    mCanDoze=" + mCurrentDream.mCanDoze);
            pw.println("    mCanDoze=" + mCurrentDream.mCanDoze);
            pw.println("    mUserId=" + mCurrentDream.mUserId);
            pw.println("    mUserId=" + mCurrentDream.mUserId);
            pw.println("    mBound=" + mCurrentDream.mBound);
            pw.println("    mBound=" + mCurrentDream.mBound);
@@ -117,7 +117,7 @@ final class DreamController {
    }
    }


    public void startDream(Binder token, ComponentName name,
    public void startDream(Binder token, ComponentName name,
            boolean isTest, boolean canDoze, int userId, PowerManager.WakeLock wakeLock,
            boolean isPreviewMode, boolean canDoze, int userId, PowerManager.WakeLock wakeLock,
            ComponentName overlayComponentName) {
            ComponentName overlayComponentName) {
        stopDream(true /*immediate*/, "starting new dream");
        stopDream(true /*immediate*/, "starting new dream");


@@ -127,10 +127,10 @@ final class DreamController {
            mContext.sendBroadcastAsUser(mCloseNotificationShadeIntent, UserHandle.ALL);
            mContext.sendBroadcastAsUser(mCloseNotificationShadeIntent, UserHandle.ALL);


            Slog.i(TAG, "Starting dream: name=" + name
            Slog.i(TAG, "Starting dream: name=" + name
                    + ", isTest=" + isTest + ", canDoze=" + canDoze
                    + ", isPreviewMode=" + isPreviewMode + ", canDoze=" + canDoze
                    + ", userId=" + userId);
                    + ", userId=" + userId);


            mCurrentDream = new DreamRecord(token, name, isTest, canDoze, userId, wakeLock);
            mCurrentDream = new DreamRecord(token, name, isPreviewMode, canDoze, userId, wakeLock);


            mDreamStartTime = SystemClock.elapsedRealtime();
            mDreamStartTime = SystemClock.elapsedRealtime();
            MetricsLogger.visible(mContext,
            MetricsLogger.visible(mContext,
@@ -140,6 +140,7 @@ final class DreamController {
            intent.setComponent(name);
            intent.setComponent(name);
            intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            intent.putExtra(DreamService.EXTRA_DREAM_OVERLAY_COMPONENT, overlayComponentName);
            intent.putExtra(DreamService.EXTRA_DREAM_OVERLAY_COMPONENT, overlayComponentName);
            intent.putExtra(DreamService.EXTRA_IS_PREVIEW, isPreviewMode);
            try {
            try {
                if (!mContext.bindServiceAsUser(intent, mCurrentDream,
                if (!mContext.bindServiceAsUser(intent, mCurrentDream,
                        Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
                        Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
@@ -190,7 +191,8 @@ final class DreamController {
            final DreamRecord oldDream = mCurrentDream;
            final DreamRecord oldDream = mCurrentDream;
            mCurrentDream = null;
            mCurrentDream = null;
            Slog.i(TAG, "Stopping dream: name=" + oldDream.mName
            Slog.i(TAG, "Stopping dream: name=" + oldDream.mName
                    + ", isTest=" + oldDream.mIsTest + ", canDoze=" + oldDream.mCanDoze
                    + ", isPreviewMode=" + oldDream.mIsPreviewMode
                    + ", canDoze=" + oldDream.mCanDoze
                    + ", userId=" + oldDream.mUserId
                    + ", userId=" + oldDream.mUserId
                    + ", reason='" + reason + "'"
                    + ", reason='" + reason + "'"
                    + (mSavedStopReason == null ? "" : "(from '" + mSavedStopReason + "')"));
                    + (mSavedStopReason == null ? "" : "(from '" + mSavedStopReason + "')"));
@@ -247,7 +249,7 @@ final class DreamController {


        mCurrentDream.mService = service;
        mCurrentDream.mService = service;


        if (!mCurrentDream.mIsTest) {
        if (!mCurrentDream.mIsPreviewMode) {
            mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL);
            mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL);
            mCurrentDream.mSentStartBroadcast = true;
            mCurrentDream.mSentStartBroadcast = true;
        }
        }
@@ -263,7 +265,7 @@ final class DreamController {
    private final class DreamRecord implements DeathRecipient, ServiceConnection {
    private final class DreamRecord implements DeathRecipient, ServiceConnection {
        public final Binder mToken;
        public final Binder mToken;
        public final ComponentName mName;
        public final ComponentName mName;
        public final boolean mIsTest;
        public final boolean mIsPreviewMode;
        public final boolean mCanDoze;
        public final boolean mCanDoze;
        public final int mUserId;
        public final int mUserId;


@@ -275,11 +277,11 @@ final class DreamController {


        public boolean mWakingGently;
        public boolean mWakingGently;


        public DreamRecord(Binder token, ComponentName name,
        DreamRecord(Binder token, ComponentName name, boolean isPreviewMode,
                boolean isTest, boolean canDoze, int userId, PowerManager.WakeLock wakeLock) {
                boolean canDoze, int userId, PowerManager.WakeLock wakeLock) {
            mToken = token;
            mToken = token;
            mName = name;
            mName = name;
            mIsTest = isTest;
            mIsPreviewMode = isPreviewMode;
            mCanDoze = canDoze;
            mCanDoze = canDoze;
            mUserId  = userId;
            mUserId  = userId;
            mWakeLock = wakeLock;
            mWakeLock = wakeLock;
Loading