summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorDarrell Shi <darrellshi@google.com>2022-02-04 00:51:59 +0000
committerDarrell Shi <darrellshi@google.com>2022-02-10 18:09:15 +0000
commit6550a928108f2219069e5d8eea850ca674617592 (patch)
treeca0594cc1e324dbab8897201dcaf52997b9af81f /core/java/android
parent91f91d7ae38cfa637d0a87a9fd546932522b1705 (diff)
(Resubmit) Read "showClockAndComplications" metadata.
Read "showClockAndComplications" from dream metadata when binding to DreamOverlayService, and pass in the value in intent extra. Test: atest DreamServiceTest Test: manually on device Bug: 211519550 Change-Id: Ie8780834eb438897191c3545acff49f82f1350a9
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/service/dreams/DreamService.java44
1 files changed, 40 insertions, 4 deletions
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index 45ddbe4b0a18..345917220b6b 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -64,6 +64,7 @@ import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
+import com.android.internal.R;
import com.android.internal.util.DumpUtils;
import org.xmlpull.v1.XmlPullParser;
@@ -256,13 +257,16 @@ public class DreamService extends Service implements Window.Callback {
mRequests = new ArrayDeque<>();
}
- public void bind(Context context, @Nullable ComponentName overlayService) {
+ public void bind(Context context, @Nullable ComponentName overlayService,
+ ComponentName dreamService) {
if (overlayService == null) {
return;
}
final Intent overlayIntent = new Intent();
overlayIntent.setComponent(overlayService);
+ overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
+ fetchShouldShowComplications(context, dreamService));
context.bindService(overlayIntent,
this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
@@ -984,7 +988,8 @@ 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));
+ mOverlayConnection.bind(this, intent.getParcelableExtra(EXTRA_DREAM_OVERLAY_COMPONENT),
+ new ComponentName(this, getClass()));
}
return mDreamServiceWrapper;
@@ -1116,7 +1121,9 @@ public class DreamService extends Service implements Window.Callback {
convertToComponentName(rawMetadata.getString(
com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo),
rawMetadata.getDrawable(
- com.android.internal.R.styleable.Dream_previewImage));
+ com.android.internal.R.styleable.Dream_previewImage),
+ rawMetadata.getBoolean(R.styleable.Dream_showClockAndComplications,
+ DEFAULT_SHOW_COMPLICATIONS));
rawMetadata.recycle();
return metadata;
}
@@ -1337,6 +1344,30 @@ public class DreamService extends Service implements Window.Callback {
return (oldFlags&~mask) | (flags&mask);
}
+ /**
+ * Fetches metadata of the dream indicated by the {@link ComponentName}, and returns whether
+ * the dream should show complications on the overlay. If not defined, returns
+ * {@link DreamService#DEFAULT_SHOW_COMPLICATIONS}.
+ */
+ private static boolean fetchShouldShowComplications(Context context,
+ ComponentName componentName) {
+ final PackageManager pm = context.getPackageManager();
+
+ try {
+ final ServiceInfo si = 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;
+ }
+
@Override
protected void dump(final FileDescriptor fd, PrintWriter pw, final String[] args) {
DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> dumpOnHandler(fd, pw1, args), pw, "", 1000);
@@ -1410,9 +1441,14 @@ public class DreamService extends Service implements Window.Callback {
@Nullable
public final Drawable previewImage;
- DreamMetadata(ComponentName settingsActivity, Drawable previewImage) {
+ @NonNull
+ public final boolean showComplications;
+
+ DreamMetadata(ComponentName settingsActivity, Drawable previewImage,
+ boolean showComplications) {
this.settingsActivity = settingsActivity;
this.previewImage = previewImage;
+ this.showComplications = showComplications;
}
}
}