blob: da55049de7ada001ce2c16dedcf3e35411037702 [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
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070019import android.content.IIntentReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import 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;
29
30import java.io.PrintWriter;
31import java.util.List;
32
33/**
34 * An active intent broadcast.
35 */
36class BroadcastRecord extends Binder {
37 final Intent intent; // the original intent that generated us
38 final ProcessRecord callerApp; // process that sent this
39 final String callerPackage; // who sent this
40 final int callingPid; // the pid of who sent this
41 final int callingUid; // the uid of who sent this
42 String requiredPermission; // a permission the caller has required
43 final List receivers; // contains BroadcastFilter and ResolveInfo
44 final IIntentReceiver resultTo; // who receives final result if non-null
45 long dispatchTime; // when dispatch started on this set of receivers
46 long startTime; // when current receiver started for timeouts.
47 int resultCode; // current result code value.
48 String resultData; // current result data value.
49 Bundle resultExtras; // current result extra data values.
50 boolean resultAbort; // current result abortBroadcast value.
51 boolean ordered; // serialize the send to receivers?
52 int nextReceiver; // next receiver to be executed.
53 IBinder receiver; // who is currently running, null if none.
54 int state;
55 int anrCount; // has this broadcast record hit any ANRs?
56
57 static final int IDLE = 0;
58 static final int APP_RECEIVE = 1;
59 static final int CALL_IN_RECEIVE = 2;
60 static final int CALL_DONE_RECEIVE = 3;
61
62 // The following are set when we are calling a receiver (one that
63 // was found in our list of registered receivers).
64 BroadcastFilter curFilter;
65
66 // The following are set only when we are launching a receiver (one
67 // that was found by querying the package manager).
68 ProcessRecord curApp; // hosting application of current receiver.
69 ComponentName curComponent; // the receiver class that is currently running.
70 ActivityInfo curReceiver; // info about the receiver that is currently running.
71
72 void dump(PrintWriter pw, String prefix) {
73 pw.println(prefix + this);
74 pw.println(prefix + intent);
75 pw.println(prefix + "proc=" + callerApp);
76 pw.println(prefix + "caller=" + callerPackage
77 + " callingPid=" + callingPid
78 + " callingUid=" + callingUid);
79 pw.println(prefix + "requiredPermission=" + requiredPermission);
80 pw.println(prefix + "dispatchTime=" + dispatchTime + " ("
81 + (SystemClock.uptimeMillis()-dispatchTime) + " since now)");
82 pw.println(prefix + "startTime=" + startTime + " ("
83 + (SystemClock.uptimeMillis()-startTime) + " since now)");
84 pw.println(prefix + "anrCount=" + anrCount);
85 pw.println(prefix + "resultTo=" + resultTo
86 + " resultCode=" + resultCode + " resultData=" + resultData);
87 pw.println(prefix + "resultExtras=" + resultExtras);
88 pw.println(prefix + "resultAbort=" + resultAbort
89 + " ordered=" + ordered);
90 pw.println(prefix + "nextReceiver=" + nextReceiver
91 + " receiver=" + receiver);
92 pw.println(prefix + "curFilter=" + curFilter);
93 pw.println(prefix + "curReceiver="
94 + ((curReceiver != null) ? curReceiver : "(null)"));
95 pw.println(prefix + "curApp=" + curApp);
96 if (curApp != null) {
97 pw.println(prefix + "curComponent="
98 + (curComponent != null ? curComponent.toShortString() : "--"));
99 pw.println(prefix + "curSourceDir=" + curReceiver.applicationInfo.sourceDir);
100 }
101 String stateStr = " (?)";
102 switch (state) {
103 case IDLE: stateStr=" (IDLE)"; break;
104 case APP_RECEIVE: stateStr=" (APP_RECEIVE)"; break;
105 case CALL_IN_RECEIVE: stateStr=" (CALL_IN_RECEIVE)"; break;
106 case CALL_DONE_RECEIVE: stateStr=" (CALL_DONE_RECEIVE)"; break;
107 }
108 pw.println(prefix + "state=" + state + stateStr);
109 final int N = receivers != null ? receivers.size() : 0;
110 String p2 = prefix + " ";
111 PrintWriterPrinter printer = new PrintWriterPrinter(pw);
112 for (int i=0; i<N; i++) {
113 Object o = receivers.get(i);
114 pw.println(prefix + "Receiver #" + i + ": " + o);
115 if (o instanceof BroadcastFilter)
116 ((BroadcastFilter)o).dump(pw, p2);
117 else if (o instanceof ResolveInfo)
118 ((ResolveInfo)o).dump(printer, p2);
119 }
120 }
121
122 BroadcastRecord(Intent _intent, ProcessRecord _callerApp, String _callerPackage,
123 int _callingPid, int _callingUid, String _requiredPermission,
124 List _receivers, IIntentReceiver _resultTo, int _resultCode,
125 String _resultData, Bundle _resultExtras, boolean _serialized) {
126 intent = _intent;
127 callerApp = _callerApp;
128 callerPackage = _callerPackage;
129 callingPid = _callingPid;
130 callingUid = _callingUid;
131 requiredPermission = _requiredPermission;
132 receivers = _receivers;
133 resultTo = _resultTo;
134 resultCode = _resultCode;
135 resultData = _resultData;
136 resultExtras = _resultExtras;
137 ordered = _serialized;
138 nextReceiver = 0;
139 state = IDLE;
140 }
141
142 public String toString() {
143 return "BroadcastRecord{"
144 + Integer.toHexString(System.identityHashCode(this))
145 + " " + intent.getAction() + "}";
146 }
147}