diff options
| author | Darrell Shi <darrellshi@google.com> | 2022-02-03 02:29:41 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-02-03 02:29:41 +0000 |
| commit | 395ff008a7ca0daeb286f4fdbdfeff959148bfe4 (patch) | |
| tree | b4fa2801aac4f48b926f040b4afdc92cce8c2718 /core/java/android | |
| parent | d965b9f5bda63025404dc01fbcc2f8a0f12c78c2 (diff) | |
| parent | 30711f85612b8db57a79090429c6dbd00abfcf74 (diff) | |
Merge "Read "showClockAndComplications" metadata."
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/service/dreams/DreamService.java | 44 |
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 d27bc9b6a424..fde8bfe7cadd 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -65,6 +65,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; @@ -257,13 +258,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); @@ -985,7 +989,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; @@ -1117,7 +1122,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; } @@ -1336,6 +1343,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); @@ -1409,9 +1440,14 @@ public class DreamService extends Service implements Window.Callback { @Nullable public final Drawable previewImage; - DreamMetadata(ComponentName settingsActivity, Drawable previewImage) { + @Nullable + public final boolean showComplications; + + DreamMetadata(ComponentName settingsActivity, Drawable previewImage, + boolean showComplications) { this.settingsActivity = settingsActivity; this.previewImage = previewImage; + this.showComplications = showComplications; } } } |
