blob: eb1df6e20dabb35b7f05f180dcd0243fef2e9be4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Dianne Hackbornf51f6122013-02-04 18:23:34 -080019import android.app.AppOpsManager;
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070020import android.content.IIntentReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.ComponentName;
22import android.content.Intent;
23import android.content.pm.ActivityInfo;
24import android.content.pm.ResolveInfo;
25import android.os.Binder;
26import android.os.Bundle;
27import android.os.IBinder;
28import android.os.SystemClock;
29import android.util.PrintWriterPrinter;
Dianne Hackborn39792d22010-08-19 18:01:52 -070030import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32import java.io.PrintWriter;
Dianne Hackbornd99b2932011-08-18 14:39:58 -070033import java.util.Date;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import java.util.List;
35
36/**
37 * An active intent broadcast.
38 */
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070039final class BroadcastRecord extends Binder {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 final Intent intent; // the original intent that generated us
Dianne Hackborna40cfeb2013-03-25 17:49:36 -070041 final ComponentName targetComp; // original component name set on the intent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 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 Hackborn68d881c2009-10-05 13:58:17 -070046 final boolean ordered; // serialize the send to receivers?
47 final boolean sticky; // originated from existing sticky data?
Dianne Hackborn12527f92009-11-11 17:39:50 -080048 final boolean initialSticky; // initial broadcast from register to sticky?
Dianne Hackborn786b4402012-08-27 15:14:02 -070049 final int userId; // user id this broadcast was for
Dianne Hackborn68d881c2009-10-05 13:58:17 -070050 final String requiredPermission; // a permission the caller has required
Dianne Hackbornf51f6122013-02-04 18:23:34 -080051 final int appOp; // an app op that is associated with this broadcast
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 final List receivers; // contains BroadcastFilter and ResolveInfo
Johannes Carlssonb5a86542010-10-27 10:08:10 +020053 IIntentReceiver resultTo; // who receives final result if non-null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 long dispatchTime; // when dispatch started on this set of receivers
Dianne Hackbornd99b2932011-08-18 14:39:58 -070055 long dispatchClockTime; // the clock time the dispatch started
Dianne Hackborn12527f92009-11-11 17:39:50 -080056 long receiverTime; // when current receiver started for timeouts.
57 long finishTime; // when we finished the broadcast.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 int resultCode; // current result code value.
59 String resultData; // current result data value.
60 Bundle resultExtras; // current result extra data values.
61 boolean resultAbort; // current result abortBroadcast value.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 int nextReceiver; // next receiver to be executed.
63 IBinder receiver; // who is currently running, null if none.
64 int state;
65 int anrCount; // has this broadcast record hit any ANRs?
Dianne Hackborn40c8db52012-02-10 18:59:48 -080066 BroadcastQueue queue; // the outbound queue handling this broadcast
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
68 static final int IDLE = 0;
69 static final int APP_RECEIVE = 1;
70 static final int CALL_IN_RECEIVE = 2;
71 static final int CALL_DONE_RECEIVE = 3;
72
73 // The following are set when we are calling a receiver (one that
74 // was found in our list of registered receivers).
75 BroadcastFilter curFilter;
76
77 // The following are set only when we are launching a receiver (one
78 // that was found by querying the package manager).
79 ProcessRecord curApp; // hosting application of current receiver.
80 ComponentName curComponent; // the receiver class that is currently running.
81 ActivityInfo curReceiver; // info about the receiver that is currently running.
82
83 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn39792d22010-08-19 18:01:52 -070084 final long now = SystemClock.uptimeMillis();
85
Dianne Hackborn786b4402012-08-27 15:14:02 -070086 pw.print(prefix); pw.print(this); pw.print(" to user "); pw.println(userId);
Dianne Hackbornc0bd7472012-10-09 14:00:30 -070087 pw.print(prefix); pw.println(intent.toInsecureString());
Dianne Hackborna40cfeb2013-03-25 17:49:36 -070088 if (targetComp != null && targetComp != intent.getComponent()) {
89 pw.print(prefix); pw.print(" targetComp: "); pw.println(targetComp.toShortString());
90 }
Dianne Hackbornc0bd7472012-10-09 14:00:30 -070091 Bundle bundle = intent.getExtras();
92 if (bundle != null) {
Dianne Hackborna40cfeb2013-03-25 17:49:36 -070093 pw.print(prefix); pw.print(" extras: "); pw.println(bundle.toString());
Dianne Hackborn12527f92009-11-11 17:39:50 -080094 }
Dianne Hackborn043fcd92010-10-06 14:27:34 -070095 pw.print(prefix); pw.print("caller="); pw.print(callerPackage); pw.print(" ");
96 pw.print(callerApp != null ? callerApp.toShortString() : "null");
Dianne Hackborn39792d22010-08-19 18:01:52 -070097 pw.print(" pid="); pw.print(callingPid);
98 pw.print(" uid="); pw.println(callingUid);
Dianne Hackbornf51f6122013-02-04 18:23:34 -080099 if (requiredPermission != null || appOp != AppOpsManager.OP_NONE) {
100 pw.print(prefix); pw.print("requiredPermission="); pw.print(requiredPermission);
101 pw.print(" appOp="); pw.println(appOp);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800102 }
Dianne Hackbornd99b2932011-08-18 14:39:58 -0700103 pw.print(prefix); pw.print("dispatchClockTime=");
104 pw.println(new Date(dispatchClockTime));
Dianne Hackborn39792d22010-08-19 18:01:52 -0700105 pw.print(prefix); pw.print("dispatchTime=");
106 TimeUtils.formatDuration(dispatchTime, now, pw);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800107 if (finishTime != 0) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700108 pw.print(" finishTime="); TimeUtils.formatDuration(finishTime, now, pw);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800109 } else {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700110 pw.print(" receiverTime="); TimeUtils.formatDuration(receiverTime, now, pw);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800111 }
Dianne Hackborn39792d22010-08-19 18:01:52 -0700112 pw.println("");
Dianne Hackborn12527f92009-11-11 17:39:50 -0800113 if (anrCount != 0) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700114 pw.print(prefix); pw.print("anrCount="); pw.println(anrCount);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800115 }
116 if (resultTo != null || resultCode != -1 || resultData != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700117 pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
118 pw.print(" resultCode="); pw.print(resultCode);
119 pw.print(" resultData="); pw.println(resultData);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800120 }
121 if (resultExtras != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700122 pw.print(prefix); pw.print("resultExtras="); pw.println(resultExtras);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800123 }
124 if (resultAbort || ordered || sticky || initialSticky) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700125 pw.print(prefix); pw.print("resultAbort="); pw.print(resultAbort);
126 pw.print(" ordered="); pw.print(ordered);
127 pw.print(" sticky="); pw.print(sticky);
128 pw.print(" initialSticky="); pw.println(initialSticky);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800129 }
130 if (nextReceiver != 0 || receiver != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700131 pw.print(prefix); pw.print("nextReceiver="); pw.print(nextReceiver);
132 pw.print(" receiver="); pw.println(receiver);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800133 }
134 if (curFilter != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700135 pw.print(prefix); pw.print("curFilter="); pw.println(curFilter);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800136 }
137 if (curReceiver != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700138 pw.print(prefix); pw.print("curReceiver="); pw.println(curReceiver);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 if (curApp != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700141 pw.print(prefix); pw.print("curApp="); pw.println(curApp);
142 pw.print(prefix); pw.print("curComponent=");
143 pw.println((curComponent != null ? curComponent.toShortString() : "--"));
Dianne Hackborn399cccb2010-04-13 22:57:49 -0700144 if (curReceiver != null && curReceiver.applicationInfo != null) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700145 pw.print(prefix); pw.print("curSourceDir=");
146 pw.println(curReceiver.applicationInfo.sourceDir);
Dianne Hackborn399cccb2010-04-13 22:57:49 -0700147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
Dianne Hackborn786b4402012-08-27 15:14:02 -0700149 if (state != IDLE) {
150 String stateStr = " (?)";
151 switch (state) {
152 case APP_RECEIVE: stateStr=" (APP_RECEIVE)"; break;
153 case CALL_IN_RECEIVE: stateStr=" (CALL_IN_RECEIVE)"; break;
154 case CALL_DONE_RECEIVE: stateStr=" (CALL_DONE_RECEIVE)"; break;
155 }
156 pw.print(prefix); pw.print("state="); pw.print(state); pw.println(stateStr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 final int N = receivers != null ? receivers.size() : 0;
159 String p2 = prefix + " ";
160 PrintWriterPrinter printer = new PrintWriterPrinter(pw);
161 for (int i=0; i<N; i++) {
162 Object o = receivers.get(i);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700163 pw.print(prefix); pw.print("Receiver #"); pw.print(i);
164 pw.print(": "); pw.println(o);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 if (o instanceof BroadcastFilter)
Dianne Hackborn12527f92009-11-11 17:39:50 -0800166 ((BroadcastFilter)o).dumpBrief(pw, p2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 else if (o instanceof ResolveInfo)
168 ((ResolveInfo)o).dump(printer, p2);
169 }
170 }
171
Dianne Hackborn40c8db52012-02-10 18:59:48 -0800172 BroadcastRecord(BroadcastQueue _queue,
Christopher Tatef46723b2012-01-26 14:19:24 -0800173 Intent _intent, ProcessRecord _callerApp, String _callerPackage,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800174 int _callingPid, int _callingUid, String _requiredPermission, int _appOp,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 List _receivers, IIntentReceiver _resultTo, int _resultCode,
Dianne Hackborn68d881c2009-10-05 13:58:17 -0700176 String _resultData, Bundle _resultExtras, boolean _serialized,
Amith Yamasani8bf06ed2012-08-27 19:30:30 -0700177 boolean _sticky, boolean _initialSticky,
Dianne Hackborn786b4402012-08-27 15:14:02 -0700178 int _userId) {
Christopher Tatef46723b2012-01-26 14:19:24 -0800179 queue = _queue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 intent = _intent;
Dianne Hackborna40cfeb2013-03-25 17:49:36 -0700181 targetComp = _intent.getComponent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 callerApp = _callerApp;
183 callerPackage = _callerPackage;
184 callingPid = _callingPid;
185 callingUid = _callingUid;
186 requiredPermission = _requiredPermission;
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800187 appOp = _appOp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 receivers = _receivers;
189 resultTo = _resultTo;
190 resultCode = _resultCode;
191 resultData = _resultData;
192 resultExtras = _resultExtras;
193 ordered = _serialized;
Dianne Hackborn68d881c2009-10-05 13:58:17 -0700194 sticky = _sticky;
Dianne Hackborn12527f92009-11-11 17:39:50 -0800195 initialSticky = _initialSticky;
Dianne Hackborn786b4402012-08-27 15:14:02 -0700196 userId = _userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 nextReceiver = 0;
198 state = IDLE;
199 }
200
201 public String toString() {
202 return "BroadcastRecord{"
203 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700204 + " u" + userId + " " + intent.getAction() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206}