BroadcastQueue.java revision d2f1511f2896e09db35bd92e0aab02ba89888a04
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 17package com.android.server.am; 18 19import java.io.FileDescriptor; 20import java.io.PrintWriter; 21import java.util.ArrayList; 22 23import android.app.ActivityManager; 24import android.app.AppGlobals; 25import android.app.AppOpsManager; 26import android.content.ComponentName; 27import android.content.IIntentReceiver; 28import android.content.Intent; 29import android.content.pm.ActivityInfo; 30import android.content.pm.ApplicationInfo; 31import android.content.pm.PackageManager; 32import android.content.pm.ResolveInfo; 33import android.os.Bundle; 34import android.os.Handler; 35import android.os.IBinder; 36import android.os.Looper; 37import android.os.Message; 38import android.os.Process; 39import android.os.RemoteException; 40import android.os.SystemClock; 41import android.os.UserHandle; 42import android.util.EventLog; 43import android.util.Log; 44import 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 */ 52public final class BroadcastQueue { 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 59 static final int MAX_BROADCAST_HISTORY = ActivityManager.isLowRamDeviceStatic() ? 10 : 50; 60 static final int MAX_BROADCAST_SUMMARY_HISTORY 61 = ActivityManager.isLowRamDeviceStatic() ? 25 : 300; 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 /** 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 /** 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 */ 88 final ArrayList<BroadcastRecord> mParallelBroadcasts = new ArrayList<BroadcastRecord>(); 89 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 */ 97 final ArrayList<BroadcastRecord> mOrderedBroadcasts = new ArrayList<BroadcastRecord>(); 98 99 /** 100 * Historical data of past broadcasts, for debugging. 101 */ 102 final BroadcastRecord[] mBroadcastHistory = new BroadcastRecord[MAX_BROADCAST_HISTORY]; 103 104 /** 105 * Summary of historical data of past broadcasts, for debugging. 106 */ 107 final Intent[] mBroadcastSummaryHistory = new Intent[MAX_BROADCAST_SUMMARY_HISTORY]; 108 109 /** 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 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 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() { 171 mService.appNotResponding(mApp, null, null, false, mAnnotation); 172 } 173 } 174 175 BroadcastQueue(ActivityManagerService service, Handler handler, 176 String name, long timeoutPeriod, boolean allowDelayBehindServices) { 177 mService = service; 178 mHandler = new BroadcastHandler(handler.getLooper()); 179 mQueueName = name; 180 mTimeoutPeriod = timeoutPeriod; 181 mDelayBehindServices = allowDelayBehindServices; 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; 232 app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER); 233 mService.updateLruProcessLocked(app, false, null); 234 mService.updateOomAdjLocked(); 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), 247 r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId, 248 app.repProcState); 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, 276 br.resultExtras, br.resultAbort, false); 277 scheduleBroadcastsLocked(); 278 // We need to reset the state if we failed to start the receiver. 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 && r.queue == this) { 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, 305 r.resultExtras, r.resultAbort, false); 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, 315 r.resultExtras, r.resultAbort, false); 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, 346 String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices) { 347 final int state = r.state; 348 final ActivityInfo receiver = r.curReceiver; 349 r.state = BroadcastRecord.IDLE; 350 if (state == BroadcastRecord.IDLE) { 351 Slog.w(TAG, "finishReceiver [" + mQueueName + "] called but state is IDLE"); 352 } 353 r.receiver = null; 354 r.intent.setComponent(null); 355 if (r.curApp != null && r.curApp.curReceiver == r) { 356 r.curApp.curReceiver = null; 357 } 358 if (r.curFilter != null) { 359 r.curFilter.receiverList.curBroadcast = null; 360 } 361 r.curFilter = null; 362 r.curReceiver = null; 363 r.curApp = null; 364 mPendingBroadcast = null; 365 366 r.resultCode = resultCode; 367 r.resultData = resultData; 368 r.resultExtras = resultExtras; 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) { 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 } 399 } 400 } 401 402 r.curComponent = null; 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 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 423 private static void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver, 424 Intent intent, int resultCode, String data, Bundle extras, 425 boolean ordered, boolean sticky, int sendingUser) throws RemoteException { 426 // Send the intent to the receiver asynchronously using one-way binder calls. 427 if (app != null) { 428 if (app.thread != null) { 429 // If we have an app thread, do the call through that so it is 430 // correctly ordered with other one-way calls. 431 app.thread.scheduleRegisteredReceiver(receiver, intent, resultCode, 432 data, extras, ordered, sticky, sendingUser, app.repProcState); 433 } else { 434 // Application has died. Receiver doesn't exist. 435 throw new RemoteException("app.thread must not be null"); 436 } 437 } else { 438 receiver.performReceive(intent, resultCode, data, extras, ordered, 439 sticky, sendingUser); 440 } 441 } 442 443 private final void deliverToRegisteredReceiverLocked(BroadcastRecord r, 444 BroadcastFilter filter, boolean ordered) { 445 boolean skip = false; 446 if (filter.requiredPermission != null) { 447 int perm = mService.checkComponentPermission(filter.requiredPermission, 448 r.callingPid, r.callingUid, -1, true); 449 if (perm != PackageManager.PERMISSION_GRANTED) { 450 Slog.w(TAG, "Permission Denial: broadcasting " 451 + r.intent.toString() 452 + " from " + r.callerPackage + " (pid=" 453 + r.callingPid + ", uid=" + r.callingUid + ")" 454 + " requires " + filter.requiredPermission 455 + " due to registered receiver " + filter); 456 skip = true; 457 } 458 } 459 if (!skip && r.requiredPermission != null) { 460 int perm = mService.checkComponentPermission(r.requiredPermission, 461 filter.receiverList.pid, filter.receiverList.uid, -1, true); 462 if (perm != PackageManager.PERMISSION_GRANTED) { 463 Slog.w(TAG, "Permission Denial: receiving " 464 + r.intent.toString() 465 + " to " + filter.receiverList.app 466 + " (pid=" + filter.receiverList.pid 467 + ", uid=" + filter.receiverList.uid + ")" 468 + " requires " + r.requiredPermission 469 + " due to sender " + r.callerPackage 470 + " (uid " + r.callingUid + ")"); 471 skip = true; 472 } 473 } 474 if (r.appOp != AppOpsManager.OP_NONE) { 475 int mode = mService.mAppOpsService.noteOperation(r.appOp, 476 filter.receiverList.uid, filter.packageName); 477 if (mode != AppOpsManager.MODE_ALLOWED) { 478 if (DEBUG_BROADCAST) Slog.v(TAG, 479 "App op " + r.appOp + " not allowed for broadcast to uid " 480 + filter.receiverList.uid + " pkg " + filter.packageName); 481 skip = true; 482 } 483 } 484 if (!skip) { 485 skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, 486 r.callingPid, r.resolvedType, filter.receiverList.uid); 487 } 488 489 if (filter.receiverList.app == null || filter.receiverList.app.crashing) { 490 Slog.w(TAG, "Skipping deliver [" + mQueueName + "] " + r 491 + " to " + filter.receiverList + ": process crashing"); 492 skip = true; 493 } 494 495 if (!skip) { 496 // If this is not being sent as an ordered broadcast, then we 497 // don't want to touch the fields that keep track of the current 498 // state of ordered broadcasts. 499 if (ordered) { 500 r.receiver = filter.receiverList.receiver.asBinder(); 501 r.curFilter = filter; 502 filter.receiverList.curBroadcast = r; 503 r.state = BroadcastRecord.CALL_IN_RECEIVE; 504 if (filter.receiverList.app != null) { 505 // Bump hosting application to no longer be in background 506 // scheduling class. Note that we can't do that if there 507 // isn't an app... but we can only be in that case for 508 // things that directly call the IActivityManager API, which 509 // are already core system stuff so don't matter for this. 510 r.curApp = filter.receiverList.app; 511 filter.receiverList.app.curReceiver = r; 512 mService.updateOomAdjLocked(r.curApp); 513 } 514 } 515 try { 516 if (DEBUG_BROADCAST_LIGHT) Slog.i(TAG, "Delivering to " + filter + " : " + r); 517 performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver, 518 new Intent(r.intent), r.resultCode, r.resultData, 519 r.resultExtras, r.ordered, r.initialSticky, r.userId); 520 if (ordered) { 521 r.state = BroadcastRecord.CALL_DONE_RECEIVE; 522 } 523 } catch (RemoteException e) { 524 Slog.w(TAG, "Failure sending broadcast " + r.intent, e); 525 if (ordered) { 526 r.receiver = null; 527 r.curFilter = null; 528 filter.receiverList.curBroadcast = null; 529 if (filter.receiverList.app != null) { 530 filter.receiverList.app.curReceiver = null; 531 } 532 } 533 } 534 } 535 } 536 537 final void processNextBroadcast(boolean fromMsg) { 538 synchronized(mService) { 539 BroadcastRecord r; 540 541 if (DEBUG_BROADCAST) Slog.v(TAG, "processNextBroadcast [" 542 + mQueueName + "]: " 543 + mParallelBroadcasts.size() + " broadcasts, " 544 + mOrderedBroadcasts.size() + " ordered broadcasts"); 545 546 mService.updateCpuStats(); 547 548 if (fromMsg) { 549 mBroadcastsScheduled = false; 550 } 551 552 // First, deliver any non-serialized broadcasts right away. 553 while (mParallelBroadcasts.size() > 0) { 554 r = mParallelBroadcasts.remove(0); 555 r.dispatchTime = SystemClock.uptimeMillis(); 556 r.dispatchClockTime = System.currentTimeMillis(); 557 final int N = r.receivers.size(); 558 if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing parallel broadcast [" 559 + mQueueName + "] " + r); 560 for (int i=0; i<N; i++) { 561 Object target = r.receivers.get(i); 562 if (DEBUG_BROADCAST) Slog.v(TAG, 563 "Delivering non-ordered on [" + mQueueName + "] to registered " 564 + target + ": " + r); 565 deliverToRegisteredReceiverLocked(r, (BroadcastFilter)target, false); 566 } 567 addBroadcastToHistoryLocked(r); 568 if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Done with parallel broadcast [" 569 + mQueueName + "] " + r); 570 } 571 572 // Now take care of the next serialized one... 573 574 // If we are waiting for a process to come up to handle the next 575 // broadcast, then do nothing at this point. Just in case, we 576 // check that the process we're waiting for still exists. 577 if (mPendingBroadcast != null) { 578 if (DEBUG_BROADCAST_LIGHT) { 579 Slog.v(TAG, "processNextBroadcast [" 580 + mQueueName + "]: waiting for " 581 + mPendingBroadcast.curApp); 582 } 583 584 boolean isDead; 585 synchronized (mService.mPidsSelfLocked) { 586 ProcessRecord proc = mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid); 587 isDead = proc == null || proc.crashing; 588 } 589 if (!isDead) { 590 // It's still alive, so keep waiting 591 return; 592 } else { 593 Slog.w(TAG, "pending app [" 594 + mQueueName + "]" + mPendingBroadcast.curApp 595 + " died before responding to broadcast"); 596 mPendingBroadcast.state = BroadcastRecord.IDLE; 597 mPendingBroadcast.nextReceiver = mPendingBroadcastRecvIndex; 598 mPendingBroadcast = null; 599 } 600 } 601 602 boolean looped = false; 603 604 do { 605 if (mOrderedBroadcasts.size() == 0) { 606 // No more broadcasts pending, so all done! 607 mService.scheduleAppGcsLocked(); 608 if (looped) { 609 // If we had finished the last ordered broadcast, then 610 // make sure all processes have correct oom and sched 611 // adjustments. 612 mService.updateOomAdjLocked(); 613 } 614 return; 615 } 616 r = mOrderedBroadcasts.get(0); 617 boolean forceReceive = false; 618 619 // Ensure that even if something goes awry with the timeout 620 // detection, we catch "hung" broadcasts here, discard them, 621 // and continue to make progress. 622 // 623 // This is only done if the system is ready so that PRE_BOOT_COMPLETED 624 // receivers don't get executed with timeouts. They're intended for 625 // one time heavy lifting after system upgrades and can take 626 // significant amounts of time. 627 int numReceivers = (r.receivers != null) ? r.receivers.size() : 0; 628 if (mService.mProcessesReady && r.dispatchTime > 0) { 629 long now = SystemClock.uptimeMillis(); 630 if ((numReceivers > 0) && 631 (now > r.dispatchTime + (2*mTimeoutPeriod*numReceivers))) { 632 Slog.w(TAG, "Hung broadcast [" 633 + mQueueName + "] discarded after timeout failure:" 634 + " now=" + now 635 + " dispatchTime=" + r.dispatchTime 636 + " startTime=" + r.receiverTime 637 + " intent=" + r.intent 638 + " numReceivers=" + numReceivers 639 + " nextReceiver=" + r.nextReceiver 640 + " state=" + r.state); 641 broadcastTimeoutLocked(false); // forcibly finish this broadcast 642 forceReceive = true; 643 r.state = BroadcastRecord.IDLE; 644 } 645 } 646 647 if (r.state != BroadcastRecord.IDLE) { 648 if (DEBUG_BROADCAST) Slog.d(TAG, 649 "processNextBroadcast(" 650 + mQueueName + ") called when not idle (state=" 651 + r.state + ")"); 652 return; 653 } 654 655 if (r.receivers == null || r.nextReceiver >= numReceivers 656 || r.resultAbort || forceReceive) { 657 // No more receivers for this broadcast! Send the final 658 // result if requested... 659 if (r.resultTo != null) { 660 try { 661 if (DEBUG_BROADCAST) Slog.i(TAG, 662 "Finishing broadcast [" + mQueueName + "] " 663 + r.intent.getAction() + " app=" + r.callerApp); 664 performReceiveLocked(r.callerApp, r.resultTo, 665 new Intent(r.intent), r.resultCode, 666 r.resultData, r.resultExtras, false, false, r.userId); 667 // Set this to null so that the reference 668 // (local and remote) isn't kept in the mBroadcastHistory. 669 r.resultTo = null; 670 } catch (RemoteException e) { 671 r.resultTo = null; 672 Slog.w(TAG, "Failure [" 673 + mQueueName + "] sending broadcast result of " 674 + r.intent, e); 675 } 676 } 677 678 if (DEBUG_BROADCAST) Slog.v(TAG, "Cancelling BROADCAST_TIMEOUT_MSG"); 679 cancelBroadcastTimeoutLocked(); 680 681 if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Finished with ordered broadcast " 682 + r); 683 684 // ... and on to the next... 685 addBroadcastToHistoryLocked(r); 686 mOrderedBroadcasts.remove(0); 687 r = null; 688 looped = true; 689 continue; 690 } 691 } while (r == null); 692 693 // Get the next receiver... 694 int recIdx = r.nextReceiver++; 695 696 // Keep track of when this receiver started, and make sure there 697 // is a timeout message pending to kill it if need be. 698 r.receiverTime = SystemClock.uptimeMillis(); 699 if (recIdx == 0) { 700 r.dispatchTime = r.receiverTime; 701 r.dispatchClockTime = System.currentTimeMillis(); 702 if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing ordered broadcast [" 703 + mQueueName + "] " + r); 704 } 705 if (! mPendingBroadcastTimeoutMessage) { 706 long timeoutTime = r.receiverTime + mTimeoutPeriod; 707 if (DEBUG_BROADCAST) Slog.v(TAG, 708 "Submitting BROADCAST_TIMEOUT_MSG [" 709 + mQueueName + "] for " + r + " at " + timeoutTime); 710 setBroadcastTimeoutLocked(timeoutTime); 711 } 712 713 Object nextReceiver = r.receivers.get(recIdx); 714 if (nextReceiver instanceof BroadcastFilter) { 715 // Simple case: this is a registered receiver who gets 716 // a direct call. 717 BroadcastFilter filter = (BroadcastFilter)nextReceiver; 718 if (DEBUG_BROADCAST) Slog.v(TAG, 719 "Delivering ordered [" 720 + mQueueName + "] to registered " 721 + filter + ": " + r); 722 deliverToRegisteredReceiverLocked(r, filter, r.ordered); 723 if (r.receiver == null || !r.ordered) { 724 // The receiver has already finished, so schedule to 725 // process the next one. 726 if (DEBUG_BROADCAST) Slog.v(TAG, "Quick finishing [" 727 + mQueueName + "]: ordered=" 728 + r.ordered + " receiver=" + r.receiver); 729 r.state = BroadcastRecord.IDLE; 730 scheduleBroadcastsLocked(); 731 } 732 return; 733 } 734 735 // Hard case: need to instantiate the receiver, possibly 736 // starting its application process to host it. 737 738 ResolveInfo info = 739 (ResolveInfo)nextReceiver; 740 ComponentName component = new ComponentName( 741 info.activityInfo.applicationInfo.packageName, 742 info.activityInfo.name); 743 744 boolean skip = false; 745 int perm = mService.checkComponentPermission(info.activityInfo.permission, 746 r.callingPid, r.callingUid, info.activityInfo.applicationInfo.uid, 747 info.activityInfo.exported); 748 if (perm != PackageManager.PERMISSION_GRANTED) { 749 if (!info.activityInfo.exported) { 750 Slog.w(TAG, "Permission Denial: broadcasting " 751 + r.intent.toString() 752 + " from " + r.callerPackage + " (pid=" + r.callingPid 753 + ", uid=" + r.callingUid + ")" 754 + " is not exported from uid " + info.activityInfo.applicationInfo.uid 755 + " due to receiver " + component.flattenToShortString()); 756 } else { 757 Slog.w(TAG, "Permission Denial: broadcasting " 758 + r.intent.toString() 759 + " from " + r.callerPackage + " (pid=" + r.callingPid 760 + ", uid=" + r.callingUid + ")" 761 + " requires " + info.activityInfo.permission 762 + " due to receiver " + component.flattenToShortString()); 763 } 764 skip = true; 765 } 766 if (info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID && 767 r.requiredPermission != null) { 768 try { 769 perm = AppGlobals.getPackageManager(). 770 checkPermission(r.requiredPermission, 771 info.activityInfo.applicationInfo.packageName); 772 } catch (RemoteException e) { 773 perm = PackageManager.PERMISSION_DENIED; 774 } 775 if (perm != PackageManager.PERMISSION_GRANTED) { 776 Slog.w(TAG, "Permission Denial: receiving " 777 + r.intent + " to " 778 + component.flattenToShortString() 779 + " requires " + r.requiredPermission 780 + " due to sender " + r.callerPackage 781 + " (uid " + r.callingUid + ")"); 782 skip = true; 783 } 784 } 785 if (r.appOp != AppOpsManager.OP_NONE) { 786 int mode = mService.mAppOpsService.noteOperation(r.appOp, 787 info.activityInfo.applicationInfo.uid, info.activityInfo.packageName); 788 if (mode != AppOpsManager.MODE_ALLOWED) { 789 if (DEBUG_BROADCAST) Slog.v(TAG, 790 "App op " + r.appOp + " not allowed for broadcast to uid " 791 + info.activityInfo.applicationInfo.uid + " pkg " 792 + info.activityInfo.packageName); 793 skip = true; 794 } 795 } 796 if (!skip) { 797 skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, 798 r.callingPid, r.resolvedType, info.activityInfo.applicationInfo.uid); 799 } 800 boolean isSingleton = false; 801 try { 802 isSingleton = mService.isSingleton(info.activityInfo.processName, 803 info.activityInfo.applicationInfo, 804 info.activityInfo.name, info.activityInfo.flags); 805 } catch (SecurityException e) { 806 Slog.w(TAG, e.getMessage()); 807 skip = true; 808 } 809 if ((info.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) { 810 if (ActivityManager.checkUidPermission( 811 android.Manifest.permission.INTERACT_ACROSS_USERS, 812 info.activityInfo.applicationInfo.uid) 813 != PackageManager.PERMISSION_GRANTED) { 814 Slog.w(TAG, "Permission Denial: Receiver " + component.flattenToShortString() 815 + " requests FLAG_SINGLE_USER, but app does not hold " 816 + android.Manifest.permission.INTERACT_ACROSS_USERS); 817 skip = true; 818 } 819 } 820 if (r.curApp != null && r.curApp.crashing) { 821 // If the target process is crashing, just skip it. 822 Slog.w(TAG, "Skipping deliver ordered [" + mQueueName + "] " + r 823 + " to " + r.curApp + ": process crashing"); 824 skip = true; 825 } 826 if (!skip) { 827 boolean isAvailable = false; 828 try { 829 isAvailable = AppGlobals.getPackageManager().isPackageAvailable( 830 info.activityInfo.packageName, 831 UserHandle.getUserId(info.activityInfo.applicationInfo.uid)); 832 } catch (Exception e) { 833 // all such failures mean we skip this receiver 834 Slog.w(TAG, "Exception getting recipient info for " 835 + info.activityInfo.packageName, e); 836 } 837 if (!isAvailable) { 838 if (DEBUG_BROADCAST) { 839 Slog.v(TAG, "Skipping delivery to " + info.activityInfo.packageName 840 + " / " + info.activityInfo.applicationInfo.uid 841 + " : package no longer available"); 842 } 843 skip = true; 844 } 845 } 846 847 if (skip) { 848 if (DEBUG_BROADCAST) Slog.v(TAG, 849 "Skipping delivery of ordered [" 850 + mQueueName + "] " + r + " for whatever reason"); 851 r.receiver = null; 852 r.curFilter = null; 853 r.state = BroadcastRecord.IDLE; 854 scheduleBroadcastsLocked(); 855 return; 856 } 857 858 r.state = BroadcastRecord.APP_RECEIVE; 859 String targetProcess = info.activityInfo.processName; 860 r.curComponent = component; 861 final int receiverUid = info.activityInfo.applicationInfo.uid; 862 // If it's a singleton, it needs to be the same app or a special app 863 if (r.callingUid != Process.SYSTEM_UID && isSingleton 864 && mService.isValidSingletonCall(r.callingUid, receiverUid)) { 865 info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0); 866 } 867 r.curReceiver = info.activityInfo; 868 if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) { 869 Slog.v(TAG_MU, "Updated broadcast record activity info for secondary user, " 870 + info.activityInfo + ", callingUid = " + r.callingUid + ", uid = " 871 + info.activityInfo.applicationInfo.uid); 872 } 873 874 // Broadcast is being executed, its package can't be stopped. 875 try { 876 AppGlobals.getPackageManager().setPackageStoppedState( 877 r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid)); 878 } catch (RemoteException e) { 879 } catch (IllegalArgumentException e) { 880 Slog.w(TAG, "Failed trying to unstop package " 881 + r.curComponent.getPackageName() + ": " + e); 882 } 883 884 // Is this receiver's application already running? 885 ProcessRecord app = mService.getProcessRecordLocked(targetProcess, 886 info.activityInfo.applicationInfo.uid, false); 887 if (app != null && app.thread != null) { 888 try { 889 app.addPackage(info.activityInfo.packageName, 890 info.activityInfo.applicationInfo.versionCode, mService.mProcessStats); 891 processCurBroadcastLocked(r, app); 892 return; 893 } catch (RemoteException e) { 894 Slog.w(TAG, "Exception when sending broadcast to " 895 + r.curComponent, e); 896 } catch (RuntimeException e) { 897 Slog.wtf(TAG, "Failed sending broadcast to " 898 + r.curComponent + " with " + r.intent, e); 899 // If some unexpected exception happened, just skip 900 // this broadcast. At this point we are not in the call 901 // from a client, so throwing an exception out from here 902 // will crash the entire system instead of just whoever 903 // sent the broadcast. 904 logBroadcastReceiverDiscardLocked(r); 905 finishReceiverLocked(r, r.resultCode, r.resultData, 906 r.resultExtras, r.resultAbort, false); 907 scheduleBroadcastsLocked(); 908 // We need to reset the state if we failed to start the receiver. 909 r.state = BroadcastRecord.IDLE; 910 return; 911 } 912 913 // If a dead object exception was thrown -- fall through to 914 // restart the application. 915 } 916 917 // Not running -- get it started, to be executed when the app comes up. 918 if (DEBUG_BROADCAST) Slog.v(TAG, 919 "Need to start app [" 920 + mQueueName + "] " + targetProcess + " for broadcast " + r); 921 if ((r.curApp=mService.startProcessLocked(targetProcess, 922 info.activityInfo.applicationInfo, true, 923 r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, 924 "broadcast", r.curComponent, 925 (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false)) 926 == null) { 927 // Ah, this recipient is unavailable. Finish it if necessary, 928 // and mark the broadcast record as ready for the next. 929 Slog.w(TAG, "Unable to launch app " 930 + info.activityInfo.applicationInfo.packageName + "/" 931 + info.activityInfo.applicationInfo.uid + " for broadcast " 932 + r.intent + ": process is bad"); 933 logBroadcastReceiverDiscardLocked(r); 934 finishReceiverLocked(r, r.resultCode, r.resultData, 935 r.resultExtras, r.resultAbort, false); 936 scheduleBroadcastsLocked(); 937 r.state = BroadcastRecord.IDLE; 938 return; 939 } 940 941 mPendingBroadcast = r; 942 mPendingBroadcastRecvIndex = recIdx; 943 } 944 } 945 946 final void setBroadcastTimeoutLocked(long timeoutTime) { 947 if (! mPendingBroadcastTimeoutMessage) { 948 Message msg = mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG, this); 949 mHandler.sendMessageAtTime(msg, timeoutTime); 950 mPendingBroadcastTimeoutMessage = true; 951 } 952 } 953 954 final void cancelBroadcastTimeoutLocked() { 955 if (mPendingBroadcastTimeoutMessage) { 956 mHandler.removeMessages(BROADCAST_TIMEOUT_MSG, this); 957 mPendingBroadcastTimeoutMessage = false; 958 } 959 } 960 961 final void broadcastTimeoutLocked(boolean fromMsg) { 962 if (fromMsg) { 963 mPendingBroadcastTimeoutMessage = false; 964 } 965 966 if (mOrderedBroadcasts.size() == 0) { 967 return; 968 } 969 970 long now = SystemClock.uptimeMillis(); 971 BroadcastRecord r = mOrderedBroadcasts.get(0); 972 if (fromMsg) { 973 if (mService.mDidDexOpt) { 974 // Delay timeouts until dexopt finishes. 975 mService.mDidDexOpt = false; 976 long timeoutTime = SystemClock.uptimeMillis() + mTimeoutPeriod; 977 setBroadcastTimeoutLocked(timeoutTime); 978 return; 979 } 980 if (!mService.mProcessesReady) { 981 // Only process broadcast timeouts if the system is ready. That way 982 // PRE_BOOT_COMPLETED broadcasts can't timeout as they are intended 983 // to do heavy lifting for system up. 984 return; 985 } 986 987 long timeoutTime = r.receiverTime + mTimeoutPeriod; 988 if (timeoutTime > now) { 989 // We can observe premature timeouts because we do not cancel and reset the 990 // broadcast timeout message after each receiver finishes. Instead, we set up 991 // an initial timeout then kick it down the road a little further as needed 992 // when it expires. 993 if (DEBUG_BROADCAST) Slog.v(TAG, 994 "Premature timeout [" 995 + mQueueName + "] @ " + now + ": resetting BROADCAST_TIMEOUT_MSG for " 996 + timeoutTime); 997 setBroadcastTimeoutLocked(timeoutTime); 998 return; 999 } 1000 } 1001 1002 BroadcastRecord br = mOrderedBroadcasts.get(0); 1003 if (br.state == BroadcastRecord.WAITING_SERVICES) { 1004 // In this case the broadcast had already finished, but we had decided to wait 1005 // for started services to finish as well before going on. So if we have actually 1006 // waited long enough time timeout the broadcast, let's give up on the whole thing 1007 // and just move on to the next. 1008 Slog.i(ActivityManagerService.TAG, "Waited long enough for: " + (br.curComponent != null 1009 ? br.curComponent.flattenToShortString() : "(null)")); 1010 br.curComponent = null; 1011 br.state = BroadcastRecord.IDLE; 1012 processNextBroadcast(false); 1013 return; 1014 } 1015 1016 Slog.w(TAG, "Timeout of broadcast " + r + " - receiver=" + r. receiver 1017 + ", started " + (now - r.receiverTime) + "ms ago"); 1018 r.receiverTime = now; 1019 r.anrCount++; 1020 1021 // Current receiver has passed its expiration date. 1022 if (r.nextReceiver <= 0) { 1023 Slog.w(TAG, "Timeout on receiver with nextReceiver <= 0"); 1024 return; 1025 } 1026 1027 ProcessRecord app = null; 1028 String anrMessage = null; 1029 1030 Object curReceiver = r.receivers.get(r.nextReceiver-1); 1031 Slog.w(TAG, "Receiver during timeout: " + curReceiver); 1032 logBroadcastReceiverDiscardLocked(r); 1033 if (curReceiver instanceof BroadcastFilter) { 1034 BroadcastFilter bf = (BroadcastFilter)curReceiver; 1035 if (bf.receiverList.pid != 0 1036 && bf.receiverList.pid != ActivityManagerService.MY_PID) { 1037 synchronized (mService.mPidsSelfLocked) { 1038 app = mService.mPidsSelfLocked.get( 1039 bf.receiverList.pid); 1040 } 1041 } 1042 } else { 1043 app = r.curApp; 1044 } 1045 1046 if (app != null) { 1047 anrMessage = "Broadcast of " + r.intent.toString(); 1048 } 1049 1050 if (mPendingBroadcast == r) { 1051 mPendingBroadcast = null; 1052 } 1053 1054 // Move on to the next receiver. 1055 finishReceiverLocked(r, r.resultCode, r.resultData, 1056 r.resultExtras, r.resultAbort, false); 1057 scheduleBroadcastsLocked(); 1058 1059 if (anrMessage != null) { 1060 // Post the ANR to the handler since we do not want to process ANRs while 1061 // potentially holding our lock. 1062 mHandler.post(new AppNotResponding(app, anrMessage)); 1063 } 1064 } 1065 1066 private final void addBroadcastToHistoryLocked(BroadcastRecord r) { 1067 if (r.callingUid < 0) { 1068 // This was from a registerReceiver() call; ignore it. 1069 return; 1070 } 1071 System.arraycopy(mBroadcastHistory, 0, mBroadcastHistory, 1, 1072 MAX_BROADCAST_HISTORY-1); 1073 r.finishTime = SystemClock.uptimeMillis(); 1074 mBroadcastHistory[0] = r; 1075 System.arraycopy(mBroadcastSummaryHistory, 0, mBroadcastSummaryHistory, 1, 1076 MAX_BROADCAST_SUMMARY_HISTORY-1); 1077 mBroadcastSummaryHistory[0] = r.intent; 1078 } 1079 1080 final void logBroadcastReceiverDiscardLocked(BroadcastRecord r) { 1081 if (r.nextReceiver > 0) { 1082 Object curReceiver = r.receivers.get(r.nextReceiver-1); 1083 if (curReceiver instanceof BroadcastFilter) { 1084 BroadcastFilter bf = (BroadcastFilter) curReceiver; 1085 EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_FILTER, 1086 bf.owningUserId, System.identityHashCode(r), 1087 r.intent.getAction(), 1088 r.nextReceiver - 1, 1089 System.identityHashCode(bf)); 1090 } else { 1091 ResolveInfo ri = (ResolveInfo)curReceiver; 1092 EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, 1093 UserHandle.getUserId(ri.activityInfo.applicationInfo.uid), 1094 System.identityHashCode(r), r.intent.getAction(), 1095 r.nextReceiver - 1, ri.toString()); 1096 } 1097 } else { 1098 Slog.w(TAG, "Discarding broadcast before first receiver is invoked: " 1099 + r); 1100 EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, 1101 -1, System.identityHashCode(r), 1102 r.intent.getAction(), 1103 r.nextReceiver, 1104 "NONE"); 1105 } 1106 } 1107 1108 final boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args, 1109 int opti, boolean dumpAll, String dumpPackage, boolean needSep) { 1110 if (mParallelBroadcasts.size() > 0 || mOrderedBroadcasts.size() > 0 1111 || mPendingBroadcast != null) { 1112 boolean printed = false; 1113 for (int i=mParallelBroadcasts.size()-1; i>=0; i--) { 1114 BroadcastRecord br = mParallelBroadcasts.get(i); 1115 if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) { 1116 continue; 1117 } 1118 if (!printed) { 1119 if (needSep) { 1120 pw.println(); 1121 } 1122 needSep = true; 1123 printed = true; 1124 pw.println(" Active broadcasts [" + mQueueName + "]:"); 1125 } 1126 pw.println(" Active Broadcast " + mQueueName + " #" + i + ":"); 1127 br.dump(pw, " "); 1128 } 1129 printed = false; 1130 needSep = true; 1131 for (int i=mOrderedBroadcasts.size()-1; i>=0; i--) { 1132 BroadcastRecord br = mOrderedBroadcasts.get(i); 1133 if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) { 1134 continue; 1135 } 1136 if (!printed) { 1137 if (needSep) { 1138 pw.println(); 1139 } 1140 needSep = true; 1141 printed = true; 1142 pw.println(" Active ordered broadcasts [" + mQueueName + "]:"); 1143 } 1144 pw.println(" Active Ordered Broadcast " + mQueueName + " #" + i + ":"); 1145 mOrderedBroadcasts.get(i).dump(pw, " "); 1146 } 1147 if (dumpPackage == null || (mPendingBroadcast != null 1148 && dumpPackage.equals(mPendingBroadcast.callerPackage))) { 1149 if (needSep) { 1150 pw.println(); 1151 } 1152 pw.println(" Pending broadcast [" + mQueueName + "]:"); 1153 if (mPendingBroadcast != null) { 1154 mPendingBroadcast.dump(pw, " "); 1155 } else { 1156 pw.println(" (null)"); 1157 } 1158 needSep = true; 1159 } 1160 } 1161 1162 int i; 1163 boolean printed = false; 1164 for (i=0; i<MAX_BROADCAST_HISTORY; i++) { 1165 BroadcastRecord r = mBroadcastHistory[i]; 1166 if (r == null) { 1167 break; 1168 } 1169 if (dumpPackage != null && !dumpPackage.equals(r.callerPackage)) { 1170 continue; 1171 } 1172 if (!printed) { 1173 if (needSep) { 1174 pw.println(); 1175 } 1176 needSep = true; 1177 pw.println(" Historical broadcasts [" + mQueueName + "]:"); 1178 printed = true; 1179 } 1180 if (dumpAll) { 1181 pw.print(" Historical Broadcast " + mQueueName + " #"); 1182 pw.print(i); pw.println(":"); 1183 r.dump(pw, " "); 1184 } else { 1185 pw.print(" #"); pw.print(i); pw.print(": "); pw.println(r); 1186 pw.print(" "); 1187 pw.println(r.intent.toShortString(false, true, true, false)); 1188 if (r.targetComp != null && r.targetComp != r.intent.getComponent()) { 1189 pw.print(" targetComp: "); pw.println(r.targetComp.toShortString()); 1190 } 1191 Bundle bundle = r.intent.getExtras(); 1192 if (bundle != null) { 1193 pw.print(" extras: "); pw.println(bundle.toString()); 1194 } 1195 } 1196 } 1197 1198 if (dumpPackage == null) { 1199 if (dumpAll) { 1200 i = 0; 1201 printed = false; 1202 } 1203 for (; i<MAX_BROADCAST_SUMMARY_HISTORY; i++) { 1204 Intent intent = mBroadcastSummaryHistory[i]; 1205 if (intent == null) { 1206 break; 1207 } 1208 if (!printed) { 1209 if (needSep) { 1210 pw.println(); 1211 } 1212 needSep = true; 1213 pw.println(" Historical broadcasts summary [" + mQueueName + "]:"); 1214 printed = true; 1215 } 1216 if (!dumpAll && i >= 50) { 1217 pw.println(" ..."); 1218 break; 1219 } 1220 pw.print(" #"); pw.print(i); pw.print(": "); 1221 pw.println(intent.toShortString(false, true, true, false)); 1222 Bundle bundle = intent.getExtras(); 1223 if (bundle != null) { 1224 pw.print(" extras: "); pw.println(bundle.toString()); 1225 } 1226 } 1227 } 1228 1229 return needSep; 1230 } 1231} 1232