Pipe the dream label to the dream overlay service.
The preview overlay needs access to the user-facing label for the dream, to show the user which dream they are previewing. Test: atest DreamOverlayServiceTest Bug: 219747041 Change-Id: I26362ce1fefcd5c9557e99ad2f44374f04017c29
This commit is contained in:
@@ -2347,6 +2347,7 @@ package android.service.dreams {
|
||||
|
||||
public abstract class DreamOverlayService extends android.app.Service {
|
||||
ctor public DreamOverlayService();
|
||||
method @Nullable public final CharSequence getDreamLabel();
|
||||
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);
|
||||
|
||||
@@ -37,6 +37,8 @@ public abstract class DreamOverlayService extends Service {
|
||||
private static final boolean DEBUG = false;
|
||||
private boolean mShowComplications;
|
||||
private boolean mIsPreviewMode;
|
||||
@Nullable
|
||||
private CharSequence mDreamLabel;
|
||||
|
||||
private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
|
||||
@Override
|
||||
@@ -58,6 +60,7 @@ public abstract class DreamOverlayService extends Service {
|
||||
mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
|
||||
DreamService.DEFAULT_SHOW_COMPLICATIONS);
|
||||
mIsPreviewMode = intent.getBooleanExtra(DreamService.EXTRA_IS_PREVIEW, false);
|
||||
mDreamLabel = intent.getCharSequenceExtra(DreamService.EXTRA_DREAM_LABEL);
|
||||
return mDreamOverlay.asBinder();
|
||||
}
|
||||
|
||||
@@ -93,4 +96,12 @@ public abstract class DreamOverlayService extends Service {
|
||||
public final boolean isPreviewMode() {
|
||||
return mIsPreviewMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user-facing label of the currently running dream.
|
||||
*/
|
||||
@Nullable
|
||||
public final CharSequence getDreamLabel() {
|
||||
return mDreamLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,12 @@ public class DreamService extends Service implements Window.Callback {
|
||||
*/
|
||||
public static final String EXTRA_IS_PREVIEW = "android.service.dreams.IS_PREVIEW";
|
||||
|
||||
/**
|
||||
* The user-facing label of the current dream service.
|
||||
* @hide
|
||||
*/
|
||||
public static final String EXTRA_DREAM_LABEL = "android.service.dreams.DREAM_LABEL";
|
||||
|
||||
/**
|
||||
* The default value for whether to show complications on the overlay.
|
||||
* @hide
|
||||
@@ -269,10 +275,13 @@ public class DreamService extends Service implements Window.Callback {
|
||||
return;
|
||||
}
|
||||
|
||||
final ServiceInfo serviceInfo = fetchServiceInfo(context, dreamService);
|
||||
|
||||
final Intent overlayIntent = new Intent();
|
||||
overlayIntent.setComponent(overlayService);
|
||||
overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
|
||||
fetchShouldShowComplications(context, dreamService));
|
||||
fetchShouldShowComplications(context, serviceInfo));
|
||||
overlayIntent.putExtra(EXTRA_DREAM_LABEL, fetchDreamLabel(context, serviceInfo));
|
||||
overlayIntent.putExtra(EXTRA_IS_PREVIEW, isPreviewMode);
|
||||
|
||||
context.bindService(overlayIntent,
|
||||
@@ -1121,7 +1130,10 @@ public class DreamService extends Service implements Window.Callback {
|
||||
* @hide
|
||||
*/
|
||||
@Nullable
|
||||
public static DreamMetadata getDreamMetadata(Context context, ServiceInfo serviceInfo) {
|
||||
public static DreamMetadata getDreamMetadata(Context context,
|
||||
@Nullable ServiceInfo serviceInfo) {
|
||||
if (serviceInfo == null) return null;
|
||||
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
|
||||
final TypedArray rawMetadata = readMetadata(pm, serviceInfo);
|
||||
@@ -1360,22 +1372,33 @@ public class DreamService extends Service implements Window.Callback {
|
||||
* {@link DreamService#DEFAULT_SHOW_COMPLICATIONS}.
|
||||
*/
|
||||
private static boolean fetchShouldShowComplications(Context context,
|
||||
ComponentName componentName) {
|
||||
@Nullable ServiceInfo serviceInfo) {
|
||||
final DreamMetadata metadata = getDreamMetadata(context, serviceInfo);
|
||||
if (metadata != null) {
|
||||
return metadata.showComplications;
|
||||
}
|
||||
return DEFAULT_SHOW_COMPLICATIONS;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static CharSequence fetchDreamLabel(Context context,
|
||||
@Nullable ServiceInfo serviceInfo) {
|
||||
if (serviceInfo == null) return null;
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
return serviceInfo.loadLabel(pm);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ServiceInfo fetchServiceInfo(Context context, ComponentName componentName) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
|
||||
try {
|
||||
final ServiceInfo si = pm.getServiceInfo(componentName,
|
||||
return pm.getServiceInfo(componentName,
|
||||
PackageManager.ComponentInfoFlags.of(PackageManager.GET_META_DATA));
|
||||
final DreamMetadata metadata = getDreamMetadata(context, si);
|
||||
|
||||
if (metadata != null) {
|
||||
return metadata.showComplications;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
if (DEBUG) Log.w(TAG, "cannot find component " + componentName.flattenToShortString());
|
||||
}
|
||||
|
||||
return DEFAULT_SHOW_COMPLICATIONS;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -178,6 +178,15 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
||||
assertThat(mService.isPreviewMode()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDreamLabel() {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(DreamService.EXTRA_DREAM_LABEL, "TestDream");
|
||||
mService.onBind(intent);
|
||||
|
||||
assertThat(mService.getDreamLabel()).isEqualTo("TestDream");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroy() {
|
||||
mService.onDestroy();
|
||||
|
||||
Reference in New Issue
Block a user