Pipeline "showComplications" to DreamOverlayService.

Allow a boolean in the intent extra when connecting to
DreamOverlayService to indicate whether complications should be rendered
on the overlay.

Test: atest DreamOverlayServiceTest
Bug: 211519550
Change-Id: I09eb8e55e0f7d494184938c217d1291000259692
This commit is contained in:
Darrell Shi
2021-12-22 16:49:28 -08:00
parent bd4a9f5806
commit 5f1bef2f8b
4 changed files with 45 additions and 0 deletions

View File

@@ -2305,6 +2305,7 @@ package android.service.dreams {
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();
method public final boolean shouldShowComplications();
}
}

View File

@@ -35,6 +35,7 @@ import android.view.WindowManager;
public abstract class DreamOverlayService extends Service {
private static final String TAG = "DreamOverlayService";
private static final boolean DEBUG = false;
private boolean mShowComplications;
private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
@Override
@@ -53,6 +54,8 @@ public abstract class DreamOverlayService extends Service {
@Nullable
@Override
public final IBinder onBind(@NonNull Intent intent) {
mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
DreamService.DEFAULT_SHOW_COMPLICATIONS);
return mDreamOverlay.asBinder();
}
@@ -74,4 +77,11 @@ public abstract class DreamOverlayService extends Service {
Log.e(TAG, "Could not request exit:" + e);
}
}
/**
* Returns whether to show complications on the dream overlay.
*/
public final boolean shouldShowComplications() {
return mShowComplications;
}
}

View File

@@ -189,6 +189,19 @@ public class DreamService extends Service implements Window.Callback {
*/
public static final String DREAM_META_DATA = "android.service.dream";
/**
* Extra containing a boolean for whether to show complications on the overlay.
* @hide
*/
public static final String EXTRA_SHOW_COMPLICATIONS =
"android.service.dreams.SHOW_COMPLICATIONS";
/**
* The default value for whether to show complications on the overlay.
* @hide
*/
public static final boolean DEFAULT_SHOW_COMPLICATIONS = true;
private final IDreamManager mDreamManager;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private IBinder mDreamToken;

View File

@@ -16,12 +16,15 @@
package com.android.systemui.dreams;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Intent;
import android.os.IBinder;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamOverlay;
import android.service.dreams.IDreamOverlayCallback;
import android.testing.AndroidTestingRunner;
@@ -195,4 +198,22 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
mService.onDestroy();
verify(mDreamOverlayStateController).removeCallback(callbackCapture.getValue());
}
@Test
public void testShouldShowComplicationsTrueByDefault() {
assertThat(mService.shouldShowComplications()).isTrue();
mService.onBind(new Intent());
assertThat(mService.shouldShowComplications()).isTrue();
}
@Test
public void testShouldShowComplicationsSetByIntentExtra() {
final Intent intent = new Intent();
intent.putExtra(DreamService.EXTRA_SHOW_COMPLICATIONS, false);
mService.onBind(intent);
assertThat(mService.shouldShowComplications()).isFalse();
}
}