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