Loading core/java/android/service/dreams/DreamService.java +40 −4 Original line number Original line Diff line number Diff line Loading @@ -65,6 +65,7 @@ import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent; import com.android.internal.R; import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser; Loading Loading @@ -257,13 +258,16 @@ public class DreamService extends Service implements Window.Callback { mRequests = new ArrayDeque<>(); mRequests = new ArrayDeque<>(); } } public void bind(Context context, @Nullable ComponentName overlayService) { public void bind(Context context, @Nullable ComponentName overlayService, ComponentName dreamService) { if (overlayService == null) { if (overlayService == null) { return; return; } } final Intent overlayIntent = new Intent(); final Intent overlayIntent = new Intent(); overlayIntent.setComponent(overlayService); overlayIntent.setComponent(overlayService); overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS, fetchShouldShowComplications(context, dreamService)); context.bindService(overlayIntent, context.bindService(overlayIntent, this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE); this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE); Loading Loading @@ -985,7 +989,8 @@ public class DreamService extends Service implements Window.Callback { // Connect to the overlay service if present. // Connect to the overlay service if present. if (!mWindowless) { 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; return mDreamServiceWrapper; Loading Loading @@ -1117,7 +1122,9 @@ public class DreamService extends Service implements Window.Callback { convertToComponentName(rawMetadata.getString( convertToComponentName(rawMetadata.getString( com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo), com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo), rawMetadata.getDrawable( 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(); rawMetadata.recycle(); return metadata; return metadata; } } Loading Loading @@ -1336,6 +1343,30 @@ public class DreamService extends Service implements Window.Callback { return (oldFlags&~mask) | (flags&mask); 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 @Override protected void dump(final FileDescriptor fd, PrintWriter pw, final String[] args) { protected void dump(final FileDescriptor fd, PrintWriter pw, final String[] args) { DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> dumpOnHandler(fd, pw1, args), pw, "", 1000); DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> dumpOnHandler(fd, pw1, args), pw, "", 1000); Loading Loading @@ -1409,9 +1440,14 @@ public class DreamService extends Service implements Window.Callback { @Nullable @Nullable public final Drawable previewImage; 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.settingsActivity = settingsActivity; this.previewImage = previewImage; this.previewImage = previewImage; this.showComplications = showComplications; } } } } } } services/tests/servicestests/res/xml/test_dream_metadata.xml +2 −1 Original line number Original line Diff line number Diff line Loading @@ -15,4 +15,5 @@ --> --> <dream xmlns:android="http://schemas.android.com/apk/res/android" <dream xmlns:android="http://schemas.android.com/apk/res/android" android:settingsActivity="com.android.server.dreams/.TestDreamSettingsActivity" /> android:settingsActivity="com.android.server.dreams/.TestDreamSettingsActivity" android:showClockAndComplications="false" /> services/tests/servicestests/src/com/android/server/dreams/DreamServiceTest.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.dreams; package com.android.server.dreams; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import android.content.ComponentName; import android.content.ComponentName; import android.content.Context; import android.content.Context; Loading Loading @@ -49,6 +50,7 @@ public class DreamServiceTest { assertEquals(0, metadata.settingsActivity.compareTo( assertEquals(0, metadata.settingsActivity.compareTo( ComponentName.unflattenFromString(testSettingsActivity))); ComponentName.unflattenFromString(testSettingsActivity))); assertFalse(metadata.showComplications); } catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); e.printStackTrace(); } } Loading Loading
core/java/android/service/dreams/DreamService.java +40 −4 Original line number Original line Diff line number Diff line Loading @@ -65,6 +65,7 @@ import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent; import com.android.internal.R; import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser; Loading Loading @@ -257,13 +258,16 @@ public class DreamService extends Service implements Window.Callback { mRequests = new ArrayDeque<>(); mRequests = new ArrayDeque<>(); } } public void bind(Context context, @Nullable ComponentName overlayService) { public void bind(Context context, @Nullable ComponentName overlayService, ComponentName dreamService) { if (overlayService == null) { if (overlayService == null) { return; return; } } final Intent overlayIntent = new Intent(); final Intent overlayIntent = new Intent(); overlayIntent.setComponent(overlayService); overlayIntent.setComponent(overlayService); overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS, fetchShouldShowComplications(context, dreamService)); context.bindService(overlayIntent, context.bindService(overlayIntent, this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE); this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE); Loading Loading @@ -985,7 +989,8 @@ public class DreamService extends Service implements Window.Callback { // Connect to the overlay service if present. // Connect to the overlay service if present. if (!mWindowless) { 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; return mDreamServiceWrapper; Loading Loading @@ -1117,7 +1122,9 @@ public class DreamService extends Service implements Window.Callback { convertToComponentName(rawMetadata.getString( convertToComponentName(rawMetadata.getString( com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo), com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo), rawMetadata.getDrawable( 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(); rawMetadata.recycle(); return metadata; return metadata; } } Loading Loading @@ -1336,6 +1343,30 @@ public class DreamService extends Service implements Window.Callback { return (oldFlags&~mask) | (flags&mask); 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 @Override protected void dump(final FileDescriptor fd, PrintWriter pw, final String[] args) { protected void dump(final FileDescriptor fd, PrintWriter pw, final String[] args) { DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> dumpOnHandler(fd, pw1, args), pw, "", 1000); DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> dumpOnHandler(fd, pw1, args), pw, "", 1000); Loading Loading @@ -1409,9 +1440,14 @@ public class DreamService extends Service implements Window.Callback { @Nullable @Nullable public final Drawable previewImage; 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.settingsActivity = settingsActivity; this.previewImage = previewImage; this.previewImage = previewImage; this.showComplications = showComplications; } } } } } }
services/tests/servicestests/res/xml/test_dream_metadata.xml +2 −1 Original line number Original line Diff line number Diff line Loading @@ -15,4 +15,5 @@ --> --> <dream xmlns:android="http://schemas.android.com/apk/res/android" <dream xmlns:android="http://schemas.android.com/apk/res/android" android:settingsActivity="com.android.server.dreams/.TestDreamSettingsActivity" /> android:settingsActivity="com.android.server.dreams/.TestDreamSettingsActivity" android:showClockAndComplications="false" />
services/tests/servicestests/src/com/android/server/dreams/DreamServiceTest.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.dreams; package com.android.server.dreams; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import android.content.ComponentName; import android.content.ComponentName; import android.content.Context; import android.content.Context; Loading Loading @@ -49,6 +50,7 @@ public class DreamServiceTest { assertEquals(0, metadata.settingsActivity.compareTo( assertEquals(0, metadata.settingsActivity.compareTo( ComponentName.unflattenFromString(testSettingsActivity))); ComponentName.unflattenFromString(testSettingsActivity))); assertFalse(metadata.showComplications); } catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); e.printStackTrace(); } } Loading