BroadcastQueue.java revision 6f357d3284a833cc50a990e14b39f389b8972254
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.PackageInfo; 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) { 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) { 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 && 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, 431 data, extras, ordered, sticky, sendingUser, app.repProcState); 432 } else { 433 receiver.performReceive(intent, resultCode, data, extras, ordered, 434 sticky, sendingUser); 435 } 436 } 437 438 private final void deliverToRegisteredReceiverLocked(BroadcastRecord r, 439 BroadcastFilter filter, boolean ordered) { 440 boolean skip = false; 441 if (filter.requiredPermission != null) { 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 } 454 if (!skip && r.requiredPermission != null) { 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 } 469 if (r.appOp != AppOpsManager.OP_NONE) { 470 int mode = mService.mAppOpsService.noteOperation(r.appOp, 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 } 479 if (!skip) { 480 skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, 481 r.callingPid, r.resolvedType, filter.receiverList.uid); 482 } 483 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 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; 507 mService.updateOomAdjLocked(r.curApp, true); 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, 517 new Intent(r.intent), r.resultCode, r.resultData, 518 r.resultExtras, r.ordered, r.initialSticky, r.userId); 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) { 585 ProcessRecord proc = mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid); 586 isDead = proc == null || proc.crashing; 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, 668 r.resultData, r.resultExtras, false, false, r.userId); 669 // Set this to null so that the reference 670 // (local and remote) isn't kept in the mBroadcastHistory. 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; 741 ComponentName component = new ComponentName( 742 info.activityInfo.applicationInfo.packageName, 743 info.activityInfo.name); 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 756 + " due to receiver " + component.flattenToShortString()); 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 763 + " due to receiver " + component.flattenToShortString()); 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 " 779 + component.flattenToShortString() 780 + " requires " + r.requiredPermission 781 + " due to sender " + r.callerPackage 782 + " (uid " + r.callingUid + ")"); 783 skip = true; 784 } 785 } 786 if (r.appOp != AppOpsManager.OP_NONE) { 787 int mode = mService.mAppOpsService.noteOperation(r.appOp, 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 } 797 if (!skip) { 798 skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, 799 r.callingPid, r.resolvedType, info.activityInfo.applicationInfo.uid); 800 } 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 } 821 if (r.curApp != null && r.curApp.crashing) { 822 // If the target process is crashing, just skip it. 823 Slog.w(TAG, "Skipping deliver ordered [" + mQueueName + "] " + r 824 + " to " + r.curApp + ": process crashing"); 825 skip = true; 826 } 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 } 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; 861 r.curComponent = component; 862 if (r.callingUid != Process.SYSTEM_UID && isSingleton) { 863 info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0); 864 } 865 r.curReceiver = info.activityInfo; 866 if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) { 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( 875 r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid)); 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, 884 info.activityInfo.applicationInfo.uid, false); 885 if (app != null && app.thread != null) { 886 try { 887 app.addPackage(info.activityInfo.packageName, mService.mProcessStats); 888 processCurBroadcastLocked(r, app); 889 return; 890 } catch (RemoteException e) { 891 Slog.w(TAG, "Exception when sending broadcast to " 892 + r.curComponent, e); 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, 903 r.resultExtras, r.resultAbort, false); 904 scheduleBroadcastsLocked(); 905 // We need to reset the state if we failed to start the receiver. 906 r.state = BroadcastRecord.IDLE; 907 return; 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, 922 (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false)) 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, 932 r.resultExtras, r.resultAbort, false); 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 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 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, 1053 r.resultExtras, r.resultAbort, false); 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; 1072 System.arraycopy(mBroadcastSummaryHistory, 0, mBroadcastSummaryHistory, 1, 1073 MAX_BROADCAST_SUMMARY_HISTORY-1); 1074 mBroadcastSummaryHistory[0] = r.intent; 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, 1083 bf.owningUserId, System.identityHashCode(r), 1084 r.intent.getAction(), 1085 r.nextReceiver - 1, 1086 System.identityHashCode(bf)); 1087 } else { 1088 ResolveInfo ri = (ResolveInfo)curReceiver; 1089 EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, 1090 UserHandle.getUserId(ri.activityInfo.applicationInfo.uid), 1091 System.identityHashCode(r), r.intent.getAction(), 1092 r.nextReceiver - 1, ri.toString()); 1093 } 1094 } else { 1095 Slog.w(TAG, "Discarding broadcast before first receiver is invoked: " 1096 + r); 1097 EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, 1098 -1, System.identityHashCode(r), 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(); 1118 } 1119 needSep = true; 1120 printed = true; 1121 pw.println(" Active broadcasts [" + mQueueName + "]:"); 1122 } 1123 pw.println(" Active Broadcast " + mQueueName + " #" + i + ":"); 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; 1138 printed = true; 1139 pw.println(" Active ordered broadcasts [" + mQueueName + "]:"); 1140 } 1141 pw.println(" Active Ordered Broadcast " + mQueueName + " #" + i + ":"); 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 1159 int i; 1160 boolean printed = false; 1161 for (i=0; i<MAX_BROADCAST_HISTORY; i++) { 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) { 1178 pw.print(" Historical Broadcast " + mQueueName + " #"); 1179 pw.print(i); pw.println(":"); 1180 r.dump(pw, " "); 1181 } else { 1182 pw.print(" #"); pw.print(i); pw.print(": "); pw.println(r); 1183 pw.print(" "); 1184 pw.println(r.intent.toShortString(false, true, true, false)); 1185 if (r.targetComp != null && r.targetComp != r.intent.getComponent()) { 1186 pw.print(" targetComp: "); pw.println(r.targetComp.toShortString()); 1187 } 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) { 1214 pw.println(" ..."); 1215 break; 1216 } 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 } 1223 } 1224 } 1225 1226 return needSep; 1227 } 1228} 1229