Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e676a22 authored by Jason Monk's avatar Jason Monk
Browse files

Add intent category for slices to help identify them

Test: cts, testMapIntentToSlice
Bug: 73123733
Change-Id: I75c3e132861d04301f5c856c235eadfc4be8f9bc
parent 0b4626aa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7270,6 +7270,7 @@ package android.app.slice {
    method public android.net.Uri mapIntentToUri(android.content.Intent);
    method public void pinSlice(android.net.Uri, java.util.List<android.app.slice.SliceSpec>);
    method public void unpinSlice(android.net.Uri);
    field public static final java.lang.String CATEGORY_SLICE = "android.app.slice.category.SLICE";
    field public static final java.lang.String SLICE_METADATA_KEY = "android.metadata.SLICE_URI";
  }
+31 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.app.slice;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemService;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
@@ -59,6 +61,18 @@ public class SliceManager {
    public static final String ACTION_REQUEST_SLICE_PERMISSION =
            "android.intent.action.REQUEST_SLICE_PERMISSION";

    /**
     * Category used to resolve intents that can be rendered as slices.
     * <p>
     * This category should be included on intent filters on providers that extend
     * {@link SliceProvider}.
     * @see SliceProvider
     * @see SliceProvider#onMapIntentToUri(Intent)
     * @see #mapIntentToUri(Intent)
     */
    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
    public static final String CATEGORY_SLICE = "android.app.slice.category.SLICE";

    /**
     * The meta-data key that allows an activity to easily be linked directly to a slice.
     * <p>
@@ -226,6 +240,18 @@ public class SliceManager {

    /**
     * Turns a slice intent into a slice uri. Expects an explicit intent.
     * <p>
     * This goes through a several stage resolution process to determine if any slice
     * can represent this intent.
     *  - If the intent contains data that {@link ContentResolver#getType} is
     *  {@link SliceProvider#SLICE_TYPE} then the data will be returned.
     *  - If the intent with {@link #CATEGORY_SLICE} added resolves to a provider, then
     *  the provider will be asked to {@link SliceProvider#onMapIntentToUri} and that result
     *  will be returned.
     *  - Lastly, if the intent explicitly points at an activity, and that activity has
     *  meta-data for key {@link #SLICE_METADATA_KEY}, then the Uri specified there will be
     *  returned.
     *  - If no slice is found, then {@code null} is returned.
     *
     * @param intent The intent associated with a slice.
     * @return The Slice Uri provided by the app or null if none exists.
@@ -245,8 +271,12 @@ public class SliceManager {
            return intentData;
        }
        // Otherwise ask the app
        Intent queryIntent = new Intent(intent);
        if (!queryIntent.hasCategory(CATEGORY_SLICE)) {
            queryIntent.addCategory(CATEGORY_SLICE);
        }
        List<ResolveInfo> providers =
                mContext.getPackageManager().queryIntentContentProviders(intent, 0);
                mContext.getPackageManager().queryIntentContentProviders(queryIntent, 0);
        if (providers == null || providers.isEmpty()) {
            // There are no providers, see if this activity has a direct link.
            ResolveInfo resolve = mContext.getPackageManager().resolveActivity(intent,
+7 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import java.util.concurrent.CountDownLatch;
 *     android:authorities="com.example.mypkg">
 *     <intent-filter>
 *         <action android:name="com.example.mypkg.intent.action.MY_SLICE_INTENT" />
 *         <category android:name="android.app.slice.category.SLICE" />
 *     </intent-filter>
 * </provider>}
 * </pre>
@@ -253,8 +254,13 @@ public abstract class SliceProvider extends ContentProvider {
     * In that case, this method can be called and is expected to return a non-null Uri representing
     * a slice. Otherwise this will throw {@link UnsupportedOperationException}.
     *
     * Any intent filter added to a slice provider should also contain
     * {@link SliceManager#CATEGORY_SLICE}, because otherwise it will not be detected by
     * {@link SliceManager#mapIntentToUri(Intent)}.
     *
     * @return Uri representing the slice associated with the provided intent.
     * @see {@link Slice}
     * @see Slice
     * @see SliceManager#mapIntentToUri(Intent)
     */
    public @NonNull Uri onMapIntentToUri(Intent intent) {
        throw new UnsupportedOperationException(