Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
| 19 | import java.io.FileDescriptor; |
| 20 | import java.io.PrintWriter; |
| 21 | import java.util.ArrayList; |
| 22 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 24 | import android.app.AppGlobals; |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
| 27 | import android.content.IIntentReceiver; |
| 28 | import android.content.Intent; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 29 | import android.content.pm.ActivityInfo; |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 30 | import android.content.pm.PackageInfo; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
| 32 | import android.content.pm.ResolveInfo; |
| 33 | import android.os.Bundle; |
| 34 | import android.os.Handler; |
| 35 | import android.os.IBinder; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 36 | import android.os.Looper; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 37 | import android.os.Message; |
| 38 | import android.os.Process; |
| 39 | import android.os.RemoteException; |
| 40 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 42 | import android.util.EventLog; |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 43 | import android.util.Log; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 44 | import android.util.Slog; |
| 45 | |
| 46 | /** |
| 47 | * BROADCASTS |
| 48 | * |
| 49 | * We keep two broadcast queues and associated bookkeeping, one for those at |
| 50 | * foreground priority, and one for normal (background-priority) broadcasts. |
| 51 | */ |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 52 | public final class BroadcastQueue { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 53 | static final String TAG = "BroadcastQueue"; |
| 54 | static final String TAG_MU = ActivityManagerService.TAG_MU; |
| 55 | static final boolean DEBUG_BROADCAST = ActivityManagerService.DEBUG_BROADCAST; |
| 56 | static final boolean DEBUG_BROADCAST_LIGHT = ActivityManagerService.DEBUG_BROADCAST_LIGHT; |
| 57 | static final boolean DEBUG_MU = ActivityManagerService.DEBUG_MU; |
| 58 | |
Dianne Hackborn | 4c51de4 | 2013-10-16 23:34:35 -0700 | [diff] [blame] | 59 | static final int MAX_BROADCAST_HISTORY = ActivityManager.isLowRamDeviceStatic() ? 10 : 50; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 60 | static final int MAX_BROADCAST_SUMMARY_HISTORY |
Dianne Hackborn | 4c51de4 | 2013-10-16 23:34:35 -0700 | [diff] [blame] | 61 | = ActivityManager.isLowRamDeviceStatic() ? 25 : 300; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 62 | |
| 63 | final ActivityManagerService mService; |
| 64 | |
| 65 | /** |
| 66 | * Recognizable moniker for this queue |
| 67 | */ |
| 68 | final String mQueueName; |
| 69 | |
| 70 | /** |
| 71 | * Timeout period for this queue's broadcasts |
| 72 | */ |
| 73 | final long mTimeoutPeriod; |
| 74 | |
| 75 | /** |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 76 | * If true, we can delay broadcasts while waiting services to finish in the previous |
| 77 | * receiver's process. |
| 78 | */ |
| 79 | final boolean mDelayBehindServices; |
| 80 | |
| 81 | /** |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 82 | * Lists of all active broadcasts that are to be executed immediately |
| 83 | * (without waiting for another broadcast to finish). Currently this only |
| 84 | * contains broadcasts to registered receivers, to avoid spinning up |
| 85 | * a bunch of processes to execute IntentReceiver components. Background- |
| 86 | * and foreground-priority broadcasts are queued separately. |
| 87 | */ |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 88 | final ArrayList<BroadcastRecord> mParallelBroadcasts = new ArrayList<BroadcastRecord>(); |
| 89 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 90 | /** |
| 91 | * List of all active broadcasts that are to be executed one at a time. |
| 92 | * The object at the top of the list is the currently activity broadcasts; |
| 93 | * those after it are waiting for the top to finish. As with parallel |
| 94 | * broadcasts, separate background- and foreground-priority queues are |
| 95 | * maintained. |
| 96 | */ |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 97 | final ArrayList<BroadcastRecord> mOrderedBroadcasts = new ArrayList<BroadcastRecord>(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * Historical data of past broadcasts, for debugging. |
| 101 | */ |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 102 | final BroadcastRecord[] mBroadcastHistory = new BroadcastRecord[MAX_BROADCAST_HISTORY]; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 105 | * Summary of historical data of past broadcasts, for debugging. |
| 106 | */ |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 107 | final Intent[] mBroadcastSummaryHistory = new Intent[MAX_BROADCAST_SUMMARY_HISTORY]; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 110 | * Set when we current have a BROADCAST_INTENT_MSG in flight. |
| 111 | */ |
| 112 | boolean mBroadcastsScheduled = false; |
| 113 | |
| 114 | /** |
| 115 | * True if we have a pending unexpired BROADCAST_TIMEOUT_MSG posted to our handler. |
| 116 | */ |
| 117 | boolean mPendingBroadcastTimeoutMessage; |
| 118 | |
| 119 | /** |
| 120 | * Intent broadcasts that we have tried to start, but are |
| 121 | * waiting for the application's process to be created. We only |
| 122 | * need one per scheduling class (instead of a list) because we always |
| 123 | * process broadcasts one at a time, so no others can be started while |
| 124 | * waiting for this one. |
| 125 | */ |
| 126 | BroadcastRecord mPendingBroadcast = null; |
| 127 | |
| 128 | /** |
| 129 | * The receiver index that is pending, to restart the broadcast if needed. |
| 130 | */ |
| 131 | int mPendingBroadcastRecvIndex; |
| 132 | |
| 133 | static final int BROADCAST_INTENT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG; |
| 134 | static final int BROADCAST_TIMEOUT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG + 1; |
| 135 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 136 | final BroadcastHandler mHandler; |
| 137 | |
| 138 | private final class BroadcastHandler extends Handler { |
| 139 | public BroadcastHandler(Looper looper) { |
| 140 | super(looper, null, true); |
| 141 | } |
| 142 | |
| 143 | @Override |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 144 | public void handleMessage(Message msg) { |
| 145 | switch (msg.what) { |
| 146 | case BROADCAST_INTENT_MSG: { |
| 147 | if (DEBUG_BROADCAST) Slog.v( |
| 148 | TAG, "Received BROADCAST_INTENT_MSG"); |
| 149 | processNextBroadcast(true); |
| 150 | } break; |
| 151 | case BROADCAST_TIMEOUT_MSG: { |
| 152 | synchronized (mService) { |
| 153 | broadcastTimeoutLocked(true); |
| 154 | } |
| 155 | } break; |
| 156 | } |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | private final class AppNotResponding implements Runnable { |
| 161 | private final ProcessRecord mApp; |
| 162 | private final String mAnnotation; |
| 163 | |
| 164 | public AppNotResponding(ProcessRecord app, String annotation) { |
| 165 | mApp = app; |
| 166 | mAnnotation = annotation; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void run() { |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 171 | mService.appNotResponding(mApp, null, null, false, mAnnotation); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 175 | BroadcastQueue(ActivityManagerService service, Handler handler, |
| 176 | String name, long timeoutPeriod, boolean allowDelayBehindServices) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 177 | mService = service; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 178 | mHandler = new BroadcastHandler(handler.getLooper()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 179 | mQueueName = name; |
| 180 | mTimeoutPeriod = timeoutPeriod; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 181 | mDelayBehindServices = allowDelayBehindServices; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | public boolean isPendingBroadcastProcessLocked(int pid) { |
| 185 | return mPendingBroadcast != null && mPendingBroadcast.curApp.pid == pid; |
| 186 | } |
| 187 | |
| 188 | public void enqueueParallelBroadcastLocked(BroadcastRecord r) { |
| 189 | mParallelBroadcasts.add(r); |
| 190 | } |
| 191 | |
| 192 | public void enqueueOrderedBroadcastLocked(BroadcastRecord r) { |
| 193 | mOrderedBroadcasts.add(r); |
| 194 | } |
| 195 | |
| 196 | public final boolean replaceParallelBroadcastLocked(BroadcastRecord r) { |
| 197 | for (int i=mParallelBroadcasts.size()-1; i>=0; i--) { |
| 198 | if (r.intent.filterEquals(mParallelBroadcasts.get(i).intent)) { |
| 199 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 200 | "***** DROPPING PARALLEL [" |
| 201 | + mQueueName + "]: " + r.intent); |
| 202 | mParallelBroadcasts.set(i, r); |
| 203 | return true; |
| 204 | } |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | public final boolean replaceOrderedBroadcastLocked(BroadcastRecord r) { |
| 210 | for (int i=mOrderedBroadcasts.size()-1; i>0; i--) { |
| 211 | if (r.intent.filterEquals(mOrderedBroadcasts.get(i).intent)) { |
| 212 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 213 | "***** DROPPING ORDERED [" |
| 214 | + mQueueName + "]: " + r.intent); |
| 215 | mOrderedBroadcasts.set(i, r); |
| 216 | return true; |
| 217 | } |
| 218 | } |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | private final void processCurBroadcastLocked(BroadcastRecord r, |
| 223 | ProcessRecord app) throws RemoteException { |
| 224 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 225 | "Process cur broadcast " + r + " for app " + app); |
| 226 | if (app.thread == null) { |
| 227 | throw new RemoteException(); |
| 228 | } |
| 229 | r.receiver = app.thread.asBinder(); |
| 230 | r.curApp = app; |
| 231 | app.curReceiver = r; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 232 | app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 233 | mService.updateLruProcessLocked(app, false, null); |
| 234 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 235 | |
| 236 | // Tell the application to launch this receiver. |
| 237 | r.intent.setComponent(r.curComponent); |
| 238 | |
| 239 | boolean started = false; |
| 240 | try { |
| 241 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, |
| 242 | "Delivering to component " + r.curComponent |
| 243 | + ": " + r); |
| 244 | mService.ensurePackageDexOpt(r.intent.getComponent().getPackageName()); |
| 245 | app.thread.scheduleReceiver(new Intent(r.intent), r.curReceiver, |
| 246 | mService.compatibilityInfoForPackageLocked(r.curReceiver.applicationInfo), |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 247 | r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId, |
| 248 | app.repProcState); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 249 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 250 | "Process cur broadcast " + r + " DELIVERED for app " + app); |
| 251 | started = true; |
| 252 | } finally { |
| 253 | if (!started) { |
| 254 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 255 | "Process cur broadcast " + r + ": NOT STARTED!"); |
| 256 | r.receiver = null; |
| 257 | r.curApp = null; |
| 258 | app.curReceiver = null; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | public boolean sendPendingBroadcastsLocked(ProcessRecord app) { |
| 264 | boolean didSomething = false; |
| 265 | final BroadcastRecord br = mPendingBroadcast; |
| 266 | if (br != null && br.curApp.pid == app.pid) { |
| 267 | try { |
| 268 | mPendingBroadcast = null; |
| 269 | processCurBroadcastLocked(br, app); |
| 270 | didSomething = true; |
| 271 | } catch (Exception e) { |
| 272 | Slog.w(TAG, "Exception in new application when starting receiver " |
| 273 | + br.curComponent.flattenToShortString(), e); |
| 274 | logBroadcastReceiverDiscardLocked(br); |
| 275 | finishReceiverLocked(br, br.resultCode, br.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 276 | br.resultExtras, br.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 277 | scheduleBroadcastsLocked(); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 278 | // We need to reset the state if we failed to start the receiver. |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 279 | br.state = BroadcastRecord.IDLE; |
| 280 | throw new RuntimeException(e.getMessage()); |
| 281 | } |
| 282 | } |
| 283 | return didSomething; |
| 284 | } |
| 285 | |
| 286 | public void skipPendingBroadcastLocked(int pid) { |
| 287 | final BroadcastRecord br = mPendingBroadcast; |
| 288 | if (br != null && br.curApp.pid == pid) { |
| 289 | br.state = BroadcastRecord.IDLE; |
| 290 | br.nextReceiver = mPendingBroadcastRecvIndex; |
| 291 | mPendingBroadcast = null; |
| 292 | scheduleBroadcastsLocked(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | public void skipCurrentReceiverLocked(ProcessRecord app) { |
| 297 | boolean reschedule = false; |
| 298 | BroadcastRecord r = app.curReceiver; |
| 299 | if (r != null) { |
| 300 | // The current broadcast is waiting for this app's receiver |
| 301 | // to be finished. Looks like that's not going to happen, so |
| 302 | // let the broadcast continue. |
| 303 | logBroadcastReceiverDiscardLocked(r); |
| 304 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 305 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 306 | reschedule = true; |
| 307 | } |
| 308 | |
| 309 | r = mPendingBroadcast; |
| 310 | if (r != null && r.curApp == app) { |
| 311 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 312 | "[" + mQueueName + "] skip & discard pending app " + r); |
| 313 | logBroadcastReceiverDiscardLocked(r); |
| 314 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 315 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 316 | reschedule = true; |
| 317 | } |
| 318 | if (reschedule) { |
| 319 | scheduleBroadcastsLocked(); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | public void scheduleBroadcastsLocked() { |
| 324 | if (DEBUG_BROADCAST) Slog.v(TAG, "Schedule broadcasts [" |
| 325 | + mQueueName + "]: current=" |
| 326 | + mBroadcastsScheduled); |
| 327 | |
| 328 | if (mBroadcastsScheduled) { |
| 329 | return; |
| 330 | } |
| 331 | mHandler.sendMessage(mHandler.obtainMessage(BROADCAST_INTENT_MSG, this)); |
| 332 | mBroadcastsScheduled = true; |
| 333 | } |
| 334 | |
| 335 | public BroadcastRecord getMatchingOrderedReceiver(IBinder receiver) { |
| 336 | if (mOrderedBroadcasts.size() > 0) { |
| 337 | final BroadcastRecord r = mOrderedBroadcasts.get(0); |
| 338 | if (r != null && r.receiver == receiver) { |
| 339 | return r; |
| 340 | } |
| 341 | } |
| 342 | return null; |
| 343 | } |
| 344 | |
| 345 | public boolean finishReceiverLocked(BroadcastRecord r, int resultCode, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 346 | String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices) { |
| 347 | final int state = r.state; |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 348 | final ActivityInfo receiver = r.curReceiver; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 349 | r.state = BroadcastRecord.IDLE; |
| 350 | if (state == BroadcastRecord.IDLE) { |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 351 | Slog.w(TAG, "finishReceiver [" + mQueueName + "] called but state is IDLE"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 352 | } |
| 353 | r.receiver = null; |
| 354 | r.intent.setComponent(null); |
| 355 | if (r.curApp != null) { |
| 356 | r.curApp.curReceiver = null; |
| 357 | } |
| 358 | if (r.curFilter != null) { |
| 359 | r.curFilter.receiverList.curBroadcast = null; |
| 360 | } |
| 361 | r.curFilter = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 362 | r.curReceiver = null; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 363 | r.curApp = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 364 | mPendingBroadcast = null; |
| 365 | |
| 366 | r.resultCode = resultCode; |
| 367 | r.resultData = resultData; |
| 368 | r.resultExtras = resultExtras; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 369 | if (resultAbort && (r.intent.getFlags()&Intent.FLAG_RECEIVER_NO_ABORT) == 0) { |
| 370 | r.resultAbort = resultAbort; |
| 371 | } else { |
| 372 | r.resultAbort = false; |
| 373 | } |
| 374 | |
| 375 | if (waitForServices && r.curComponent != null && r.queue.mDelayBehindServices |
| 376 | && r.queue.mOrderedBroadcasts.size() > 0 |
| 377 | && r.queue.mOrderedBroadcasts.get(0) == r) { |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 378 | ActivityInfo nextReceiver; |
| 379 | if (r.nextReceiver < r.receivers.size()) { |
| 380 | Object obj = r.receivers.get(r.nextReceiver); |
| 381 | nextReceiver = (obj instanceof ActivityInfo) ? (ActivityInfo)obj : null; |
| 382 | } else { |
| 383 | nextReceiver = null; |
| 384 | } |
| 385 | // Don't do this if the next receive is in the same process as the current one. |
| 386 | if (receiver == null || nextReceiver == null |
| 387 | || receiver.applicationInfo.uid != nextReceiver.applicationInfo.uid |
| 388 | || !receiver.processName.equals(nextReceiver.processName)) { |
| 389 | // In this case, we are ready to process the next receiver for the current broadcast, |
| 390 | //Â but are on a queue that would like to wait for services to finish before moving |
| 391 | // on. If there are background services currently starting, then we will go into a |
| 392 | // special state where we hold off on continuing this broadcast until they are done. |
| 393 | if (mService.mServices.hasBackgroundServices(r.userId)) { |
| 394 | Slog.i(ActivityManagerService.TAG, "Delay finish: " |
| 395 | + r.curComponent.flattenToShortString()); |
| 396 | r.state = BroadcastRecord.WAITING_SERVICES; |
| 397 | return false; |
| 398 | } |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | r.curComponent = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 403 | |
| 404 | // We will process the next receiver right now if this is finishing |
| 405 | // an app receiver (which is always asynchronous) or after we have |
| 406 | // come back from calling a receiver. |
| 407 | return state == BroadcastRecord.APP_RECEIVE |
| 408 | || state == BroadcastRecord.CALL_DONE_RECEIVE; |
| 409 | } |
| 410 | |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 411 | public void backgroundServicesFinishedLocked(int userId) { |
| 412 | if (mOrderedBroadcasts.size() > 0) { |
| 413 | BroadcastRecord br = mOrderedBroadcasts.get(0); |
| 414 | if (br.userId == userId && br.state == BroadcastRecord.WAITING_SERVICES) { |
| 415 | Slog.i(ActivityManagerService.TAG, "Resuming delayed broadcast"); |
| 416 | br.curComponent = null; |
| 417 | br.state = BroadcastRecord.IDLE; |
| 418 | processNextBroadcast(false); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 423 | private static void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver, |
| 424 | Intent intent, int resultCode, String data, Bundle extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 425 | boolean ordered, boolean sticky, int sendingUser) throws RemoteException { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 426 | // Send the intent to the receiver asynchronously using one-way binder calls. |
| 427 | if (app != null && app.thread != null) { |
| 428 | // If we have an app thread, do the call through that so it is |
| 429 | // correctly ordered with other one-way calls. |
| 430 | app.thread.scheduleRegisteredReceiver(receiver, intent, resultCode, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 431 | data, extras, ordered, sticky, sendingUser, app.repProcState); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 432 | } else { |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 433 | receiver.performReceive(intent, resultCode, data, extras, ordered, |
| 434 | sticky, sendingUser); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
| 438 | private final void deliverToRegisteredReceiverLocked(BroadcastRecord r, |
| 439 | BroadcastFilter filter, boolean ordered) { |
| 440 | boolean skip = false; |
Amith Yamasani | 8bf06ed | 2012-08-27 19:30:30 -0700 | [diff] [blame] | 441 | if (filter.requiredPermission != null) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 442 | int perm = mService.checkComponentPermission(filter.requiredPermission, |
| 443 | r.callingPid, r.callingUid, -1, true); |
| 444 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 445 | Slog.w(TAG, "Permission Denial: broadcasting " |
| 446 | + r.intent.toString() |
| 447 | + " from " + r.callerPackage + " (pid=" |
| 448 | + r.callingPid + ", uid=" + r.callingUid + ")" |
| 449 | + " requires " + filter.requiredPermission |
| 450 | + " due to registered receiver " + filter); |
| 451 | skip = true; |
| 452 | } |
| 453 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 454 | if (!skip && r.requiredPermission != null) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 455 | int perm = mService.checkComponentPermission(r.requiredPermission, |
| 456 | filter.receiverList.pid, filter.receiverList.uid, -1, true); |
| 457 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 458 | Slog.w(TAG, "Permission Denial: receiving " |
| 459 | + r.intent.toString() |
| 460 | + " to " + filter.receiverList.app |
| 461 | + " (pid=" + filter.receiverList.pid |
| 462 | + ", uid=" + filter.receiverList.uid + ")" |
| 463 | + " requires " + r.requiredPermission |
| 464 | + " due to sender " + r.callerPackage |
| 465 | + " (uid " + r.callingUid + ")"); |
| 466 | skip = true; |
| 467 | } |
| 468 | } |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 469 | if (r.appOp != AppOpsManager.OP_NONE) { |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 470 | int mode = mService.mAppOpsService.noteOperation(r.appOp, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 471 | filter.receiverList.uid, filter.packageName); |
| 472 | if (mode != AppOpsManager.MODE_ALLOWED) { |
| 473 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 474 | "App op " + r.appOp + " not allowed for broadcast to uid " |
| 475 | + filter.receiverList.uid + " pkg " + filter.packageName); |
| 476 | skip = true; |
| 477 | } |
| 478 | } |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 479 | if (!skip) { |
| 480 | skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, |
| 481 | r.callingPid, r.resolvedType, filter.receiverList.uid); |
| 482 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 483 | |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 484 | if (filter.receiverList.app == null || filter.receiverList.app.crashing) { |
| 485 | Slog.w(TAG, "Skipping deliver [" + mQueueName + "] " + r |
| 486 | + " to " + filter.receiverList + ": process crashing"); |
| 487 | skip = true; |
| 488 | } |
| 489 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 490 | if (!skip) { |
| 491 | // If this is not being sent as an ordered broadcast, then we |
| 492 | // don't want to touch the fields that keep track of the current |
| 493 | // state of ordered broadcasts. |
| 494 | if (ordered) { |
| 495 | r.receiver = filter.receiverList.receiver.asBinder(); |
| 496 | r.curFilter = filter; |
| 497 | filter.receiverList.curBroadcast = r; |
| 498 | r.state = BroadcastRecord.CALL_IN_RECEIVE; |
| 499 | if (filter.receiverList.app != null) { |
| 500 | // Bump hosting application to no longer be in background |
| 501 | // scheduling class. Note that we can't do that if there |
| 502 | // isn't an app... but we can only be in that case for |
| 503 | // things that directly call the IActivityManager API, which |
| 504 | // are already core system stuff so don't matter for this. |
| 505 | r.curApp = filter.receiverList.app; |
| 506 | filter.receiverList.app.curReceiver = r; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 507 | mService.updateOomAdjLocked(r.curApp, true); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | try { |
| 511 | if (DEBUG_BROADCAST_LIGHT) { |
| 512 | int seq = r.intent.getIntExtra("seq", -1); |
| 513 | Slog.i(TAG, "Delivering to " + filter |
| 514 | + " (seq=" + seq + "): " + r); |
| 515 | } |
| 516 | performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 517 | new Intent(r.intent), r.resultCode, r.resultData, |
| 518 | r.resultExtras, r.ordered, r.initialSticky, r.userId); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 519 | if (ordered) { |
| 520 | r.state = BroadcastRecord.CALL_DONE_RECEIVE; |
| 521 | } |
| 522 | } catch (RemoteException e) { |
| 523 | Slog.w(TAG, "Failure sending broadcast " + r.intent, e); |
| 524 | if (ordered) { |
| 525 | r.receiver = null; |
| 526 | r.curFilter = null; |
| 527 | filter.receiverList.curBroadcast = null; |
| 528 | if (filter.receiverList.app != null) { |
| 529 | filter.receiverList.app.curReceiver = null; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | final void processNextBroadcast(boolean fromMsg) { |
| 537 | synchronized(mService) { |
| 538 | BroadcastRecord r; |
| 539 | |
| 540 | if (DEBUG_BROADCAST) Slog.v(TAG, "processNextBroadcast [" |
| 541 | + mQueueName + "]: " |
| 542 | + mParallelBroadcasts.size() + " broadcasts, " |
| 543 | + mOrderedBroadcasts.size() + " ordered broadcasts"); |
| 544 | |
| 545 | mService.updateCpuStats(); |
| 546 | |
| 547 | if (fromMsg) { |
| 548 | mBroadcastsScheduled = false; |
| 549 | } |
| 550 | |
| 551 | // First, deliver any non-serialized broadcasts right away. |
| 552 | while (mParallelBroadcasts.size() > 0) { |
| 553 | r = mParallelBroadcasts.remove(0); |
| 554 | r.dispatchTime = SystemClock.uptimeMillis(); |
| 555 | r.dispatchClockTime = System.currentTimeMillis(); |
| 556 | final int N = r.receivers.size(); |
| 557 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing parallel broadcast [" |
| 558 | + mQueueName + "] " + r); |
| 559 | for (int i=0; i<N; i++) { |
| 560 | Object target = r.receivers.get(i); |
| 561 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 562 | "Delivering non-ordered on [" + mQueueName + "] to registered " |
| 563 | + target + ": " + r); |
| 564 | deliverToRegisteredReceiverLocked(r, (BroadcastFilter)target, false); |
| 565 | } |
| 566 | addBroadcastToHistoryLocked(r); |
| 567 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Done with parallel broadcast [" |
| 568 | + mQueueName + "] " + r); |
| 569 | } |
| 570 | |
| 571 | // Now take care of the next serialized one... |
| 572 | |
| 573 | // If we are waiting for a process to come up to handle the next |
| 574 | // broadcast, then do nothing at this point. Just in case, we |
| 575 | // check that the process we're waiting for still exists. |
| 576 | if (mPendingBroadcast != null) { |
| 577 | if (DEBUG_BROADCAST_LIGHT) { |
| 578 | Slog.v(TAG, "processNextBroadcast [" |
| 579 | + mQueueName + "]: waiting for " |
| 580 | + mPendingBroadcast.curApp); |
| 581 | } |
| 582 | |
| 583 | boolean isDead; |
| 584 | synchronized (mService.mPidsSelfLocked) { |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 585 | ProcessRecord proc = mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid); |
| 586 | isDead = proc == null || proc.crashing; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 587 | } |
| 588 | if (!isDead) { |
| 589 | // It's still alive, so keep waiting |
| 590 | return; |
| 591 | } else { |
| 592 | Slog.w(TAG, "pending app [" |
| 593 | + mQueueName + "]" + mPendingBroadcast.curApp |
| 594 | + " died before responding to broadcast"); |
| 595 | mPendingBroadcast.state = BroadcastRecord.IDLE; |
| 596 | mPendingBroadcast.nextReceiver = mPendingBroadcastRecvIndex; |
| 597 | mPendingBroadcast = null; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | boolean looped = false; |
| 602 | |
| 603 | do { |
| 604 | if (mOrderedBroadcasts.size() == 0) { |
| 605 | // No more broadcasts pending, so all done! |
| 606 | mService.scheduleAppGcsLocked(); |
| 607 | if (looped) { |
| 608 | // If we had finished the last ordered broadcast, then |
| 609 | // make sure all processes have correct oom and sched |
| 610 | // adjustments. |
| 611 | mService.updateOomAdjLocked(); |
| 612 | } |
| 613 | return; |
| 614 | } |
| 615 | r = mOrderedBroadcasts.get(0); |
| 616 | boolean forceReceive = false; |
| 617 | |
| 618 | // Ensure that even if something goes awry with the timeout |
| 619 | // detection, we catch "hung" broadcasts here, discard them, |
| 620 | // and continue to make progress. |
| 621 | // |
| 622 | // This is only done if the system is ready so that PRE_BOOT_COMPLETED |
| 623 | // receivers don't get executed with timeouts. They're intended for |
| 624 | // one time heavy lifting after system upgrades and can take |
| 625 | // significant amounts of time. |
| 626 | int numReceivers = (r.receivers != null) ? r.receivers.size() : 0; |
| 627 | if (mService.mProcessesReady && r.dispatchTime > 0) { |
| 628 | long now = SystemClock.uptimeMillis(); |
| 629 | if ((numReceivers > 0) && |
| 630 | (now > r.dispatchTime + (2*mTimeoutPeriod*numReceivers))) { |
| 631 | Slog.w(TAG, "Hung broadcast [" |
| 632 | + mQueueName + "] discarded after timeout failure:" |
| 633 | + " now=" + now |
| 634 | + " dispatchTime=" + r.dispatchTime |
| 635 | + " startTime=" + r.receiverTime |
| 636 | + " intent=" + r.intent |
| 637 | + " numReceivers=" + numReceivers |
| 638 | + " nextReceiver=" + r.nextReceiver |
| 639 | + " state=" + r.state); |
| 640 | broadcastTimeoutLocked(false); // forcibly finish this broadcast |
| 641 | forceReceive = true; |
| 642 | r.state = BroadcastRecord.IDLE; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | if (r.state != BroadcastRecord.IDLE) { |
| 647 | if (DEBUG_BROADCAST) Slog.d(TAG, |
| 648 | "processNextBroadcast(" |
| 649 | + mQueueName + ") called when not idle (state=" |
| 650 | + r.state + ")"); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | if (r.receivers == null || r.nextReceiver >= numReceivers |
| 655 | || r.resultAbort || forceReceive) { |
| 656 | // No more receivers for this broadcast! Send the final |
| 657 | // result if requested... |
| 658 | if (r.resultTo != null) { |
| 659 | try { |
| 660 | if (DEBUG_BROADCAST) { |
| 661 | int seq = r.intent.getIntExtra("seq", -1); |
| 662 | Slog.i(TAG, "Finishing broadcast [" |
| 663 | + mQueueName + "] " + r.intent.getAction() |
| 664 | + " seq=" + seq + " app=" + r.callerApp); |
| 665 | } |
| 666 | performReceiveLocked(r.callerApp, r.resultTo, |
| 667 | new Intent(r.intent), r.resultCode, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 668 | r.resultData, r.resultExtras, false, false, r.userId); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 669 | // Set this to null so that the reference |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 670 | // (local and remote) isn't kept in the mBroadcastHistory. |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 671 | r.resultTo = null; |
| 672 | } catch (RemoteException e) { |
| 673 | Slog.w(TAG, "Failure [" |
| 674 | + mQueueName + "] sending broadcast result of " |
| 675 | + r.intent, e); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | if (DEBUG_BROADCAST) Slog.v(TAG, "Cancelling BROADCAST_TIMEOUT_MSG"); |
| 680 | cancelBroadcastTimeoutLocked(); |
| 681 | |
| 682 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Finished with ordered broadcast " |
| 683 | + r); |
| 684 | |
| 685 | // ... and on to the next... |
| 686 | addBroadcastToHistoryLocked(r); |
| 687 | mOrderedBroadcasts.remove(0); |
| 688 | r = null; |
| 689 | looped = true; |
| 690 | continue; |
| 691 | } |
| 692 | } while (r == null); |
| 693 | |
| 694 | // Get the next receiver... |
| 695 | int recIdx = r.nextReceiver++; |
| 696 | |
| 697 | // Keep track of when this receiver started, and make sure there |
| 698 | // is a timeout message pending to kill it if need be. |
| 699 | r.receiverTime = SystemClock.uptimeMillis(); |
| 700 | if (recIdx == 0) { |
| 701 | r.dispatchTime = r.receiverTime; |
| 702 | r.dispatchClockTime = System.currentTimeMillis(); |
| 703 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing ordered broadcast [" |
| 704 | + mQueueName + "] " + r); |
| 705 | } |
| 706 | if (! mPendingBroadcastTimeoutMessage) { |
| 707 | long timeoutTime = r.receiverTime + mTimeoutPeriod; |
| 708 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 709 | "Submitting BROADCAST_TIMEOUT_MSG [" |
| 710 | + mQueueName + "] for " + r + " at " + timeoutTime); |
| 711 | setBroadcastTimeoutLocked(timeoutTime); |
| 712 | } |
| 713 | |
| 714 | Object nextReceiver = r.receivers.get(recIdx); |
| 715 | if (nextReceiver instanceof BroadcastFilter) { |
| 716 | // Simple case: this is a registered receiver who gets |
| 717 | // a direct call. |
| 718 | BroadcastFilter filter = (BroadcastFilter)nextReceiver; |
| 719 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 720 | "Delivering ordered [" |
| 721 | + mQueueName + "] to registered " |
| 722 | + filter + ": " + r); |
| 723 | deliverToRegisteredReceiverLocked(r, filter, r.ordered); |
| 724 | if (r.receiver == null || !r.ordered) { |
| 725 | // The receiver has already finished, so schedule to |
| 726 | // process the next one. |
| 727 | if (DEBUG_BROADCAST) Slog.v(TAG, "Quick finishing [" |
| 728 | + mQueueName + "]: ordered=" |
| 729 | + r.ordered + " receiver=" + r.receiver); |
| 730 | r.state = BroadcastRecord.IDLE; |
| 731 | scheduleBroadcastsLocked(); |
| 732 | } |
| 733 | return; |
| 734 | } |
| 735 | |
| 736 | // Hard case: need to instantiate the receiver, possibly |
| 737 | // starting its application process to host it. |
| 738 | |
| 739 | ResolveInfo info = |
| 740 | (ResolveInfo)nextReceiver; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 741 | ComponentName component = new ComponentName( |
| 742 | info.activityInfo.applicationInfo.packageName, |
| 743 | info.activityInfo.name); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 744 | |
| 745 | boolean skip = false; |
| 746 | int perm = mService.checkComponentPermission(info.activityInfo.permission, |
| 747 | r.callingPid, r.callingUid, info.activityInfo.applicationInfo.uid, |
| 748 | info.activityInfo.exported); |
| 749 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 750 | if (!info.activityInfo.exported) { |
| 751 | Slog.w(TAG, "Permission Denial: broadcasting " |
| 752 | + r.intent.toString() |
| 753 | + " from " + r.callerPackage + " (pid=" + r.callingPid |
| 754 | + ", uid=" + r.callingUid + ")" |
| 755 | + " is not exported from uid " + info.activityInfo.applicationInfo.uid |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 756 | + " due to receiver " + component.flattenToShortString()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 757 | } else { |
| 758 | Slog.w(TAG, "Permission Denial: broadcasting " |
| 759 | + r.intent.toString() |
| 760 | + " from " + r.callerPackage + " (pid=" + r.callingPid |
| 761 | + ", uid=" + r.callingUid + ")" |
| 762 | + " requires " + info.activityInfo.permission |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 763 | + " due to receiver " + component.flattenToShortString()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 764 | } |
| 765 | skip = true; |
| 766 | } |
| 767 | if (info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID && |
| 768 | r.requiredPermission != null) { |
| 769 | try { |
| 770 | perm = AppGlobals.getPackageManager(). |
| 771 | checkPermission(r.requiredPermission, |
| 772 | info.activityInfo.applicationInfo.packageName); |
| 773 | } catch (RemoteException e) { |
| 774 | perm = PackageManager.PERMISSION_DENIED; |
| 775 | } |
| 776 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 777 | Slog.w(TAG, "Permission Denial: receiving " |
| 778 | + r.intent + " to " |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 779 | + component.flattenToShortString() |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 780 | + " requires " + r.requiredPermission |
| 781 | + " due to sender " + r.callerPackage |
| 782 | + " (uid " + r.callingUid + ")"); |
| 783 | skip = true; |
| 784 | } |
| 785 | } |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 786 | if (r.appOp != AppOpsManager.OP_NONE) { |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 787 | int mode = mService.mAppOpsService.noteOperation(r.appOp, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 788 | info.activityInfo.applicationInfo.uid, info.activityInfo.packageName); |
| 789 | if (mode != AppOpsManager.MODE_ALLOWED) { |
| 790 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 791 | "App op " + r.appOp + " not allowed for broadcast to uid " |
| 792 | + info.activityInfo.applicationInfo.uid + " pkg " |
| 793 | + info.activityInfo.packageName); |
| 794 | skip = true; |
| 795 | } |
| 796 | } |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 797 | if (!skip) { |
| 798 | skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, |
| 799 | r.callingPid, r.resolvedType, info.activityInfo.applicationInfo.uid); |
| 800 | } |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 801 | boolean isSingleton = false; |
| 802 | try { |
| 803 | isSingleton = mService.isSingleton(info.activityInfo.processName, |
| 804 | info.activityInfo.applicationInfo, |
| 805 | info.activityInfo.name, info.activityInfo.flags); |
| 806 | } catch (SecurityException e) { |
| 807 | Slog.w(TAG, e.getMessage()); |
| 808 | skip = true; |
| 809 | } |
| 810 | if ((info.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) { |
| 811 | if (ActivityManager.checkUidPermission( |
| 812 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 813 | info.activityInfo.applicationInfo.uid) |
| 814 | != PackageManager.PERMISSION_GRANTED) { |
| 815 | Slog.w(TAG, "Permission Denial: Receiver " + component.flattenToShortString() |
| 816 | + " requests FLAG_SINGLE_USER, but app does not hold " |
| 817 | + android.Manifest.permission.INTERACT_ACROSS_USERS); |
| 818 | skip = true; |
| 819 | } |
| 820 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 821 | if (r.curApp != null && r.curApp.crashing) { |
| 822 | // If the target process is crashing, just skip it. |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 823 | Slog.w(TAG, "Skipping deliver ordered [" + mQueueName + "] " + r |
| 824 | + " to " + r.curApp + ": process crashing"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 825 | skip = true; |
| 826 | } |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 827 | if (!skip) { |
| 828 | boolean isAvailable = false; |
| 829 | try { |
| 830 | isAvailable = AppGlobals.getPackageManager().isPackageAvailable( |
| 831 | info.activityInfo.packageName, |
| 832 | UserHandle.getUserId(info.activityInfo.applicationInfo.uid)); |
| 833 | } catch (Exception e) { |
| 834 | // all such failures mean we skip this receiver |
| 835 | Slog.w(TAG, "Exception getting recipient info for " |
| 836 | + info.activityInfo.packageName, e); |
| 837 | } |
| 838 | if (!isAvailable) { |
| 839 | if (DEBUG_BROADCAST) { |
| 840 | Slog.v(TAG, "Skipping delivery to " + info.activityInfo.packageName |
| 841 | + " / " + info.activityInfo.applicationInfo.uid |
| 842 | + " : package no longer available"); |
| 843 | } |
| 844 | skip = true; |
| 845 | } |
| 846 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 847 | |
| 848 | if (skip) { |
| 849 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 850 | "Skipping delivery of ordered [" |
| 851 | + mQueueName + "] " + r + " for whatever reason"); |
| 852 | r.receiver = null; |
| 853 | r.curFilter = null; |
| 854 | r.state = BroadcastRecord.IDLE; |
| 855 | scheduleBroadcastsLocked(); |
| 856 | return; |
| 857 | } |
| 858 | |
| 859 | r.state = BroadcastRecord.APP_RECEIVE; |
| 860 | String targetProcess = info.activityInfo.processName; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 861 | r.curComponent = component; |
| 862 | if (r.callingUid != Process.SYSTEM_UID && isSingleton) { |
| 863 | info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 864 | } |
| 865 | r.curReceiver = info.activityInfo; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 866 | if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 867 | Slog.v(TAG_MU, "Updated broadcast record activity info for secondary user, " |
| 868 | + info.activityInfo + ", callingUid = " + r.callingUid + ", uid = " |
| 869 | + info.activityInfo.applicationInfo.uid); |
| 870 | } |
| 871 | |
| 872 | // Broadcast is being executed, its package can't be stopped. |
| 873 | try { |
| 874 | AppGlobals.getPackageManager().setPackageStoppedState( |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 875 | r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid)); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 876 | } catch (RemoteException e) { |
| 877 | } catch (IllegalArgumentException e) { |
| 878 | Slog.w(TAG, "Failed trying to unstop package " |
| 879 | + r.curComponent.getPackageName() + ": " + e); |
| 880 | } |
| 881 | |
| 882 | // Is this receiver's application already running? |
| 883 | ProcessRecord app = mService.getProcessRecordLocked(targetProcess, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 884 | info.activityInfo.applicationInfo.uid, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 885 | if (app != null && app.thread != null) { |
| 886 | try { |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 887 | app.addPackage(info.activityInfo.packageName, mService.mProcessStats); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 888 | processCurBroadcastLocked(r, app); |
| 889 | return; |
| 890 | } catch (RemoteException e) { |
| 891 | Slog.w(TAG, "Exception when sending broadcast to " |
| 892 | + r.curComponent, e); |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 893 | } catch (RuntimeException e) { |
| 894 | Log.wtf(TAG, "Failed sending broadcast to " |
| 895 | + r.curComponent + " with " + r.intent, e); |
| 896 | // If some unexpected exception happened, just skip |
| 897 | // this broadcast. At this point we are not in the call |
| 898 | // from a client, so throwing an exception out from here |
| 899 | // will crash the entire system instead of just whoever |
| 900 | // sent the broadcast. |
| 901 | logBroadcastReceiverDiscardLocked(r); |
| 902 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 903 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 904 | scheduleBroadcastsLocked(); |
| 905 | // We need to reset the state if we failed to start the receiver. |
| 906 | r.state = BroadcastRecord.IDLE; |
| 907 | return; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | // If a dead object exception was thrown -- fall through to |
| 911 | // restart the application. |
| 912 | } |
| 913 | |
| 914 | // Not running -- get it started, to be executed when the app comes up. |
| 915 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 916 | "Need to start app [" |
| 917 | + mQueueName + "] " + targetProcess + " for broadcast " + r); |
| 918 | if ((r.curApp=mService.startProcessLocked(targetProcess, |
| 919 | info.activityInfo.applicationInfo, true, |
| 920 | r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, |
| 921 | "broadcast", r.curComponent, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 922 | (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false)) |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 923 | == null) { |
| 924 | // Ah, this recipient is unavailable. Finish it if necessary, |
| 925 | // and mark the broadcast record as ready for the next. |
| 926 | Slog.w(TAG, "Unable to launch app " |
| 927 | + info.activityInfo.applicationInfo.packageName + "/" |
| 928 | + info.activityInfo.applicationInfo.uid + " for broadcast " |
| 929 | + r.intent + ": process is bad"); |
| 930 | logBroadcastReceiverDiscardLocked(r); |
| 931 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 932 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 933 | scheduleBroadcastsLocked(); |
| 934 | r.state = BroadcastRecord.IDLE; |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | mPendingBroadcast = r; |
| 939 | mPendingBroadcastRecvIndex = recIdx; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | final void setBroadcastTimeoutLocked(long timeoutTime) { |
| 944 | if (! mPendingBroadcastTimeoutMessage) { |
| 945 | Message msg = mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG, this); |
| 946 | mHandler.sendMessageAtTime(msg, timeoutTime); |
| 947 | mPendingBroadcastTimeoutMessage = true; |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | final void cancelBroadcastTimeoutLocked() { |
| 952 | if (mPendingBroadcastTimeoutMessage) { |
| 953 | mHandler.removeMessages(BROADCAST_TIMEOUT_MSG, this); |
| 954 | mPendingBroadcastTimeoutMessage = false; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | final void broadcastTimeoutLocked(boolean fromMsg) { |
| 959 | if (fromMsg) { |
| 960 | mPendingBroadcastTimeoutMessage = false; |
| 961 | } |
| 962 | |
| 963 | if (mOrderedBroadcasts.size() == 0) { |
| 964 | return; |
| 965 | } |
| 966 | |
| 967 | long now = SystemClock.uptimeMillis(); |
| 968 | BroadcastRecord r = mOrderedBroadcasts.get(0); |
| 969 | if (fromMsg) { |
| 970 | if (mService.mDidDexOpt) { |
| 971 | // Delay timeouts until dexopt finishes. |
| 972 | mService.mDidDexOpt = false; |
| 973 | long timeoutTime = SystemClock.uptimeMillis() + mTimeoutPeriod; |
| 974 | setBroadcastTimeoutLocked(timeoutTime); |
| 975 | return; |
| 976 | } |
| 977 | if (!mService.mProcessesReady) { |
| 978 | // Only process broadcast timeouts if the system is ready. That way |
| 979 | // PRE_BOOT_COMPLETED broadcasts can't timeout as they are intended |
| 980 | // to do heavy lifting for system up. |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | long timeoutTime = r.receiverTime + mTimeoutPeriod; |
| 985 | if (timeoutTime > now) { |
| 986 | // We can observe premature timeouts because we do not cancel and reset the |
| 987 | // broadcast timeout message after each receiver finishes. Instead, we set up |
| 988 | // an initial timeout then kick it down the road a little further as needed |
| 989 | // when it expires. |
| 990 | if (DEBUG_BROADCAST) Slog.v(TAG, |
| 991 | "Premature timeout [" |
| 992 | + mQueueName + "] @ " + now + ": resetting BROADCAST_TIMEOUT_MSG for " |
| 993 | + timeoutTime); |
| 994 | setBroadcastTimeoutLocked(timeoutTime); |
| 995 | return; |
| 996 | } |
| 997 | } |
| 998 | |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 999 | BroadcastRecord br = mOrderedBroadcasts.get(0); |
| 1000 | if (br.state == BroadcastRecord.WAITING_SERVICES) { |
| 1001 | // In this case the broadcast had already finished, but we had decided to wait |
| 1002 | // for started services to finish as well before going on. So if we have actually |
| 1003 | // waited long enough time timeout the broadcast, let's give up on the whole thing |
| 1004 | // and just move on to the next. |
| 1005 | Slog.i(ActivityManagerService.TAG, "Waited long enough for: " + (br.curComponent != null |
| 1006 | ? br.curComponent.flattenToShortString() : "(null)")); |
| 1007 | br.curComponent = null; |
| 1008 | br.state = BroadcastRecord.IDLE; |
| 1009 | processNextBroadcast(false); |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | Slog.w(TAG, "Timeout of broadcast " + r + " - receiver=" + r. receiver |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1014 | + ", started " + (now - r.receiverTime) + "ms ago"); |
| 1015 | r.receiverTime = now; |
| 1016 | r.anrCount++; |
| 1017 | |
| 1018 | // Current receiver has passed its expiration date. |
| 1019 | if (r.nextReceiver <= 0) { |
| 1020 | Slog.w(TAG, "Timeout on receiver with nextReceiver <= 0"); |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | ProcessRecord app = null; |
| 1025 | String anrMessage = null; |
| 1026 | |
| 1027 | Object curReceiver = r.receivers.get(r.nextReceiver-1); |
| 1028 | Slog.w(TAG, "Receiver during timeout: " + curReceiver); |
| 1029 | logBroadcastReceiverDiscardLocked(r); |
| 1030 | if (curReceiver instanceof BroadcastFilter) { |
| 1031 | BroadcastFilter bf = (BroadcastFilter)curReceiver; |
| 1032 | if (bf.receiverList.pid != 0 |
| 1033 | && bf.receiverList.pid != ActivityManagerService.MY_PID) { |
| 1034 | synchronized (mService.mPidsSelfLocked) { |
| 1035 | app = mService.mPidsSelfLocked.get( |
| 1036 | bf.receiverList.pid); |
| 1037 | } |
| 1038 | } |
| 1039 | } else { |
| 1040 | app = r.curApp; |
| 1041 | } |
| 1042 | |
| 1043 | if (app != null) { |
| 1044 | anrMessage = "Broadcast of " + r.intent.toString(); |
| 1045 | } |
| 1046 | |
| 1047 | if (mPendingBroadcast == r) { |
| 1048 | mPendingBroadcast = null; |
| 1049 | } |
| 1050 | |
| 1051 | // Move on to the next receiver. |
| 1052 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 1053 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1054 | scheduleBroadcastsLocked(); |
| 1055 | |
| 1056 | if (anrMessage != null) { |
| 1057 | // Post the ANR to the handler since we do not want to process ANRs while |
| 1058 | // potentially holding our lock. |
| 1059 | mHandler.post(new AppNotResponding(app, anrMessage)); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | private final void addBroadcastToHistoryLocked(BroadcastRecord r) { |
| 1064 | if (r.callingUid < 0) { |
| 1065 | // This was from a registerReceiver() call; ignore it. |
| 1066 | return; |
| 1067 | } |
| 1068 | System.arraycopy(mBroadcastHistory, 0, mBroadcastHistory, 1, |
| 1069 | MAX_BROADCAST_HISTORY-1); |
| 1070 | r.finishTime = SystemClock.uptimeMillis(); |
| 1071 | mBroadcastHistory[0] = r; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1072 | System.arraycopy(mBroadcastSummaryHistory, 0, mBroadcastSummaryHistory, 1, |
| 1073 | MAX_BROADCAST_SUMMARY_HISTORY-1); |
| 1074 | mBroadcastSummaryHistory[0] = r.intent; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | final void logBroadcastReceiverDiscardLocked(BroadcastRecord r) { |
| 1078 | if (r.nextReceiver > 0) { |
| 1079 | Object curReceiver = r.receivers.get(r.nextReceiver-1); |
| 1080 | if (curReceiver instanceof BroadcastFilter) { |
| 1081 | BroadcastFilter bf = (BroadcastFilter) curReceiver; |
| 1082 | EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_FILTER, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1083 | bf.owningUserId, System.identityHashCode(r), |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1084 | r.intent.getAction(), |
| 1085 | r.nextReceiver - 1, |
| 1086 | System.identityHashCode(bf)); |
| 1087 | } else { |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1088 | ResolveInfo ri = (ResolveInfo)curReceiver; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1089 | EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1090 | UserHandle.getUserId(ri.activityInfo.applicationInfo.uid), |
| 1091 | System.identityHashCode(r), r.intent.getAction(), |
| 1092 | r.nextReceiver - 1, ri.toString()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1093 | } |
| 1094 | } else { |
| 1095 | Slog.w(TAG, "Discarding broadcast before first receiver is invoked: " |
| 1096 | + r); |
| 1097 | EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1098 | -1, System.identityHashCode(r), |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1099 | r.intent.getAction(), |
| 1100 | r.nextReceiver, |
| 1101 | "NONE"); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | final boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 1106 | int opti, boolean dumpAll, String dumpPackage, boolean needSep) { |
| 1107 | if (mParallelBroadcasts.size() > 0 || mOrderedBroadcasts.size() > 0 |
| 1108 | || mPendingBroadcast != null) { |
| 1109 | boolean printed = false; |
| 1110 | for (int i=mParallelBroadcasts.size()-1; i>=0; i--) { |
| 1111 | BroadcastRecord br = mParallelBroadcasts.get(i); |
| 1112 | if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) { |
| 1113 | continue; |
| 1114 | } |
| 1115 | if (!printed) { |
| 1116 | if (needSep) { |
| 1117 | pw.println(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1118 | } |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1119 | needSep = true; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1120 | printed = true; |
| 1121 | pw.println(" Active broadcasts [" + mQueueName + "]:"); |
| 1122 | } |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1123 | pw.println(" Active Broadcast " + mQueueName + " #" + i + ":"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1124 | br.dump(pw, " "); |
| 1125 | } |
| 1126 | printed = false; |
| 1127 | needSep = true; |
| 1128 | for (int i=mOrderedBroadcasts.size()-1; i>=0; i--) { |
| 1129 | BroadcastRecord br = mOrderedBroadcasts.get(i); |
| 1130 | if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) { |
| 1131 | continue; |
| 1132 | } |
| 1133 | if (!printed) { |
| 1134 | if (needSep) { |
| 1135 | pw.println(); |
| 1136 | } |
| 1137 | needSep = true; |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1138 | printed = true; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1139 | pw.println(" Active ordered broadcasts [" + mQueueName + "]:"); |
| 1140 | } |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1141 | pw.println(" Active Ordered Broadcast " + mQueueName + " #" + i + ":"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1142 | mOrderedBroadcasts.get(i).dump(pw, " "); |
| 1143 | } |
| 1144 | if (dumpPackage == null || (mPendingBroadcast != null |
| 1145 | && dumpPackage.equals(mPendingBroadcast.callerPackage))) { |
| 1146 | if (needSep) { |
| 1147 | pw.println(); |
| 1148 | } |
| 1149 | pw.println(" Pending broadcast [" + mQueueName + "]:"); |
| 1150 | if (mPendingBroadcast != null) { |
| 1151 | mPendingBroadcast.dump(pw, " "); |
| 1152 | } else { |
| 1153 | pw.println(" (null)"); |
| 1154 | } |
| 1155 | needSep = true; |
| 1156 | } |
| 1157 | } |
| 1158 | |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1159 | int i; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1160 | boolean printed = false; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1161 | for (i=0; i<MAX_BROADCAST_HISTORY; i++) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1162 | BroadcastRecord r = mBroadcastHistory[i]; |
| 1163 | if (r == null) { |
| 1164 | break; |
| 1165 | } |
| 1166 | if (dumpPackage != null && !dumpPackage.equals(r.callerPackage)) { |
| 1167 | continue; |
| 1168 | } |
| 1169 | if (!printed) { |
| 1170 | if (needSep) { |
| 1171 | pw.println(); |
| 1172 | } |
| 1173 | needSep = true; |
| 1174 | pw.println(" Historical broadcasts [" + mQueueName + "]:"); |
| 1175 | printed = true; |
| 1176 | } |
| 1177 | if (dumpAll) { |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1178 | pw.print(" Historical Broadcast " + mQueueName + " #"); |
| 1179 | pw.print(i); pw.println(":"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1180 | r.dump(pw, " "); |
| 1181 | } else { |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1182 | pw.print(" #"); pw.print(i); pw.print(": "); pw.println(r); |
| 1183 | pw.print(" "); |
| 1184 | pw.println(r.intent.toShortString(false, true, true, false)); |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 1185 | if (r.targetComp != null && r.targetComp != r.intent.getComponent()) { |
| 1186 | pw.print(" targetComp: "); pw.println(r.targetComp.toShortString()); |
| 1187 | } |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1188 | Bundle bundle = r.intent.getExtras(); |
| 1189 | if (bundle != null) { |
| 1190 | pw.print(" extras: "); pw.println(bundle.toString()); |
| 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | if (dumpPackage == null) { |
| 1196 | if (dumpAll) { |
| 1197 | i = 0; |
| 1198 | printed = false; |
| 1199 | } |
| 1200 | for (; i<MAX_BROADCAST_SUMMARY_HISTORY; i++) { |
| 1201 | Intent intent = mBroadcastSummaryHistory[i]; |
| 1202 | if (intent == null) { |
| 1203 | break; |
| 1204 | } |
| 1205 | if (!printed) { |
| 1206 | if (needSep) { |
| 1207 | pw.println(); |
| 1208 | } |
| 1209 | needSep = true; |
| 1210 | pw.println(" Historical broadcasts summary [" + mQueueName + "]:"); |
| 1211 | printed = true; |
| 1212 | } |
| 1213 | if (!dumpAll && i >= 50) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1214 | pw.println(" ..."); |
| 1215 | break; |
| 1216 | } |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1217 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 1218 | pw.println(intent.toShortString(false, true, true, false)); |
| 1219 | Bundle bundle = intent.getExtras(); |
| 1220 | if (bundle != null) { |
| 1221 | pw.print(" extras: "); pw.println(bundle.toString()); |
| 1222 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | return needSep; |
| 1227 | } |
| 1228 | } |