summaryrefslogtreecommitdiffstats
path: root/core/java/android/service
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2015-07-15 20:14:57 -0700
committerAdam Powell <adamp@google.com>2015-07-16 16:29:59 -0700
commit666d82a6d5c6a90e87591aea1aabac3d647cd541 (patch)
tree1ed5786f84c0ee6fc6695c6e81f58684cd14cede /core/java/android/service
parent5aff3b5489262ccff4b6f9e18e0d990ebfe4d7bc (diff)
downloadframeworks_base-666d82a6d5c6a90e87591aea1aabac3d647cd541.zip
frameworks_base-666d82a6d5c6a90e87591aea1aabac3d647cd541.tar.gz
frameworks_base-666d82a6d5c6a90e87591aea1aabac3d647cd541.tar.bz2
Update ChooserTarget constructor to take ComponentName, Bundle
Simplify ChooserTarget handling by requiring a target component and an extras bundle instead of a full PendingIntent/IntentSender. This simplifies the handling of URI grants from sending apps. Prune ChooserTargets that point at ComponentNames that don't share a package with the original matching Activity target or that aren't exported so that we don't show the user something they can't launch. Bug 22516282 Change-Id: I3439c0910b4fa4f95c7a881b529942c96ffc953e
Diffstat (limited to 'core/java/android/service')
-rw-r--r--core/java/android/service/chooser/ChooserTarget.java128
-rw-r--r--core/java/android/service/chooser/ChooserTargetService.java5
-rw-r--r--core/java/android/service/chooser/IChooserTargetResult.aidl2
3 files changed, 39 insertions, 96 deletions
diff --git a/core/java/android/service/chooser/ChooserTarget.java b/core/java/android/service/chooser/ChooserTarget.java
index 50c435a..c2f70cc 100644
--- a/core/java/android/service/chooser/ChooserTarget.java
+++ b/core/java/android/service/chooser/ChooserTarget.java
@@ -17,20 +17,14 @@
package android.service.chooser;
-import android.app.Activity;
-import android.app.PendingIntent;
+import android.annotation.Nullable;
import android.content.ComponentName;
-import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.IntentSender;
-import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
-import android.os.UserHandle;
-import android.util.Log;
/**
* A ChooserTarget represents a deep-link into an application as returned by a
@@ -62,52 +56,21 @@ public final class ChooserTarget implements Parcelable {
private Icon mIcon;
/**
- * The IntentSender that will be used to deliver the intent to the target.
- * It will be {@link android.content.Intent#fillIn(android.content.Intent, int)} filled in}
- * by the real intent sent by the application.
+ * The ComponentName of the Activity to be invoked. Must be part of the target creator's
+ * own package or an Activity exported by its package.
*/
- private IntentSender mIntentSender;
+ private ComponentName mComponentName;
/**
- * The score given to this item. It can be normalized.
+ * A Bundle to merge with the extras of the intent sent to this target.
+ * Any extras here will override the extras from the original intent.
*/
- private float mScore;
+ private Bundle mIntentExtras;
/**
- * Construct a deep link target for presentation by a chooser UI.
- *
- * <p>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.</p>
- *
- * <p>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.</p>
- *
- * <p>Before being sent, the PendingIntent supplied will be
- * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied
- * to the chooser. When constructing a PendingIntent for use in a ChooserTarget, make sure
- * that you permit the relevant fields to be filled in using the appropriate flags such as
- * {@link Intent#FILL_IN_ACTION}, {@link Intent#FILL_IN_CATEGORIES},
- * {@link Intent#FILL_IN_DATA} and {@link Intent#FILL_IN_CLIP_DATA}. Note that
- * {@link Intent#FILL_IN_CLIP_DATA} is required to appropriately receive URI permission grants
- * for {@link Intent#ACTION_SEND} intents.</p>
- *
- * <p>Take care not to place custom {@link android.os.Parcelable} types into
- * the PendingIntent as extras, as the system will not be able to unparcel it to merge
- * additional extras.</p>
- *
- * @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 pendingIntent PendingIntent to fill in and send if the user chooses this target
+ * The score given to this item. It can be normalized.
*/
- public ChooserTarget(CharSequence title, Icon icon, float score,
- PendingIntent pendingIntent) {
- this(title, icon, score, pendingIntent.getIntentSender());
- }
+ private float mScore;
/**
* Construct a deep link target for presentation by a chooser UI.
@@ -122,25 +85,23 @@ public final class ChooserTarget implements Parcelable {
* 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.</p>
*
- * <p>Before being sent, the IntentSender supplied will be
- * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied
- * to the chooser. When constructing an IntentSender for use in a ChooserTarget, make sure
- * that you permit the relevant fields to be filled in using the appropriate flags such as
- * {@link Intent#FILL_IN_ACTION}, {@link Intent#FILL_IN_CATEGORIES},
- * {@link Intent#FILL_IN_DATA} and {@link Intent#FILL_IN_CLIP_DATA}. Note that
- * {@link Intent#FILL_IN_CLIP_DATA} is required to appropriately receive URI permission grants
- * for {@link Intent#ACTION_SEND} intents.</p>
+ * <p>The ComponentName must be the name of an Activity component in the creator's own
+ * package, or an exported component from any other package. You may provide an optional
+ * Bundle of extras that will be merged into the final intent before it is sent to the
+ * target Activity; use this to add any additional data about the deep link that the target
+ * activity will read. e.g. conversation IDs, email addresses, etc.</p>
*
* <p>Take care not to place custom {@link android.os.Parcelable} types into
- * the IntentSender as extras, as the system will not be able to unparcel it to merge
- * additional extras.</p>
+ * the extras bundle, as the system will not be able to unparcel them to merge them.</p>
*
* @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 intentSender IntentSender to fill in and send if the user chooses this target
+ * @param componentName Name of the component to be launched if this target is chosen
+ * @param intentExtras Bundle of extras to merge with the extras of the launched intent
*/
- public ChooserTarget(CharSequence title, Icon icon, float score, IntentSender intentSender) {
+ public ChooserTarget(CharSequence title, Icon icon, float score,
+ ComponentName componentName, @Nullable Bundle intentExtras) {
mTitle = title;
mIcon = icon;
if (score > 1.f || score < 0.f) {
@@ -148,7 +109,8 @@ public final class ChooserTarget implements Parcelable {
+ "must be between 0.0f and 1.0f");
}
mScore = score;
- mIntentSender = intentSender;
+ mComponentName = componentName;
+ mIntentExtras = intentExtras;
}
ChooserTarget(Parcel in) {
@@ -159,7 +121,8 @@ public final class ChooserTarget implements Parcelable {
mIcon = null;
}
mScore = in.readFloat();
- mIntentSender = IntentSender.readIntentSenderOrNullFromParcel(in);
+ mComponentName = ComponentName.readFromParcel(in);
+ mIntentExtras = in.readBundle();
}
/**
@@ -194,49 +157,29 @@ public final class ChooserTarget implements Parcelable {
}
/**
- * Returns the raw IntentSender supplied by the ChooserTarget's creator.
- * This may be null if the creator specified a regular Intent instead.
- *
- * <p>To fill in and send the intent, see {@link #sendIntent(Context, Intent)}.</p>
+ * Returns the ComponentName of the Activity that should be launched for this ChooserTarget.
*
- * @return the IntentSender supplied by the ChooserTarget's creator
+ * @return the name of the target Activity to launch
*/
- public IntentSender getIntentSender() {
- return mIntentSender;
+ public ComponentName getComponentName() {
+ return mComponentName;
}
/**
- * Fill in the IntentSender supplied by the ChooserTarget's creator and send it.
+ * Returns the Bundle of extras to be added to an intent launched to this target.
*
- * @param context the sending Context; generally the Activity presenting the chooser UI
- * @param fillInIntent the Intent provided to the Chooser to be sent to a selected target
- * @return true if sending the Intent was successful
+ * @return the extras to merge with the extras of the intent being launched
*/
- public boolean sendIntent(Context context, Intent fillInIntent) {
- if (fillInIntent != null) {
- fillInIntent.migrateExtraStreamToClipData();
- fillInIntent.prepareToLeaveProcess();
- }
- if (mIntentSender != null) {
- try {
- mIntentSender.sendIntent(context, 0, fillInIntent, null, null);
- return true;
- } catch (IntentSender.SendIntentException e) {
- Log.e(TAG, "sendIntent " + this + " failed", e);
- return false;
- }
- } else {
- Log.e(TAG, "sendIntent " + this + " failed - no IntentSender to send");
- return false;
- }
+ public Bundle getIntentExtras() {
+ return mIntentExtras;
}
@Override
public String toString() {
return "ChooserTarget{"
- + (mIntentSender != null ? mIntentSender.getCreatorPackage() : null)
- + ", "
- + "'" + mTitle
+ + mComponentName
+ + ", " + mIntentExtras
+ + ", '" + mTitle
+ "', " + mScore + "}";
}
@@ -255,7 +198,8 @@ public final class ChooserTarget implements Parcelable {
dest.writeInt(0);
}
dest.writeFloat(mScore);
- IntentSender.writeIntentSenderOrNullToParcel(mIntentSender, dest);
+ ComponentName.writeToParcel(mComponentName, dest);
+ dest.writeBundle(mIntentExtras);
}
public static final Creator<ChooserTarget> CREATOR
diff --git a/core/java/android/service/chooser/ChooserTargetService.java b/core/java/android/service/chooser/ChooserTargetService.java
index a3bfece..e054185 100644
--- a/core/java/android/service/chooser/ChooserTargetService.java
+++ b/core/java/android/service/chooser/ChooserTargetService.java
@@ -105,9 +105,8 @@ public abstract class ChooserTargetService extends Service {
* can handle an intent.
*
* <p>The returned list should be sorted such that the most relevant targets appear first.
- * Any PendingIntents used to construct the resulting ChooserTargets should always be prepared
- * to have the relevant data fields filled in by the sender. See
- * {@link ChooserTarget#ChooserTarget(CharSequence, android.graphics.drawable.Icon, float, android.app.PendingIntent) ChooserTarget}.</p>
+ * The score for each ChooserTarget will be combined with the system's score for the original
+ * target Activity to sort and filter targets presented to the user.</p>
*
* <p><em>Important:</em> Calls to this method from other applications will occur on
* a binder thread, not on your app's main thread. Make sure that access to relevant data
diff --git a/core/java/android/service/chooser/IChooserTargetResult.aidl b/core/java/android/service/chooser/IChooserTargetResult.aidl
index dbd7cbd..6c648a2 100644
--- a/core/java/android/service/chooser/IChooserTargetResult.aidl
+++ b/core/java/android/service/chooser/IChooserTargetResult.aidl
@@ -21,7 +21,7 @@ import android.service.chooser.ChooserTarget;
/**
* @hide
*/
-interface IChooserTargetResult
+oneway interface IChooserTargetResult
{
void sendResult(in List<ChooserTarget> targets);
}