diff options
| author | 2018-01-16 15:32:53 -0500 | |
|---|---|---|
| committer | 2018-01-16 17:12:06 -0500 | |
| commit | b9e06a8458487892758e5ef1d374182f9a6c6c46 (patch) | |
| tree | 3955374a93392f1bd4d83a3d4beb0ba512430643 | |
| parent | fb0152d494181b3b94e1ad0e4d540393e7d1607d (diff) | |
Update slice APIs
- Remove deprecated onBindSlice
- Move bindSlice to SliceManager since it exists.
Test: update-api
Bug: 68378571
Change-Id: I1bfde10b5da5f80d395c69a6408fa5b13cd113f0
| -rw-r--r-- | api/current.txt | 7 | ||||
| -rw-r--r-- | core/java/android/app/slice/Slice.java | 74 | ||||
| -rw-r--r-- | core/java/android/app/slice/SliceManager.java | 102 | ||||
| -rw-r--r-- | core/java/android/app/slice/SliceProvider.java | 8 |
4 files changed, 115 insertions, 76 deletions
diff --git a/api/current.txt b/api/current.txt index 567c162450bc..4b8c3ebc4b28 100644 --- a/api/current.txt +++ b/api/current.txt @@ -7066,8 +7066,8 @@ package android.app.slice { public final class Slice implements android.os.Parcelable { ctor protected Slice(android.os.Parcel); - method public static android.app.slice.Slice bindSlice(android.content.ContentResolver, android.net.Uri, java.util.List<android.app.slice.SliceSpec>); - method public static android.app.slice.Slice bindSlice(android.content.Context, android.content.Intent, java.util.List<android.app.slice.SliceSpec>); + method public static deprecated android.app.slice.Slice bindSlice(android.content.ContentResolver, android.net.Uri, java.util.List<android.app.slice.SliceSpec>); + method public static deprecated android.app.slice.Slice bindSlice(android.content.Context, android.content.Intent, java.util.List<android.app.slice.SliceSpec>); method public int describeContents(); method public java.util.List<java.lang.String> getHints(); method public java.util.List<android.app.slice.SliceItem> getItems(); @@ -7153,6 +7153,8 @@ package android.app.slice { } public class SliceManager { + method public android.app.slice.Slice bindSlice(android.net.Uri, java.util.List<android.app.slice.SliceSpec>); + method public android.app.slice.Slice bindSlice(android.content.Intent, java.util.List<android.app.slice.SliceSpec>); method public java.util.List<android.app.slice.SliceSpec> getPinnedSpecs(android.net.Uri); method public void pinSlice(android.net.Uri, java.util.List<android.app.slice.SliceSpec>); method public void registerSliceCallback(android.net.Uri, android.app.slice.SliceManager.SliceCallback, java.util.List<android.app.slice.SliceSpec>); @@ -7172,7 +7174,6 @@ package android.app.slice { method public final java.lang.String getType(android.net.Uri); method public final android.net.Uri insert(android.net.Uri, android.content.ContentValues); method public android.app.slice.Slice onBindSlice(android.net.Uri, java.util.List<android.app.slice.SliceSpec>); - method public deprecated android.app.slice.Slice onBindSlice(android.net.Uri); method public android.net.Uri onMapIntentToUri(android.content.Intent); method public void onSlicePinned(android.net.Uri); method public void onSliceUnpinned(android.net.Uri); diff --git a/core/java/android/app/slice/Slice.java b/core/java/android/app/slice/Slice.java index b8fb2e34d083..27cd6e56dc0c 100644 --- a/core/java/android/app/slice/Slice.java +++ b/core/java/android/app/slice/Slice.java @@ -21,12 +21,10 @@ import android.annotation.Nullable; import android.annotation.StringDef; import android.app.PendingIntent; import android.app.RemoteInput; -import android.content.ContentProvider; import android.content.ContentResolver; import android.content.Context; import android.content.IContentProvider; import android.content.Intent; -import android.content.pm.ResolveInfo; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Bundle; @@ -553,16 +551,11 @@ public final class Slice implements Parcelable { } /** - * Turns a slice Uri into slice content. - * - * @param resolver ContentResolver to be used. - * @param uri The URI to a slice provider - * @param supportedSpecs List of supported specs. - * @return The Slice provided by the app or null if none is given. - * @see Slice - */ - public static @Nullable Slice bindSlice(ContentResolver resolver, @NonNull Uri uri, - List<SliceSpec> supportedSpecs) { + * @deprecated TO BE REMOVED. + */ + @Deprecated + public static @Nullable Slice bindSlice(ContentResolver resolver, + @NonNull Uri uri, @NonNull List<SliceSpec> supportedSpecs) { Preconditions.checkNotNull(uri, "uri"); IContentProvider provider = resolver.acquireProvider(uri); if (provider == null) { @@ -590,60 +583,11 @@ public final class Slice implements Parcelable { } /** - * Turns a slice intent into slice content. Expects an explicit intent. If there is no - * {@link ContentProvider} associated with the given intent this will throw - * {@link IllegalArgumentException}. - * - * @param context The context to use. - * @param intent The intent associated with a slice. - * @param supportedSpecs List of supported specs. - * @return The Slice provided by the app or null if none is given. - * @see Slice - * @see SliceProvider#onMapIntentToUri(Intent) - * @see Intent + * @deprecated TO BE REMOVED. */ + @Deprecated public static @Nullable Slice bindSlice(Context context, @NonNull Intent intent, - List<SliceSpec> supportedSpecs) { - Preconditions.checkNotNull(intent, "intent"); - Preconditions.checkArgument(intent.getComponent() != null || intent.getPackage() != null, - "Slice intent must be explicit " + intent); - ContentResolver resolver = context.getContentResolver(); - - // Check if the intent has data for the slice uri on it and use that - final Uri intentData = intent.getData(); - if (intentData != null && SliceProvider.SLICE_TYPE.equals(resolver.getType(intentData))) { - return bindSlice(resolver, intentData, supportedSpecs); - } - // Otherwise ask the app - List<ResolveInfo> providers = - context.getPackageManager().queryIntentContentProviders(intent, 0); - if (providers == null) { - throw new IllegalArgumentException("Unable to resolve intent " + intent); - } - String authority = providers.get(0).providerInfo.authority; - Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) - .authority(authority).build(); - IContentProvider provider = resolver.acquireProvider(uri); - if (provider == null) { - throw new IllegalArgumentException("Unknown URI " + uri); - } - try { - Bundle extras = new Bundle(); - extras.putParcelable(SliceProvider.EXTRA_INTENT, intent); - extras.putParcelableArrayList(SliceProvider.EXTRA_SUPPORTED_SPECS, - new ArrayList<>(supportedSpecs)); - final Bundle res = provider.call(resolver.getPackageName(), - SliceProvider.METHOD_MAP_INTENT, null, extras); - if (res == null) { - return null; - } - return res.getParcelable(SliceProvider.EXTRA_SLICE); - } catch (RemoteException e) { - // Arbitrary and not worth documenting, as Activity - // Manager will kill this process shortly anyway. - return null; - } finally { - resolver.releaseProvider(provider); - } + @NonNull List<SliceSpec> supportedSpecs) { + return context.getSystemService(SliceManager.class).bindSlice(intent, supportedSpecs); } } diff --git a/core/java/android/app/slice/SliceManager.java b/core/java/android/app/slice/SliceManager.java index 0c5f225d515e..0e7c64f07245 100644 --- a/core/java/android/app/slice/SliceManager.java +++ b/core/java/android/app/slice/SliceManager.java @@ -17,9 +17,15 @@ package android.app.slice; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.SystemService; +import android.content.ContentResolver; import android.content.Context; +import android.content.IContentProvider; +import android.content.Intent; +import android.content.pm.ResolveInfo; import android.net.Uri; +import android.os.Bundle; import android.os.Handler; import android.os.RemoteException; import android.os.ServiceManager; @@ -27,6 +33,9 @@ import android.os.ServiceManager.ServiceNotFoundException; import android.util.ArrayMap; import android.util.Pair; +import com.android.internal.util.Preconditions; + +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; @@ -224,6 +233,99 @@ public class SliceManager { } /** + * Turns a slice Uri into slice content. + * + * @param uri The URI to a slice provider + * @param supportedSpecs List of supported specs. + * @return The Slice provided by the app or null if none is given. + * @see Slice + */ + public @Nullable Slice bindSlice(@NonNull Uri uri, @NonNull List<SliceSpec> supportedSpecs) { + Preconditions.checkNotNull(uri, "uri"); + ContentResolver resolver = mContext.getContentResolver(); + IContentProvider provider = resolver.acquireProvider(uri); + if (provider == null) { + throw new IllegalArgumentException("Unknown URI " + uri); + } + try { + Bundle extras = new Bundle(); + extras.putParcelable(SliceProvider.EXTRA_BIND_URI, uri); + extras.putParcelableArrayList(SliceProvider.EXTRA_SUPPORTED_SPECS, + new ArrayList<>(supportedSpecs)); + final Bundle res = provider.call(resolver.getPackageName(), SliceProvider.METHOD_SLICE, + null, extras); + Bundle.setDefusable(res, true); + if (res == null) { + return null; + } + return res.getParcelable(SliceProvider.EXTRA_SLICE); + } catch (RemoteException e) { + // Arbitrary and not worth documenting, as Activity + // Manager will kill this process shortly anyway. + return null; + } finally { + resolver.releaseProvider(provider); + } + } + + /** + * Turns a slice intent into slice content. Expects an explicit intent. If there is no + * {@link android.content.ContentProvider} associated with the given intent this will throw + * {@link IllegalArgumentException}. + * + * @param intent The intent associated with a slice. + * @param supportedSpecs List of supported specs. + * @return The Slice provided by the app or null if none is given. + * @see Slice + * @see SliceProvider#onMapIntentToUri(Intent) + * @see Intent + */ + public @Nullable Slice bindSlice(@NonNull Intent intent, + @NonNull List<SliceSpec> supportedSpecs) { + Preconditions.checkNotNull(intent, "intent"); + Preconditions.checkArgument(intent.getComponent() != null || intent.getPackage() != null, + "Slice intent must be explicit " + intent); + ContentResolver resolver = mContext.getContentResolver(); + + // Check if the intent has data for the slice uri on it and use that + final Uri intentData = intent.getData(); + if (intentData != null && SliceProvider.SLICE_TYPE.equals(resolver.getType(intentData))) { + return bindSlice(intentData, supportedSpecs); + } + // Otherwise ask the app + List<ResolveInfo> providers = + mContext.getPackageManager().queryIntentContentProviders(intent, 0); + if (providers == null) { + throw new IllegalArgumentException("Unable to resolve intent " + intent); + } + String authority = providers.get(0).providerInfo.authority; + Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) + .authority(authority).build(); + IContentProvider provider = resolver.acquireProvider(uri); + if (provider == null) { + throw new IllegalArgumentException("Unknown URI " + uri); + } + try { + Bundle extras = new Bundle(); + extras.putParcelable(SliceProvider.EXTRA_INTENT, intent); + extras.putParcelableArrayList(SliceProvider.EXTRA_SUPPORTED_SPECS, + new ArrayList<>(supportedSpecs)); + final Bundle res = provider.call(resolver.getPackageName(), + SliceProvider.METHOD_MAP_INTENT, null, extras); + if (res == null) { + return null; + } + return res.getParcelable(SliceProvider.EXTRA_SLICE); + } catch (RemoteException e) { + // Arbitrary and not worth documenting, as Activity + // Manager will kill this process shortly anyway. + return null; + } finally { + resolver.releaseProvider(provider); + } + } + + /** * Class that listens to changes in {@link Slice}s. */ public interface SliceCallback { diff --git a/core/java/android/app/slice/SliceProvider.java b/core/java/android/app/slice/SliceProvider.java index 8483931ceaec..06614b5ecbfe 100644 --- a/core/java/android/app/slice/SliceProvider.java +++ b/core/java/android/app/slice/SliceProvider.java @@ -139,14 +139,6 @@ public abstract class SliceProvider extends ContentProvider { * @see {@link Slice#HINT_PARTIAL} */ public Slice onBindSlice(Uri sliceUri, List<SliceSpec> supportedSpecs) { - return onBindSlice(sliceUri); - } - - /** - * @deprecated migrating to {@link #onBindSlice(Uri, List)} - */ - @Deprecated - public Slice onBindSlice(Uri sliceUri) { return null; } |