From c6d5e3a406c0e80638304980bac13abaa703a9a0 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Thu, 23 Apr 2015 12:22:20 -0700 Subject: Fixes for ChooserTargetActivity * Always ensure intent filter is supplied to a ChooserTargetService. * Add and clarify docs for ChooserTarget constructors. * Fix a bug where ChooserTargets were being parceled incorrectly. Change-Id: I32b70c424b0e6bb317e2eeb810566a30c21b9d53 --- .../android/service/chooser/ChooserTarget.java | 36 ++++++++++++++++++++-- .../com/android/internal/app/ChooserActivity.java | 5 +++ .../com/android/internal/app/ResolverActivity.java | 6 +++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/core/java/android/service/chooser/ChooserTarget.java b/core/java/android/service/chooser/ChooserTarget.java index d21cc3c81be5..f0ca276f11f2 100644 --- a/core/java/android/service/chooser/ChooserTarget.java +++ b/core/java/android/service/chooser/ChooserTarget.java @@ -78,7 +78,8 @@ public final class ChooserTarget implements Parcelable { *

The creator of a target may supply a ranking score. This score is assumed to be relative * to the other targets supplied by the same * {@link ChooserTargetService#onGetChooserTargets(ComponentName, IntentFilter) query}. - * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).

+ * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match). + * Scores for a set of targets do not need to sum to 1.

* *

Before being sent, the PendingIntent supplied will be * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied @@ -113,7 +114,8 @@ public final class ChooserTarget implements Parcelable { *

The creator of a target may supply a ranking score. This score is assumed to be relative * to the other targets supplied by the same * {@link ChooserTargetService#onGetChooserTargets(ComponentName, IntentFilter) query}. - * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).

+ * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match). + * Scores for a set of targets do not need to sum to 1.

* *

Before being sent, the IntentSender supplied will be * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied @@ -144,6 +146,32 @@ public final class ChooserTarget implements Parcelable { mIntentSender = intentSender; } + /** + * Construct a deep link target for presentation by a chooser UI. + * + *

A target is composed of a title and an icon for presentation to the user. + * The UI presenting this target may truncate the title if it is too long to be presented + * in the available space, as well as crop, resize or overlay the supplied icon.

+ * + *

The creator of a target may supply a ranking score. This score is assumed to be relative + * to the other targets supplied by the same + * {@link ChooserTargetService#onGetChooserTargets(ComponentName, IntentFilter) query}. + * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match). + * Scores for a set of targets do not need to sum to 1.

+ * + *

Before being sent, the Intent supplied will be + * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied + * to the chooser.

+ * + *

Take care not to place custom {@link android.os.Parcelable} types into + * the Intent as extras, as the system will not be able to unparcel it to merge + * additional extras.

+ * + * @param title title of this target that will be shown to a user + * @param icon icon to represent this target + * @param score ranking score for this target between 0.0f and 1.0f, inclusive + * @param intent Intent to fill in and send if the user chooses this target + */ public ChooserTarget(CharSequence title, Bitmap icon, float score, Intent intent) { mTitle = title; mIcon = icon; @@ -358,6 +386,10 @@ public final class ChooserTarget implements Parcelable { } dest.writeFloat(mScore); IntentSender.writeIntentSenderOrNullToParcel(mIntentSender, dest); + dest.writeInt(mIntent != null ? 1 : 0); + if (mIntent != null) { + mIntent.writeToParcel(dest, 0); + } } public static final Creator CREATOR diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 8403e77f7368..a6c39e60be03 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -400,6 +400,11 @@ public class ChooserActivity extends ResolverActivity { } } + @Override + public boolean shouldGetResolvedFilter() { + return true; + } + @Override public int getCount() { int count = super.getCount(); diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 3cd69a136920..7f51d9267906 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -1062,7 +1062,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } else { currentResolveList = mOrigResolveList = mPm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY - | (mFilterLastUsed ? PackageManager.GET_RESOLVED_FILTER : 0) + | (shouldGetResolvedFilter() ? PackageManager.GET_RESOLVED_FILTER : 0) | (shouldGetActivityMetadata() ? PackageManager.GET_META_DATA : 0) ); // Filter out any activities that the launched uid does not @@ -1188,6 +1188,10 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic // This space for rent } + public boolean shouldGetResolvedFilter() { + return mFilterLastUsed; + } + private void processGroup(List rList, int start, int end, ResolveInfo ro, CharSequence roLabel) { // Process labels from start to i -- cgit v1.2.3-59-g8ed1b