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; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 20 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.ComponentName; |
| 22 | import android.content.Intent; |
| 23 | import android.content.pm.ActivityInfo; |
| 24 | import android.content.pm.ResolveInfo; |
| 25 | import android.os.Binder; |
| 26 | import android.os.Bundle; |
| 27 | import android.os.IBinder; |
| 28 | import android.os.SystemClock; |
| 29 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 30 | import android.util.TimeUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| 32 | import java.io.PrintWriter; |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 33 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import java.util.List; |
| 35 | |
| 36 | /** |
| 37 | * An active intent broadcast. |
| 38 | */ |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 39 | final class BroadcastRecord extends Binder { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | final Intent intent; // the original intent that generated us |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 41 | 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] | 42 | final ProcessRecord callerApp; // process that sent this |
| 43 | final String callerPackage; // who sent this |
| 44 | final int callingPid; // the pid of who sent this |
| 45 | final int callingUid; // the uid of who sent this |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 46 | final boolean ordered; // serialize the send to receivers? |
| 47 | final boolean sticky; // originated from existing sticky data? |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 48 | final boolean initialSticky; // initial broadcast from register to sticky? |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 49 | final int userId; // user id this broadcast was for |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 50 | final String resolvedType; // the resolved data type |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 51 | final String requiredPermission; // a permission the caller has required |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 52 | final int appOp; // an app op that is associated with this broadcast |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | final List receivers; // contains BroadcastFilter and ResolveInfo |
Johannes Carlsson | b5a8654 | 2010-10-27 10:08:10 +0200 | [diff] [blame] | 54 | IIntentReceiver resultTo; // who receives final result if non-null |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 55 | long enqueueClockTime; // the clock time the broadcast was enqueued |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | long dispatchTime; // when dispatch started on this set of receivers |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 57 | long dispatchClockTime; // the clock time the dispatch started |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 58 | long receiverTime; // when current receiver started for timeouts. |
| 59 | long finishTime; // when we finished the broadcast. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | int resultCode; // current result code value. |
| 61 | String resultData; // current result data value. |
| 62 | Bundle resultExtras; // current result extra data values. |
| 63 | boolean resultAbort; // current result abortBroadcast value. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | int nextReceiver; // next receiver to be executed. |
| 65 | IBinder receiver; // who is currently running, null if none. |
| 66 | int state; |
| 67 | int anrCount; // has this broadcast record hit any ANRs? |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 68 | BroadcastQueue queue; // the outbound queue handling this broadcast |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
| 70 | static final int IDLE = 0; |
| 71 | static final int APP_RECEIVE = 1; |
| 72 | static final int CALL_IN_RECEIVE = 2; |
| 73 | static final int CALL_DONE_RECEIVE = 3; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 74 | static final int WAITING_SERVICES = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | |
| 76 | // The following are set when we are calling a receiver (one that |
| 77 | // was found in our list of registered receivers). |
| 78 | BroadcastFilter curFilter; |
| 79 | |
| 80 | // The following are set only when we are launching a receiver (one |
| 81 | // that was found by querying the package manager). |
| 82 | ProcessRecord curApp; // hosting application of current receiver. |
| 83 | ComponentName curComponent; // the receiver class that is currently running. |
| 84 | ActivityInfo curReceiver; // info about the receiver that is currently running. |
| 85 | |
| 86 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 87 | final long now = SystemClock.uptimeMillis(); |
| 88 | |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 89 | 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] | 90 | pw.print(prefix); pw.println(intent.toInsecureString()); |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 91 | if (targetComp != null && targetComp != intent.getComponent()) { |
| 92 | pw.print(prefix); pw.print(" targetComp: "); pw.println(targetComp.toShortString()); |
| 93 | } |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 94 | Bundle bundle = intent.getExtras(); |
| 95 | if (bundle != null) { |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 96 | pw.print(prefix); pw.print(" extras: "); pw.println(bundle.toString()); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 97 | } |
Dianne Hackborn | 043fcd9 | 2010-10-06 14:27:34 -0700 | [diff] [blame] | 98 | pw.print(prefix); pw.print("caller="); pw.print(callerPackage); pw.print(" "); |
| 99 | pw.print(callerApp != null ? callerApp.toShortString() : "null"); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 100 | pw.print(" pid="); pw.print(callingPid); |
| 101 | pw.print(" uid="); pw.println(callingUid); |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 102 | if (requiredPermission != null || appOp != AppOpsManager.OP_NONE) { |
| 103 | pw.print(prefix); pw.print("requiredPermission="); pw.print(requiredPermission); |
| 104 | pw.print(" appOp="); pw.println(appOp); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 105 | } |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 106 | pw.print(prefix); pw.print("enqueueClockTime="); |
| 107 | pw.print(new Date(enqueueClockTime)); |
| 108 | pw.print(" dispatchClockTime="); |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 109 | pw.println(new Date(dispatchClockTime)); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 110 | pw.print(prefix); pw.print("dispatchTime="); |
| 111 | TimeUtils.formatDuration(dispatchTime, now, pw); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 112 | if (finishTime != 0) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 113 | pw.print(" finishTime="); TimeUtils.formatDuration(finishTime, now, pw); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 114 | } else { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 115 | pw.print(" receiverTime="); TimeUtils.formatDuration(receiverTime, now, pw); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 116 | } |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 117 | pw.println(""); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 118 | if (anrCount != 0) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 119 | pw.print(prefix); pw.print("anrCount="); pw.println(anrCount); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 120 | } |
| 121 | if (resultTo != null || resultCode != -1 || resultData != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 122 | pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); |
| 123 | pw.print(" resultCode="); pw.print(resultCode); |
| 124 | pw.print(" resultData="); pw.println(resultData); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 125 | } |
| 126 | if (resultExtras != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 127 | pw.print(prefix); pw.print("resultExtras="); pw.println(resultExtras); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 128 | } |
| 129 | if (resultAbort || ordered || sticky || initialSticky) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 130 | pw.print(prefix); pw.print("resultAbort="); pw.print(resultAbort); |
| 131 | pw.print(" ordered="); pw.print(ordered); |
| 132 | pw.print(" sticky="); pw.print(sticky); |
| 133 | pw.print(" initialSticky="); pw.println(initialSticky); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 134 | } |
| 135 | if (nextReceiver != 0 || receiver != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 136 | pw.print(prefix); pw.print("nextReceiver="); pw.print(nextReceiver); |
| 137 | pw.print(" receiver="); pw.println(receiver); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 138 | } |
| 139 | if (curFilter != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 140 | pw.print(prefix); pw.print("curFilter="); pw.println(curFilter); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 141 | } |
| 142 | if (curReceiver != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 143 | pw.print(prefix); pw.print("curReceiver="); pw.println(curReceiver); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 144 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | if (curApp != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 146 | pw.print(prefix); pw.print("curApp="); pw.println(curApp); |
| 147 | pw.print(prefix); pw.print("curComponent="); |
| 148 | pw.println((curComponent != null ? curComponent.toShortString() : "--")); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 149 | if (curReceiver != null && curReceiver.applicationInfo != null) { |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 150 | pw.print(prefix); pw.print("curSourceDir="); |
| 151 | pw.println(curReceiver.applicationInfo.sourceDir); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 154 | if (state != IDLE) { |
| 155 | String stateStr = " (?)"; |
| 156 | switch (state) { |
| 157 | case APP_RECEIVE: stateStr=" (APP_RECEIVE)"; break; |
| 158 | case CALL_IN_RECEIVE: stateStr=" (CALL_IN_RECEIVE)"; break; |
| 159 | case CALL_DONE_RECEIVE: stateStr=" (CALL_DONE_RECEIVE)"; break; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 160 | case WAITING_SERVICES: stateStr=" (WAITING_SERVICES)"; break; |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 161 | } |
| 162 | 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] | 163 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | final int N = receivers != null ? receivers.size() : 0; |
| 165 | String p2 = prefix + " "; |
| 166 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 167 | for (int i=0; i<N; i++) { |
| 168 | Object o = receivers.get(i); |
Dianne Hackborn | 39792d2 | 2010-08-19 18:01:52 -0700 | [diff] [blame] | 169 | pw.print(prefix); pw.print("Receiver #"); pw.print(i); |
| 170 | pw.print(": "); pw.println(o); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | if (o instanceof BroadcastFilter) |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 172 | ((BroadcastFilter)o).dumpBrief(pw, p2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | else if (o instanceof ResolveInfo) |
| 174 | ((ResolveInfo)o).dump(printer, p2); |
| 175 | } |
| 176 | } |
| 177 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 178 | BroadcastRecord(BroadcastQueue _queue, |
Christopher Tate | f46723b | 2012-01-26 14:19:24 -0800 | [diff] [blame] | 179 | Intent _intent, ProcessRecord _callerApp, String _callerPackage, |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 180 | int _callingPid, int _callingUid, String _resolvedType, String _requiredPermission, |
| 181 | int _appOp, List _receivers, IIntentReceiver _resultTo, int _resultCode, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 182 | String _resultData, Bundle _resultExtras, boolean _serialized, |
Amith Yamasani | 8bf06ed | 2012-08-27 19:30:30 -0700 | [diff] [blame] | 183 | boolean _sticky, boolean _initialSticky, |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 184 | int _userId) { |
Christopher Tate | f46723b | 2012-01-26 14:19:24 -0800 | [diff] [blame] | 185 | queue = _queue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | intent = _intent; |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 187 | targetComp = _intent.getComponent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | callerApp = _callerApp; |
| 189 | callerPackage = _callerPackage; |
| 190 | callingPid = _callingPid; |
| 191 | callingUid = _callingUid; |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 192 | resolvedType = _resolvedType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | requiredPermission = _requiredPermission; |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 194 | appOp = _appOp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | receivers = _receivers; |
| 196 | resultTo = _resultTo; |
| 197 | resultCode = _resultCode; |
| 198 | resultData = _resultData; |
| 199 | resultExtras = _resultExtras; |
| 200 | ordered = _serialized; |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 201 | sticky = _sticky; |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 202 | initialSticky = _initialSticky; |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 203 | userId = _userId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | nextReceiver = 0; |
| 205 | state = IDLE; |
| 206 | } |
| 207 | |
| 208 | public String toString() { |
| 209 | return "BroadcastRecord{" |
| 210 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 211 | + " u" + userId + " " + intent.getAction() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | } |
| 213 | } |