Add ChooserTargetService API

A ChooserTargetService can be implemented by apps that wish to offer
additional deep-link targets for the system intent chooser to in turn
offer to the user. This allows apps to create contextually relevant
shortcuts for UI flows that would otherwise require several steps of
explicit disambiguation. For example, a chat app might offer one-touch
access to recent conversations when sharing a photo to it from
elsewhere.

The chooser implementation must limit the number of
ChooserTargetServices it elects to query in order to respect available
system resources. Only the system chooser is permitted to bind to a
ChooserTargetService.

Change-Id: Ia7e075ee649c51cf2035f20aee166c5a27d91aeb
diff --git a/Android.mk b/Android.mk
index f3f1acb..545c6ef 100644
--- a/Android.mk
+++ b/Android.mk
@@ -238,6 +238,8 @@
 	core/java/android/service/wallpaper/IWallpaperConnection.aidl \
 	core/java/android/service/wallpaper/IWallpaperEngine.aidl \
 	core/java/android/service/wallpaper/IWallpaperService.aidl \
+	core/java/android/service/chooser/IChooserTargetService.aidl \
+	core/java/android/service/chooser/IChooserTargetResult.aidl \
 	core/java/android/view/accessibility/IAccessibilityInteractionConnection.aidl\
 	core/java/android/view/accessibility/IAccessibilityInteractionConnectionCallback.aidl\
 	core/java/android/view/accessibility/IAccessibilityManager.aidl \
@@ -545,6 +547,7 @@
 	frameworks/base/core/java/android/view/textservice/SuggestionsInfo.aidl \
 	frameworks/base/core/java/android/service/carrier/MessagePdu.aidl \
 	frameworks/base/core/java/android/service/notification/StatusBarNotification.aidl \
+	frameworks/base/core/java/android/service/chooser/ChooserTarget.aidl \
 	frameworks/base/core/java/android/speech/tts/Voice.aidl \
 	frameworks/base/core/java/android/app/usage/UsageEvents.aidl \
 	frameworks/base/core/java/android/app/Notification.aidl \
diff --git a/api/current.txt b/api/current.txt
index 163e9d0..0f527c7 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -21,6 +21,7 @@
     field public static final java.lang.String BIND_ACCESSIBILITY_SERVICE = "android.permission.BIND_ACCESSIBILITY_SERVICE";
     field public static final java.lang.String BIND_APPWIDGET = "android.permission.BIND_APPWIDGET";
     field public static final java.lang.String BIND_CARRIER_MESSAGING_SERVICE = "android.permission.BIND_CARRIER_MESSAGING_SERVICE";
+    field public static final java.lang.String BIND_CHOOSER_TARGET_SERVICE = "android.permission.BIND_CHOOSER_TARGET_SERVICE";
     field public static final java.lang.String BIND_DEVICE_ADMIN = "android.permission.BIND_DEVICE_ADMIN";
     field public static final java.lang.String BIND_DREAM_SERVICE = "android.permission.BIND_DREAM_SERVICE";
     field public static final java.lang.String BIND_INPUT_METHOD = "android.permission.BIND_INPUT_METHOD";
@@ -27460,6 +27461,30 @@
 
 }
 
