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 | |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 19 | import android.annotation.Nullable; |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 21 | import android.app.BroadcastOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
Ng Zhi An | 1eb7d38 | 2018-08-24 13:27:54 -0700 | [diff] [blame] | 23 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.pm.ActivityInfo; |
| 26 | import android.content.pm.ResolveInfo; |
| 27 | import android.os.Binder; |
| 28 | import android.os.Bundle; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.SystemClock; |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 31 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 33 | import android.util.TimeUtils; |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 34 | import android.util.proto.ProtoOutputStream; |
| 35 | |
Riddle Hsu | 7fdd90a | 2018-05-01 00:37:59 +0800 | [diff] [blame] | 36 | import com.android.internal.annotations.VisibleForTesting; |
| 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import java.io.PrintWriter; |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 39 | import java.text.SimpleDateFormat; |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 40 | import java.util.ArrayList; |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 41 | import java.util.Arrays; |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 42 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import java.util.List; |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 44 | import java.util.Set; |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 45 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * An active intent broadcast. |
| 49 | */ |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 50 | final class BroadcastRecord extends Binder { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | final Intent intent; // the original intent that generated us |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 52 | final ComponentName targetComp; // original component name set on the intent |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | final ProcessRecord callerApp; // process that sent this |
| 54 | final String callerPackage; // who sent this |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 55 | final @Nullable String callerFeatureId; // which feature in the package sent this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | final int callingPid; // the pid of who sent this |
| 57 | final int callingUid; // the uid of who sent this |
Chad Brubaker | 816c83b | 2017-03-02 10:27:59 -0800 | [diff] [blame] | 58 | final boolean callerInstantApp; // caller is an Instant App? |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 59 | final boolean ordered; // serialize the send to receivers? |
| 60 | final boolean sticky; // originated from existing sticky data? |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 61 | final boolean initialSticky; // initial broadcast from register to sticky? |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 62 | final int userId; // user id this broadcast was for |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 63 | final String resolvedType; // the resolved data type |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 64 | final String[] requiredPermissions; // permissions the caller has required |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 65 | final int appOp; // an app op that is associated with this broadcast |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 66 | final BroadcastOptions options; // BroadcastOptions supplied by caller |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | final List receivers; // contains BroadcastFilter and ResolveInfo |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 68 | final int[] delivery; // delivery state of each receiver |
Ng Zhi An | 1eb7d38 | 2018-08-24 13:27:54 -0700 | [diff] [blame] | 69 | final long[] duration; // duration a receiver took to process broadcast |
Johannes Carlsson | b5a8654 | 2010-10-27 10:08:10 +0200 | [diff] [blame] | 70 | IIntentReceiver resultTo; // who receives final result if non-null |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 71 | boolean deferred; |
| 72 | int splitCount; // refcount for result callback, when split |
| 73 | int splitToken; // identifier for cross-BroadcastRecord refcount |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 74 | long enqueueClockTime; // the clock time the broadcast was enqueued |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | long dispatchTime; // when dispatch started on this set of receivers |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 76 | long dispatchClockTime; // the clock time the dispatch started |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 77 | long receiverTime; // when current receiver started for timeouts. |
| 78 | long finishTime; // when we finished the broadcast. |
Christopher Tate | 1b72ca3 | 2019-01-30 16:25:53 -0800 | [diff] [blame] | 79 | boolean timeoutExempt; // true if this broadcast is not subject to receiver timeouts |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | int resultCode; // current result code value. |
| 81 | String resultData; // current result data value. |
| 82 | Bundle resultExtras; // current result extra data values. |
| 83 | boolean resultAbort; // current result abortBroadcast value. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | int nextReceiver; // next receiver to be executed. |
| 85 | IBinder receiver; // who is currently running, null if none. |
| 86 | int state; |
| 87 | int anrCount; // has this broadcast record hit any ANRs? |
Dianne Hackborn | bc02a39 | 2016-06-02 17:15:08 -0700 | [diff] [blame] | 88 | int manifestCount; // number of manifest receivers dispatched. |
| 89 | int manifestSkipCount; // number of manifest receivers skipped. |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 90 | BroadcastQueue queue; // the outbound queue handling this broadcast |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 92 | // if set to true, app's process will be temporarily whitelisted to start activities |
| 93 | // from background for the duration of the broadcast dispatch |
| 94 | final boolean allowBackgroundActivityStarts; |
| 95 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | static final int IDLE = 0; |
| 97 | static final int APP_RECEIVE = 1; |
| 98 | static final int CALL_IN_RECEIVE = 2; |
| 99 | static final int CALL_DONE_RECEIVE = 3; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 100 | static final int WAITING_SERVICES = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 102 | static final int DELIVERY_PENDING = 0; |
| 103 | static final int DELIVERY_DELIVERED = 1; |
| 104 | static final int DELIVERY_SKIPPED = 2; |
| 105 | static final int DELIVERY_TIMEOUT = 3; |
| 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | // The following are set when we are calling a receiver (one that |
| 108 | // was found in our list of registered receivers). |
| 109 | BroadcastFilter curFilter; |
| 110 | |
| 111 | // The following are set only when we are launching a receiver (one |
| 112 | // that was found by querying the package manager). |
| 113 | ProcessRecord curApp; // hosting application of current receiver. |
| 114 | ComponentName curComponent; // the receiver class that is currently running. |
| 115 | ActivityInfo curReceiver; // info about the receiver that is currently running. |
| 116 | |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 117 | // Private refcount-management bookkeeping; start > 0 |
| 118 | static AtomicInteger sNextToken = new AtomicInteger(1); |
| 119 | |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 120 | void dump(PrintWriter pw, String prefix, SimpleDateFormat sdf) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 121 | final long now = SystemClock.uptimeMillis(); |
| 122 | |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 123 | pw.print(prefix); pw.print(this); pw.print(" to user "); pw.println(userId); |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 124 | pw.print(prefix); pw.println(intent.toInsecureString()); |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 125 | if (targetComp != null && targetComp != intent.getComponent()) { |
| 126 | pw.print(prefix); pw.print(" targetComp: "); pw.println(targetComp.toShortString()); |
| 127 | } |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 128 | Bundle bundle = intent.getExtras(); |
| 129 | if (bundle != null) { |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 130 | pw.print(prefix); pw.print(" extras: "); pw.println(bundle.toString()); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 131 | } |
Dianne Hackborn | 043fcd9 | 2010-10-06 14:27:34 -0700 | [diff] [blame] | 132 | pw.print(prefix); pw.print("caller="); pw.print(callerPackage); pw.print(" "); |
| 133 | pw.print(callerApp != null ? callerApp.toShortString() : "null"); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 134 | pw.print(" pid="); pw.print(callingPid); |
| 135 | pw.print(" uid="); pw.println(callingUid); |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 136 | if ((requiredPermissions != null && requiredPermissions.length > 0) |
| 137 | || appOp != AppOpsManager.OP_NONE) { |
| 138 | pw.print(prefix); pw.print("requiredPermissions="); |
| 139 | pw.print(Arrays.toString(requiredPermissions)); |
| 140 | pw.print(" appOp="); pw.println(appOp); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 141 | } |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 142 | if (options != null) { |
| 143 | pw.print(prefix); pw.print("options="); pw.println(options.toBundle()); |
| 144 | } |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 145 | pw.print(prefix); pw.print("enqueueClockTime="); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 146 | pw.print(sdf.format(new Date(enqueueClockTime))); |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 147 | pw.print(" dispatchClockTime="); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 148 | pw.println(sdf.format(new Date(dispatchClockTime))); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 149 | pw.print(prefix); pw.print("dispatchTime="); |
| 150 | TimeUtils.formatDuration(dispatchTime, now, pw); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 151 | pw.print(" ("); |
| 152 | TimeUtils.formatDuration(dispatchClockTime-enqueueClockTime, pw); |
| 153 | pw.print(" since enq)"); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 154 | if (finishTime != 0) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 155 | pw.print(" finishTime="); TimeUtils.formatDuration(finishTime, now, pw); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 156 | pw.print(" ("); |
| 157 | TimeUtils.formatDuration(finishTime-dispatchTime, pw); |
| 158 | pw.print(" since disp)"); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 159 | } else { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 160 | pw.print(" receiverTime="); TimeUtils.formatDuration(receiverTime, now, pw); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 161 | } |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 162 | pw.println(""); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 163 | if (anrCount != 0) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 164 | pw.print(prefix); pw.print("anrCount="); pw.println(anrCount); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 165 | } |
| 166 | if (resultTo != null || resultCode != -1 || resultData != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 167 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 168 | pw.print(" resultCode="); pw.print(resultCode); |
| 169 | pw.print(" resultData="); pw.println(resultData); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 170 | } |
| 171 | if (resultExtras != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 172 | pw.print(prefix); pw.print("resultExtras="); pw.println(resultExtras); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 173 | } |
| 174 | if (resultAbort || ordered || sticky || initialSticky) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 175 | pw.print(prefix); pw.print("resultAbort="); pw.print(resultAbort); |
| 176 | pw.print(" ordered="); pw.print(ordered); |
| 177 | pw.print(" sticky="); pw.print(sticky); |
| 178 | pw.print(" initialSticky="); pw.println(initialSticky); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 179 | } |
| 180 | if (nextReceiver != 0 || receiver != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 181 | pw.print(prefix); pw.print("nextReceiver="); pw.print(nextReceiver); |
| 182 | pw.print(" receiver="); pw.println(receiver); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 183 | } |
| 184 | if (curFilter != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 185 | pw.print(prefix); pw.print("curFilter="); pw.println(curFilter); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 186 | } |
| 187 | if (curReceiver != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 188 | pw.print(prefix); pw.print("curReceiver="); pw.println(curReceiver); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 189 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | if (curApp != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 191 | pw.print(prefix); pw.print("curApp="); pw.println(curApp); |
| 192 | pw.print(prefix); pw.print("curComponent="); |
| 193 | pw.println((curComponent != null ? curComponent.toShortString() : "--")); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 194 | if (curReceiver != null && curReceiver.applicationInfo != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 195 | pw.print(prefix); pw.print("curSourceDir="); |
| 196 | pw.println(curReceiver.applicationInfo.sourceDir); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 197 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | } |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 199 | if (state != IDLE) { |
| 200 | String stateStr = " (?)"; |
| 201 | switch (state) { |
| 202 | case APP_RECEIVE: stateStr=" (APP_RECEIVE)"; break; |
| 203 | case CALL_IN_RECEIVE: stateStr=" (CALL_IN_RECEIVE)"; break; |
| 204 | case CALL_DONE_RECEIVE: stateStr=" (CALL_DONE_RECEIVE)"; break; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 205 | case WAITING_SERVICES: stateStr=" (WAITING_SERVICES)"; break; |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 206 | } |
| 207 | pw.print(prefix); pw.print("state="); pw.print(state); pw.println(stateStr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | final int N = receivers != null ? receivers.size() : 0; |
| 210 | String p2 = prefix + " "; |
| 211 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 212 | for (int i = 0; i < N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | Object o = receivers.get(i); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 214 | pw.print(prefix); |
| 215 | switch (delivery[i]) { |
| 216 | case DELIVERY_PENDING: pw.print("Pending"); break; |
| 217 | case DELIVERY_DELIVERED: pw.print("Deliver"); break; |
| 218 | case DELIVERY_SKIPPED: pw.print("Skipped"); break; |
| 219 | case DELIVERY_TIMEOUT: pw.print("Timeout"); break; |
| 220 | default: pw.print("???????"); break; |
| 221 | } |
Ng Zhi An | 1eb7d38 | 2018-08-24 13:27:54 -0700 | [diff] [blame] | 222 | pw.print(" "); TimeUtils.formatDuration(duration[i], pw); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 223 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 224 | if (o instanceof BroadcastFilter) { |
| 225 | pw.println(o); |
| 226 | ((BroadcastFilter) o).dumpBrief(pw, p2); |
| 227 | } else if (o instanceof ResolveInfo) { |
| 228 | pw.println("(manifest)"); |
| 229 | ((ResolveInfo) o).dump(printer, p2, 0); |
| 230 | } else { |
| 231 | pw.println(o); |
| 232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 236 | BroadcastRecord(BroadcastQueue _queue, |
Christopher Tate | f46723b | 2012-01-26 14:19:24 -0800 | [diff] [blame] | 237 | Intent _intent, ProcessRecord _callerApp, String _callerPackage, |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 238 | @Nullable String _callerFeatureId, int _callingPid, int _callingUid, |
| 239 | boolean _callerInstantApp, String _resolvedType, |
Chad Brubaker | 816c83b | 2017-03-02 10:27:59 -0800 | [diff] [blame] | 240 | String[] _requiredPermissions, int _appOp, BroadcastOptions _options, List _receivers, |
| 241 | IIntentReceiver _resultTo, int _resultCode, String _resultData, Bundle _resultExtras, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 242 | boolean _serialized, boolean _sticky, boolean _initialSticky, int _userId, |
Christopher Tate | 1b72ca3 | 2019-01-30 16:25:53 -0800 | [diff] [blame] | 243 | boolean _allowBackgroundActivityStarts, boolean _timeoutExempt) { |
Dianne Hackborn | 448489a | 2016-09-29 10:55:10 -0700 | [diff] [blame] | 244 | if (_intent == null) { |
| 245 | throw new NullPointerException("Can't construct with a null intent"); |
| 246 | } |
Christopher Tate | f46723b | 2012-01-26 14:19:24 -0800 | [diff] [blame] | 247 | queue = _queue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | intent = _intent; |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 249 | targetComp = _intent.getComponent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | callerApp = _callerApp; |
| 251 | callerPackage = _callerPackage; |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 252 | callerFeatureId = _callerFeatureId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | callingPid = _callingPid; |
| 254 | callingUid = _callingUid; |
Chad Brubaker | 816c83b | 2017-03-02 10:27:59 -0800 | [diff] [blame] | 255 | callerInstantApp = _callerInstantApp; |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 256 | resolvedType = _resolvedType; |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 257 | requiredPermissions = _requiredPermissions; |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 258 | appOp = _appOp; |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 259 | options = _options; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | receivers = _receivers; |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 261 | delivery = new int[_receivers != null ? _receivers.size() : 0]; |
Ng Zhi An | 1eb7d38 | 2018-08-24 13:27:54 -0700 | [diff] [blame] | 262 | duration = new long[delivery.length]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | resultTo = _resultTo; |
| 264 | resultCode = _resultCode; |
| 265 | resultData = _resultData; |
| 266 | resultExtras = _resultExtras; |
| 267 | ordered = _serialized; |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 268 | sticky = _sticky; |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 269 | initialSticky = _initialSticky; |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 270 | userId = _userId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | nextReceiver = 0; |
| 272 | state = IDLE; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 273 | allowBackgroundActivityStarts = _allowBackgroundActivityStarts; |
Christopher Tate | 1b72ca3 | 2019-01-30 16:25:53 -0800 | [diff] [blame] | 274 | timeoutExempt = _timeoutExempt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Copy constructor which takes a different intent. |
| 279 | * Only used by {@link #maybeStripForHistory}. |
| 280 | */ |
| 281 | private BroadcastRecord(BroadcastRecord from, Intent newIntent) { |
| 282 | intent = newIntent; |
| 283 | targetComp = newIntent.getComponent(); |
| 284 | |
| 285 | callerApp = from.callerApp; |
| 286 | callerPackage = from.callerPackage; |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 287 | callerFeatureId = from.callerFeatureId; |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 288 | callingPid = from.callingPid; |
| 289 | callingUid = from.callingUid; |
| 290 | callerInstantApp = from.callerInstantApp; |
| 291 | ordered = from.ordered; |
| 292 | sticky = from.sticky; |
| 293 | initialSticky = from.initialSticky; |
| 294 | userId = from.userId; |
| 295 | resolvedType = from.resolvedType; |
| 296 | requiredPermissions = from.requiredPermissions; |
| 297 | appOp = from.appOp; |
| 298 | options = from.options; |
| 299 | receivers = from.receivers; |
| 300 | delivery = from.delivery; |
Ng Zhi An | 1eb7d38 | 2018-08-24 13:27:54 -0700 | [diff] [blame] | 301 | duration = from.duration; |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 302 | resultTo = from.resultTo; |
| 303 | enqueueClockTime = from.enqueueClockTime; |
| 304 | dispatchTime = from.dispatchTime; |
| 305 | dispatchClockTime = from.dispatchClockTime; |
| 306 | receiverTime = from.receiverTime; |
| 307 | finishTime = from.finishTime; |
| 308 | resultCode = from.resultCode; |
| 309 | resultData = from.resultData; |
| 310 | resultExtras = from.resultExtras; |
| 311 | resultAbort = from.resultAbort; |
| 312 | nextReceiver = from.nextReceiver; |
| 313 | receiver = from.receiver; |
| 314 | state = from.state; |
| 315 | anrCount = from.anrCount; |
| 316 | manifestCount = from.manifestCount; |
| 317 | manifestSkipCount = from.manifestSkipCount; |
| 318 | queue = from.queue; |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 319 | allowBackgroundActivityStarts = from.allowBackgroundActivityStarts; |
Christopher Tate | 1b72ca3 | 2019-01-30 16:25:53 -0800 | [diff] [blame] | 320 | timeoutExempt = from.timeoutExempt; |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 323 | /** |
| 324 | * Split off a new BroadcastRecord that clones this one, but contains only the |
| 325 | * recipient records for the current (just-finished) receiver's app, starting |
| 326 | * after the just-finished receiver [i.e. at r.nextReceiver]. Returns null |
| 327 | * if there are no matching subsequent receivers in this BroadcastRecord. |
| 328 | */ |
| 329 | BroadcastRecord splitRecipientsLocked(int slowAppUid, int startingAt) { |
| 330 | // Do we actually have any matching receivers down the line...? |
| 331 | ArrayList splitReceivers = null; |
| 332 | for (int i = startingAt; i < receivers.size(); ) { |
| 333 | Object o = receivers.get(i); |
| 334 | if (getReceiverUid(o) == slowAppUid) { |
| 335 | if (splitReceivers == null) { |
| 336 | splitReceivers = new ArrayList<>(); |
| 337 | } |
| 338 | splitReceivers.add(o); |
| 339 | receivers.remove(i); |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 340 | } else { |
| 341 | i++; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // No later receivers in the same app, so we have no more to do |
| 346 | if (splitReceivers == null) { |
| 347 | return null; |
| 348 | } |
| 349 | |
| 350 | // build a new BroadcastRecord around that single-target list |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 351 | BroadcastRecord split = new BroadcastRecord(queue, intent, callerApp, callerPackage, |
| 352 | callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType, |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 353 | requiredPermissions, appOp, options, splitReceivers, resultTo, resultCode, |
| 354 | resultData, resultExtras, ordered, sticky, initialSticky, userId, |
Christopher Tate | 1b72ca3 | 2019-01-30 16:25:53 -0800 | [diff] [blame] | 355 | allowBackgroundActivityStarts, timeoutExempt); |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 356 | |
Christopher Tate | 41c5691 | 2019-03-01 18:56:58 -0800 | [diff] [blame] | 357 | split.splitToken = this.splitToken; |
Christopher Tate | 2f558d2 | 2019-01-17 16:58:31 -0800 | [diff] [blame] | 358 | return split; |
| 359 | } |
| 360 | |
| 361 | int getReceiverUid(Object receiver) { |
| 362 | if (receiver instanceof BroadcastFilter) { |
| 363 | return ((BroadcastFilter) receiver).owningUid; |
| 364 | } else /* if (receiver instanceof ResolveInfo) */ { |
| 365 | return ((ResolveInfo) receiver).activityInfo.applicationInfo.uid; |
| 366 | } |
| 367 | } |
| 368 | |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 369 | public BroadcastRecord maybeStripForHistory() { |
| 370 | if (!intent.canStripForHistory()) { |
| 371 | return this; |
| 372 | } |
| 373 | return new BroadcastRecord(this, intent.maybeStripForHistory()); |
| 374 | } |
| 375 | |
Riddle Hsu | 7fdd90a | 2018-05-01 00:37:59 +0800 | [diff] [blame] | 376 | @VisibleForTesting |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 377 | boolean cleanupDisabledPackageReceiversLocked( |
| 378 | String packageName, Set<String> filterByClasses, int userId, boolean doit) { |
Riddle Hsu | 7fdd90a | 2018-05-01 00:37:59 +0800 | [diff] [blame] | 379 | if (receivers == null) { |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | final boolean cleanupAllUsers = userId == UserHandle.USER_ALL; |
| 384 | final boolean sendToAllUsers = this.userId == UserHandle.USER_ALL; |
| 385 | if (this.userId != userId && !cleanupAllUsers && !sendToAllUsers) { |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 386 | return false; |
| 387 | } |
| 388 | |
| 389 | boolean didSomething = false; |
| 390 | Object o; |
| 391 | for (int i = receivers.size() - 1; i >= 0; i--) { |
| 392 | o = receivers.get(i); |
| 393 | if (!(o instanceof ResolveInfo)) { |
| 394 | continue; |
| 395 | } |
| 396 | ActivityInfo info = ((ResolveInfo)o).activityInfo; |
| 397 | |
| 398 | final boolean sameComponent = packageName == null |
| 399 | || (info.applicationInfo.packageName.equals(packageName) |
| 400 | && (filterByClasses == null || filterByClasses.contains(info.name))); |
Riddle Hsu | 7fdd90a | 2018-05-01 00:37:59 +0800 | [diff] [blame] | 401 | if (sameComponent && (cleanupAllUsers |
| 402 | || UserHandle.getUserId(info.applicationInfo.uid) == userId)) { |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 403 | if (!doit) { |
| 404 | return true; |
| 405 | } |
| 406 | didSomething = true; |
| 407 | receivers.remove(i); |
Wale Ogunwale | 9a6e13c | 2015-08-03 15:21:44 -0700 | [diff] [blame] | 408 | if (i < nextReceiver) { |
| 409 | nextReceiver--; |
| 410 | } |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
Wale Ogunwale | 9a6e13c | 2015-08-03 15:21:44 -0700 | [diff] [blame] | 413 | nextReceiver = Math.min(nextReceiver, receivers.size()); |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 414 | |
| 415 | return didSomething; |
| 416 | } |
| 417 | |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 418 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | public String toString() { |
| 420 | return "BroadcastRecord{" |
| 421 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 422 | + " u" + userId + " " + intent.getAction() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 424 | |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 425 | public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 426 | long token = proto.start(fieldId); |
| 427 | proto.write(BroadcastRecordProto.USER_ID, userId); |
| 428 | proto.write(BroadcastRecordProto.INTENT_ACTION, intent.getAction()); |
| 429 | proto.end(token); |
| 430 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | } |