blob: b8348c7d4f221036ec1cbe7e34aca44a7d1f748e [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;
Artur Satayevc895b1b2019-12-10 17:47:51 +000022import android.compat.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.
Suprabh Shuklae513a8d2019-11-01 17:49:25 -070097 *
98 * <p>Also note that flags like {@link #FLAG_ONE_SHOT} or {@link #FLAG_IMMUTABLE} describe the
99 * PendingIntent instance and thus, are used to identify it. Any calls to retrieve or modify a
100 * PendingIntent created with these flags will also require these flags to be supplied in
101 * conjunction with others. E.g. To retrieve an existing PendingIntent created with
102 * FLAG_ONE_SHOT, <b>both</b> FLAG_ONE_SHOT and FLAG_NO_CREATE need to be supplied.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 */
104public final class PendingIntent implements Parcelable {
105 private final IIntentSender mTarget;
Selim Cinekd83203c2018-04-18 14:34:27 +0800106 private IResultReceiver mCancelReceiver;
Dianne Hackborn98305522017-05-05 17:53:53 -0700107 private IBinder mWhitelistToken;
Selim Cinekd83203c2018-04-18 14:34:27 +0800108 private ArraySet<CancelListener> mCancelListeners;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109
Tor Norbyed9273d62013-05-30 15:59:53 -0700110 /** @hide */
111 @IntDef(flag = true,
112 value = {
113 FLAG_ONE_SHOT,
114 FLAG_NO_CREATE,
115 FLAG_CANCEL_CURRENT,
116 FLAG_UPDATE_CURRENT,
Tor Norbyedfd1b582017-05-31 08:02:52 -0700117 FLAG_IMMUTABLE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700118
119 Intent.FILL_IN_ACTION,
120 Intent.FILL_IN_DATA,
121 Intent.FILL_IN_CATEGORIES,
122 Intent.FILL_IN_COMPONENT,
123 Intent.FILL_IN_PACKAGE,
124 Intent.FILL_IN_SOURCE_BOUNDS,
125 Intent.FILL_IN_SELECTOR,
126 Intent.FILL_IN_CLIP_DATA
127 })
128 @Retention(RetentionPolicy.SOURCE)
129 public @interface Flags {}
130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 /**
Scott Maindf75bdc2013-01-15 15:12:13 -0800132 * Flag indicating that this PendingIntent can be used only once.
133 * For use with {@link #getActivity}, {@link #getBroadcast}, and
134 * {@link #getService}. <p>If set, after
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 * {@link #send()} is called on it, it will be automatically
136 * canceled for you and any future attempt to send through it will fail.
137 */
138 public static final int FLAG_ONE_SHOT = 1<<30;
139 /**
Katie McCormick87d9d1a2014-03-31 16:16:32 -0700140 * Flag indicating that if the described PendingIntent does not
141 * already exist, then simply return null instead of creating it.
Scott Maindf75bdc2013-01-15 15:12:13 -0800142 * For use with {@link #getActivity}, {@link #getBroadcast}, and
143 * {@link #getService}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 */
145 public static final int FLAG_NO_CREATE = 1<<29;
146 /**
Scott Maindf75bdc2013-01-15 15:12:13 -0800147 * Flag indicating that if the described PendingIntent already exists,
148 * the current one should be canceled before generating a new one.
149 * For use with {@link #getActivity}, {@link #getBroadcast}, and
150 * {@link #getService}. <p>You can use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 * this to retrieve a new PendingIntent when you are only changing the
152 * extra data in the Intent; by canceling the previous pending intent,
153 * this ensures that only entities given the new data will be able to
154 * launch it. If this assurance is not an issue, consider
155 * {@link #FLAG_UPDATE_CURRENT}.
156 */
157 public static final int FLAG_CANCEL_CURRENT = 1<<28;
158 /**
Scott Maindf75bdc2013-01-15 15:12:13 -0800159 * Flag indicating that if the described PendingIntent already exists,
160 * then keep it but replace its extra data with what is in this new
161 * Intent. For use with {@link #getActivity}, {@link #getBroadcast}, and
162 * {@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 -0800163 * extras change, and don't care that any entities that received your
164 * previous PendingIntent will be able to launch it with your new
165 * extras even if they are not explicitly given to it.
166 */
167 public static final int FLAG_UPDATE_CURRENT = 1<<27;
168
169 /**
Svetoslavb0a78392015-04-10 17:25:35 -0700170 * Flag indicating that the created PendingIntent should be immutable.
171 * This means that the additional intent argument passed to the send
172 * methods to fill in unpopulated properties of this intent will be
173 * ignored.
174 */
175 public static final int FLAG_IMMUTABLE = 1<<26;
176
177 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 * Exception thrown when trying to send through a PendingIntent that
179 * has been canceled or is otherwise no longer able to execute the request.
180 */
181 public static class CanceledException extends AndroidException {
182 public CanceledException() {
183 }
184
185 public CanceledException(String name) {
186 super(name);
187 }
188
189 public CanceledException(Exception cause) {
190 super(cause);
191 }
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -0700192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193
194 /**
195 * Callback interface for discovering when a send operation has
196 * completed. Primarily for use with a PendingIntent that is
197 * performing a broadcast, this provides the same information as
198 * calling {@link Context#sendOrderedBroadcast(Intent, String,
199 * android.content.BroadcastReceiver, Handler, int, String, Bundle)
200 * Context.sendBroadcast()} with a final BroadcastReceiver.
201 */
202 public interface OnFinished {
203 /**
204 * Called when a send operation as completed.
205 *
206 * @param pendingIntent The PendingIntent this operation was sent through.
207 * @param intent The original Intent that was sent.
208 * @param resultCode The final result code determined by the send.
209 * @param resultData The final data collected by a broadcast.
210 * @param resultExtras The final extras collected by a broadcast.
211 */
212 void onSendFinished(PendingIntent pendingIntent, Intent intent,
213 int resultCode, String resultData, Bundle resultExtras);
214 }
215
216 private static class FinishedDispatcher extends IIntentReceiver.Stub
217 implements Runnable {
218 private final PendingIntent mPendingIntent;
219 private final OnFinished mWho;
220 private final Handler mHandler;
221 private Intent mIntent;
222 private int mResultCode;
223 private String mResultData;
224 private Bundle mResultExtras;
Wale Ogunwale9a6ef1e2015-06-02 13:41:00 -0700225 private static Handler sDefaultSystemHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 FinishedDispatcher(PendingIntent pi, OnFinished who, Handler handler) {
227 mPendingIntent = pi;
228 mWho = who;
Wale Ogunwale9a6ef1e2015-06-02 13:41:00 -0700229 if (handler == null && ActivityThread.isSystem()) {
230 // We assign a default handler for the system process to avoid deadlocks when
231 // processing receivers in various components that hold global service locks.
232 if (sDefaultSystemHandler == null) {
233 sDefaultSystemHandler = new Handler(Looper.getMainLooper());
234 }
235 mHandler = sDefaultSystemHandler;
236 } else {
237 mHandler = handler;
238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 }
Dianne Hackborn20e80982012-08-31 19:00:44 -0700240 public void performReceive(Intent intent, int resultCode, String data,
241 Bundle extras, boolean serialized, boolean sticky, int sendingUser) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 mIntent = intent;
243 mResultCode = resultCode;
244 mResultData = data;
245 mResultExtras = extras;
246 if (mHandler == null) {
247 run();
248 } else {
249 mHandler.post(this);
250 }
251 }
252 public void run() {
253 mWho.onSendFinished(mPendingIntent, mIntent, mResultCode,
254 mResultData, mResultExtras);
255 }
256 }
257
258 /**
Svet Ganovddb94882016-06-23 19:55:24 -0700259 * Listener for observing when pending intents are written to a parcel.
260 *
261 * @hide
262 */
263 public interface OnMarshaledListener {
264 /**
265 * Called when a pending intent is written to a parcel.
266 *
267 * @param intent The pending intent.
268 * @param parcel The parcel to which it was written.
269 * @param flags The parcel flags when it was written.
270 */
271 void onMarshaled(PendingIntent intent, Parcel parcel, int flags);
272 }
273
274 private static final ThreadLocal<OnMarshaledListener> sOnMarshaledListener
275 = new ThreadLocal<>();
276
277 /**
278 * Registers an listener for pending intents being written to a parcel.
279 *
280 * @param listener The listener, null to clear.
281 *
282 * @hide
283 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100284 @UnsupportedAppUsage
Svet Ganovddb94882016-06-23 19:55:24 -0700285 public static void setOnMarshaledListener(OnMarshaledListener listener) {
286 sOnMarshaledListener.set(listener);
287 }
288
289 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 * Retrieve a PendingIntent that will start a new activity, like calling
291 * {@link Context#startActivity(Intent) Context.startActivity(Intent)}.
292 * Note that the activity will be started outside of the context of an
293 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
294 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent.
295 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800296 * <p class="note">For security reasons, the {@link android.content.Intent}
297 * you supply here should almost always be an <em>explicit intent</em>,
298 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500299 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800300 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 * @param context The Context in which this PendingIntent should start
302 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200303 * @param requestCode Private request code for the sender
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 * @param intent Intent of the activity to be launched.
305 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
306 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
307 * or any of the flags as supported by
308 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
309 * of the intent that can be supplied when the actual send happens.
310 *
311 * @return Returns an existing or new PendingIntent matching the given
312 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
313 * supplied.
314 */
315 public static PendingIntent getActivity(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700316 Intent intent, @Flags int flags) {
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700317 return getActivity(context, requestCode, intent, flags, null);
318 }
319
320 /**
321 * Retrieve a PendingIntent that will start a new activity, like calling
322 * {@link Context#startActivity(Intent) Context.startActivity(Intent)}.
323 * Note that the activity will be started outside of the context of an
324 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
325 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent.
326 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800327 * <p class="note">For security reasons, the {@link android.content.Intent}
328 * you supply here should almost always be an <em>explicit intent</em>,
329 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500330 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800331 *
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700332 * @param context The Context in which this PendingIntent should start
333 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200334 * @param requestCode Private request code for the sender
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700335 * @param intent Intent of the activity to be launched.
336 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
337 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
338 * or any of the flags as supported by
339 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
340 * of the intent that can be supplied when the actual send happens.
341 * @param options Additional options for how the Activity should be started.
342 * May be null if there are no options.
343 *
344 * @return Returns an existing or new PendingIntent matching the given
345 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
346 * supplied.
347 */
348 public static PendingIntent getActivity(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700349 @NonNull Intent intent, @Flags int flags, @Nullable Bundle options) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 String packageName = context.getPackageName();
351 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
352 context.getContentResolver()) : null;
353 try {
Jeff Sharkey02ffba92013-03-08 16:13:15 -0800354 intent.migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700355 intent.prepareToLeaveProcess(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 IIntentSender target =
Philip P. Moltmanne7421e92020-02-10 16:14:12 +0000357 ActivityManager.getService().getIntentSender(
358 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800359 null, null, requestCode, new Intent[] { intent },
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700360 resolvedType != null ? new String[] { resolvedType } : null,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700361 flags, options, context.getUserId());
Dianne Hackborn41203752012-08-31 14:05:51 -0700362 return target != null ? new PendingIntent(target) : null;
363 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100364 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -0700365 }
Dianne Hackborn41203752012-08-31 14:05:51 -0700366 }
367
368 /**
369 * @hide
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700370 * Note that UserHandle.CURRENT will be interpreted at the time the
371 * activity is started, not when the pending intent is created.
Dianne Hackborn41203752012-08-31 14:05:51 -0700372 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100373 @UnsupportedAppUsage
Dianne Hackborn41203752012-08-31 14:05:51 -0700374 public static PendingIntent getActivityAsUser(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700375 @NonNull Intent intent, int flags, Bundle options, UserHandle user) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700376 String packageName = context.getPackageName();
377 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
378 context.getContentResolver()) : null;
379 try {
Jeff Sharkey02ffba92013-03-08 16:13:15 -0800380 intent.migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700381 intent.prepareToLeaveProcess(context);
Dianne Hackborn41203752012-08-31 14:05:51 -0700382 IIntentSender target =
Philip P. Moltmanne7421e92020-02-10 16:14:12 +0000383 ActivityManager.getService().getIntentSender(
384 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -0700385 null, null, requestCode, new Intent[] { intent },
386 resolvedType != null ? new String[] { resolvedType } : null,
387 flags, options, user.getIdentifier());
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800388 return target != null ? new PendingIntent(target) : null;
389 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100390 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800391 }
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800392 }
393
394 /**
395 * Like {@link #getActivity(Context, int, Intent, int)}, but allows an
Tim Hutt5313c9f2012-12-10 12:34:19 +0000396 * array of Intents to be supplied. The last Intent in the array is
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800397 * taken as the primary key for the PendingIntent, like the single Intent
398 * given to {@link #getActivity(Context, int, Intent, int)}. Upon sending
399 * the resulting PendingIntent, all of the Intents are started in the same
400 * way as they would be by passing them to {@link Context#startActivities(Intent[])}.
401 *
402 * <p class="note">
403 * The <em>first</em> intent in the array will be started outside of the context of an
404 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
405 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent. (Activities after
406 * the first in the array are started in the context of the previous activity
407 * in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
408 * </p>
409 *
410 * <p class="note">
411 * The <em>last</em> intent in the array represents the key for the
412 * PendingIntent. In other words, it is the significant element for matching
413 * (as done with the single intent given to {@link #getActivity(Context, int, Intent, int)},
414 * its content will be the subject of replacement by
415 * {@link #send(Context, int, Intent)} and {@link #FLAG_UPDATE_CURRENT}, etc.
416 * This is because it is the most specific of the supplied intents, and the
417 * UI the user actually sees when the intents are started.
418 * </p>
419 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800420 * <p class="note">For security reasons, the {@link android.content.Intent} objects
421 * you supply here should almost always be <em>explicit intents</em>,
422 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500423 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800424 *
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800425 * @param context The Context in which this PendingIntent should start
426 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200427 * @param requestCode Private request code for the sender
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800428 * @param intents Array of Intents of the activities to be launched.
429 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
430 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
431 * or any of the flags as supported by
432 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
433 * of the intent that can be supplied when the actual send happens.
434 *
435 * @return Returns an existing or new PendingIntent matching the given
436 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
437 * supplied.
438 */
439 public static PendingIntent getActivities(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700440 @NonNull Intent[] intents, @Flags int flags) {
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700441 return getActivities(context, requestCode, intents, flags, null);
442 }
443
444 /**
445 * Like {@link #getActivity(Context, int, Intent, int)}, but allows an
Tim Hutt5313c9f2012-12-10 12:34:19 +0000446 * array of Intents to be supplied. The last Intent in the array is
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700447 * taken as the primary key for the PendingIntent, like the single Intent
448 * given to {@link #getActivity(Context, int, Intent, int)}. Upon sending
449 * the resulting PendingIntent, all of the Intents are started in the same
450 * way as they would be by passing them to {@link Context#startActivities(Intent[])}.
451 *
452 * <p class="note">
453 * The <em>first</em> intent in the array will be started outside of the context of an
454 * existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
455 * Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent. (Activities after
456 * the first in the array are started in the context of the previous activity
457 * in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
458 * </p>
459 *
460 * <p class="note">
461 * The <em>last</em> intent in the array represents the key for the
462 * PendingIntent. In other words, it is the significant element for matching
463 * (as done with the single intent given to {@link #getActivity(Context, int, Intent, int)},
464 * its content will be the subject of replacement by
465 * {@link #send(Context, int, Intent)} and {@link #FLAG_UPDATE_CURRENT}, etc.
466 * This is because it is the most specific of the supplied intents, and the
467 * UI the user actually sees when the intents are started.
468 * </p>
469 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800470 * <p class="note">For security reasons, the {@link android.content.Intent} objects
471 * you supply here should almost always be <em>explicit intents</em>,
472 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500473 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800474 *
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700475 * @param context The Context in which this PendingIntent should start
476 * the activity.
Danny Baumannf15a4192013-04-05 13:42:57 +0200477 * @param requestCode Private request code for the sender
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700478 * @param intents Array of Intents of the activities to be launched.
479 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
480 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
Svet Ganovf2acc542015-11-06 09:02:00 -0800481 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700482 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
483 * of the intent that can be supplied when the actual send happens.
484 *
485 * @return Returns an existing or new PendingIntent matching the given
486 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
487 * supplied.
488 */
489 public static PendingIntent getActivities(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700490 @NonNull Intent[] intents, @Flags int flags, @Nullable Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800491 String packageName = context.getPackageName();
492 String[] resolvedTypes = new String[intents.length];
493 for (int i=0; i<intents.length; i++) {
Jeff Sharkeya14acd22013-04-02 18:27:45 -0700494 intents[i].migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700495 intents[i].prepareToLeaveProcess(context);
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800496 resolvedTypes[i] = intents[i].resolveTypeIfNeeded(context.getContentResolver());
497 }
498 try {
499 IIntentSender target =
Philip P. Moltmanne7421e92020-02-10 16:14:12 +0000500 ActivityManager.getService().getIntentSender(
501 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -0700502 null, null, requestCode, intents, resolvedTypes, flags, options,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700503 context.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 return target != null ? new PendingIntent(target) : null;
505 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100506 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 }
509
510 /**
Adam Powelld56b4d12012-09-30 18:27:31 -0700511 * @hide
512 * Note that UserHandle.CURRENT will be interpreted at the time the
513 * activity is started, not when the pending intent is created.
514 */
515 public static PendingIntent getActivitiesAsUser(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700516 @NonNull Intent[] intents, int flags, Bundle options, UserHandle user) {
Adam Powelld56b4d12012-09-30 18:27:31 -0700517 String packageName = context.getPackageName();
518 String[] resolvedTypes = new String[intents.length];
519 for (int i=0; i<intents.length; i++) {
Jeff Sharkeya14acd22013-04-02 18:27:45 -0700520 intents[i].migrateExtraStreamToClipData();
Jeff Sharkey344744b2016-01-28 19:03:30 -0700521 intents[i].prepareToLeaveProcess(context);
Adam Powelld56b4d12012-09-30 18:27:31 -0700522 resolvedTypes[i] = intents[i].resolveTypeIfNeeded(context.getContentResolver());
523 }
524 try {
525 IIntentSender target =
Philip P. Moltmanne7421e92020-02-10 16:14:12 +0000526 ActivityManager.getService().getIntentSender(
527 ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
Adam Powelld56b4d12012-09-30 18:27:31 -0700528 null, null, requestCode, intents, resolvedTypes,
529 flags, options, user.getIdentifier());
530 return target != null ? new PendingIntent(target) : null;
531 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100532 throw e.rethrowFromSystemServer();
Adam Powelld56b4d12012-09-30 18:27:31 -0700533 }
Adam Powelld56b4d12012-09-30 18:27:31 -0700534 }
535
536 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 * Retrieve a PendingIntent that will perform a broadcast, like calling
538 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
539 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800540 * <p class="note">For security reasons, the {@link android.content.Intent}
541 * you supply here should almost always be an <em>explicit intent</em>,
542 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500543 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800544 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 * @param context The Context in which this PendingIntent should perform
546 * the broadcast.
Danny Baumannf15a4192013-04-05 13:42:57 +0200547 * @param requestCode Private request code for the sender
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 * @param intent The Intent to be broadcast.
549 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
550 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
Svet Ganovf2acc542015-11-06 09:02:00 -0800551 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
553 * of the intent that can be supplied when the actual send happens.
554 *
555 * @return Returns an existing or new PendingIntent matching the given
556 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
557 * supplied.
558 */
559 public static PendingIntent getBroadcast(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700560 Intent intent, @Flags int flags) {
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700561 return getBroadcastAsUser(context, requestCode, intent, flags, context.getUser());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700562 }
563
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700564 /**
565 * @hide
566 * Note that UserHandle.CURRENT will be interpreted at the time the
567 * broadcast is sent, not when the pending intent is created.
568 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100569 @UnsupportedAppUsage
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700570 public static PendingIntent getBroadcastAsUser(Context context, int requestCode,
571 Intent intent, int flags, UserHandle userHandle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 String packageName = context.getPackageName();
573 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
574 context.getContentResolver()) : null;
575 try {
Jeff Sharkey344744b2016-01-28 19:03:30 -0700576 intent.prepareToLeaveProcess(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 IIntentSender target =
Philip P. Moltmanne7421e92020-02-10 16:14:12 +0000578 ActivityManager.getService().getIntentSender(
579 ActivityManager.INTENT_SENDER_BROADCAST, packageName,
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800580 null, null, requestCode, new Intent[] { intent },
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700581 resolvedType != null ? new String[] { resolvedType } : null,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700582 flags, null, userHandle.getIdentifier());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 return target != null ? new PendingIntent(target) : null;
584 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100585 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
588
589 /**
590 * Retrieve a PendingIntent that will start a service, like calling
591 * {@link Context#startService Context.startService()}. The start
592 * arguments given to the service will come from the extras of the Intent.
593 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800594 * <p class="note">For security reasons, the {@link android.content.Intent}
595 * you supply here should almost always be an <em>explicit intent</em>,
596 * that is specify an explicit component to be delivered to through
John Spurlockba231fc2014-02-18 13:19:57 -0500597 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
Dianne Hackborna53ee352013-02-20 12:47:02 -0800598 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 * @param context The Context in which this PendingIntent should start
600 * the service.
Danny Baumannf15a4192013-04-05 13:42:57 +0200601 * @param requestCode Private request code for the sender
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 * @param intent An Intent describing the service to be started.
603 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
604 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
Svet Ganovf2acc542015-11-06 09:02:00 -0800605 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
607 * of the intent that can be supplied when the actual send happens.
608 *
609 * @return Returns an existing or new PendingIntent matching the given
610 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
611 * supplied.
612 */
613 public static PendingIntent getService(Context context, int requestCode,
Tor Norbyed9273d62013-05-30 15:59:53 -0700614 @NonNull Intent intent, @Flags int flags) {
Christopher Tate08992ac2017-03-21 11:37:06 -0700615 return buildServicePendingIntent(context, requestCode, intent, flags,
616 ActivityManager.INTENT_SENDER_SERVICE);
617 }
618
619 /**
620 * Retrieve a PendingIntent that will start a foreground service, like calling
Dianne Hackborn6aba8532017-06-16 14:43:36 -0700621 * {@link Context#startForegroundService Context.startForegroundService()}. The start
Christopher Tate08992ac2017-03-21 11:37:06 -0700622 * arguments given to the service will come from the extras of the Intent.
623 *
624 * <p class="note">For security reasons, the {@link android.content.Intent}
625 * you supply here should almost always be an <em>explicit intent</em>,
626 * that is specify an explicit component to be delivered to through
627 * {@link Intent#setClass(android.content.Context, Class) Intent.setClass}</p>
628 *
629 * @param context The Context in which this PendingIntent should start
630 * the service.
631 * @param requestCode Private request code for the sender
632 * @param intent An Intent describing the service to be started.
633 * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
634 * {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
635 * {@link #FLAG_IMMUTABLE} or any of the flags as supported by
636 * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
637 * of the intent that can be supplied when the actual send happens.
638 *
639 * @return Returns an existing or new PendingIntent matching the given
640 * parameters. May return null only if {@link #FLAG_NO_CREATE} has been
641 * supplied.
642 */
643 public static PendingIntent getForegroundService(Context context, int requestCode,
644 @NonNull Intent intent, @Flags int flags) {
645 return buildServicePendingIntent(context, requestCode, intent, flags,
646 ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE);
647 }
648
649 private static PendingIntent buildServicePendingIntent(Context context, int requestCode,
650 Intent intent, int flags, int serviceKind) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 String packageName = context.getPackageName();
652 String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
653 context.getContentResolver()) : null;
654 try {
Jeff Sharkey344744b2016-01-28 19:03:30 -0700655 intent.prepareToLeaveProcess(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 IIntentSender target =
Philip P. Moltmanne7421e92020-02-10 16:14:12 +0000657 ActivityManager.getService().getIntentSender(
658 serviceKind, packageName,
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800659 null, null, requestCode, new Intent[] { intent },
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700660 resolvedType != null ? new String[] { resolvedType } : null,
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700661 flags, null, context.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 return target != null ? new PendingIntent(target) : null;
663 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100664 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 }
667
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -0700668 /**
669 * Retrieve a IntentSender object that wraps the existing sender of the PendingIntent
670 *
671 * @return Returns a IntentSender object that wraps the sender of PendingIntent
672 *
673 */
674 public IntentSender getIntentSender() {
Dianne Hackborn98305522017-05-05 17:53:53 -0700675 return new IntentSender(mTarget, mWhitelistToken);
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -0700676 }
677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 /**
679 * Cancel a currently active PendingIntent. Only the original application
Ken Wakasaf76a50c2012-03-09 19:56:35 +0900680 * owning a PendingIntent can cancel it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 */
682 public void cancel() {
683 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800684 ActivityManager.getService().cancelIntentSender(mTarget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 } catch (RemoteException e) {
686 }
687 }
688
689 /**
690 * Perform the operation associated with this PendingIntent.
691 *
692 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
693 *
694 * @throws CanceledException Throws CanceledException if the PendingIntent
695 * is no longer allowing more intents to be sent through it.
696 */
697 public void send() throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700698 send(null, 0, null, null, null, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 }
700
701 /**
702 * Perform the operation associated with this PendingIntent.
703 *
704 * @param code Result code to supply back to the PendingIntent's target.
705 *
706 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
707 *
708 * @throws CanceledException Throws CanceledException if the PendingIntent
709 * is no longer allowing more intents to be sent through it.
710 */
711 public void send(int code) throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700712 send(null, code, null, null, null, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 }
714
715 /**
716 * Perform the operation associated with this PendingIntent, allowing the
717 * caller to specify information about the Intent to use.
718 *
719 * @param context The Context of the caller.
720 * @param code Result code to supply back to the PendingIntent's target.
721 * @param intent Additional Intent data. See {@link Intent#fillIn
722 * Intent.fillIn()} for information on how this is applied to the
Svetoslavb0a78392015-04-10 17:25:35 -0700723 * original Intent. If flag {@link #FLAG_IMMUTABLE} was set when this
724 * pending intent was created, this argument will be ignored.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 *
726 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
727 *
728 * @throws CanceledException Throws CanceledException if the PendingIntent
729 * is no longer allowing more intents to be sent through it.
730 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700731 public void send(Context context, int code, @Nullable Intent intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700733 send(context, code, intent, null, null, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 }
735
736 /**
737 * Perform the operation associated with this PendingIntent, allowing the
738 * caller to be notified when the send has completed.
739 *
740 * @param code Result code to supply back to the PendingIntent's target.
741 * @param onFinished The object to call back on when the send has
742 * completed, or null for no callback.
743 * @param handler Handler identifying the thread on which the callback
744 * should happen. If null, the callback will happen from the thread
745 * pool of the process.
746 *
747 * @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
748 *
749 * @throws CanceledException Throws CanceledException if the PendingIntent
750 * is no longer allowing more intents to be sent through it.
751 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700752 public void send(int code, @Nullable OnFinished onFinished, @Nullable Handler handler)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 throws CanceledException {
Dianne Hackborna750a632015-06-16 17:18:23 -0700754 send(null, code, null, onFinished, handler, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 }
756
757 /**
758 * Perform the operation associated with this PendingIntent, allowing the
759 * caller to specify information about the Intent to use and be notified
760 * when the send has completed.
761 *
762 * <p>For the intent parameter, a PendingIntent
763 * often has restrictions on which fields can be supplied here, based on
764 * how the PendingIntent was retrieved in {@link #getActivity},
765 * {@link #getBroadcast}, or {@link #getService}.
766 *
767 * @param context The Context of the caller. This may be null if
768 * <var>intent</var> is also null.
769 * @param code Result code to supply back to the PendingIntent's target.
770 * @param intent Additional Intent data. See {@link Intent#fillIn
771 * Intent.fillIn()} for information on how this is applied to the
772 * original Intent. Use null to not modify the original Intent.
Svetoslavb0a78392015-04-10 17:25:35 -0700773 * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
774 * created, this argument will be ignored.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 * @param onFinished The object to call back on when the send has
776 * completed, or null for no callback.
777 * @param handler Handler identifying the thread on which the callback
778 * should happen. If null, the callback will happen from the thread
779 * pool of the process.
780 *
781 * @see #send()
782 * @see #send(int)
783 * @see #send(Context, int, Intent)
784 * @see #send(int, android.app.PendingIntent.OnFinished, Handler)
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700785 * @see #send(Context, int, Intent, OnFinished, Handler, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 *
787 * @throws CanceledException Throws CanceledException if the PendingIntent
788 * is no longer allowing more intents to be sent through it.
789 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700790 public void send(Context context, int code, @Nullable Intent intent,
791 @Nullable OnFinished onFinished, @Nullable Handler handler) throws CanceledException {
792 send(context, code, intent, onFinished, handler, null, null);
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700793 }
794
795 /**
796 * Perform the operation associated with this PendingIntent, allowing the
797 * caller to specify information about the Intent to use and be notified
798 * when the send has completed.
799 *
800 * <p>For the intent parameter, a PendingIntent
801 * often has restrictions on which fields can be supplied here, based on
802 * how the PendingIntent was retrieved in {@link #getActivity},
803 * {@link #getBroadcast}, or {@link #getService}.
804 *
805 * @param context The Context of the caller. This may be null if
806 * <var>intent</var> is also null.
807 * @param code Result code to supply back to the PendingIntent's target.
808 * @param intent Additional Intent data. See {@link Intent#fillIn
809 * Intent.fillIn()} for information on how this is applied to the
810 * original Intent. Use null to not modify the original Intent.
Svetoslavb0a78392015-04-10 17:25:35 -0700811 * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
812 * created, this argument will be ignored.
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700813 * @param onFinished The object to call back on when the send has
814 * completed, or null for no callback.
815 * @param handler Handler identifying the thread on which the callback
816 * should happen. If null, the callback will happen from the thread
817 * pool of the process.
818 * @param requiredPermission Name of permission that a recipient of the PendingIntent
819 * is required to hold. This is only valid for broadcast intents, and
820 * corresponds to the permission argument in
821 * {@link Context#sendBroadcast(Intent, String) Context.sendOrderedBroadcast(Intent, String)}.
822 * If null, no permission is required.
823 *
824 * @see #send()
825 * @see #send(int)
826 * @see #send(Context, int, Intent)
827 * @see #send(int, android.app.PendingIntent.OnFinished, Handler)
828 * @see #send(Context, int, Intent, OnFinished, Handler)
829 *
830 * @throws CanceledException Throws CanceledException if the PendingIntent
831 * is no longer allowing more intents to be sent through it.
832 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700833 public void send(Context context, int code, @Nullable Intent intent,
834 @Nullable OnFinished onFinished, @Nullable Handler handler,
835 @Nullable String requiredPermission)
836 throws CanceledException {
837 send(context, code, intent, onFinished, handler, requiredPermission, null);
838 }
839
840 /**
841 * Perform the operation associated with this PendingIntent, allowing the
842 * caller to specify information about the Intent to use and be notified
843 * when the send has completed.
844 *
845 * <p>For the intent parameter, a PendingIntent
846 * often has restrictions on which fields can be supplied here, based on
847 * how the PendingIntent was retrieved in {@link #getActivity},
848 * {@link #getBroadcast}, or {@link #getService}.
849 *
850 * @param context The Context of the caller. This may be null if
851 * <var>intent</var> is also null.
852 * @param code Result code to supply back to the PendingIntent's target.
853 * @param intent Additional Intent data. See {@link Intent#fillIn
854 * Intent.fillIn()} for information on how this is applied to the
855 * original Intent. Use null to not modify the original Intent.
856 * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
857 * created, this argument will be ignored.
858 * @param onFinished The object to call back on when the send has
859 * completed, or null for no callback.
860 * @param handler Handler identifying the thread on which the callback
861 * should happen. If null, the callback will happen from the thread
862 * pool of the process.
863 * @param requiredPermission Name of permission that a recipient of the PendingIntent
864 * is required to hold. This is only valid for broadcast intents, and
865 * corresponds to the permission argument in
866 * {@link Context#sendBroadcast(Intent, String) Context.sendOrderedBroadcast(Intent, String)}.
867 * If null, no permission is required.
868 * @param options Additional options the caller would like to provide to modify the sending
869 * behavior. May be built from an {@link ActivityOptions} to apply to an activity start.
870 *
871 * @see #send()
872 * @see #send(int)
873 * @see #send(Context, int, Intent)
874 * @see #send(int, android.app.PendingIntent.OnFinished, Handler)
875 * @see #send(Context, int, Intent, OnFinished, Handler)
876 *
877 * @throws CanceledException Throws CanceledException if the PendingIntent
878 * is no longer allowing more intents to be sent through it.
879 */
880 public void send(Context context, int code, @Nullable Intent intent,
881 @Nullable OnFinished onFinished, @Nullable Handler handler,
882 @Nullable String requiredPermission, @Nullable Bundle options)
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700883 throws CanceledException {
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100884 if (sendAndReturnResult(context, code, intent, onFinished, handler, requiredPermission,
885 options) < 0) {
886 throw new CanceledException();
887 }
888 }
889
890 /**
891 * Like {@link #send}, but returns the result
892 * @hide
893 */
894 public int sendAndReturnResult(Context context, int code, @Nullable Intent intent,
895 @Nullable OnFinished onFinished, @Nullable Handler handler,
896 @Nullable String requiredPermission, @Nullable Bundle options)
897 throws CanceledException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 try {
899 String resolvedType = intent != null ?
900 intent.resolveTypeIfNeeded(context.getContentResolver())
901 : null;
Louis Chang477e93e2019-04-24 18:35:20 +0800902
903 if (context != null && isActivity()) {
904 // Set the context display id as preferred for this activity launches, so that it
905 // can land on caller's display. Or just brought the task to front at the display
906 // where it was on since it has higher preference.
907 ActivityOptions activityOptions = options != null ? new ActivityOptions(options)
908 : ActivityOptions.makeBasic();
909 activityOptions.setCallerDisplayId(context.getDisplayId());
910 options = activityOptions.toBundle();
911 }
912
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100913 return ActivityManager.getService().sendIntentSender(
Dianne Hackborn98305522017-05-05 17:53:53 -0700914 mTarget, mWhitelistToken, code, intent, resolvedType,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 onFinished != null
Dianne Hackborn6c418d52011-06-29 14:05:33 -0700916 ? new FinishedDispatcher(this, onFinished, handler)
917 : null,
Dianne Hackborna750a632015-06-16 17:18:23 -0700918 requiredPermission, options);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 } catch (RemoteException e) {
920 throw new CanceledException(e);
921 }
922 }
923
924 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700925 * @deprecated Renamed to {@link #getCreatorPackage()}.
926 */
927 @Deprecated
928 public String getTargetPackage() {
929 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800930 return ActivityManager.getService()
Dianne Hackborn8832c182012-09-17 17:20:24 -0700931 .getPackageForIntentSender(mTarget);
932 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100933 throw e.rethrowFromSystemServer();
Dianne Hackborn8832c182012-09-17 17:20:24 -0700934 }
935 }
936
937 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 * Return the package name of the application that created this
939 * PendingIntent, that is the identity under which you will actually be
940 * sending the Intent. The returned string is supplied by the system, so
941 * that an application can not spoof its package.
942 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800943 * <p class="note">Be careful about how you use this. All this tells you is
944 * who created the PendingIntent. It does <strong>not</strong> tell you who
945 * handed the PendingIntent to you: that is, PendingIntent objects are intended to be
946 * passed between applications, so the PendingIntent you receive from an application
947 * could actually be one it received from another application, meaning the result
948 * you get here will identify the original application. Because of this, you should
949 * only use this information to identify who you expect to be interacting with
950 * through a {@link #send} call, not who gave you the PendingIntent.</p>
951 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 * @return The package name of the PendingIntent, or null if there is
953 * none associated with it.
954 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700955 @Nullable
Dianne Hackborn8832c182012-09-17 17:20:24 -0700956 public String getCreatorPackage() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800958 return ActivityManager.getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 .getPackageForIntentSender(mTarget);
960 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100961 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 }
963 }
964
965 /**
Dianne Hackbornc7501272012-08-14 18:05:05 -0700966 * Return the uid of the application that created this
967 * PendingIntent, that is the identity under which you will actually be
968 * sending the Intent. The returned integer is supplied by the system, so
969 * that an application can not spoof its uid.
970 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800971 * <p class="note">Be careful about how you use this. All this tells you is
972 * who created the PendingIntent. It does <strong>not</strong> tell you who
973 * handed the PendingIntent to you: that is, PendingIntent objects are intended to be
974 * passed between applications, so the PendingIntent you receive from an application
975 * could actually be one it received from another application, meaning the result
976 * you get here will identify the original application. Because of this, you should
977 * only use this information to identify who you expect to be interacting with
978 * through a {@link #send} call, not who gave you the PendingIntent.</p>
979 *
Dianne Hackbornc7501272012-08-14 18:05:05 -0700980 * @return The uid of the PendingIntent, or -1 if there is
981 * none associated with it.
982 */
Dianne Hackborn8832c182012-09-17 17:20:24 -0700983 public int getCreatorUid() {
Dianne Hackbornc7501272012-08-14 18:05:05 -0700984 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800985 return ActivityManager.getService()
Dianne Hackbornc7501272012-08-14 18:05:05 -0700986 .getUidForIntentSender(mTarget);
987 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +0100988 throw e.rethrowFromSystemServer();
Dianne Hackbornc7501272012-08-14 18:05:05 -0700989 }
990 }
991
992 /**
Selim Cinekd83203c2018-04-18 14:34:27 +0800993 * Register a listener to when this pendingIntent is cancelled. There are no guarantees on which
994 * thread a listener will be called and it's up to the caller to synchronize. This may
995 * trigger a synchronous binder call so should therefore usually be called on a background
996 * thread.
997 *
998 * @hide
999 */
1000 public void registerCancelListener(CancelListener cancelListener) {
1001 synchronized (this) {
1002 if (mCancelReceiver == null) {
1003 mCancelReceiver = new IResultReceiver.Stub() {
1004 @Override
1005 public void send(int resultCode, Bundle resultData) throws RemoteException {
1006 notifyCancelListeners();
1007 }
1008 };
1009 }
1010 if (mCancelListeners == null) {
1011 mCancelListeners = new ArraySet<>();
1012 }
1013 boolean wasEmpty = mCancelListeners.isEmpty();
1014 mCancelListeners.add(cancelListener);
1015 if (wasEmpty) {
1016 try {
1017 ActivityManager.getService().registerIntentSenderCancelListener(mTarget,
1018 mCancelReceiver);
1019 } catch (RemoteException e) {
1020 throw e.rethrowFromSystemServer();
1021 }
1022 }
1023 }
1024 }
1025
1026 private void notifyCancelListeners() {
1027 ArraySet<CancelListener> cancelListeners;
1028 synchronized (this) {
1029 cancelListeners = new ArraySet<>(mCancelListeners);
1030 }
1031 int size = cancelListeners.size();
1032 for (int i = 0; i < size; i++) {
1033 cancelListeners.valueAt(i).onCancelled(this);
1034 }
1035 }
1036
1037 /**
1038 * Un-register a listener to when this pendingIntent is cancelled.
1039 *
1040 * @hide
1041 */
1042 public void unregisterCancelListener(CancelListener cancelListener) {
1043 synchronized (this) {
1044 if (mCancelListeners == null) {
1045 return;
1046 }
1047 boolean wasEmpty = mCancelListeners.isEmpty();
1048 mCancelListeners.remove(cancelListener);
1049 if (mCancelListeners.isEmpty() && !wasEmpty) {
1050 try {
1051 ActivityManager.getService().unregisterIntentSenderCancelListener(mTarget,
1052 mCancelReceiver);
1053 } catch (RemoteException e) {
1054 throw e.rethrowFromSystemServer();
1055 }
1056 }
1057 }
1058 }
1059
1060 /**
Dianne Hackbornc7501272012-08-14 18:05:05 -07001061 * Return the user handle of the application that created this
1062 * PendingIntent, that is the user under which you will actually be
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001063 * sending the Intent. The returned UserHandle is supplied by the system, so
Dianne Hackbornc7501272012-08-14 18:05:05 -07001064 * that an application can not spoof its user. See
1065 * {@link android.os.Process#myUserHandle() Process.myUserHandle()} for
1066 * more explanation of user handles.
1067 *
Dianne Hackborna53ee352013-02-20 12:47:02 -08001068 * <p class="note">Be careful about how you use this. All this tells you is
1069 * who created the PendingIntent. It does <strong>not</strong> tell you who
1070 * handed the PendingIntent to you: that is, PendingIntent objects are intended to be
1071 * passed between applications, so the PendingIntent you receive from an application
1072 * could actually be one it received from another application, meaning the result
1073 * you get here will identify the original application. Because of this, you should
1074 * only use this information to identify who you expect to be interacting with
1075 * through a {@link #send} call, not who gave you the PendingIntent.</p>
1076 *
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001077 * @return The user handle of the PendingIntent, or null if there is
Dianne Hackbornc7501272012-08-14 18:05:05 -07001078 * none associated with it.
1079 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001080 @Nullable
Dianne Hackborn8832c182012-09-17 17:20:24 -07001081 public UserHandle getCreatorUserHandle() {
Dianne Hackbornc7501272012-08-14 18:05:05 -07001082 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001083 int uid = ActivityManager.getService()
Dianne Hackbornc7501272012-08-14 18:05:05 -07001084 .getUidForIntentSender(mTarget);
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001085 return uid > 0 ? new UserHandle(UserHandle.getUserId(uid)) : null;
Dianne Hackbornc7501272012-08-14 18:05:05 -07001086 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001087 throw e.rethrowFromSystemServer();
Dianne Hackbornc7501272012-08-14 18:05:05 -07001088 }
1089 }
1090
1091 /**
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001092 * @hide
1093 * Check to verify that this PendingIntent targets a specific package.
1094 */
1095 public boolean isTargetedToPackage() {
1096 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001097 return ActivityManager.getService()
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001098 .isIntentSenderTargetedToPackage(mTarget);
1099 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001100 throw e.rethrowFromSystemServer();
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001101 }
1102 }
1103
1104 /**
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001105 * @hide
1106 * Check whether this PendingIntent will launch an Activity.
1107 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001108 @UnsupportedAppUsage
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001109 public boolean isActivity() {
1110 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001111 return ActivityManager.getService()
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001112 .isIntentSenderAnActivity(mTarget);
1113 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001114 throw e.rethrowFromSystemServer();
Dianne Hackborn1927ae82012-06-22 15:21:36 -07001115 }
1116 }
1117
1118 /**
Dianne Hackborn81038902012-11-26 17:04:09 -08001119 * @hide
Suprabh Shukladb6bf662017-08-30 15:41:53 -07001120 * Check whether this PendingIntent will launch a foreground service
1121 */
1122 public boolean isForegroundService() {
1123 try {
1124 return ActivityManager.getService()
1125 .isIntentSenderAForegroundService(mTarget);
1126 } catch (RemoteException e) {
1127 throw e.rethrowFromSystemServer();
1128 }
1129 }
1130
1131 /**
1132 * @hide
Christopher Tate2f558d22019-01-17 16:58:31 -08001133 * Check whether this PendingIntent will launch an Activity.
1134 */
1135 public boolean isBroadcast() {
1136 try {
1137 return ActivityManager.getService()
1138 .isIntentSenderABroadcast(mTarget);
1139 } catch (RemoteException e) {
1140 throw e.rethrowFromSystemServer();
1141 }
1142 }
1143
1144 /**
1145 * @hide
Dianne Hackborn81038902012-11-26 17:04:09 -08001146 * Return the Intent of this PendingIntent.
1147 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001148 @UnsupportedAppUsage
Dianne Hackborn81038902012-11-26 17:04:09 -08001149 public Intent getIntent() {
1150 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001151 return ActivityManager.getService()
Dianne Hackborn81038902012-11-26 17:04:09 -08001152 .getIntentForIntentSender(mTarget);
1153 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001154 throw e.rethrowFromSystemServer();
Dianne Hackborn81038902012-11-26 17:04:09 -08001155 }
1156 }
1157
1158 /**
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001159 * @hide
1160 * Return descriptive tag for this PendingIntent.
1161 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001162 @UnsupportedAppUsage
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001163 public String getTag(String prefix) {
1164 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001165 return ActivityManager.getService()
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001166 .getTagForIntentSender(mTarget, prefix);
1167 } catch (RemoteException e) {
Adrian Roos75409232017-02-13 14:48:57 +01001168 throw e.rethrowFromSystemServer();
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001169 }
1170 }
1171
1172 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 * Comparison operator on two PendingIntent objects, such that true
1174 * is returned then they both represent the same operation from the
1175 * same package. This allows you to use {@link #getActivity},
1176 * {@link #getBroadcast}, or {@link #getService} multiple times (even
1177 * across a process being killed), resulting in different PendingIntent
1178 * objects but whose equals() method identifies them as being the same
1179 * operation.
1180 */
1181 @Override
1182 public boolean equals(Object otherObj) {
1183 if (otherObj instanceof PendingIntent) {
1184 return mTarget.asBinder().equals(((PendingIntent)otherObj)
1185 .mTarget.asBinder());
1186 }
1187 return false;
1188 }
1189
1190 @Override
1191 public int hashCode() {
1192 return mTarget.asBinder().hashCode();
1193 }
1194
1195 @Override
1196 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001197 StringBuilder sb = new StringBuilder(128);
1198 sb.append("PendingIntent{");
1199 sb.append(Integer.toHexString(System.identityHashCode(this)));
1200 sb.append(": ");
1201 sb.append(mTarget != null ? mTarget.asBinder() : null);
1202 sb.append('}');
1203 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 }
Kweku Adams61e03292017-10-19 14:27:12 -07001205
1206 /** @hide */
Jeffrey Huangcb782852019-12-05 11:28:11 -08001207 public void dumpDebug(ProtoOutputStream proto, long fieldId) {
Kweku Adams61e03292017-10-19 14:27:12 -07001208 final long token = proto.start(fieldId);
1209 if (mTarget != null) {
1210 proto.write(PendingIntentProto.TARGET, mTarget.asBinder().toString());
1211 }
1212 proto.end(token);
1213 }
1214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 public int describeContents() {
1216 return 0;
1217 }
1218
1219 public void writeToParcel(Parcel out, int flags) {
1220 out.writeStrongBinder(mTarget.asBinder());
Svet Ganovddb94882016-06-23 19:55:24 -07001221 OnMarshaledListener listener = sOnMarshaledListener.get();
1222 if (listener != null) {
1223 listener.onMarshaled(this, out, flags);
1224 }
1225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 }
1227
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001228 public static final @android.annotation.NonNull Parcelable.Creator<PendingIntent> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 = new Parcelable.Creator<PendingIntent>() {
1230 public PendingIntent createFromParcel(Parcel in) {
1231 IBinder target = in.readStrongBinder();
Dianne Hackborn98305522017-05-05 17:53:53 -07001232 return target != null
1233 ? new PendingIntent(target, in.getClassCookie(PendingIntent.class))
1234 : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 }
1236
1237 public PendingIntent[] newArray(int size) {
1238 return new PendingIntent[size];
1239 }
1240 };
1241
1242 /**
1243 * Convenience function for writing either a PendingIntent or null pointer to
1244 * a Parcel. You must use this with {@link #readPendingIntentOrNullFromParcel}
1245 * for later reading it.
1246 *
1247 * @param sender The PendingIntent to write, or null.
1248 * @param out Where to write the PendingIntent.
1249 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001250 public static void writePendingIntentOrNullToParcel(@Nullable PendingIntent sender,
1251 @NonNull Parcel out) {
Adrian Roosfb921842017-10-26 14:49:56 +02001252 out.writeStrongBinder(sender != null ? sender.mTarget.asBinder() : null);
1253 if (sender != null) {
1254 OnMarshaledListener listener = sOnMarshaledListener.get();
1255 if (listener != null) {
1256 listener.onMarshaled(sender, out, 0 /* flags */);
1257 }
1258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 }
1260
1261 /**
Dianne Hackborn98305522017-05-05 17:53:53 -07001262 * Convenience function for reading either a PendingIntent or null pointer from
1263 * a Parcel. You must have previously written the PendingIntent with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 * {@link #writePendingIntentOrNullToParcel}.
1265 *
Dianne Hackborn98305522017-05-05 17:53:53 -07001266 * @param in The Parcel containing the written PendingIntent.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 *
Dianne Hackborn98305522017-05-05 17:53:53 -07001268 * @return Returns the PendingIntent read from the Parcel, or null if null had
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 * been written.
1270 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001271 @Nullable
1272 public static PendingIntent readPendingIntentOrNullFromParcel(@NonNull Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 IBinder b = in.readStrongBinder();
Dianne Hackborn98305522017-05-05 17:53:53 -07001274 return b != null ? new PendingIntent(b, in.getClassCookie(PendingIntent.class)) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 }
1276
Suprabh Shukla0d51a8b2019-10-30 18:56:44 -07001277 /**
1278 * Creates a PendingIntent with the given target.
1279 * @param target the backing IIntentSender
1280 * @hide
1281 */
1282 public PendingIntent(IIntentSender target) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 mTarget = target;
1284 }
1285
Dianne Hackborn98305522017-05-05 17:53:53 -07001286 /*package*/ PendingIntent(IBinder target, Object cookie) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 mTarget = IIntentSender.Stub.asInterface(target);
Dianne Hackborn98305522017-05-05 17:53:53 -07001288 if (cookie != null) {
1289 mWhitelistToken = (IBinder)cookie;
1290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 }
1292
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07001293 /** @hide */
1294 public IIntentSender getTarget() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 return mTarget;
1296 }
Dianne Hackborn98305522017-05-05 17:53:53 -07001297
1298 /** @hide */
1299 public IBinder getWhitelistToken() {
1300 return mWhitelistToken;
1301 }
Selim Cinekd83203c2018-04-18 14:34:27 +08001302
1303 /**
1304 * A listener to when a pending intent is cancelled
1305 *
1306 * @hide
1307 */
1308 public interface CancelListener {
1309 /**
1310 * Called when a Pending Intent is cancelled.
1311 *
1312 * @param intent The intent that was cancelled.
1313 */
1314 void onCancelled(PendingIntent intent);
1315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316}