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
This commit is contained in:
Lucas Silva
2022-02-16 17:06:59 +00:00
parent d8dd4b4197
commit 52f6324514
6 changed files with 61 additions and 23 deletions

View File

@@ -2347,6 +2347,7 @@ package android.service.dreams {
public abstract class DreamOverlayService extends android.app.Service {
ctor public DreamOverlayService();
method public final boolean isPreviewMode();
method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
method public abstract void onStartDream(@NonNull android.view.WindowManager.LayoutParams);
method public final void requestExit();

View File

@@ -36,6 +36,7 @@ public abstract class DreamOverlayService extends Service {
private static final String TAG = "DreamOverlayService";
private static final boolean DEBUG = false;
private boolean mShowComplications;
private boolean mIsPreviewMode;
private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
@Override
@@ -56,6 +57,7 @@ public abstract class DreamOverlayService extends Service {
public final IBinder onBind(@NonNull Intent intent) {
mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
DreamService.DEFAULT_SHOW_COMPLICATIONS);
mIsPreviewMode = intent.getBooleanExtra(DreamService.EXTRA_IS_PREVIEW, false);
return mDreamOverlay.asBinder();
}
@@ -84,4 +86,11 @@ public abstract class DreamOverlayService extends Service {
public final boolean shouldShowComplications() {
return mShowComplications;
}
/**
* Returns whether the dream is running in preview mode.
*/
public final boolean isPreviewMode() {
return mIsPreviewMode;
}
}

View File

@@ -215,6 +215,12 @@ public class DreamService extends Service implements Window.Callback {
public static final String EXTRA_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.
* @hide
@@ -258,7 +264,7 @@ public class DreamService extends Service implements Window.Callback {
}
public void bind(Context context, @Nullable ComponentName overlayService,
ComponentName dreamService) {
ComponentName dreamService, boolean isPreviewMode) {
if (overlayService == null) {
return;
}
@@ -267,6 +273,7 @@ public class DreamService extends Service implements Window.Callback {
overlayIntent.setComponent(overlayService);
overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
fetchShouldShowComplications(context, dreamService));
overlayIntent.putExtra(EXTRA_IS_PREVIEW, isPreviewMode);
context.bindService(overlayIntent,
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.
if (!mWindowless) {
mOverlayConnection.bind(this, intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
new ComponentName(this, getClass()));
mOverlayConnection.bind(
/* context= */ this,
intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
new ComponentName(this, getClass()),
intent.getBooleanExtra(EXTRA_IS_PREVIEW, /* defaultValue= */ false));
}
return mDreamServiceWrapper;

View File

@@ -162,6 +162,22 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
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
public void testDestroy() {
mService.onDestroy();

View File

@@ -104,7 +104,7 @@ final class DreamController {
pw.println(" mCurrentDream:");
pw.println(" mToken=" + mCurrentDream.mToken);
pw.println(" mName=" + mCurrentDream.mName);
pw.println(" mIsTest=" + mCurrentDream.mIsTest);
pw.println(" mIsPreviewMode=" + mCurrentDream.mIsPreviewMode);
pw.println(" mCanDoze=" + mCurrentDream.mCanDoze);
pw.println(" mUserId=" + mCurrentDream.mUserId);
pw.println(" mBound=" + mCurrentDream.mBound);
@@ -117,7 +117,7 @@ final class DreamController {
}
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) {
stopDream(true /*immediate*/, "starting new dream");
@@ -127,10 +127,10 @@ final class DreamController {
mContext.sendBroadcastAsUser(mCloseNotificationShadeIntent, UserHandle.ALL);
Slog.i(TAG, "Starting dream: name=" + name
+ ", isTest=" + isTest + ", canDoze=" + canDoze
+ ", isPreviewMode=" + isPreviewMode + ", canDoze=" + canDoze
+ ", userId=" + userId);
mCurrentDream = new DreamRecord(token, name, isTest, canDoze, userId, wakeLock);
mCurrentDream = new DreamRecord(token, name, isPreviewMode, canDoze, userId, wakeLock);
mDreamStartTime = SystemClock.elapsedRealtime();
MetricsLogger.visible(mContext,
@@ -140,6 +140,7 @@ final class DreamController {
intent.setComponent(name);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.putExtra(DreamService.EXTRA_DREAM_OVERLAY_COMPONENT, overlayComponentName);
intent.putExtra(DreamService.EXTRA_IS_PREVIEW, isPreviewMode);
try {
if (!mContext.bindServiceAsUser(intent, mCurrentDream,
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
@@ -190,7 +191,8 @@ final class DreamController {
final DreamRecord oldDream = mCurrentDream;
mCurrentDream = null;
Slog.i(TAG, "Stopping dream: name=" + oldDream.mName
+ ", isTest=" + oldDream.mIsTest + ", canDoze=" + oldDream.mCanDoze
+ ", isPreviewMode=" + oldDream.mIsPreviewMode
+ ", canDoze=" + oldDream.mCanDoze
+ ", userId=" + oldDream.mUserId
+ ", reason='" + reason + "'"
+ (mSavedStopReason == null ? "" : "(from '" + mSavedStopReason + "')"));
@@ -247,7 +249,7 @@ final class DreamController {
mCurrentDream.mService = service;
if (!mCurrentDream.mIsTest) {
if (!mCurrentDream.mIsPreviewMode) {
mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL);
mCurrentDream.mSentStartBroadcast = true;
}
@@ -263,7 +265,7 @@ final class DreamController {
private final class DreamRecord implements DeathRecipient, ServiceConnection {
public final Binder mToken;
public final ComponentName mName;
public final boolean mIsTest;
public final boolean mIsPreviewMode;
public final boolean mCanDoze;
public final int mUserId;
@@ -275,11 +277,11 @@ final class DreamController {
public boolean mWakingGently;
public DreamRecord(Binder token, ComponentName name,
boolean isTest, boolean canDoze, int userId, PowerManager.WakeLock wakeLock) {
DreamRecord(Binder token, ComponentName name, boolean isPreviewMode,
boolean canDoze, int userId, PowerManager.WakeLock wakeLock) {
mToken = token;
mName = name;
mIsTest = isTest;
mIsPreviewMode = isPreviewMode;
mCanDoze = canDoze;
mUserId = userId;
mWakeLock = wakeLock;

View File

@@ -87,7 +87,7 @@ public final class DreamManagerService extends SystemService {
private Binder mCurrentDreamToken;
private ComponentName mCurrentDreamName;
private int mCurrentDreamUserId;
private boolean mCurrentDreamIsTest;
private boolean mCurrentDreamIsPreview;
private boolean mCurrentDreamCanDoze;
private boolean mCurrentDreamIsDozing;
private boolean mCurrentDreamIsWaking;
@@ -169,7 +169,7 @@ public final class DreamManagerService extends SystemService {
pw.println("mCurrentDreamToken=" + mCurrentDreamToken);
pw.println("mCurrentDreamName=" + mCurrentDreamName);
pw.println("mCurrentDreamUserId=" + mCurrentDreamUserId);
pw.println("mCurrentDreamIsTest=" + mCurrentDreamIsTest);
pw.println("mCurrentDreamIsPreview=" + mCurrentDreamIsPreview);
pw.println("mCurrentDreamCanDoze=" + mCurrentDreamCanDoze);
pw.println("mCurrentDreamIsDozing=" + mCurrentDreamIsDozing);
pw.println("mCurrentDreamIsWaking=" + mCurrentDreamIsWaking);
@@ -190,7 +190,7 @@ public final class DreamManagerService extends SystemService {
private boolean isDreamingInternal() {
synchronized (mLock) {
return mCurrentDreamToken != null && !mCurrentDreamIsTest
return mCurrentDreamToken != null && !mCurrentDreamIsPreview
&& !mCurrentDreamIsWaking;
}
}
@@ -235,7 +235,7 @@ public final class DreamManagerService extends SystemService {
private void testDreamInternal(ComponentName dream, int userId) {
synchronized (mLock) {
startDreamLocked(dream, true /*isTest*/, false /*canDoze*/, userId);
startDreamLocked(dream, true /*isPreviewMode*/, false /*canDoze*/, userId);
}
}
@@ -244,7 +244,7 @@ public final class DreamManagerService extends SystemService {
final ComponentName dream = chooseDreamForUser(doze, userId);
if (dream != null) {
synchronized (mLock) {
startDreamLocked(dream, false /*isTest*/, doze, userId);
startDreamLocked(dream, false /*isPreviewMode*/, doze, userId);
}
}
}
@@ -395,10 +395,10 @@ public final class DreamManagerService extends SystemService {
}
private void startDreamLocked(final ComponentName name,
final boolean isTest, final boolean canDoze, final int userId) {
final boolean isPreviewMode, final boolean canDoze, final int userId) {
if (!mCurrentDreamIsWaking
&& Objects.equals(mCurrentDreamName, name)
&& mCurrentDreamIsTest == isTest
&& mCurrentDreamIsPreview == isPreviewMode
&& mCurrentDreamCanDoze == canDoze
&& mCurrentDreamUserId == userId) {
Slog.i(TAG, "Already in target dream.");
@@ -412,7 +412,7 @@ public final class DreamManagerService extends SystemService {
final Binder newToken = new Binder();
mCurrentDreamToken = newToken;
mCurrentDreamName = name;
mCurrentDreamIsTest = isTest;
mCurrentDreamIsPreview = isPreviewMode;
mCurrentDreamCanDoze = canDoze;
mCurrentDreamUserId = userId;
@@ -424,7 +424,7 @@ public final class DreamManagerService extends SystemService {
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "startDream");
mHandler.post(wakeLock.wrap(() -> {
mAtmInternal.notifyDreamStateChanged(true);
mController.startDream(newToken, name, isTest, canDoze, userId, wakeLock,
mController.startDream(newToken, name, isPreviewMode, canDoze, userId, wakeLock,
mDreamOverlayServiceName);
}));
}
@@ -457,7 +457,7 @@ public final class DreamManagerService extends SystemService {
}
mCurrentDreamToken = null;
mCurrentDreamName = null;
mCurrentDreamIsTest = false;
mCurrentDreamIsPreview = false;
mCurrentDreamCanDoze = false;
mCurrentDreamUserId = 0;
mCurrentDreamIsWaking = false;