BroadcastRecord.java revision 8bf06edac2088ad100e67dcb00a46d3f0f95c126
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 17package com.android.server.am; 18 19import android.content.IIntentReceiver; 20import android.content.ComponentName; 21import android.content.Intent; 22import android.content.pm.ActivityInfo; 23import android.content.pm.ResolveInfo; 24import android.os.Binder; 25import android.os.Bundle; 26import android.os.IBinder; 27import android.os.SystemClock; 28import android.util.PrintWriterPrinter; 29import android.util.TimeUtils; 30 31import java.io.PrintWriter; 32import java.util.Date; 33import java.util.List; 34 35/** 36 * An active intent broadcast. 37 */ 38class BroadcastRecord extends Binder { 39 final Intent intent; // the original intent that generated us 40 final ProcessRecord callerApp; // process that sent this 41 final String callerPackage; // who sent this 42 final int callingPid; // the pid of who sent this 43 final int callingUid; // the uid of who sent this 44 final boolean ordered; // serialize the send to receivers? 45 final boolean sticky; // originated from existing sticky data? 46 final boolean initialSticky; // initial broadcast from register to sticky? 47 final int userId; // user id this broadcast was for 48 final String requiredPermission; // a permission the caller has required 49 final List receivers; // contains BroadcastFilter and ResolveInfo 50 IIntentReceiver resultTo; // who receives final result if non-null 51 long dispatchTime; // when dispatch started on this set of receivers 52 long dispatchClockTime; // the clock time the dispatch started 53 long receiverTime; // when current receiver started for timeouts. 54 long finishTime; // when we finished the broadcast. 55 int resultCode; // current result code value. 56 String resultData; // current result data value. 57 Bundle resultExtras; // current result extra data values. 58 boolean resultAbort; // current result abortBroadcast value. 59 int nextReceiver; // next receiver to be executed. 60 IBinder receiver; // who is currently running, null if none. 61 int state; 62 int anrCount; // has this broadcast record hit any ANRs? 63 BroadcastQueue queue; // the outbound queue handling this broadcast 64 65 static final int IDLE = 0; 66 static final int APP_RECEIVE = 1; 67 static final int CALL_IN_RECEIVE = 2; 68 static final int CALL_DONE_RECEIVE = 3; 69 70 // The following are set when we are calling a receiver (one that 71 // was found in our list of registered receivers). 72 BroadcastFilter curFilter; 73 74 // The following are set only when we are launching a receiver (one 75 // that was found by querying the package manager). 76 ProcessRecord curApp; // hosting application of current receiver. 77 ComponentName curComponent; // the receiver class that is currently running. 78 ActivityInfo curReceiver; // info about the receiver that is currently running. 79 80 void dump(PrintWriter pw, String prefix) { 81 final long now = SystemClock.uptimeMillis(); 82 83 pw.print(prefix); pw.print(this); pw.print(" to user "); pw.println(userId); 84 pw.print(prefix); pw.println(intent); 85 if (sticky) { 86 Bundle bundle = intent.getExtras(); 87 if (bundle != null) { 88 pw.print(prefix); pw.print("extras: "); pw.println(bundle.toString()); 89 } 90 } 91 pw.print(prefix); pw.print("caller="); pw.print(callerPackage); pw.print(" "); 92 pw.print(callerApp != null ? callerApp.toShortString() : "null"); 93 pw.print(" pid="); pw.print(callingPid); 94 pw.print(" uid="); pw.println(callingUid); 95 if (requiredPermission != null) { 96 pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission); 97 } 98 pw.print(prefix); pw.print("dispatchClockTime="); 99 pw.println(new Date(dispatchClockTime)); 100 pw.print(prefix); pw.print("dispatchTime="); 101 TimeUtils.formatDuration(dispatchTime, now, pw); 102 if (finishTime != 0) { 103 pw.print(" finishTime="); TimeUtils.formatDuration(finishTime, now, pw); 104 } else { 105 pw.print(" receiverTime="); TimeUtils.formatDuration(receiverTime, now, pw); 106 } 107 pw.println(""); 108 if (anrCount != 0) { 109 pw.print(prefix); pw.print("anrCount="); pw.println(anrCount); 110 } 111 if (resultTo != null || resultCode != -1 || resultData != null) { 112 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo); 113 pw.print(" resultCode="); pw.print(resultCode); 114 pw.print(" resultData="); pw.println(resultData); 115 } 116 if (resultExtras != null) { 117 pw.print(prefix); pw.print("resultExtras="); pw.println(resultExtras); 118 } 119 if (resultAbort || ordered || sticky || initialSticky) { 120 pw.print(prefix); pw.print("resultAbort="); pw.print(resultAbort); 121 pw.print(" ordered="); pw.print(ordered); 122 pw.print(" sticky="); pw.print(sticky); 123 pw.print(" initialSticky="); pw.println(initialSticky); 124 } 125 if (nextReceiver != 0 || receiver != null) { 126 pw.print(prefix); pw.print("nextReceiver="); pw.print(nextReceiver); 127 pw.print(" receiver="); pw.println(receiver); 128 } 129 if (curFilter != null) { 130 pw.print(prefix); pw.print("curFilter="); pw.println(curFilter); 131 } 132 if (curReceiver != null) { 133 pw.print(prefix); pw.print("curReceiver="); pw.println(curReceiver); 134 } 135 if (curApp != null) { 136 pw.print(prefix); pw.print("curApp="); pw.println(curApp); 137 pw.print(prefix); pw.print("curComponent="); 138 pw.println((curComponent != null ? curComponent.toShortString() : "--")); 139 if (curReceiver != null && curReceiver.applicationInfo != null) { 140 pw.print(prefix); pw.print("curSourceDir="); 141 pw.println(curReceiver.applicationInfo.sourceDir); 142 } 143 } 144 if (state != IDLE) { 145 String stateStr = " (?)"; 146 switch (state) { 147 case APP_RECEIVE: stateStr=" (APP_RECEIVE)"; break; 148 case CALL_IN_RECEIVE: stateStr=" (CALL_IN_RECEIVE)"; break; 149 case CALL_DONE_RECEIVE: stateStr=" (CALL_DONE_RECEIVE)"; break; 150 } 151 pw.print(prefix); pw.print("state="); pw.print(state); pw.println(stateStr); 152 } 153 final int N = receivers != null ? receivers.size() : 0; 154 String p2 = prefix + " "; 155 PrintWriterPrinter printer = new PrintWriterPrinter(pw); 156 for (int i=0; i<N; i++) { 157 Object o = receivers.get(i); 158 pw.print(prefix); pw.print("Receiver #"); pw.print(i); 159 pw.print(": "); pw.println(o); 160 if (o instanceof BroadcastFilter) 161 ((BroadcastFilter)o).dumpBrief(pw, p2); 162 else if (o instanceof ResolveInfo) 163 ((ResolveInfo)o).dump(printer, p2); 164 } 165 } 166 167 BroadcastRecord(BroadcastQueue _queue, 168 Intent _intent, ProcessRecord _callerApp, String _callerPackage, 169 int _callingPid, int _callingUid, String _requiredPermission, 170 List _receivers, IIntentReceiver _resultTo, int _resultCode, 171 String _resultData, Bundle _resultExtras, boolean _serialized, 172 boolean _sticky, boolean _initialSticky, 173 int _userId) { 174 queue = _queue; 175 intent = _intent; 176 callerApp = _callerApp; 177 callerPackage = _callerPackage; 178 callingPid = _callingPid; 179 callingUid = _callingUid; 180 requiredPermission = _requiredPermission; 181 receivers = _receivers; 182 resultTo = _resultTo; 183 resultCode = _resultCode; 184 resultData = _resultData; 185 resultExtras = _resultExtras; 186 ordered = _serialized; 187 sticky = _sticky; 188 initialSticky = _initialSticky; 189 userId = _userId; 190 nextReceiver = 0; 191 state = IDLE; 192 } 193 194 public String toString() { 195 return "BroadcastRecord{" 196 + Integer.toHexString(System.identityHashCode(this)) 197 + " " + intent.getAction() + "}"; 198 } 199} 200