+package android.service.chooser {
+
+  public final class ChooserTarget implements android.os.Parcelable {
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.app.PendingIntent);
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.content.IntentSender);
+    method public int describeContents();
+    method public android.graphics.Bitmap getIcon();
+    method public android.content.IntentSender getIntentSender();
+    method public float getScore();
+    method public java.lang.CharSequence getTitle();
+    method public boolean sendIntent(android.content.Context, android.content.Intent);
+    method public void writeToParcel(android.os.Parcel, int);
+    field public static final android.os.Parcelable.Creator<android.service.chooser.ChooserTarget> CREATOR;
+  }
+
+  public abstract class ChooserTargetService extends android.app.Service {
+    ctor public ChooserTargetService();
+    method public android.os.IBinder onBind(android.content.Intent);
+    method public abstract java.util.List<android.service.chooser.ChooserTarget> onGetChooserTargets(android.content.ComponentName, android.content.IntentFilter);
+    field public static final java.lang.String SERVICE_INTERFACE = "android.service.chooser.ChooserTargetService";
+  }
+
+}
+
 package android.service.dreams {
 
   public class DreamService extends android.app.Service implements android.view.Window.Callback {
diff --git a/api/system-current.txt b/api/system-current.txt
index 8a9259f..099081b 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -29,6 +29,7 @@
     field public static final java.lang.String BIND_ACCESSIBILITY_SERVICE = "android.permission.BIND_ACCESSIBILITY_SERVICE";
     field public static final java.lang.String BIND_APPWIDGET = "android.permission.BIND_APPWIDGET";
     field public static final java.lang.String BIND_CARRIER_MESSAGING_SERVICE = "android.permission.BIND_CARRIER_MESSAGING_SERVICE";
+    field public static final java.lang.String BIND_CHOOSER_TARGET_SERVICE = "android.permission.BIND_CHOOSER_TARGET_SERVICE";
     field public static final java.lang.String BIND_CONDITION_PROVIDER_SERVICE = "android.permission.BIND_CONDITION_PROVIDER_SERVICE";
     field public static final java.lang.String BIND_CONNECTION_SERVICE = "android.permission.BIND_CONNECTION_SERVICE";
     field public static final java.lang.String BIND_DEVICE_ADMIN = "android.permission.BIND_DEVICE_ADMIN";
@@ -29061,6 +29062,30 @@
 
 }
 
+package android.service.chooser {
+
+  public final class ChooserTarget implements android.os.Parcelable {
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.app.PendingIntent);
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.content.IntentSender);
+    method public int describeContents();
+    method public android.graphics.Bitmap getIcon();
+    method public android.content.IntentSender getIntentSender();
+    method public float getScore();
+    method public java.lang.CharSequence getTitle();
+    method public boolean sendIntent(android.content.Context, android.content.Intent);
+    method public void writeToParcel(android.os.Parcel, int);
+    field public static final android.os.Parcelable.Creator<android.service.chooser.ChooserTarget> CREATOR;
+  }
+
+  public abstract class ChooserTargetService extends android.app.Service {
+    ctor public ChooserTargetService();
+    method public android.os.IBinder onBind(android.content.Intent);
+    method public abstract java.util.List<android.service.chooser.ChooserTarget> onGetChooserTargets(android.content.ComponentName, android.content.IntentFilter);
+    field public static final java.lang.String SERVICE_INTERFACE = "android.service.chooser.ChooserTargetService";
+  }
+
+}
+
 package android.service.dreams {
 
   public class DreamService extends android.app.Service implements android.view.Window.Callback {
@@ -30906,8 +30931,8 @@
     method public void unregisterPhoneAccount(android.telecom.PhoneAccountHandle);
     field public static final java.lang.String ACTION_CHANGE_PHONE_ACCOUNTS = "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
     field public static final java.lang.String ACTION_CONNECTION_SERVICE_CONFIGURE = "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
-    field public static final java.lang.String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS = "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
     field public static final java.lang.String ACTION_PHONE_ACCOUNT_REGISTERED = "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
+    field public static final java.lang.String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS = "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
     field public static final java.lang.String ACTION_SHOW_CALL_SETTINGS = "android.telecom.action.SHOW_CALL_SETTINGS";
     field public static final java.lang.String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS = "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
     field public static final char DTMF_CHARACTER_PAUSE = 44; // 0x002c ','
diff --git a/core/java/android/service/chooser/ChooserTarget.aidl b/core/java/android/service/chooser/ChooserTarget.aidl
new file mode 100644
index 0000000..ca91bc8
--- /dev/null
+++ b/core/java/android/service/chooser/ChooserTarget.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.chooser;
+
+parcelable ChooserTarget;
diff --git a/core/java/android/service/chooser/ChooserTarget.java b/core/java/android/service/chooser/ChooserTarget.java
new file mode 100644
index 0000000..7fd1d10
--- /dev/null
+++ b/core/java/android/service/chooser/ChooserTarget.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package android.service.chooser;
+
+import android.app.PendingIntent;
+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.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+/**
+ * A ChooserTarget represents a deep-link into an application as returned by a
+ * {@link android.service.chooser.ChooserTargetService}.
+ */
+public final class ChooserTarget implements Parcelable {
+    private static final String TAG = "ChooserTarget";
+
+    /**
+     * The title of this target that will be shown to the user. The title may be truncated
+     * if it is too long to display in the space provided.
+     */
+    private CharSequence mTitle;
+
+    /**
+     * The icon that will be shown to the user to represent this target.
+     * The system may resize this icon as appropriate.
+     */
+    private Bitmap 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.
+     */
+    private IntentSender mIntentSender;
+
+    /**
+     * The score given to this item. It can be normalized.
+     */
+    private float mScore;
+
+    /**
+     * 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).</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
+     */
+    public ChooserTarget(CharSequence title, Bitmap icon, float score,
+            PendingIntent pendingIntent) {
+        this(title, icon, score, pendingIntent.getIntentSender());
+    }
+
+    /**
+     * 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).</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>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>
+     *
+     * @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
+     */
+    public ChooserTarget(CharSequence title, Bitmap icon, float score, IntentSender intentSender) {
+        mTitle = title;
+        mIcon = icon;
+        if (score > 1.f || score < 0.f) {
+            throw new IllegalArgumentException("Score " + score + " out of range; "
+                    + "must be between 0.0f and 1.0f");
+        }
+        mScore = score;
+        mIntentSender = intentSender;
+    }
+
+    ChooserTarget(Parcel in) {
+        mTitle = in.readCharSequence();
+        if (in.readInt() != 0) {
+            mIcon = Bitmap.CREATOR.createFromParcel(in);
+        } else {
+            mIcon = null;
+        }
+        mScore = in.readFloat();
+        mIntentSender = IntentSender.readIntentSenderOrNullFromParcel(in);
+    }
+
+    /**
+     * Returns the title of this target for display to a user. The UI displaying the title
+     * may truncate this title if it is too long to be displayed in full.
+     *
+     * @return the title of this target, intended to be shown to a user
+     */
+    public CharSequence getTitle() {
+        return mTitle;
+    }
+
+    /**
+     * Returns the icon representing this target for display to a user. The UI displaying the icon
+     * may crop, resize or overlay this icon.
+     *
+     * @return the icon representing this target, intended to be shown to a user
+     */
+    public Bitmap getIcon() {
+        return mIcon;
+    }
+
+    /**
+     * Returns the ranking score supplied by the creator of this ChooserTarget.
+     * Values are between 0.0f and 1.0f. The UI displaying the target may
+     * take this score into account when sorting and merging targets from multiple sources.
+     *
+     * @return the ranking score for this target between 0.0f and 1.0f, inclusive
+     */
+    public float getScore() {
+        return mScore;
+    }
+
+    /**
+     * Returns the raw IntentSender supplied by the ChooserTarget's creator.
+     *
+     * <p>To fill in and send the intent, see {@link #sendIntent(Context, Intent)}.</p>
+     *
+     * @return the IntentSender supplied by the ChooserTarget's creator
+     */
+    public IntentSender getIntentSender() {
+        return mIntentSender;
+    }
+
+    /**
+     * Fill in the IntentSender supplied by the ChooserTarget's creator and send it.
+     *
+     * @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
+     */
+    public boolean sendIntent(Context context, Intent fillInIntent) {
+        if (fillInIntent != null) {
+            fillInIntent.migrateExtraStreamToClipData();
+            fillInIntent.prepareToLeaveProcess();
+        }
+        try {
+            mIntentSender.sendIntent(context, 0, fillInIntent, null, null);
+            return true;
+        } catch (IntentSender.SendIntentException e) {
+            Log.e(TAG, "sendIntent " + this + " failed", e);
+            return false;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "ChooserTarget{" + mIntentSender.getCreatorPackage() + "'" + mTitle
+                + "', " + mScore + "}";
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeCharSequence(mTitle);
+        if (mIcon != null) {
+            dest.writeInt(1);
+            mIcon.writeToParcel(dest, 0);
+        } else {
+            dest.writeInt(0);
+        }
+        dest.writeFloat(mScore);
+        IntentSender.writeIntentSenderOrNullToParcel(mIntentSender, dest);
+    }
+
+    public static final Creator<ChooserTarget> CREATOR
+            = new Creator<ChooserTarget>() {
+        @Override
+        public ChooserTarget createFromParcel(Parcel source) {
+            return new ChooserTarget(source);
+        }
+
+        @Override
+        public ChooserTarget[] newArray(int size) {
+            return new ChooserTarget[size];
+        }
+    };
+}
diff --git a/core/java/android/service/chooser/ChooserTargetService.java b/core/java/android/service/chooser/ChooserTargetService.java
new file mode 100644
index 0000000..9188806
--- /dev/null
+++ b/core/java/android/service/chooser/ChooserTargetService.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package android.service.chooser;
+
+import android.annotation.SdkConstant;
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.IBinder;
+import android.os.RemoteException;
+
+import java.util.List;
+
+/**
+ * A service that receives calls from the system when the user is asked to choose
+ * a target for an intent explicitly by another app. The calling app must have invoked
+ * {@link android.content.Intent#ACTION_CHOOSER ACTION_CHOOSER} as handled by the system;
+ * applications do not have the ability to query a ChooserTargetService directly.
+ *
+ * <p>Which ChooserTargetServices are queried depends on a system-level policy decision
+ * made at the moment the chooser is invoked, including but not limited to user time
+ * spent with the app package or associated components in the foreground, recency of usage
+ * or frequency of usage. These will generally correlate with the order that app targets
+ * are shown in the list of intent handlers shown in the system chooser or resolver.</p>
+ *
+ * <p>To extend this class, you must declare the service in your manifest file with
+ * the {@link android.Manifest.permission#BIND_CHOOSER_TARGET_SERVICE} permission
+ * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p>
+ * <pre>
+ *     &lt;service android:name=".ChooserTargetService"
+ *             android:label="&#64;string/service_name"
+ *             android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
+ *         &lt;intent-filter>
+ *             &lt;action android:name="android.service.chooser.ChooserTargetService" />
+ *         &lt;/intent-filter>
+ *     &lt;/service>
+ * </pre>
+ *
+ * <p>For the system to query your service, you must add a &lt;meta-data> element to the
+ * Activity in your manifest that can handle Intents that you would also like to provide
+ * optional deep links for. For example, a chat app might offer deep links to recent active
+ * conversations instead of invoking a generic picker after the app itself is chosen as a target.
+ * </p>
+ *
+ * <p>The meta-data element should have the name
+ * <code>android.service.chooser.chooser_target_service</code> and a value corresponding to
+ * the component name of your service. Example:</p>
+ * <pre>
+ *     &lt;activity android:name=".MyShareActivity"
+ *             android:label="&#64;string/share_activity_label">
+ *         &lt;intent-filter>
+ *             &lt;action android:name="android.intent.action.SEND" />
+ *         &lt;/intent-filter>
+ *         &lt;meta-data android:name="android.service.chooser.chooser_target_service"
+ *                 android:value=".ChooserTargetService" />
+ *     &lt;/activity>
+ * </pre>
+ */
+public abstract class ChooserTargetService extends Service {
+    // TAG = "ChooserTargetService[MySubclass]";
+    private final String TAG = ChooserTargetService.class.getSimpleName()
+            + '[' + getClass().getSimpleName() + ']';
+
+    @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
+    public static final String SERVICE_INTERFACE = "android.service.chooser.ChooserTargetService";
+
+    private IChooserTargetServiceWrapper mWrapper = null;
+
+    /**
+     * Called by the system to retrieve a set of deep-link {@link ChooserTarget targets} that
+     * 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.Bitmap, float, android.app.PendingIntent) ChooserTarget}.</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
+     * within your app is thread-safe.</p>
+     *
+     * @param targetActivityName the ComponentName of the matched activity that referred the system
+     *                           to this ChooserTargetService
+     * @param matchedFilter the specific IntentFilter on the component that was matched
+     * @return a list of deep-link targets to fulfill the intent match, sorted by relevance
+     */
+    public abstract List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
+            IntentFilter matchedFilter);
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        if (!SERVICE_INTERFACE.equals(intent.getAction())) {
+            return null;
+        }
+
+        if (mWrapper == null) {
+            mWrapper = new IChooserTargetServiceWrapper();
+        }
+        return mWrapper;
+    }
+
+    private class IChooserTargetServiceWrapper extends IChooserTargetService.Stub {
+        @Override
+        public void getChooserTargets(ComponentName targetComponentName,
+                IntentFilter matchedFilter, IChooserTargetResult result) throws RemoteException {
+            List<ChooserTarget> targets = null;
+            try {
+                targets = onGetChooserTargets(targetComponentName, matchedFilter);
+            } finally {
+                result.sendResult(targets);
+            }
+        }
+    }
+}
diff --git a/core/java/android/service/chooser/IChooserTargetResult.aidl b/core/java/android/service/chooser/IChooserTargetResult.aidl
new file mode 100644
index 0000000..dbd7cbd
--- /dev/null
+++ b/core/java/android/service/chooser/IChooserTargetResult.aidl
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.chooser;
+
+import android.service.chooser.ChooserTarget;
+
+/**
+ * @hide
+ */
+interface IChooserTargetResult
+{
+    void sendResult(in List<ChooserTarget> targets);
+}
diff --git a/core/java/android/service/chooser/IChooserTargetService.aidl b/core/java/android/service/chooser/IChooserTargetService.aidl
new file mode 100644
index 0000000..6cfa9a2
--- /dev/null
+++ b/core/java/android/service/chooser/IChooserTargetService.aidl
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.chooser;
+
+import android.content.ComponentName;
+import android.content.IntentFilter;
+import android.service.chooser.IChooserTargetResult;
+
+/**
+ * @hide
+ */
+oneway interface IChooserTargetService
+{
+    void getChooserTargets(in ComponentName targetComponentName,
+            in IntentFilter matchedFilter, IChooserTargetResult result);
+}
\ No newline at end of file
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index b550558..2ce5bb3 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2892,6 +2892,14 @@
         android:description="@string/permdesc_bindNotificationListenerService"
         android:protectionLevel="signature" />
 
+    <!-- Must be required by a {@link
+         android.service.chooser.ChooserTargetService}, to ensure that
+         only the system can bind to it. -->
+    <permission android:name="android.permission.BIND_CHOOSER_TARGET_SERVICE"
+        android:label="@string/permlab_bindChooserTargetService"
+        android:description="@string/permdesc_bindChooserTargetService"
+        android:protectionLevel="signature" />
+
     <!-- @SystemApi Must be required by a {@link
          android.service.notification.ConditionProviderService},
          to ensure that only the system can bind to it.
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 7c745ac..3f729ce 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2354,6 +2354,11 @@
     <string name="permdesc_bindNotificationListenerService">Allows the holder to bind to the top-level interface of a notification listener service. Should never be needed for normal apps.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_bindChooserTargetService">bind to a chooser target service</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_bindChooserTargetService">Allows the holder to bind to the top-level interface of a chooser target service. Should never be needed for normal apps.</string>
+
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_bindConditionProviderService">bind to a condition provider service</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_bindConditionProviderService">Allows the holder to bind to the top-level interface of a condition provider service. Should never be needed for normal apps.</string>