blob: 55014ebf1fcb18450048a1a188ed412a7ae565c6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbyed9273d62013-05-30 15:59:53 -070019import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.Nullable;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010022import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070024import android.content.IIntentReceiver;
25import android.content.IIntentSender;
Suprabh Shukladb6bf662017-08-30 15:41:53 -070026import android.content.Intent;
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070027import android.content.IntentSender;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Handler;
30import android.os.IBinder;
Suprabh Shukladb6bf662017-08-30 15:41:53 -070031import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Parcel;
33import android.os.Parcelable;
Suprabh Shukladb6bf662017-08-30 15:41:53 -070034import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070035import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.AndroidException;
Selim Cinekd83203c2018-04-18 14:34:27 +080037import android.util.ArraySet;
Kweku Adams61e03292017-10-19 14:27:12 -070038import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Selim Cinekd83203c2018-04-18 14:34:27 +080040import com.android.internal.os.IResultReceiver;
41
Tor Norbyed9273d62013-05-30 15:59:53 -070042import java.lang.annotation.Retention;
43import java.lang.annotation.RetentionPolicy;
44
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045/**
46 * A description of an Intent and target action to perform with it. Instances
Dianne Hackborn8832c182012-09-17 17:20:24 -070047 * of this class are created with {@link #getActivity}, {@link #getActivities},
48 * {@link #getBroadcast}, and {@link #getService}; the returned object can be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 * handed to other applications so that they can perform the action you
50 * described on your behalf at a later time.
51 *
52 * <p>By giving a PendingIntent to another application,
53 * you are granting it the right to perform the operation you have specified
54 * as if the other application was yourself (with the same permissions and
55 * identity). As such, you should be careful about how you build the PendingIntent:
Dianne Hackborna53ee352013-02-20 12:47:02 -080056 * almost always, for example, the base Intent you supply should have the component
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 * name explicitly set to one of your own components, to ensure it is ultimately
58 * sent there and nowhere else.
59 *
60 * <p>A PendingIntent itself is simply a reference to a token maintained by
61 * the system describing the original data used to retrieve it. This means
62 * that, even if its owning application's process is killed, the
63 * PendingIntent itself will remain usable from other processes that
64 * have been given it. If the creating application later re-retrieves the
65 * same kind of PendingIntent (same operation, same Intent action, data,
66 * categories, and components, and same flags), it will receive a PendingIntent
67 * representing the same token if that is still valid, and can thus call
68 * {@link #cancel} to remove it.
Dianne Hackborn8832c182012-09-17 17:20:24 -070069 *
70 * <p>Because of this behavior, it is important to know when two Intents
71 * are considered to be the same for purposes of retrieving a PendingIntent.
72 * A common mistake people make is to create multiple PendingIntent objects
73 * with Intents that only vary in their "extra" contents, expecting to get
74 * a different PendingIntent each time. This does <em>not</em> happen. The
75 * parts of the Intent that are used for matching are the same ones defined
76 * by {@link Intent#filterEquals(Intent) Intent.filterEquals}. If you use two
77 * Intent objects that are equivalent as per
78 * {@link Intent#filterEquals(Intent) Intent.filterEquals}, then you will get
79 * the same PendingIntent for both of them.
80 *
81 * <p>There are two typical ways to deal with this.
82 *
83 * <p>If you truly need multiple distinct PendingIntent objects active at
84 * the same time (such as to use as two notifications that are both shown
85 * at the same time), then you will need to ensure there is something that
86 * is different about them to associate them with different PendingIntents.
87 * This may be any of the Intent attributes considered by
88 * {@link Intent#filterEquals(Intent) Intent.filterEquals}, or different
89 * request code integers supplied to {@link #getActivity}, {@link #getActivities},
90 * {@link #getBroadcast}, or {@link #getService}.
91 *
92 * <p>If you only need one PendingIntent active at a time for any of the
93 * Intents you will use, then you can alternatively use the flags
94 * {@link #FLAG_CANCEL_CURRENT} or {@link #FLAG_UPDATE_CURRENT} to either
95 * cancel or modify whatever current PendingIntent is associated with the
96 * Intent you are supplying.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 */
98public final class PendingIntent implements Parcelable {
99 private final IIntentSender mTarget;
Selim Cinekd83203c2018-04-18 14:34:27 +0800100 private IResultReceiver mCancelReceiver;
Dianne Hackborn98305522017-05-05 17:53:53 -0700101 private IBinder mWhitelistToken;
Selim Cinekd83203c2018-04-18 14:34:27 +0800102 private ArraySet<CancelListener> mCancelListeners;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103
Tor Norbyed9273d62013-05-30 15:59:53 -0700104 /** @hide */
105 @IntDef(flag = true,
106 value = {
107 FLAG_ONE_SHOT,
108 FLAG_NO_CREATE,
109 FLAG_CANCEL_CURRENT,
110 FLAG_UPDATE_CURRENT,
Tor Norbyedfd1b582017-05-31 08:02:52 -0700111 FLAG_IMMUTABLE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700112
113 Intent.FILL_IN_ACTION,
114 Intent.FILL_IN_DATA,
115 Intent.FILL_IN_CATEGORIES,
116 Intent.FILL_IN_COMPONENT,
117 Intent.FILL_IN_PACKAGE,
118 Intent.FILL_IN_SOURCE_BOUNDS,
119 Intent.FILL_IN_SELECTOR,
120 Intent.FILL_IN_CLIP_DATA
121 })
122 @Retention(RetentionPolicy.SOURCE)
123 public @interface Flags {}
124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 /**
Scott Maindf75bdc2013-01-15 15:12:13 -0800126 * Flag indicating that this PendingIntent can be used only once.
127 * For use with {@link #getActivity}, {@link #getBroadcast}, and
128 * {@link #getService}. <p>If set, after
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 * {@link #send()} is called on it, it will be automatically
130 * canceled for you and any future attempt to send through it will fail.
131 */
132 public static final int FLAG_ONE_SHOT = 1<<30;
133 /**
Katie McCormick87d9d1a2014-03-31 16:16:32 -0700134 * Flag indicating that if the described PendingIntent does not
135 * already exist, then simply return null instead of creating it.
Scott Maindf75bdc2013-01-15 15:12:13 -0800136 * For use with {@link #getActivity}, {@link #getBroadcast}, and
137 * {@link #getService}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 */
139 public static final int FLAG_NO_CREATE = 1<<29;
140 /**
Scott Maindf75bdc2013-01-15 15:12:13 -0800141 * Flag indicating that if the described PendingIntent already exists,
142 * the current one should be canceled before generating a new one.
143 * For use with {@link #getActivity}, {@link #getBroadcast}, and
144 * {@link #getService}. <p>You can use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 * this to retrieve a new PendingIntent when you are only changing the
146 * extra data in the Intent; by canceling the previous pending intent,
147 * this ensures that only entities given the new data will be able to
148 * launch it. If this assurance is not an issue, consider
149 * {@link #FLAG_UPDATE_CURRENT}.
150 */
151 public static final int FLAG_CANCEL_CURRENT = 1<<28;
152 /**
Scott Maindf75bdc2013-01-15 15:12:13 -0800153 * Flag indicating that if the described PendingIntent already exists,
154 * then keep it but replace its extra data with what is in this new
155 * Intent. For use with {@link #getActivity}, {@link #getBroadcast}, and
156 * {@link #getService}. <p>This can be used if you are creating intents where only the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 * extras change, and don't care that any entities that received your
158 * previous PendingIntent will be able to launch it with your new
159 * extras even if they are not explicitly given to it.
160 */
161 public static final int FLAG_UPDATE_CURRENT = 1<<27;
162
163 /**
Svetoslavb0a78392015-04-10 17:25:35 -0700164 * Flag indicating that the created PendingIntent should be immutable.
165 * This means that the additional intent argument passed to the send
166 * methods to fill in unpopulated properties of this intent will be
167 * ignored.
168 */
169 public static final int FLAG_IMMUTABLE = 1<<26;
170
171 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 * Exception thrown when trying to send through a PendingIntent that
173 * has been canceled or is otherwise no longer able to execute the request.
174 */
175 public static class CanceledException extends AndroidException {
176 public CanceledException() {
177 }
178
179 public CanceledException(String name) {
180 super(name);
181 }
182
183 public CanceledException(Exception cause) {
184 super(cause);
185 }
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -0700186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187
188 /**
189 * Callback interface for discovering when a send operation has
190 * completed. Primarily for use with a PendingIntent that is
191 * performing a broadcast, this provides the same information as
192 * calling {@link Context#sendOrderedBroadcast(Intent, String,
193 * android.content.BroadcastReceiver, Handler, int, String, Bundle)
194 * Context.sendBroadcast()} with a final BroadcastReceiver.
195 */
196 public interface OnFinished {
197 /**
198 * Called when a send operation as completed.
199 *
200 * @param pendingIntent The PendingIntent this operation was sent through.
201 * @param intent The original Intent that was sent.
202 * @param resultCode The final result code determined by the send.
203 * @param resultData The final data collected by a broadcast.
204 * @param resultExtras The final extras collected by a broadcast.
205 */
206 void onSendFinished(PendingIntent pendingIntent, Intent intent,
207 int resultCode, String resultData, Bundle resultExtras);
208 }
209
210 private static class FinishedDispatcher extends IIntentReceiver.Stub
211 implements Runnable {
212 private final PendingIntent mPendingIntent;
213 private final OnFinished mWho;
214 private final Handler mHandler;
215 private Intent mIntent;
216 private int mResultCode;
217 private String mResultData;
218 private Bundle mResultExtras;
Wale Ogunwale9a6ef1e2015-06-02 13:41:00 -0700219 private static Handler sDefaultSystemHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 FinishedDispatcher(PendingIntent pi, OnFinished who, Handler handler) {
221 mPendingIntent = pi;
222 mWho = who;
Wale Ogunwale9a6ef1e2015-06-02 13:41:00 -0700223 if (handler == null && ActivityThread.isSystem()) {
224 // We assign a default handler for the system process to avoid deadlocks when
225 // processing receivers in various components that hold global service locks.
226 if (sDefaultSystemHandler == null) {
227 sDefaultSystemHandler = new Handler(Looper.getMainLooper());
228 }
229 mHandler = sDefaultSystemHandler;
230 } else {
231 mHandler = handler;
232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 }
Dianne Hackborn20e80982012-08-31 19:00:44 -0700234 public void performReceive(Intent intent, int resultCode, String data,
235 Bundle extras, boolean serialized, boolean sticky, int sendingUser) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 mIntent = intent;
237 mResultCode = resultCode;
238 mResultData = data;
239 mResultExtras = extras;
240 if (mHandler == null) {
241 run();
242 } else {
243 mHandler.post(this);
244 }
245 }
246 public void run() {
247 mWho.onSendFinished(mPendingIntent, mIntent, mResultCode,
248 mResultData, mResultExtras);
249 }
250 }
251
252 /**
Svet Ganovddb94882016-06-23 19:55:24 -0700253 * Listener for observing when pending intents are written to a parcel.
254 *
255 * @hide
256 */
257 public interface OnMarshaledListener {
258 /**
259 * Called when a pending intent is written to a parcel.
260 *
261 * @param intent The pending intent.
262 * @param parcel The parcel to which it was written.
263 * @param flags The parcel flags when it was written.
264 */
265 void onMarshaled(PendingIntent intent, Parcel parcel, int flags);
266 }
267
268 private static final ThreadLocal<OnMarshaledListener> sOnMarshaledListener
269 = new ThreadLocal<>();
270
271 /**
272 * Registers an listener for pending intents being written to a parcel.
273 *
274 * @param listener The listener, null to clear.
275 *
276 * @hide
277 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100278 @UnsupportedAppUsage
Svet Ganovddb94882016-06-23 19:55:24 -0700279 public static void setOnMarshaledListener(OnMarshaledListener listener) {
280 sOnMarshaledListener.set(listener);
281 }
282
283 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 * Retrieve a PendingIntent that will start a new activity, like calling
285 * {@link Context#startActivity(Intent) Context.startActivity(Intent)}.
286 * Note that the activity will be started outside of the context of an
287 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
288 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent.
289 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800290 * <p class="note">For security reasons, the {@link android.content.Intent}
291 * you supply here should almost always be an <em>explicit intent</em>,
292 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500293 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800294 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 * @param context The Context in which this PendingIntent should start
296 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200297 * @param requestCode Private request code for the sender
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 * @param intent Intent of the activity to be launched.
299 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
300 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
301 * or any of the flags as supported by
302 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
303 * of the intent that can be supplied when the actual send happens.
304 *
305 * @return Returns an existing or new PendingIntent matching the given
306 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
307 * supplied.
308 */
309 public static PendingIntent getActivity(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700310 Intent intent, @Flags int flags) {
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700311 return getActivity(context, requestCode, intent, flags, null);
312 }
313
314 /**
315 * Retrieve a PendingIntent that will start a new activity, like calling
316 * {@link Context#startActivity(Intent) Context.startActivity(Intent)}.
317 * Note that the activity will be started outside of the context of an
318 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
319 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent.
320 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800321 * <p class="note">For security reasons, the {@link android.content.Intent}
322 * you supply here should almost always be an <em>explicit intent</em>,
323 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500324 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800325 *
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700326 * @param context The Context in which this PendingIntent should start
327 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200328 * @param requestCode Private request code for the sender
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700329 * @param intent Intent of the activity to be launched.
330 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
331 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
332 * or any of the flags as supported by
333 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
334 * of the intent that can be supplied when the actual send happens.
335 * @param options Additional options for how the Activity should be started.
336 * May be null if there are no options.
337 *
338 * @return Returns an existing or new PendingIntent matching the given
339 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
340 * supplied.
341 */
342 public static PendingIntent getActivity(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700343 @NonNull Intent intent, @Flags int flags, @Nullable Bundle options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 String packageName = context.getPackageName();
345 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
346 context.getContentResolver()) : null;
347 try {
Jeff Sharkey02ffba92013-03-08 16:13:15 -0800348 intent.migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700349 intent.prepareToLeaveProcess(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 IIntentSender target =
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800351 ActivityManager.getService().getIntentSender(
Dianne Hackborna4972e92012-03-14 10:38:05 -0700352 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800353 null, null, requestCode, new Intent[] { intent },
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700354 resolvedType != null ? new String[] { resolvedType } : null,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700355 flags, options, context.getUserId());
Dianne Hackborn41203752012-08-31 14:05:51 -0700356 return target != null ? new PendingIntent(target) : null;
357 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100358 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -0700359 }
Dianne Hackborn41203752012-08-31 14:05:51 -0700360 }
361
362 /**
363 * @hide
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700364 * Note that UserHandle.CURRENT will be interpreted at the time the
365 * activity is started, not when the pending intent is created.
Dianne Hackborn41203752012-08-31 14:05:51 -0700366 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100367 @UnsupportedAppUsage
Dianne Hackborn41203752012-08-31 14:05:51 -0700368 public static PendingIntent getActivityAsUser(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700369 @NonNull Intent intent, int flags, Bundle options, UserHandle user) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700370 String packageName = context.getPackageName();
371 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
372 context.getContentResolver()) : null;
373 try {
Jeff Sharkey02ffba92013-03-08 16:13:15 -0800374 intent.migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700375 intent.prepareToLeaveProcess(context);
Dianne Hackborn41203752012-08-31 14:05:51 -0700376 IIntentSender target =
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800377 ActivityManager.getService().getIntentSender(
Dianne Hackborn41203752012-08-31 14:05:51 -0700378 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
379 null, null, requestCode, new Intent[] { intent },
380 resolvedType != null ? new String[] { resolvedType } : null,
381 flags, options, user.getIdentifier());
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800382 return target != null ? new PendingIntent(target) : null;
383 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100384 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800385 }
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800386 }
387
388 /**
389 * Like {@link #getActivity(Context, int, Intent, int)}, but allows an
Tim Hutt5313c9f2012-12-10 12:34:19 +0000390 * array of Intents to be supplied. The last Intent in the array is
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800391 * taken as the primary key for the PendingIntent, like the single Intent
392 * given to {@link #getActivity(Context, int, Intent, int)}. Upon sending
393 * the resulting PendingIntent, all of the Intents are started in the same
394 * way as they would be by passing them to {@link Context#startActivities(Intent[])}.
395 *
396 * <p class="note">
397 * The <em>first</em> intent in the array will be started outside of the context of an
398 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
399 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent. (Activities after
400 * the first in the array are started in the context of the previous activity
401 * in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
402 * </p>
403 *
404 * <p class="note">
405 * The <em>last</em> intent in the array represents the key for the
406 * PendingIntent. In other words, it is the significant element for matching
407 * (as done with the single intent given to {@link #getActivity(Context, int, Intent, int)},
408 * its content will be the subject of replacement by
409 * {@link #send(Context, int, Intent)} and {@link #FLAG_UPDATE_CURRENT}, etc.
410 * This is because it is the most specific of the supplied intents, and the
411 * UI the user actually sees when the intents are started.
412 * </p>
413 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800414 * <p class="note">For security reasons, the {@link android.content.Intent} objects
415 * you supply here should almost always be <em>explicit intents</em>,
416 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500417 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800418 *
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800419 * @param context The Context in which this PendingIntent should start
420 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200421 * @param requestCode Private request code for the sender
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800422 * @param intents Array of Intents of the activities to be launched.
423 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
424 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
425 * or any of the flags as supported by
426 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
427 * of the intent that can be supplied when the actual send happens.
428 *
429 * @return Returns an existing or new PendingIntent matching the given
430 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
431 * supplied.
432 */
433 public static PendingIntent getActivities(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700434 @NonNull Intent[] intents, @Flags int flags) {
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700435 return getActivities(context, requestCode, intents, flags, null);
436 }
437
438 /**
439 * Like {@link #getActivity(Context, int, Intent, int)}, but allows an
Tim Hutt5313c9f2012-12-10 12:34:19 +0000440 * array of Intents to be supplied. The last Intent in the array is
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700441 * taken as the primary key for the PendingIntent, like the single Intent
442 * given to {@link #getActivity(Context, int, Intent, int)}. Upon sending
443 * the resulting PendingIntent, all of the Intents are started in the same
444 * way as they would be by passing them to {@link Context#startActivities(Intent[])}.
445 *
446 * <p class="note">
447 * The <em>first</em> intent in the array will be started outside of the context of an
448 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
449 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent. (Activities after
450 * the first in the array are started in the context of the previous activity
451 * in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
452 * </p>
453 *
454 * <p class="note">
455 * The <em>last</em> intent in the array represents the key for the
456 * PendingIntent. In other words, it is the significant element for matching
457 * (as done with the single intent given to {@link #getActivity(Context, int, Intent, int)},
458 * its content will be the subject of replacement by
459 * {@link #send(Context, int, Intent)} and {@link #FLAG_UPDATE_CURRENT}, etc.
460 * This is because it is the most specific of the supplied intents, and the
461 * UI the user actually sees when the intents are started.
462 * </p>
463 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800464 * <p class="note">For security reasons, the {@link android.content.Intent} objects
465 * you supply here should almost always be <em>explicit intents</em>,
466 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500467 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800468 *
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700469 * @param context The Context in which this PendingIntent should start
470 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200471 * @param requestCode Private request code for the sender
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700472 * @param intents Array of Intents of the activities to be launched.
473 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
474 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
Svet Ganovf2acc542015-11-06 09:02:00 -0800475 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700476 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
477 * of the intent that can be supplied when the actual send happens.
478 *
479 * @return Returns an existing or new PendingIntent matching the given
480 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
481 * supplied.
482 */
483 public static PendingIntent getActivities(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700484 @NonNull Intent[] intents, @Flags int flags, @Nullable Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800485 String packageName = context.getPackageName();
486 String[] resolvedTypes = new String[intents.length];
487 for (int i=0; i<intents.length; i++) {
Jeff Sharkeya14acd22013-04-02 18:27:45 -0700488 intents[i].migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700489 intents[i].prepareToLeaveProcess(context);
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800490 resolvedTypes[i] = intents[i].resolveTypeIfNeeded(context.getContentResolver());
491 }
492 try {
493 IIntentSender target =
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800494 ActivityManager.getService().getIntentSender(
Dianne Hackborna4972e92012-03-14 10:38:05 -0700495 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -0700496 null, null, requestCode, intents, resolvedTypes, flags, options,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700497 context.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 return target != null ? new PendingIntent(target) : null;
499 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100500 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 }
503
504 /**
Adam Powelld56b4d12012-09-30 18:27:31 -0700505 * @hide
506 * Note that UserHandle.CURRENT will be interpreted at the time the
507 * activity is started, not when the pending intent is created.
508 */
509 public static PendingIntent getActivitiesAsUser(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700510 @NonNull Intent[] intents, int flags, Bundle options, UserHandle user) {
Adam Powelld56b4d12012-09-30 18:27:31 -0700511 String packageName = context.getPackageName();
512 String[] resolvedTypes = new String[intents.length];
513 for (int i=0; i<intents.length; i++) {
Jeff Sharkeya14acd22013-04-02 18:27:45 -0700514 intents[i].migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700515 intents[i].prepareToLeaveProcess(context);
Adam Powelld56b4d12012-09-30 18:27:31 -0700516 resolvedTypes[i] = intents[i].resolveTypeIfNeeded(context.getContentResolver());
517 }
518 try {
519 IIntentSender target =
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800520 ActivityManager.getService().getIntentSender(
Adam Powelld56b4d12012-09-30 18:27:31 -0700521 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
522 null, null, requestCode, intents, resolvedTypes,
523 flags, options, user.getIdentifier());
524 return target != null ? new PendingIntent(target) : null;
525 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100526 throw e.rethrowFromSystemServer();
Adam Powelld56b4d12012-09-30 18:27:31 -0700527 }
Adam Powelld56b4d12012-09-30 18:27:31 -0700528 }
529
530 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 * Retrieve a PendingIntent that will perform a broadcast, like calling
532 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
533 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800534 * <p class="note">For security reasons, the {@link android.content.Intent}
535 * you supply here should almost always be an <em>explicit intent</em>,
536 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500537 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800538 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 * @param context The Context in which this PendingIntent should perform
540 * the broadcast.
Danny Baumannf15a4192013-04-05 13:42:57 +0200541 * @param requestCode Private request code for the sender
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 * @param intent The Intent to be broadcast.
543 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
544 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
Svet Ganovf2acc542015-11-06 09:02:00 -0800545 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
547 * of the intent that can be supplied when the actual send happens.
548 *
549 * @return Returns an existing or new PendingIntent matching the given
550 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
551 * supplied.
552 */
553 public static PendingIntent getBroadcast(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700554 Intent intent, @Flags int flags) {
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700555 return getBroadcastAsUser(context, requestCode, intent, flags, context.getUser());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700556 }
557
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700558 /**
559 * @hide
560 * Note that UserHandle.CURRENT will be interpreted at the time the
561 * broadcast is sent, not when the pending intent is created.
562 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100563 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700564 public static PendingIntent getBroadcastAsUser(Context context, int requestCode,
565 Intent intent, int flags, UserHandle userHandle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 String packageName = context.getPackageName();
567 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
568 context.getContentResolver()) : null;
569 try {
Jeff Sharkey344744b2016-01-28 19:03:30 -0700570 intent.prepareToLeaveProcess(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 IIntentSender target =
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800572 ActivityManager.getService().getIntentSender(
Dianne Hackborna4972e92012-03-14 10:38:05 -0700573 ActivityManager.INTENT_SENDER_BROADCAST, packageName,
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800574 null, null, requestCode, new Intent[] { intent },
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700575 resolvedType != null ? new String[] { resolvedType } : null,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700576 flags, null, userHandle.getIdentifier());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 return target != null ? new PendingIntent(target) : null;
578 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100579 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
582
583 /**
584 * Retrieve a PendingIntent that will start a service, like calling
585 * {@link Context#startService Context.startService()}. The start
586 * arguments given to the service will come from the extras of the Intent.
587 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800588 * <p class="note">For security reasons, the {@link android.content.Intent}
589 * you supply here should almost always be an <em>explicit intent</em>,
590 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500591 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800592 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 * @param context The Context in which this PendingIntent should start
594 * the service.
Danny Baumannf15a4192013-04-05 13:42:57 +0200595 * @param requestCode Private request code for the sender
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 * @param intent An Intent describing the service to be started.
597 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
598 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
Svet Ganovf2acc542015-11-06 09:02:00 -0800599 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
601 * of the intent that can be supplied when the actual send happens.
602 *
603 * @return Returns an existing or new PendingIntent matching the given
604 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
605 * supplied.
606 */
607 public static PendingIntent getService(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700608 @NonNull Intent intent, @Flags int flags) {
Christopher Tate08992ac2017-03-21 11:37:06 -0700609 return buildServicePendingIntent(context, requestCode, intent, flags,
610 ActivityManager.INTENT_SENDER_SERVICE);
611 }
612
613 /**
614 * Retrieve a PendingIntent that will start a foreground service, like calling
Dianne Hackborn6aba8532017-06-16 14:43:36 -0700615 * {@link Context#startForegroundService Context.startForegroundService()}. The start
Christopher Tate08992ac2017-03-21 11:37:06 -0700616 * arguments given to the service will come from the extras of the Intent.
617 *
618 * <p class="note">For security reasons, the {@link android.content.Intent}
619 * you supply here should almost always be an <em>explicit intent</em>,
620 * that is specify an explicit component to be delivered to through
621 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
622 *
623 * @param context The Context in which this PendingIntent should start
624 * the service.
625 * @param requestCode Private request code for the sender
626 * @param intent An Intent describing the service to be started.
627 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
628 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
629 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
630 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
631 * of the intent that can be supplied when the actual send happens.
632 *
633 * @return Returns an existing or new PendingIntent matching the given
634 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
635 * supplied.
636 */
637 public static PendingIntent getForegroundService(Context context, int requestCode,
638 @NonNull Intent intent, @Flags int flags) {
639 return buildServicePendingIntent(context, requestCode, intent, flags,
640 ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE);
641 }
642
643 private static PendingIntent buildServicePendingIntent(Context context, int requestCode,
644 Intent intent, int flags, int serviceKind) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 String packageName = context.getPackageName();
646 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
647 context.getContentResolver()) : null;
648 try {
Jeff Sharkey344744b2016-01-28 19:03:30 -0700649 intent.prepareToLeaveProcess(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 IIntentSender target =
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800651 ActivityManager.getService().getIntentSender(
Christopher Tate08992ac2017-03-21 11:37:06 -0700652 serviceKind, packageName,
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800653 null, null, requestCode, new Intent[] { intent },
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700654 resolvedType != null ? new String[] { resolvedType } : null,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700655 flags, null, context.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 return target != null ? new PendingIntent(target) : null;
657 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100658 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 }
661
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -0700662 /**
663 * Retrieve a IntentSender object that wraps the existing sender of the PendingIntent
664 *
665 * @return Returns a IntentSender object that wraps the sender of PendingIntent
666 *
667 */
668 public IntentSender getIntentSender() {
Dianne Hackborn98305522017-05-05 17:53:53 -0700669 return new IntentSender(mTarget, mWhitelistToken);
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -0700670 }
671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 /**
673 * Cancel a currently active PendingIntent. Only the original application
Ken Wakasaf76a50c2012-03-09 19:56:35 +0900674 * owning a PendingIntent can cancel it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 */
676 public void cancel() {
677 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800678 ActivityManager.getService().cancelIntentSender(mTarget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 } catch (RemoteException e) {
680 }
681 }
682
683 /**
684 * Perform the operation associated with this PendingIntent.
685 *
686 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
687 *
688 * @throws CanceledException Throws CanceledException if the PendingIntent
689 * is no longer allowing more intents to be sent through it.
690 */
691 public void send() throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700692 send(null, 0, null, null, null, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 }
694
695 /**
696 * Perform the operation associated with this PendingIntent.
697 *
698 * @param code Result code to supply back to the PendingIntent's target.
699 *
700 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
701 *
702 * @throws CanceledException Throws CanceledException if the PendingIntent
703 * is no longer allowing more intents to be sent through it.
704 */
705 public void send(int code) throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700706 send(null, code, null, null, null, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 }
708
709 /**
710 * Perform the operation associated with this PendingIntent, allowing the
711 * caller to specify information about the Intent to use.
712 *
713 * @param context The Context of the caller.
714 * @param code Result code to supply back to the PendingIntent's target.
715 * @param intent Additional Intent data. See {@link Intent#fillIn
716 * Intent.fillIn()} for information on how this is applied to the
Svetoslavb0a78392015-04-10 17:25:35 -0700717 * original Intent. If flag {@link #FLAG_IMMUTABLE} was set when this
718 * pending intent was created, this argument will be ignored.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 *
720 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
721 *
722 * @throws CanceledException Throws CanceledException if the PendingIntent
723 * is no longer allowing more intents to be sent through it.
724 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700725 public void send(Context context, int code, @Nullable Intent intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700727 send(context, code, intent, null, null, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 }
729
730 /**
731 * Perform the operation associated with this PendingIntent, allowing the
732 * caller to be notified when the send has completed.
733 *
734 * @param code Result code to supply back to the PendingIntent's target.
735 * @param onFinished The object to call back on when the send has
736 * completed, or null for no callback.
737 * @param handler Handler identifying the thread on which the callback
738 * should happen. If null, the callback will happen from the thread
739 * pool of the process.
740 *
741 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
742 *
743 * @throws CanceledException Throws CanceledException if the PendingIntent
744 * is no longer allowing more intents to be sent through it.
745 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700746 public void send(int code, @Nullable OnFinished onFinished, @Nullable Handler handler)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700748 send(null, code, null, onFinished, handler, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 }
750
751 /**
752 * Perform the operation associated with this PendingIntent, allowing the
753 * caller to specify information about the Intent to use and be notified
754 * when the send has completed.
755 *
756 * <p>For the intent parameter, a PendingIntent
757 * often has restrictions on which fields can be supplied here, based on
758 * how the PendingIntent was retrieved in {@link #getActivity},
759 * {@link #getBroadcast}, or {@link #getService}.
760 *
761 * @param context The Context of the caller. This may be null if
762 * <var>intent</var> is also null.
763 * @param code Result code to supply back to the PendingIntent's target.
764 * @param intent Additional Intent data. See {@link Intent#fillIn
765 * Intent.fillIn()} for information on how this is applied to the
766 * original Intent. Use null to not modify the original Intent.
Svetoslavb0a78392015-04-10 17:25:35 -0700767 * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
768 * created, this argument will be ignored.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 * @param onFinished The object to call back on when the send has
770 * completed, or null for no callback.
771 * @param handler Handler identifying the thread on which the callback
772 * should happen. If null, the callback will happen from the thread
773 * pool of the process.
774 *
775 * @see #send()
776 * @see #send(int)
777 * @see #send(Context, int, Intent)
778 * @see #send(int, android.app.PendingIntent.OnFinished, Handler)
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700779 * @see #send(Context, int, Intent, OnFinished, Handler, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 *
781 * @throws CanceledException Throws CanceledException if the PendingIntent
782 * is no longer allowing more intents to be sent through it.
783 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700784 public void send(Context context, int code, @Nullable Intent intent,
785 @Nullable OnFinished onFinished, @Nullable Handler handler) throws CanceledException {
786 send(context, code, intent, onFinished, handler, null, null);
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700787 }
788
789 /**
790 * Perform the operation associated with this PendingIntent, allowing the
791 * caller to specify information about the Intent to use and be notified
792 * when the send has completed.
793 *
794 * <p>For the intent parameter, a PendingIntent
795 * often has restrictions on which fields can be supplied here, based on
796 * how the PendingIntent was retrieved in {@link #getActivity},
797 * {@link #getBroadcast}, or {@link #getService}.
798 *
799 * @param context The Context of the caller. This may be null if
800 * <var>intent</var> is also null.
801 * @param code Result code to supply back to the PendingIntent's target.
802 * @param intent Additional Intent data. See {@link Intent#fillIn
803 * Intent.fillIn()} for information on how this is applied to the
804 * original Intent. Use null to not modify the original Intent.
Svetoslavb0a78392015-04-10 17:25:35 -0700805 * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
806 * created, this argument will be ignored.
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700807 * @param onFinished The object to call back on when the send has
808 * completed, or null for no callback.
809 * @param handler Handler identifying the thread on which the callback
810 * should happen. If null, the callback will happen from the thread
811 * pool of the process.
812 * @param requiredPermission Name of permission that a recipient of the PendingIntent
813 * is required to hold. This is only valid for broadcast intents, and
814 * corresponds to the permission argument in
815 * {@link Context#sendBroadcast(Intent, String) Context.sendOrderedBroadcast(Intent, String)}.
816 * If null, no permission is required.
817 *
818 * @see #send()
819 * @see #send(int)
820 * @see #send(Context, int, Intent)
821 * @see #send(int, android.app.PendingIntent.OnFinished, Handler)
822 * @see #send(Context, int, Intent, OnFinished, Handler)
823 *
824 * @throws CanceledException Throws CanceledException if the PendingIntent
825 * is no longer allowing more intents to be sent through it.
826 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700827 public void send(Context context, int code, @Nullable Intent intent,
828 @Nullable OnFinished onFinished, @Nullable Handler handler,
829 @Nullable String requiredPermission)
830 throws CanceledException {
831 send(context, code, intent, onFinished, handler, requiredPermission, null);
832 }
833
834 /**
835 * Perform the operation associated with this PendingIntent, allowing the
836 * caller to specify information about the Intent to use and be notified
837 * when the send has completed.
838 *
839 * <p>For the intent parameter, a PendingIntent
840 * often has restrictions on which fields can be supplied here, based on
841 * how the PendingIntent was retrieved in {@link #getActivity},
842 * {@link #getBroadcast}, or {@link #getService}.
843 *
844 * @param context The Context of the caller. This may be null if
845 * <var>intent</var> is also null.
846 * @param code Result code to supply back to the PendingIntent's target.
847 * @param intent Additional Intent data. See {@link Intent#fillIn
848 * Intent.fillIn()} for information on how this is applied to the
849 * original Intent. Use null to not modify the original Intent.
850 * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
851 * created, this argument will be ignored.
852 * @param onFinished The object to call back on when the send has
853 * completed, or null for no callback.
854 * @param handler Handler identifying the thread on which the callback
855 * should happen. If null, the callback will happen from the thread
856 * pool of the process.
857 * @param requiredPermission Name of permission that a recipient of the PendingIntent
858 * is required to hold. This is only valid for broadcast intents, and
859 * corresponds to the permission argument in
860 * {@link Context#sendBroadcast(Intent, String) Context.sendOrderedBroadcast(Intent, String)}.
861 * If null, no permission is required.
862 * @param options Additional options the caller would like to provide to modify the sending
863 * behavior. May be built from an {@link ActivityOptions} to apply to an activity start.
864 *
865 * @see #send()
866 * @see #send(int)
867 * @see #send(Context, int, Intent)
868 * @see #send(int, android.app.PendingIntent.OnFinished, Handler)
869 * @see #send(Context, int, Intent, OnFinished, Handler)
870 *
871 * @throws CanceledException Throws CanceledException if the PendingIntent
872 * is no longer allowing more intents to be sent through it.
873 */
874 public void send(Context context, int code, @Nullable Intent intent,
875 @Nullable OnFinished onFinished, @Nullable Handler handler,
876 @Nullable String requiredPermission, @Nullable Bundle options)
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700877 throws CanceledException {
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100878 if (sendAndReturnResult(context, code, intent, onFinished, handler, requiredPermission,
879 options) < 0) {
880 throw new CanceledException();
881 }
882 }
883
884 /**
885 * Like {@link #send}, but returns the result
886 * @hide
887 */
888 public int sendAndReturnResult(Context context, int code, @Nullable Intent intent,
889 @Nullable OnFinished onFinished, @Nullable Handler handler,
890 @Nullable String requiredPermission, @Nullable Bundle options)
891 throws CanceledException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 try {
893 String resolvedType = intent != null ?
894 intent.resolveTypeIfNeeded(context.getContentResolver())
895 : null;
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100896 return ActivityManager.getService().sendIntentSender(
Dianne Hackborn98305522017-05-05 17:53:53 -0700897 mTarget, mWhitelistToken, code, intent, resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 onFinished != null
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700899 ? new FinishedDispatcher(this, onFinished, handler)
900 : null,
Dianne Hackborna750a632015-06-16 17:18:23 -0700901 requiredPermission, options);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 } catch (RemoteException e) {
903 throw new CanceledException(e);
904 }
905 }
906
907 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700908 * @deprecated Renamed to {@link #getCreatorPackage()}.
909 */
910 @Deprecated
911 public String getTargetPackage() {
912 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800913 return ActivityManager.getService()
Dianne Hackborn8832c182012-09-17 17:20:24 -0700914 .getPackageForIntentSender(mTarget);
915 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100916 throw e.rethrowFromSystemServer();
Dianne Hackborn8832c182012-09-17 17:20:24 -0700917 }
918 }
919
920 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 * Return the package name of the application that created this
922 * PendingIntent, that is the identity under which you will actually be
923 * sending the Intent. The returned string is supplied by the system, so
924 * that an application can not spoof its package.
925 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800926 * <p class="note">Be careful about how you use this. All this tells you is
927 * who created the PendingIntent. It does <strong>not</strong> tell you who
928 * handed the PendingIntent to you: that is, PendingIntent objects are intended to be
929 * passed between applications, so the PendingIntent you receive from an application
930 * could actually be one it received from another application, meaning the result
931 * you get here will identify the original application. Because of this, you should
932 * only use this information to identify who you expect to be interacting with
933 * through a {@link #send} call, not who gave you the PendingIntent.</p>
934 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 * @return The package name of the PendingIntent, or null if there is
936 * none associated with it.
937 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700938 @Nullable
Dianne Hackborn8832c182012-09-17 17:20:24 -0700939 public String getCreatorPackage() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800941 return ActivityManager.getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 .getPackageForIntentSender(mTarget);
943 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100944 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 }
946 }
947
948 /**
Dianne Hackbornc7501272012-08-14 18:05:05 -0700949 * Return the uid of the application that created this
950 * PendingIntent, that is the identity under which you will actually be
951 * sending the Intent. The returned integer is supplied by the system, so
952 * that an application can not spoof its uid.
953 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800954 * <p class="note">Be careful about how you use this. All this tells you is
955 * who created the PendingIntent. It does <strong>not</strong> tell you who
956 * handed the PendingIntent to you: that is, PendingIntent objects are intended to be
957 * passed between applications, so the PendingIntent you receive from an application
958 * could actually be one it received from another application, meaning the result
959 * you get here will identify the original application. Because of this, you should
960 * only use this information to identify who you expect to be interacting with
961 * through a {@link #send} call, not who gave you the PendingIntent.</p>
962 *
Dianne Hackbornc7501272012-08-14 18:05:05 -0700963 * @return The uid of the PendingIntent, or -1 if there is
964 * none associated with it.
965 */
Dianne Hackborn8832c182012-09-17 17:20:24 -0700966 public int getCreatorUid() {
Dianne Hackbornc7501272012-08-14 18:05:05 -0700967 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800968 return ActivityManager.getService()
Dianne Hackbornc7501272012-08-14 18:05:05 -0700969 .getUidForIntentSender(mTarget);
970 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100971 throw e.rethrowFromSystemServer();
Dianne Hackbornc7501272012-08-14 18:05:05 -0700972 }
973 }
974
975 /**
Selim Cinekd83203c2018-04-18 14:34:27 +0800976 * Register a listener to when this pendingIntent is cancelled. There are no guarantees on which
977 * thread a listener will be called and it's up to the caller to synchronize. This may
978 * trigger a synchronous binder call so should therefore usually be called on a background
979 * thread.
980 *
981 * @hide
982 */
983 public void registerCancelListener(CancelListener cancelListener) {
984 synchronized (this) {
985 if (mCancelReceiver == null) {
986 mCancelReceiver = new IResultReceiver.Stub() {
987 @Override
988 public void send(int resultCode, Bundle resultData) throws RemoteException {
989 notifyCancelListeners();
990 }
991 };
992 }
993 if (mCancelListeners == null) {
994 mCancelListeners = new ArraySet<>();
995 }
996 boolean wasEmpty = mCancelListeners.isEmpty();
997 mCancelListeners.add(cancelListener);
998 if (wasEmpty) {
999 try {
1000 ActivityManager.getService().registerIntentSenderCancelListener(mTarget,
1001 mCancelReceiver);
1002 } catch (RemoteException e) {
1003 throw e.rethrowFromSystemServer();
1004 }
1005 }
1006 }
1007 }
1008
1009 private void notifyCancelListeners() {
1010 ArraySet<CancelListener> cancelListeners;
1011 synchronized (this) {
1012 cancelListeners = new ArraySet<>(mCancelListeners);
1013 }
1014 int size = cancelListeners.size();
1015 for (int i = 0; i < size; i++) {
1016 cancelListeners.valueAt(i).onCancelled(this);
1017 }
1018 }
1019
1020 /**
1021 * Un-register a listener to when this pendingIntent is cancelled.
1022 *
1023 * @hide
1024 */
1025 public void unregisterCancelListener(CancelListener cancelListener) {
1026 synchronized (this) {
1027 if (mCancelListeners == null) {
1028 return;
1029 }
1030 boolean wasEmpty = mCancelListeners.isEmpty();
1031 mCancelListeners.remove(cancelListener);
1032 if (mCancelListeners.isEmpty() && !wasEmpty) {
1033 try {
1034 ActivityManager.getService().unregisterIntentSenderCancelListener(mTarget,
1035 mCancelReceiver);
1036 } catch (RemoteException e) {
1037 throw e.rethrowFromSystemServer();
1038 }
1039 }
1040 }
1041 }
1042
1043 /**
Dianne Hackbornc7501272012-08-14 18:05:05 -07001044 * Return the user handle of the application that created this
1045 * PendingIntent, that is the user under which you will actually be
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001046 * sending the Intent. The returned UserHandle is supplied by the system, so
Dianne Hackbornc7501272012-08-14 18:05:05 -07001047 * that an application can not spoof its user. See
1048 * {@link android.os.Process#myUserHandle() Process.myUserHandle()} for
1049 * more explanation of user handles.
1050 *
Dianne Hackborna53ee352013-02-20 12:47:02 -08001051 * <p class="note">Be careful about how you use this. All this tells you is
1052 * who created the PendingIntent. It does <strong>not</strong> tell you who
1053 * handed the PendingIntent to you: that is, PendingIntent objects are intended to be
1054 * passed between applications, so the PendingIntent you receive from an application
1055 * could actually be one it received from another application, meaning the result
1056 * you get here will identify the original application. Because of this, you should
1057 * only use this information to identify who you expect to be interacting with
1058 * through a {@link #send} call, not who gave you the PendingIntent.</p>
1059 *
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001060 * @return The user handle of the PendingIntent, or null if there is
Dianne Hackbornc7501272012-08-14 18:05:05 -07001061 * none associated with it.
1062 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001063 @Nullable
Dianne Hackborn8832c182012-09-17 17:20:24 -07001064 public UserHandle getCreatorUserHandle() {
Dianne Hackbornc7501272012-08-14 18:05:05 -07001065 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001066 int uid = ActivityManager.getService()
Dianne Hackbornc7501272012-08-14 18:05:05 -07001067 .getUidForIntentSender(mTarget);
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001068 return uid > 0 ? new UserHandle(UserHandle.getUserId(uid)) : null;
Dianne Hackbornc7501272012-08-14 18:05:05 -07001069 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001070 throw e.rethrowFromSystemServer();
Dianne Hackbornc7501272012-08-14 18:05:05 -07001071 }
1072 }
1073
1074 /**
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001075 * @hide
1076 * Check to verify that this PendingIntent targets a specific package.
1077 */
1078 public boolean isTargetedToPackage() {
1079 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001080 return ActivityManager.getService()
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001081 .isIntentSenderTargetedToPackage(mTarget);
1082 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001083 throw e.rethrowFromSystemServer();
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001084 }
1085 }
1086
1087 /**
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001088 * @hide
1089 * Check whether this PendingIntent will launch an Activity.
1090 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001091 @UnsupportedAppUsage
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001092 public boolean isActivity() {
1093 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001094 return ActivityManager.getService()
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001095 .isIntentSenderAnActivity(mTarget);
1096 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001097 throw e.rethrowFromSystemServer();
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001098 }
1099 }
1100
1101 /**
Dianne Hackborn81038902012-11-26 17:04:09 -08001102 * @hide
Suprabh Shukladb6bf662017-08-30 15:41:53 -07001103 * Check whether this PendingIntent will launch a foreground service
1104 */
1105 public boolean isForegroundService() {
1106 try {
1107 return ActivityManager.getService()
1108 .isIntentSenderAForegroundService(mTarget);
1109 } catch (RemoteException e) {
1110 throw e.rethrowFromSystemServer();
1111 }
1112 }
1113
1114 /**
1115 * @hide
Christopher Tate2f558d22019-01-17 16:58:31 -08001116 * Check whether this PendingIntent will launch an Activity.
1117 */
1118 public boolean isBroadcast() {
1119 try {
1120 return ActivityManager.getService()
1121 .isIntentSenderABroadcast(mTarget);
1122 } catch (RemoteException e) {
1123 throw e.rethrowFromSystemServer();
1124 }
1125 }
1126
1127 /**
1128 * @hide
Dianne Hackborn81038902012-11-26 17:04:09 -08001129 * Return the Intent of this PendingIntent.
1130 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001131 @UnsupportedAppUsage
Dianne Hackborn81038902012-11-26 17:04:09 -08001132 public Intent getIntent() {
1133 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001134 return ActivityManager.getService()
Dianne Hackborn81038902012-11-26 17:04:09 -08001135 .getIntentForIntentSender(mTarget);
1136 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001137 throw e.rethrowFromSystemServer();
Dianne Hackborn81038902012-11-26 17:04:09 -08001138 }
1139 }
1140
1141 /**
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001142 * @hide
1143 * Return descriptive tag for this PendingIntent.
1144 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001145 @UnsupportedAppUsage
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001146 public String getTag(String prefix) {
1147 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001148 return ActivityManager.getService()
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001149 .getTagForIntentSender(mTarget, prefix);
1150 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001151 throw e.rethrowFromSystemServer();
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001152 }
1153 }
1154
1155 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 * Comparison operator on two PendingIntent objects, such that true
1157 * is returned then they both represent the same operation from the
1158 * same package. This allows you to use {@link #getActivity},
1159 * {@link #getBroadcast}, or {@link #getService} multiple times (even
1160 * across a process being killed), resulting in different PendingIntent
1161 * objects but whose equals() method identifies them as being the same
1162 * operation.
1163 */
1164 @Override
1165 public boolean equals(Object otherObj) {
1166 if (otherObj instanceof PendingIntent) {
1167 return mTarget.asBinder().equals(((PendingIntent)otherObj)
1168 .mTarget.asBinder());
1169 }
1170 return false;
1171 }
1172
1173 @Override
1174 public int hashCode() {
1175 return mTarget.asBinder().hashCode();
1176 }
1177
1178 @Override
1179 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001180 StringBuilder sb = new StringBuilder(128);
1181 sb.append("PendingIntent{");
1182 sb.append(Integer.toHexString(System.identityHashCode(this)));
1183 sb.append(": ");
1184 sb.append(mTarget != null ? mTarget.asBinder() : null);
1185 sb.append('}');
1186 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 }
Kweku Adams61e03292017-10-19 14:27:12 -07001188
1189 /** @hide */
1190 public void writeToProto(ProtoOutputStream proto, long fieldId) {
1191 final long token = proto.start(fieldId);
1192 if (mTarget != null) {
1193 proto.write(PendingIntentProto.TARGET, mTarget.asBinder().toString());
1194 }
1195 proto.end(token);
1196 }
1197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 public int describeContents() {
1199 return 0;
1200 }
1201
1202 public void writeToParcel(Parcel out, int flags) {
1203 out.writeStrongBinder(mTarget.asBinder());
Svet Ganovddb94882016-06-23 19:55:24 -07001204 OnMarshaledListener listener = sOnMarshaledListener.get();
1205 if (listener != null) {
1206 listener.onMarshaled(this, out, flags);
1207 }
1208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 }
1210
1211 public static final Parcelable.Creator<PendingIntent> CREATOR
1212 = new Parcelable.Creator<PendingIntent>() {
1213 public PendingIntent createFromParcel(Parcel in) {
1214 IBinder target = in.readStrongBinder();
Dianne Hackborn98305522017-05-05 17:53:53 -07001215 return target != null
1216 ? new PendingIntent(target, in.getClassCookie(PendingIntent.class))
1217 : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 }
1219
1220 public PendingIntent[] newArray(int size) {
1221 return new PendingIntent[size];
1222 }
1223 };
1224
1225 /**
1226 * Convenience function for writing either a PendingIntent or null pointer to
1227 * a Parcel. You must use this with {@link #readPendingIntentOrNullFromParcel}
1228 * for later reading it.
1229 *
1230 * @param sender The PendingIntent to write, or null.
1231 * @param out Where to write the PendingIntent.
1232 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001233 public static void writePendingIntentOrNullToParcel(@Nullable PendingIntent sender,
1234 @NonNull Parcel out) {
Adrian Roosfb921842017-10-26 14:49:56 +02001235 out.writeStrongBinder(sender != null ? sender.mTarget.asBinder() : null);
1236 if (sender != null) {
1237 OnMarshaledListener listener = sOnMarshaledListener.get();
1238 if (listener != null) {
1239 listener.onMarshaled(sender, out, 0 /* flags */);
1240 }
1241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243
1244 /**
Dianne Hackborn98305522017-05-05 17:53:53 -07001245 * Convenience function for reading either a PendingIntent or null pointer from
1246 * a Parcel. You must have previously written the PendingIntent with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 * {@link #writePendingIntentOrNullToParcel}.
1248 *
Dianne Hackborn98305522017-05-05 17:53:53 -07001249 * @param in The Parcel containing the written PendingIntent.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 *
Dianne Hackborn98305522017-05-05 17:53:53 -07001251 * @return Returns the PendingIntent read from the Parcel, or null if null had
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 * been written.
1253 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001254 @Nullable
1255 public static PendingIntent readPendingIntentOrNullFromParcel(@NonNull Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 IBinder b = in.readStrongBinder();
Dianne Hackborn98305522017-05-05 17:53:53 -07001257 return b != null ? new PendingIntent(b, in.getClassCookie(PendingIntent.class)) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 }
1259
1260 /*package*/ PendingIntent(IIntentSender target) {
1261 mTarget = target;
1262 }
1263
Dianne Hackborn98305522017-05-05 17:53:53 -07001264 /*package*/ PendingIntent(IBinder target, Object cookie) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 mTarget = IIntentSender.Stub.asInterface(target);
Dianne Hackborn98305522017-05-05 17:53:53 -07001266 if (cookie != null) {
1267 mWhitelistToken = (IBinder)cookie;
1268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 }
1270
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07001271 /** @hide */
1272 public IIntentSender getTarget() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 return mTarget;
1274 }
Dianne Hackborn98305522017-05-05 17:53:53 -07001275
1276 /** @hide */
1277 public IBinder getWhitelistToken() {
1278 return mWhitelistToken;
1279 }
Selim Cinekd83203c2018-04-18 14:34:27 +08001280
1281 /**
1282 * A listener to when a pending intent is cancelled
1283 *
1284 * @hide
1285 */
1286 public interface CancelListener {
1287 /**
1288 * Called when a Pending Intent is cancelled.
1289 *
1290 * @param intent The intent that was cancelled.
1291 */
1292 void onCancelled(PendingIntent intent);
1293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294}