The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Jorim Jaggi | e2ad37f | 2018-01-22 22:41:22 +0100 | [diff] [blame] | 19 | import static android.app.ActivityManager.START_SUCCESS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 20 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 21 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 22 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 24 | import android.app.ActivityOptions; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 25 | import android.content.IIntentSender; |
| 26 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.app.PendingIntent; |
| 28 | import android.content.Intent; |
| 29 | import android.os.Binder; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 30 | import android.os.Bundle; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 31 | import android.os.IBinder; |
Dianne Hackborn | f66adfd | 2017-04-13 11:01:48 -0700 | [diff] [blame] | 32 | import android.os.RemoteCallbackList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.os.RemoteException; |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 34 | import android.os.TransactionTooLargeException; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 35 | import android.os.UserHandle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 36 | import android.util.ArrayMap; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 37 | import android.util.Slog; |
Dianne Hackborn | bc02a39 | 2016-06-02 17:15:08 -0700 | [diff] [blame] | 38 | import android.util.TimeUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Dianne Hackborn | f66adfd | 2017-04-13 11:01:48 -0700 | [diff] [blame] | 40 | import com.android.internal.os.IResultReceiver; |
Craig Mautner | b916836 | 2015-02-26 20:40:19 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import java.io.PrintWriter; |
| 43 | import java.lang.ref.WeakReference; |
Rubin Xu | f24d606 | 2016-07-20 17:34:50 +0100 | [diff] [blame] | 44 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 46 | final class PendingIntentRecord extends IIntentSender.Stub { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 47 | private static final String TAG = TAG_WITH_CLASS_NAME ? "PendingIntentRecord" : TAG_AM; |
| 48 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | 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 Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 55 | private ArrayMap<IBinder, Long> whitelistDuration; |
Dianne Hackborn | f66adfd | 2017-04-13 11:01:48 -0700 | [diff] [blame] | 56 | private RemoteCallbackList<IResultReceiver> mCancelCallbacks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 58 | String stringName; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 59 | String lastTagPrefix; |
| 60 | String lastTag; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | final static class Key { |
| 63 | final int type; |
| 64 | final String packageName; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 65 | final ActivityRecord activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | final String who; |
| 67 | final int requestCode; |
| 68 | final Intent requestIntent; |
| 69 | final String requestResolvedType; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 70 | final SafeActivityOptions options; |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 71 | Intent[] allIntents; |
| 72 | String[] allResolvedTypes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | final int flags; |
| 74 | final int hashCode; |
Amith Yamasani | 4ea6069 | 2012-08-28 14:34:53 -0700 | [diff] [blame] | 75 | final int userId; |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | private static final int ODD_PRIME_NUMBER = 37; |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 78 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 79 | Key(int _t, String _p, ActivityRecord _a, String _w, |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 80 | int _r, Intent[] _i, String[] _it, int _f, SafeActivityOptions _o, int _userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | type = _t; |
| 82 | packageName = _p; |
| 83 | activity = _a; |
| 84 | who = _w; |
| 85 | requestCode = _r; |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 86 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | flags = _f; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 91 | options = _o; |
Amith Yamasani | 4ea6069 | 2012-08-28 14:34:53 -0700 | [diff] [blame] | 92 | userId = _userId; |
| 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | int hash = 23; |
| 95 | hash = (ODD_PRIME_NUMBER*hash) + _f; |
| 96 | hash = (ODD_PRIME_NUMBER*hash) + _r; |
Amith Yamasani | 4ea6069 | 2012-08-28 14:34:53 -0700 | [diff] [blame] | 97 | hash = (ODD_PRIME_NUMBER*hash) + _userId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | 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 Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 104 | if (requestIntent != null) { |
| 105 | hash = (ODD_PRIME_NUMBER*hash) + requestIntent.filterHashCode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 107 | if (requestResolvedType != null) { |
| 108 | hash = (ODD_PRIME_NUMBER*hash) + requestResolvedType.hashCode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | } |
Rubin Xu | f24d606 | 2016-07-20 17:34:50 +0100 | [diff] [blame] | 110 | hash = (ODD_PRIME_NUMBER*hash) + (_p != null ? _p.hashCode() : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | hash = (ODD_PRIME_NUMBER*hash) + _t; |
| 112 | hashCode = hash; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 113 | //Slog.i(ActivityManagerService.TAG, this + " hashCode=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | // + Integer.toHexString(hashCode)); |
| 115 | } |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | 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 Yamasani | 4ea6069 | 2012-08-28 14:34:53 -0700 | [diff] [blame] | 126 | if (userId != other.userId){ |
| 127 | return false; |
| 128 | } |
Rubin Xu | f24d606 | 2016-07-20 17:34:50 +0100 | [diff] [blame] | 129 | if (!Objects.equals(packageName, other.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | return false; |
| 131 | } |
| 132 | if (activity != other.activity) { |
| 133 | return false; |
| 134 | } |
Rubin Xu | f24d606 | 2016-07-20 17:34:50 +0100 | [diff] [blame] | 135 | if (!Objects.equals(who, other.who)) { |
| 136 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | } |
| 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 Xu | f24d606 | 2016-07-20 17:34:50 +0100 | [diff] [blame] | 150 | if (!Objects.equals(requestResolvedType, other.requestResolvedType)) { |
| 151 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | } |
| 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 Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | public String toString() { |
| 167 | return "Key{" + typeName() + " pkg=" + packageName |
Dianne Hackborn | c3b91fd | 2010-02-23 17:25:30 -0800 | [diff] [blame] | 168 | + " intent=" |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 169 | + (requestIntent != null |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 170 | ? requestIntent.toShortString(false, true, false, false) : "<null>") |
Amith Yamasani | 4ea6069 | 2012-08-28 14:34:53 -0700 | [diff] [blame] | 171 | + " flags=0x" + Integer.toHexString(flags) + " u=" + userId + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | String typeName() { |
| 175 | switch (type) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 176 | case ActivityManager.INTENT_SENDER_ACTIVITY: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | return "startActivity"; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 178 | case ActivityManager.INTENT_SENDER_BROADCAST: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | return "broadcastIntent"; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 180 | case ActivityManager.INTENT_SENDER_SERVICE: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | return "startService"; |
Christopher Tate | 08992ac | 2017-03-21 11:37:06 -0700 | [diff] [blame] | 182 | case ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE: |
| 183 | return "startForegroundService"; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 184 | case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | return "activityResult"; |
| 186 | } |
| 187 | return Integer.toString(type); |
| 188 | } |
| 189 | } |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | 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 Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 198 | 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 Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 211 | this.stringName = null; |
| 212 | } |
| 213 | |
Dianne Hackborn | f66adfd | 2017-04-13 11:01:48 -0700 | [diff] [blame] | 214 | 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) { |
| 222 | mCancelCallbacks.unregister(receiver); |
| 223 | if (mCancelCallbacks.getRegisteredCallbackCount() <= 0) { |
| 224 | mCancelCallbacks = null; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | public RemoteCallbackList<IResultReceiver> detachCancelListenersLocked() { |
| 229 | RemoteCallbackList<IResultReceiver> listeners = mCancelCallbacks; |
| 230 | mCancelCallbacks = null; |
| 231 | return listeners; |
| 232 | } |
| 233 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 234 | public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken, |
Dianne Hackborn | 0c4e6a8 | 2016-05-13 17:37:08 -0700 | [diff] [blame] | 235 | IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) { |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 236 | sendInner(code, intent, resolvedType, whitelistToken, finishedReceiver, |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 237 | requiredPermission, null, null, 0, 0, 0, options); |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 238 | } |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 239 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 240 | public int sendWithResult(int code, Intent intent, String resolvedType, IBinder whitelistToken, |
| 241 | IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) { |
| 242 | return sendInner(code, intent, resolvedType, whitelistToken, finishedReceiver, |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 243 | requiredPermission, null, null, 0, 0, 0, options); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | int sendInner(int code, Intent intent, String resolvedType, IBinder whitelistToken, |
| 247 | IIntentReceiver finishedReceiver, |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 248 | String requiredPermission, IBinder resultTo, String resultWho, int requestCode, |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 249 | int flagsMask, int flagsValues, Bundle options) { |
Jeff Sharkey | f0ec2e0 | 2016-03-21 12:37:54 -0600 | [diff] [blame] | 250 | if (intent != null) intent.setDefusable(true); |
| 251 | if (options != null) options.setDefusable(true); |
| 252 | |
| 253 | synchronized (owner) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | if (!canceled) { |
| 255 | sent = true; |
| 256 | if ((key.flags&PendingIntent.FLAG_ONE_SHOT) != 0) { |
| 257 | owner.cancelIntentSenderLocked(this, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
Svetoslav | b0a7839 | 2015-04-10 17:25:35 -0700 | [diff] [blame] | 259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | Intent finalIntent = key.requestIntent != null |
| 261 | ? new Intent(key.requestIntent) : new Intent(); |
Svetoslav | b0a7839 | 2015-04-10 17:25:35 -0700 | [diff] [blame] | 262 | |
| 263 | final boolean immutable = (key.flags & PendingIntent.FLAG_IMMUTABLE) != 0; |
| 264 | if (!immutable) { |
| 265 | if (intent != null) { |
| 266 | int changes = finalIntent.fillIn(intent, key.flags); |
| 267 | if ((changes & Intent.FILL_IN_DATA) == 0) { |
| 268 | resolvedType = key.requestResolvedType; |
| 269 | } |
| 270 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | resolvedType = key.requestResolvedType; |
| 272 | } |
Svetoslav | b0a7839 | 2015-04-10 17:25:35 -0700 | [diff] [blame] | 273 | flagsMask &= ~Intent.IMMUTABLE_FLAGS; |
| 274 | flagsValues &= flagsMask; |
| 275 | finalIntent.setFlags((finalIntent.getFlags() & ~flagsMask) | flagsValues); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | } else { |
| 277 | resolvedType = key.requestResolvedType; |
| 278 | } |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 279 | |
Amith Yamasani | 83c994f | 2017-05-01 14:29:19 -0700 | [diff] [blame] | 280 | final int callingUid = Binder.getCallingUid(); |
| 281 | final int callingPid = Binder.getCallingPid(); |
| 282 | |
| 283 | final long origId = Binder.clearCallingIdentity(); |
| 284 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 285 | if (whitelistDuration != null) { |
| 286 | Long duration = whitelistDuration.get(whitelistToken); |
| 287 | if (duration != null) { |
| 288 | int procState = owner.getUidState(callingUid); |
| 289 | if (!ActivityManager.isProcStateBackground(procState)) { |
| 290 | StringBuilder tag = new StringBuilder(64); |
| 291 | tag.append("pendingintent:"); |
| 292 | UserHandle.formatUid(tag, callingUid); |
| 293 | tag.append(":"); |
| 294 | if (finalIntent.getAction() != null) { |
| 295 | tag.append(finalIntent.getAction()); |
| 296 | } else if (finalIntent.getComponent() != null) { |
| 297 | finalIntent.getComponent().appendShortString(tag); |
| 298 | } else if (finalIntent.getData() != null) { |
| 299 | tag.append(finalIntent.getData()); |
| 300 | } |
| 301 | owner.tempWhitelistForPendingIntentLocked(callingPid, |
| 302 | callingUid, uid, duration, tag.toString()); |
| 303 | } else { |
| 304 | Slog.w(TAG, "Not doing whitelist " + this + ": caller state=" |
| 305 | + procState); |
| 306 | } |
Dianne Hackborn | e4d1a2e | 2017-04-14 17:57:33 -0700 | [diff] [blame] | 307 | } |
Dianne Hackborn | e4d1a2e | 2017-04-14 17:57:33 -0700 | [diff] [blame] | 308 | } |
| 309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | boolean sendFinish = finishedReceiver != null; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 311 | int userId = key.userId; |
| 312 | if (userId == UserHandle.USER_CURRENT) { |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 313 | userId = owner.mUserController.getCurrentOrTargetUserId(); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 314 | } |
Jorim Jaggi | e2ad37f | 2018-01-22 22:41:22 +0100 | [diff] [blame] | 315 | int res = START_SUCCESS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | switch (key.type) { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 317 | case ActivityManager.INTENT_SENDER_ACTIVITY: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | try { |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 319 | SafeActivityOptions mergedOptions = key.options; |
| 320 | if (mergedOptions == null) { |
| 321 | mergedOptions = SafeActivityOptions.fromBundle(options); |
| 322 | } else { |
| 323 | mergedOptions.setCallerOptions(ActivityOptions.fromBundle(options)); |
| 324 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 325 | if (key.allIntents != null && key.allIntents.length > 1) { |
| 326 | Intent[] allIntents = new Intent[key.allIntents.length]; |
| 327 | String[] allResolvedTypes = new String[key.allIntents.length]; |
| 328 | System.arraycopy(key.allIntents, 0, allIntents, 0, |
| 329 | key.allIntents.length); |
| 330 | if (key.allResolvedTypes != null) { |
| 331 | System.arraycopy(key.allResolvedTypes, 0, allResolvedTypes, 0, |
| 332 | key.allResolvedTypes.length); |
| 333 | } |
| 334 | allIntents[allIntents.length-1] = finalIntent; |
| 335 | allResolvedTypes[allResolvedTypes.length-1] = resolvedType; |
Jorim Jaggi | e2ad37f | 2018-01-22 22:41:22 +0100 | [diff] [blame] | 336 | res = owner.getActivityStartController().startActivitiesInPackage( |
| 337 | uid, key.packageName, allIntents, allResolvedTypes, |
Makoto Onuki | 7041c4b | 2018-02-06 13:36:34 -0800 | [diff] [blame] | 338 | resultTo, mergedOptions, userId, |
| 339 | true /* validateIncomingUser */); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 340 | } else { |
Jorim Jaggi | e2ad37f | 2018-01-22 22:41:22 +0100 | [diff] [blame] | 341 | res = owner.getActivityStartController().startActivityInPackage(uid, |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 342 | callingPid, callingUid, key.packageName, finalIntent, |
| 343 | resolvedType, resultTo, resultWho, requestCode, 0, |
| 344 | mergedOptions, userId, null, "PendingIntentRecord"); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 345 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | } catch (RuntimeException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 347 | Slog.w(TAG, "Unable to send startActivity intent", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | } |
| 349 | break; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 350 | case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT: |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 351 | final ActivityStack stack = key.activity.getStack(); |
| 352 | if (stack != null) { |
| 353 | stack.sendActivityResultLocked(-1, key.activity, key.who, |
| 354 | key.requestCode, code, finalIntent); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 355 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | break; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 357 | case ActivityManager.INTENT_SENDER_BROADCAST: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | try { |
| 359 | // If a completion callback has been requested, require |
| 360 | // that the broadcast be delivered synchronously |
Amith Yamasani | 83b6ef0 | 2014-11-07 15:34:04 -0800 | [diff] [blame] | 361 | int sent = owner.broadcastIntentInPackage(key.packageName, uid, |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 362 | finalIntent, resolvedType, finishedReceiver, code, null, null, |
| 363 | requiredPermission, options, (finishedReceiver != null), |
| 364 | false, userId); |
Amith Yamasani | 83b6ef0 | 2014-11-07 15:34:04 -0800 | [diff] [blame] | 365 | if (sent == ActivityManager.BROADCAST_SUCCESS) { |
| 366 | sendFinish = false; |
| 367 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | } catch (RuntimeException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 369 | Slog.w(TAG, "Unable to send startActivity intent", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | } |
| 371 | break; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 372 | case ActivityManager.INTENT_SENDER_SERVICE: |
Christopher Tate | 08992ac | 2017-03-21 11:37:06 -0700 | [diff] [blame] | 373 | case ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | try { |
Christopher Tate | 08992ac | 2017-03-21 11:37:06 -0700 | [diff] [blame] | 375 | owner.startServiceInPackage(uid, finalIntent, resolvedType, |
| 376 | key.type == ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE, |
| 377 | key.packageName, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | } catch (RuntimeException e) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 379 | Slog.w(TAG, "Unable to send startService intent", e); |
Dianne Hackborn | 0c4e6a8 | 2016-05-13 17:37:08 -0700 | [diff] [blame] | 380 | } catch (TransactionTooLargeException e) { |
| 381 | res = ActivityManager.START_CANCELED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | } |
| 383 | break; |
| 384 | } |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 385 | |
Dianne Hackborn | 0c4e6a8 | 2016-05-13 17:37:08 -0700 | [diff] [blame] | 386 | if (sendFinish && res != ActivityManager.START_CANCELED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | try { |
| 388 | finishedReceiver.performReceive(new Intent(finalIntent), 0, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 389 | null, null, false, false, key.userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | } catch (RemoteException e) { |
| 391 | } |
| 392 | } |
Dianne Hackborn | 0c4e6a8 | 2016-05-13 17:37:08 -0700 | [diff] [blame] | 393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 0c4e6a8 | 2016-05-13 17:37:08 -0700 | [diff] [blame] | 395 | |
| 396 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | } |
| 398 | } |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 399 | return ActivityManager.START_CANCELED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 401 | |
| 402 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | protected void finalize() throws Throwable { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 404 | try { |
| 405 | if (!canceled) { |
| 406 | owner.mHandler.sendMessage(owner.mHandler.obtainMessage( |
| 407 | ActivityManagerService.FINALIZE_PENDING_INTENT_MSG, this)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | } |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 409 | } finally { |
| 410 | super.finalize(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 414 | public void completeFinalize() { |
| 415 | synchronized(owner) { |
| 416 | WeakReference<PendingIntentRecord> current = |
| 417 | owner.mIntentSenderRecords.get(key); |
| 418 | if (current == ref) { |
| 419 | owner.mIntentSenderRecords.remove(key); |
| 420 | } |
| 421 | } |
| 422 | } |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 425 | pw.print(prefix); pw.print("uid="); pw.print(uid); |
| 426 | pw.print(" packageName="); pw.print(key.packageName); |
| 427 | pw.print(" type="); pw.print(key.typeName()); |
| 428 | pw.print(" flags=0x"); pw.println(Integer.toHexString(key.flags)); |
| 429 | if (key.activity != null || key.who != null) { |
| 430 | pw.print(prefix); pw.print("activity="); pw.print(key.activity); |
| 431 | pw.print(" who="); pw.println(key.who); |
| 432 | } |
| 433 | if (key.requestCode != 0 || key.requestResolvedType != null) { |
| 434 | pw.print(prefix); pw.print("requestCode="); pw.print(key.requestCode); |
| 435 | pw.print(" requestResolvedType="); pw.println(key.requestResolvedType); |
| 436 | } |
Dianne Hackborn | c3b91fd | 2010-02-23 17:25:30 -0800 | [diff] [blame] | 437 | if (key.requestIntent != null) { |
| 438 | pw.print(prefix); pw.print("requestIntent="); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 439 | pw.println(key.requestIntent.toShortString(false, true, true, true)); |
Dianne Hackborn | c3b91fd | 2010-02-23 17:25:30 -0800 | [diff] [blame] | 440 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 441 | if (sent || canceled) { |
| 442 | pw.print(prefix); pw.print("sent="); pw.print(sent); |
| 443 | pw.print(" canceled="); pw.println(canceled); |
| 444 | } |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 445 | if (whitelistDuration != null) { |
Dianne Hackborn | bc02a39 | 2016-06-02 17:15:08 -0700 | [diff] [blame] | 446 | pw.print(prefix); |
| 447 | pw.print("whitelistDuration="); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 448 | for (int i = 0; i < whitelistDuration.size(); i++) { |
| 449 | if (i != 0) { |
| 450 | pw.print(", "); |
| 451 | } |
| 452 | pw.print(Integer.toHexString(System.identityHashCode(whitelistDuration.keyAt(i)))); |
| 453 | pw.print(":"); |
| 454 | TimeUtils.formatDuration(whitelistDuration.valueAt(i), pw); |
| 455 | } |
Dianne Hackborn | bc02a39 | 2016-06-02 17:15:08 -0700 | [diff] [blame] | 456 | pw.println(); |
| 457 | } |
Dianne Hackborn | f66adfd | 2017-04-13 11:01:48 -0700 | [diff] [blame] | 458 | if (mCancelCallbacks != null) { |
| 459 | pw.print(prefix); pw.println("mCancelCallbacks:"); |
| 460 | for (int i = 0; i < mCancelCallbacks.getRegisteredCallbackCount(); i++) { |
| 461 | pw.print(prefix); pw.print(" #"); pw.print(i); pw.print(": "); |
| 462 | pw.println(mCancelCallbacks.getRegisteredCallbackItem(i)); |
| 463 | } |
| 464 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 468 | if (stringName != null) { |
| 469 | return stringName; |
| 470 | } |
| 471 | StringBuilder sb = new StringBuilder(128); |
| 472 | sb.append("PendingIntentRecord{"); |
| 473 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 474 | sb.append(' '); |
| 475 | sb.append(key.packageName); |
| 476 | sb.append(' '); |
| 477 | sb.append(key.typeName()); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 478 | if (whitelistDuration != null) { |
Dianne Hackborn | bc02a39 | 2016-06-02 17:15:08 -0700 | [diff] [blame] | 479 | sb.append( " (whitelist: "); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 480 | for (int i = 0; i < whitelistDuration.size(); i++) { |
| 481 | if (i != 0) { |
| 482 | sb.append(","); |
| 483 | } |
| 484 | sb.append(Integer.toHexString(System.identityHashCode(whitelistDuration.keyAt(i)))); |
| 485 | sb.append(":"); |
| 486 | TimeUtils.formatDuration(whitelistDuration.valueAt(i), sb); |
| 487 | } |
Dianne Hackborn | bc02a39 | 2016-06-02 17:15:08 -0700 | [diff] [blame] | 488 | sb.append(")"); |
Felipe Leme | a1b79bf | 2016-05-24 13:06:54 -0700 | [diff] [blame] | 489 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 490 | sb.append('}'); |
| 491 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | } |
| 493 | } |