blob: e0aa2a261b3c47e44fb4f1ec0d984648390b2931 [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 com.android.server.am;
18
Jorim Jaggie2ad37f2018-01-22 22:41:22 +010019import static android.app.ActivityManager.START_SUCCESS;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080020import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
21import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
22
Dianne Hackborna4972e92012-03-14 10:38:05 -070023import android.app.ActivityManager;
Jorim Jaggi4d8d32c2018-01-19 15:57:41 +010024import android.app.ActivityOptions;
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070025import android.content.IIntentSender;
26import android.content.IIntentReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.app.PendingIntent;
28import android.content.Intent;
29import android.os.Binder;
Dianne Hackborna4972e92012-03-14 10:38:05 -070030import android.os.Bundle;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070031import android.os.IBinder;
Dianne Hackbornf66adfd2017-04-13 11:01:48 -070032import android.os.RemoteCallbackList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Craig Mautner5f2bb4c2015-03-12 16:10:27 -070034import android.os.TransactionTooLargeException;
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -070035import android.os.UserHandle;
Dianne Hackborn98305522017-05-05 17:53:53 -070036import android.util.ArrayMap;
Joe Onorato8a9b2202010-02-26 18:56:32 -080037import android.util.Slog;
Dianne Hackbornbc02a392016-06-02 17:15:08 -070038import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Dianne Hackbornf66adfd2017-04-13 11:01:48 -070040import com.android.internal.os.IResultReceiver;
Craig Mautnerb9168362015-02-26 20:40:19 -080041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import java.io.PrintWriter;
43import java.lang.ref.WeakReference;
Rubin Xuf24d6062016-07-20 17:34:50 +010044import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070046final class PendingIntentRecord extends IIntentSender.Stub {
Wale Ogunwalee23149f2015-03-06 15:39:44 -080047 private static final String TAG = TAG_WITH_CLASS_NAME ? "PendingIntentRecord" : TAG_AM;
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 final ActivityManagerService owner;
50 final Key key;
51 final int uid;
52 final WeakReference<PendingIntentRecord> ref;
53 boolean sent = false;
54 boolean canceled = false;
Dianne Hackborn98305522017-05-05 17:53:53 -070055 private ArrayMap<IBinder, Long> whitelistDuration;
Dianne Hackbornf66adfd2017-04-13 11:01:48 -070056 private RemoteCallbackList<IResultReceiver> mCancelCallbacks;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Dianne Hackborn1d442e02009-04-20 18:14:05 -070058 String stringName;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -080059 String lastTagPrefix;
60 String lastTag;
Wale Ogunwalee23149f2015-03-06 15:39:44 -080061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 final static class Key {
63 final int type;
64 final String packageName;
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070065 final ActivityRecord activity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 final String who;
67 final int requestCode;
68 final Intent requestIntent;
69 final String requestResolvedType;
Jorim Jaggi4d8d32c2018-01-19 15:57:41 +010070 final SafeActivityOptions options;
Dianne Hackborn621e17d2010-11-22 15:59:56 -080071 Intent[] allIntents;
72 String[] allResolvedTypes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 final int flags;
74 final int hashCode;
Amith Yamasani4ea60692012-08-28 14:34:53 -070075 final int userId;
Felipe Lemea1b79bf2016-05-24 13:06:54 -070076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 private static final int ODD_PRIME_NUMBER = 37;
Felipe Lemea1b79bf2016-05-24 13:06:54 -070078
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070079 Key(int _t, String _p, ActivityRecord _a, String _w,
Jorim Jaggi4d8d32c2018-01-19 15:57:41 +010080 int _r, Intent[] _i, String[] _it, int _f, SafeActivityOptions _o, int _userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 type = _t;
82 packageName = _p;
83 activity = _a;
84 who = _w;
85 requestCode = _r;
Dianne Hackborn621e17d2010-11-22 15:59:56 -080086 requestIntent = _i != null ? _i[_i.length-1] : null;
87 requestResolvedType = _it != null ? _it[_it.length-1] : null;
88 allIntents = _i;
89 allResolvedTypes = _it;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 flags = _f;
Dianne Hackborn7a2195c2012-03-19 17:38:00 -070091 options = _o;
Amith Yamasani4ea60692012-08-28 14:34:53 -070092 userId = _userId;
93
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 int hash = 23;
95 hash = (ODD_PRIME_NUMBER*hash) + _f;
96 hash = (ODD_PRIME_NUMBER*hash) + _r;
Amith Yamasani4ea60692012-08-28 14:34:53 -070097 hash = (ODD_PRIME_NUMBER*hash) + _userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 if (_w != null) {
99 hash = (ODD_PRIME_NUMBER*hash) + _w.hashCode();
100 }
101 if (_a != null) {
102 hash = (ODD_PRIME_NUMBER*hash) + _a.hashCode();
103 }
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800104 if (requestIntent != null) {
105 hash = (ODD_PRIME_NUMBER*hash) + requestIntent.filterHashCode();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 }
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800107 if (requestResolvedType != null) {
108 hash = (ODD_PRIME_NUMBER*hash) + requestResolvedType.hashCode();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
Rubin Xuf24d6062016-07-20 17:34:50 +0100110 hash = (ODD_PRIME_NUMBER*hash) + (_p != null ? _p.hashCode() : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 hash = (ODD_PRIME_NUMBER*hash) + _t;
112 hashCode = hash;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800113 //Slog.i(ActivityManagerService.TAG, this + " hashCode=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 // + Integer.toHexString(hashCode));
115 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 public boolean equals(Object otherObj) {
118 if (otherObj == null) {
119 return false;
120 }
121 try {
122 Key other = (Key)otherObj;
123 if (type != other.type) {
124 return false;
125 }
Amith Yamasani4ea60692012-08-28 14:34:53 -0700126 if (userId != other.userId){
127 return false;
128 }
Rubin Xuf24d6062016-07-20 17:34:50 +0100129 if (!Objects.equals(packageName, other.packageName)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 return false;
131 }
132 if (activity != other.activity) {
133 return false;
134 }
Rubin Xuf24d6062016-07-20 17:34:50 +0100135 if (!Objects.equals(who, other.who)) {
136 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 }
138 if (requestCode != other.requestCode) {
139 return false;
140 }
141 if (requestIntent != other.requestIntent) {
142 if (requestIntent != null) {
143 if (!requestIntent.filterEquals(other.requestIntent)) {
144 return false;
145 }
146 } else if (other.requestIntent != null) {
147 return false;
148 }
149 }
Rubin Xuf24d6062016-07-20 17:34:50 +0100150 if (!Objects.equals(requestResolvedType, other.requestResolvedType)) {
151 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 }
153 if (flags != other.flags) {
154 return false;
155 }
156 return true;
157 } catch (ClassCastException e) {
158 }
159 return false;
160 }
161
162 public int hashCode() {
163 return hashCode;
164 }
Craig Mautner5f2bb4c2015-03-12 16:10:27 -0700165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 public String toString() {
167 return "Key{" + typeName() + " pkg=" + packageName
Dianne Hackbornc3b91fd2010-02-23 17:25:30 -0800168 + " intent="
Dianne Hackborn90c52de2011-09-23 12:57:44 -0700169 + (requestIntent != null
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800170 ? requestIntent.toShortString(false, true, false, false) : "<null>")
Amith Yamasani4ea60692012-08-28 14:34:53 -0700171 + " flags=0x" + Integer.toHexString(flags) + " u=" + userId + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 }
Craig Mautner5f2bb4c2015-03-12 16:10:27 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 String typeName() {
175 switch (type) {
Dianne Hackborna4972e92012-03-14 10:38:05 -0700176 case ActivityManager.INTENT_SENDER_ACTIVITY:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 return "startActivity";
Dianne Hackborna4972e92012-03-14 10:38:05 -0700178 case ActivityManager.INTENT_SENDER_BROADCAST:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 return "broadcastIntent";
Dianne Hackborna4972e92012-03-14 10:38:05 -0700180 case ActivityManager.INTENT_SENDER_SERVICE:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 return "startService";
Christopher Tate08992ac2017-03-21 11:37:06 -0700182 case ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE:
183 return "startForegroundService";
Dianne Hackborna4972e92012-03-14 10:38:05 -0700184 case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 return "activityResult";
186 }
187 return Integer.toString(type);
188 }
189 }
Craig Mautner5f2bb4c2015-03-12 16:10:27 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 PendingIntentRecord(ActivityManagerService _owner, Key _k, int _u) {
192 owner = _owner;
193 key = _k;
194 uid = _u;
195 ref = new WeakReference<PendingIntentRecord>(this);
196 }
197
Dianne Hackborn98305522017-05-05 17:53:53 -0700198 void setWhitelistDurationLocked(IBinder whitelistToken, long duration) {
199 if (duration > 0) {
200 if (whitelistDuration == null) {
201 whitelistDuration = new ArrayMap<>();
202 }
203 whitelistDuration.put(whitelistToken, duration);
204 } else if (whitelistDuration != null) {
205 whitelistDuration.remove(whitelistToken);
206 if (whitelistDuration.size() <= 0) {
207 whitelistDuration = null;
208 }
209
210 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700211 this.stringName = null;
212 }
213
Dianne Hackbornf66adfd2017-04-13 11:01:48 -0700214 public void registerCancelListenerLocked(IResultReceiver receiver) {
215 if (mCancelCallbacks == null) {
216 mCancelCallbacks = new RemoteCallbackList<>();
217 }
218 mCancelCallbacks.register(receiver);
219 }
220
221 public void unregisterCancelListenerLocked(IResultReceiver receiver) {
Makoto Onuki8a0319a2018-04-25 16:31:05 -0700222 if (mCancelCallbacks == null) {
223 return; // Already unregistered or detached.
224 }
Dianne Hackbornf66adfd2017-04-13 11:01:48 -0700225 mCancelCallbacks.unregister(receiver);
226 if (mCancelCallbacks.getRegisteredCallbackCount() <= 0) {
227 mCancelCallbacks = null;
228 }
229 }
230
231 public RemoteCallbackList<IResultReceiver> detachCancelListenersLocked() {
232 RemoteCallbackList<IResultReceiver> listeners = mCancelCallbacks;
233 mCancelCallbacks = null;
234 return listeners;
235 }
236
Dianne Hackborn98305522017-05-05 17:53:53 -0700237 public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
Dianne Hackborn0c4e6a82016-05-13 17:37:08 -0700238 IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
Dianne Hackborn98305522017-05-05 17:53:53 -0700239 sendInner(code, intent, resolvedType, whitelistToken, finishedReceiver,
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700240 requiredPermission, null, null, 0, 0, 0, options);
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -0700241 }
Craig Mautner5f2bb4c2015-03-12 16:10:27 -0700242
Dianne Hackborn98305522017-05-05 17:53:53 -0700243 public int sendWithResult(int code, Intent intent, String resolvedType, IBinder whitelistToken,
244 IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
245 return sendInner(code, intent, resolvedType, whitelistToken, finishedReceiver,
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700246 requiredPermission, null, null, 0, 0, 0, options);
Dianne Hackborn98305522017-05-05 17:53:53 -0700247 }
248
249 int sendInner(int code, Intent intent, String resolvedType, IBinder whitelistToken,
250 IIntentReceiver finishedReceiver,
Craig Mautner5f2bb4c2015-03-12 16:10:27 -0700251 String requiredPermission, IBinder resultTo, String resultWho, int requestCode,
Andrii Kulianb1cdb102017-07-13 15:33:06 -0700252 int flagsMask, int flagsValues, Bundle options) {
Jeff Sharkeyf0ec2e02016-03-21 12:37:54 -0600253 if (intent != null) intent.setDefusable(true);
254 if (options != null) options.setDefusable(true);
255
256 synchronized (owner) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 if (!canceled) {
258 sent = true;
259 if ((key.flags&PendingIntent.FLAG_ONE_SHOT) != 0) {
260 owner.cancelIntentSenderLocked(this, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 }
Svetoslavb0a78392015-04-10 17:25:35 -0700262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 Intent finalIntent = key.requestIntent != null
264 ? new Intent(key.requestIntent) : new Intent();
Svetoslavb0a78392015-04-10 17:25:35 -0700265
266 final boolean immutable = (key.flags & PendingIntent.FLAG_IMMUTABLE) != 0;
267 if (!immutable) {
268 if (intent != null) {
269 int changes = finalIntent.fillIn(intent, key.flags);
270 if ((changes & Intent.FILL_IN_DATA) == 0) {
271 resolvedType = key.requestResolvedType;
272 }
273 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 resolvedType = key.requestResolvedType;
275 }
Svetoslavb0a78392015-04-10 17:25:35 -0700276 flagsMask &= ~Intent.IMMUTABLE_FLAGS;
277 flagsValues &= flagsMask;
278 finalIntent.setFlags((finalIntent.getFlags() & ~flagsMask) | flagsValues);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 } else {
280 resolvedType = key.requestResolvedType;
281 }
Craig Mautner5f2bb4c2015-03-12 16:10:27 -0700282
Amith Yamasani83c994f2017-05-01 14:29:19 -0700283 final int callingUid = Binder.getCallingUid();
284 final int callingPid = Binder.getCallingPid();
285
Jorim Jaggi12d38a82018-04-26 18:51:16 +0200286 // Extract options before clearing calling identity
287 SafeActivityOptions mergedOptions = key.options;
288 if (mergedOptions == null) {
289 mergedOptions = SafeActivityOptions.fromBundle(options);
290 } else {
291 mergedOptions.setCallerOptions(ActivityOptions.fromBundle(options));
292 }
293
Amith Yamasani83c994f2017-05-01 14:29:19 -0700294 final long origId = Binder.clearCallingIdentity();
295
Dianne Hackborn98305522017-05-05 17:53:53 -0700296 if (whitelistDuration != null) {
297 Long duration = whitelistDuration.get(whitelistToken);
298 if (duration != null) {
299 int procState = owner.getUidState(callingUid);
300 if (!ActivityManager.isProcStateBackground(procState)) {
301 StringBuilder tag = new StringBuilder(64);
302 tag.append("pendingintent:");
303 UserHandle.formatUid(tag, callingUid);
304 tag.append(":");
305 if (finalIntent.getAction() != null) {
306 tag.append(finalIntent.getAction());
307 } else if (finalIntent.getComponent() != null) {
308 finalIntent.getComponent().appendShortString(tag);
309 } else if (finalIntent.getData() != null) {
310 tag.append(finalIntent.getData());
311 }
312 owner.tempWhitelistForPendingIntentLocked(callingPid,
313 callingUid, uid, duration, tag.toString());
314 } else {
315 Slog.w(TAG, "Not doing whitelist " + this + ": caller state="
316 + procState);
317 }
Dianne Hackborne4d1a2e2017-04-14 17:57:33 -0700318 }
Dianne Hackborne4d1a2e2017-04-14 17:57:33 -0700319 }
320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 boolean sendFinish = finishedReceiver != null;
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700322 int userId = key.userId;
323 if (userId == UserHandle.USER_CURRENT) {
Fyodor Kupolov1b3edac2017-09-19 15:48:06 -0700324 userId = owner.mUserController.getCurrentOrTargetUserId();
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700325 }
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100326 int res = START_SUCCESS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 switch (key.type) {
Dianne Hackborna4972e92012-03-14 10:38:05 -0700328 case ActivityManager.INTENT_SENDER_ACTIVITY:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 try {
Makoto Onukic00ea712018-04-13 12:06:39 -0700330 // Note when someone has a pending intent, even from different
331 // users, then there's no need to ensure the calling user matches
332 // the target user, so validateIncomingUser is always false below.
333
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800334 if (key.allIntents != null && key.allIntents.length > 1) {
335 Intent[] allIntents = new Intent[key.allIntents.length];
336 String[] allResolvedTypes = new String[key.allIntents.length];
337 System.arraycopy(key.allIntents, 0, allIntents, 0,
338 key.allIntents.length);
339 if (key.allResolvedTypes != null) {
340 System.arraycopy(key.allResolvedTypes, 0, allResolvedTypes, 0,
341 key.allResolvedTypes.length);
342 }
343 allIntents[allIntents.length-1] = finalIntent;
344 allResolvedTypes[allResolvedTypes.length-1] = resolvedType;
Makoto Onukic00ea712018-04-13 12:06:39 -0700345
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100346 res = owner.getActivityStartController().startActivitiesInPackage(
347 uid, key.packageName, allIntents, allResolvedTypes,
Makoto Onuki7041c4b2018-02-06 13:36:34 -0800348 resultTo, mergedOptions, userId,
Makoto Onukic00ea712018-04-13 12:06:39 -0700349 false /* validateIncomingUser */);
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800350 } else {
Jorim Jaggie2ad37f2018-01-22 22:41:22 +0100351 res = owner.getActivityStartController().startActivityInPackage(uid,
Jorim Jaggi4d8d32c2018-01-19 15:57:41 +0100352 callingPid, callingUid, key.packageName, finalIntent,
353 resolvedType, resultTo, resultWho, requestCode, 0,
Makoto Onukic00ea712018-04-13 12:06:39 -0700354 mergedOptions, userId, null, "PendingIntentRecord",
355 false /* validateIncomingUser */);
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800356 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 } catch (RuntimeException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800358 Slog.w(TAG, "Unable to send startActivity intent", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360 break;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700361 case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT:
Andrii Kulian02b7a832016-10-06 23:11:56 -0700362 final ActivityStack stack = key.activity.getStack();
363 if (stack != null) {
364 stack.sendActivityResultLocked(-1, key.activity, key.who,
365 key.requestCode, code, finalIntent);
Wale Ogunwale7d701172015-03-11 15:36:30 -0700366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 break;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700368 case ActivityManager.INTENT_SENDER_BROADCAST:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 try {
370 // If a completion callback has been requested, require
371 // that the broadcast be delivered synchronously
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800372 int sent = owner.broadcastIntentInPackage(key.packageName, uid,
Dianne Hackborna750a632015-06-16 17:18:23 -0700373 finalIntent, resolvedType, finishedReceiver, code, null, null,
374 requiredPermission, options, (finishedReceiver != null),
375 false, userId);
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800376 if (sent == ActivityManager.BROADCAST_SUCCESS) {
377 sendFinish = false;
378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 } catch (RuntimeException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800380 Slog.w(TAG, "Unable to send startActivity intent", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
382 break;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700383 case ActivityManager.INTENT_SENDER_SERVICE:
Christopher Tate08992ac2017-03-21 11:37:06 -0700384 case ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 try {
Christopher Tate08992ac2017-03-21 11:37:06 -0700386 owner.startServiceInPackage(uid, finalIntent, resolvedType,
387 key.type == ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE,
388 key.packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 } catch (RuntimeException e) {
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800390 Slog.w(TAG, "Unable to send startService intent", e);
Dianne Hackborn0c4e6a82016-05-13 17:37:08 -0700391 } catch (TransactionTooLargeException e) {
392 res = ActivityManager.START_CANCELED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 }
394 break;
395 }
Wale Ogunwalee23149f2015-03-06 15:39:44 -0800396
Dianne Hackborn0c4e6a82016-05-13 17:37:08 -0700397 if (sendFinish && res != ActivityManager.START_CANCELED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 try {
399 finishedReceiver.performReceive(new Intent(finalIntent), 0,
Dianne Hackborn20e80982012-08-31 19:00:44 -0700400 null, null, false, false, key.userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 } catch (RemoteException e) {
402 }
403 }
Dianne Hackborn0c4e6a82016-05-13 17:37:08 -0700404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 Binder.restoreCallingIdentity(origId);
Dianne Hackborn0c4e6a82016-05-13 17:37:08 -0700406
407 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 }
409 }
Dianne Hackborna4972e92012-03-14 10:38:05 -0700410 return ActivityManager.START_CANCELED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800412
413 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 protected void finalize() throws Throwable {
Dianne Hackborn9e0f5d92010-02-22 15:05:42 -0800415 try {
416 if (!canceled) {
417 owner.mHandler.sendMessage(owner.mHandler.obtainMessage(
418 ActivityManagerService.FINALIZE_PENDING_INTENT_MSG, this));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 }
Dianne Hackborn9e0f5d92010-02-22 15:05:42 -0800420 } finally {
421 super.finalize();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 }
423 }
424
Dianne Hackborn9e0f5d92010-02-22 15:05:42 -0800425 public void completeFinalize() {
426 synchronized(owner) {
427 WeakReference<PendingIntentRecord> current =
428 owner.mIntentSenderRecords.get(key);
429 if (current == ref) {
430 owner.mIntentSenderRecords.remove(key);
431 }
432 }
433 }
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700436 pw.print(prefix); pw.print("uid="); pw.print(uid);
437 pw.print(" packageName="); pw.print(key.packageName);
438 pw.print(" type="); pw.print(key.typeName());
439 pw.print(" flags=0x"); pw.println(Integer.toHexString(key.flags));
440 if (key.activity != null || key.who != null) {
441 pw.print(prefix); pw.print("activity="); pw.print(key.activity);
442 pw.print(" who="); pw.println(key.who);
443 }
444 if (key.requestCode != 0 || key.requestResolvedType != null) {
445 pw.print(prefix); pw.print("requestCode="); pw.print(key.requestCode);
446 pw.print(" requestResolvedType="); pw.println(key.requestResolvedType);
447 }
Dianne Hackbornc3b91fd2010-02-23 17:25:30 -0800448 if (key.requestIntent != null) {
449 pw.print(prefix); pw.print("requestIntent=");
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800450 pw.println(key.requestIntent.toShortString(false, true, true, true));
Dianne Hackbornc3b91fd2010-02-23 17:25:30 -0800451 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700452 if (sent || canceled) {
453 pw.print(prefix); pw.print("sent="); pw.print(sent);
454 pw.print(" canceled="); pw.println(canceled);
455 }
Dianne Hackborn98305522017-05-05 17:53:53 -0700456 if (whitelistDuration != null) {
Dianne Hackbornbc02a392016-06-02 17:15:08 -0700457 pw.print(prefix);
458 pw.print("whitelistDuration=");
Dianne Hackborn98305522017-05-05 17:53:53 -0700459 for (int i = 0; i < whitelistDuration.size(); i++) {
460 if (i != 0) {
461 pw.print(", ");
462 }
463 pw.print(Integer.toHexString(System.identityHashCode(whitelistDuration.keyAt(i))));
464 pw.print(":");
465 TimeUtils.formatDuration(whitelistDuration.valueAt(i), pw);
466 }
Dianne Hackbornbc02a392016-06-02 17:15:08 -0700467 pw.println();
468 }
Dianne Hackbornf66adfd2017-04-13 11:01:48 -0700469 if (mCancelCallbacks != null) {
470 pw.print(prefix); pw.println("mCancelCallbacks:");
471 for (int i = 0; i < mCancelCallbacks.getRegisteredCallbackCount(); i++) {
472 pw.print(prefix); pw.print(" #"); pw.print(i); pw.print(": ");
473 pw.println(mCancelCallbacks.getRegisteredCallbackItem(i));
474 }
475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
477
478 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700479 if (stringName != null) {
480 return stringName;
481 }
482 StringBuilder sb = new StringBuilder(128);
483 sb.append("PendingIntentRecord{");
484 sb.append(Integer.toHexString(System.identityHashCode(this)));
485 sb.append(' ');
486 sb.append(key.packageName);
487 sb.append(' ');
488 sb.append(key.typeName());
Dianne Hackborn98305522017-05-05 17:53:53 -0700489 if (whitelistDuration != null) {
Dianne Hackbornbc02a392016-06-02 17:15:08 -0700490 sb.append( " (whitelist: ");
Dianne Hackborn98305522017-05-05 17:53:53 -0700491 for (int i = 0; i < whitelistDuration.size(); i++) {
492 if (i != 0) {
493 sb.append(",");
494 }
495 sb.append(Integer.toHexString(System.identityHashCode(whitelistDuration.keyAt(i))));
496 sb.append(":");
497 TimeUtils.formatDuration(whitelistDuration.valueAt(i), sb);
498 }
Dianne Hackbornbc02a392016-06-02 17:15:08 -0700499 sb.append(")");
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700500 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700501 sb.append('}');
502 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
504}