diff --git a/api/current.txt b/api/current.txt index 1983fb483ecd5..2f0dfc0cce86e 100755 --- a/api/current.txt +++ b/api/current.txt @@ -1199,6 +1199,7 @@ package android { field public static final deprecated int selectedWeekBackgroundColor = 16843586; // 0x1010342 field public static final int sessionService = 16843837; // 0x101043d field public static final int settingsActivity = 16843301; // 0x1010225 + field public static final int settingsSliceUri = 16844179; // 0x1010593 field public static final int setupActivity = 16843766; // 0x10103f6 field public static final int shadowColor = 16843105; // 0x1010161 field public static final int shadowDx = 16843106; // 0x1010162 @@ -6320,6 +6321,7 @@ package android.app { method public android.content.pm.ServiceInfo getServiceInfo(); method public java.lang.String getServiceName(); method public java.lang.String getSettingsActivity(); + method public android.net.Uri getSettingsSliceUri(); method public boolean getShowMetadataInPreview(); method public java.lang.CharSequence loadAuthor(android.content.pm.PackageManager) throws android.content.res.Resources.NotFoundException; method public java.lang.CharSequence loadContextDescription(android.content.pm.PackageManager) throws android.content.res.Resources.NotFoundException; diff --git a/core/java/android/app/WallpaperInfo.java b/core/java/android/app/WallpaperInfo.java index 9873a8152b3fd..e33d1fed4b4c2 100644 --- a/core/java/android/app/WallpaperInfo.java +++ b/core/java/android/app/WallpaperInfo.java @@ -16,6 +16,7 @@ package android.app; +import android.app.slice.Slice; import android.content.ComponentName; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -77,6 +78,7 @@ public final class WallpaperInfo implements Parcelable { final int mContextDescriptionResource; final boolean mShowMetadataInPreview; final boolean mSupportsAmbientMode; + final String mSettingsSliceUri; /** * Constructor. @@ -118,7 +120,6 @@ public final class WallpaperInfo implements Parcelable { com.android.internal.R.styleable.Wallpaper); mSettingsActivityName = sa.getString( com.android.internal.R.styleable.Wallpaper_settingsActivity); - mThumbnailResource = sa.getResourceId( com.android.internal.R.styleable.Wallpaper_thumbnail, -1); @@ -140,6 +141,8 @@ public final class WallpaperInfo implements Parcelable { mSupportsAmbientMode = sa.getBoolean( com.android.internal.R.styleable.Wallpaper_supportsAmbientMode, false); + mSettingsSliceUri = sa.getString( + com.android.internal.R.styleable.Wallpaper_settingsSliceUri); sa.recycle(); } catch (NameNotFoundException e) { @@ -159,6 +162,7 @@ public final class WallpaperInfo implements Parcelable { mContextDescriptionResource = source.readInt(); mShowMetadataInPreview = source.readInt() != 0; mSupportsAmbientMode = source.readInt() != 0; + mSettingsSliceUri = source.readString(); mService = ResolveInfo.CREATOR.createFromParcel(source); } @@ -332,13 +336,28 @@ public final class WallpaperInfo implements Parcelable { * explicit {@link android.content.ComponentName} * composed of {@link #getPackageName} and the class name returned here. * - *

A null will be returned if there is no settings activity associated + *

{@code null} will be returned if there is no settings activity associated * with the wallpaper. */ public String getSettingsActivity() { return mSettingsActivityName; } + /** + * Returns an URI that provides a settings {@link Slice} for this wallpaper. + * + *

{@code null} will be returned if there is no settings Slice URI associated + * with the wallpaper. + * + * @return The URI. + */ + public Uri getSettingsSliceUri() { + if (mSettingsSliceUri == null) { + return null; + } + return Uri.parse(mSettingsSliceUri); + } + public void dump(Printer pw, String prefix) { pw.println(prefix + "Service:"); mService.dump(pw, prefix + " "); @@ -367,6 +386,7 @@ public final class WallpaperInfo implements Parcelable { dest.writeInt(mContextDescriptionResource); dest.writeInt(mShowMetadataInPreview ? 1 : 0); dest.writeInt(mSupportsAmbientMode ? 1 : 0); + dest.writeString(mSettingsSliceUri); mService.writeToParcel(dest, flags); } diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 9bedab53bb2c8..32cf2e8bac865 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -7894,6 +7894,9 @@ + + + \ No newline at end of file + android:settingsSliceUri="content://com.android.internal.tests/slice" + android:supportsAmbientMode="true"/> diff --git a/tests/Internal/src/android/app/WallpaperInfoTest.java b/tests/Internal/src/android/app/WallpaperInfoTest.java index 98045ae985416..7f06f2cb7aebe 100644 --- a/tests/Internal/src/android/app/WallpaperInfoTest.java +++ b/tests/Internal/src/android/app/WallpaperInfoTest.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.net.Uri; import android.os.Parcel; import android.service.wallpaper.WallpaperService; import android.support.test.InstrumentationRegistry; @@ -64,5 +65,31 @@ public class WallpaperInfoTest { fromParcel.supportsAmbientMode()); parcel.recycle(); } + + @Test + public void testGetSettingsSliceUri() throws Exception { + Context context = InstrumentationRegistry.getTargetContext(); + + Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); + intent.setPackage("com.android.internal.tests"); + PackageManager pm = context.getPackageManager(); + List result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); + assertEquals(1, result.size()); + ResolveInfo info = result.get(0); + WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); + + // This expected Uri must be the same as that in livewallpaper.xml + Uri expectedUri = Uri.parse("content://com.android.internal.tests/slice"); + Uri settingsUri = wallpaperInfo.getSettingsSliceUri(); + assertEquals("The loaded URI should equal to the string in livewallpaper.xml", + 0, expectedUri.compareTo(settingsUri)); + Parcel parcel = Parcel.obtain(); + wallpaperInfo.writeToParcel(parcel, 0 /* flags */); + parcel.setDataPosition(0); + WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); + assertEquals("settingsSliceUri should be restorable from parcelable", + 0, expectedUri.compareTo(fromParcel.getSettingsSliceUri())); + parcel.recycle(); + } }