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; |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 21 | import java.text.SimpleDateFormat; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 22 | import java.util.ArrayList; |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 23 | import java.util.Date; |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 24 | import java.util.Set; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 25 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 27 | import android.app.AppGlobals; |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 28 | import android.app.AppOpsManager; |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 29 | import android.app.BroadcastOptions; |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 30 | import android.app.PendingIntent; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
| 32 | import android.content.IIntentReceiver; |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 33 | import android.content.IIntentSender; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 34 | import android.content.Intent; |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 35 | import android.content.IntentSender; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 36 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
| 38 | import android.content.pm.ResolveInfo; |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 39 | import android.os.Build; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 40 | import android.os.Bundle; |
Joe Onorato | 5869d1c | 2016-04-20 15:38:07 -0700 | [diff] [blame^] | 41 | import android.os.DeadObjectException; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 42 | import android.os.Handler; |
| 43 | import android.os.IBinder; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 44 | import android.os.Looper; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 45 | import android.os.Message; |
| 46 | import android.os.Process; |
| 47 | import android.os.RemoteException; |
| 48 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 49 | import android.os.UserHandle; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 50 | import android.util.EventLog; |
| 51 | import android.util.Slog; |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 52 | import android.util.TimeUtils; |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 53 | import com.android.server.DeviceIdleController; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 54 | |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 55 | import static com.android.server.am.ActivityManagerDebugConfig.*; |
| 56 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 57 | /** |
| 58 | * BROADCASTS |
| 59 | * |
| 60 | * We keep two broadcast queues and associated bookkeeping, one for those at |
| 61 | * foreground priority, and one for normal (background-priority) broadcasts. |
| 62 | */ |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 63 | public final class BroadcastQueue { |
Wale Ogunwale | bfac468 | 2015-04-08 14:33:21 -0700 | [diff] [blame] | 64 | private static final String TAG = "BroadcastQueue"; |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 65 | private static final String TAG_MU = TAG + POSTFIX_MU; |
| 66 | private static final String TAG_BROADCAST = TAG + POSTFIX_BROADCAST; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 67 | |
Dianne Hackborn | 4c51de4 | 2013-10-16 23:34:35 -0700 | [diff] [blame] | 68 | static final int MAX_BROADCAST_HISTORY = ActivityManager.isLowRamDeviceStatic() ? 10 : 50; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 69 | static final int MAX_BROADCAST_SUMMARY_HISTORY |
Dianne Hackborn | 4c51de4 | 2013-10-16 23:34:35 -0700 | [diff] [blame] | 70 | = ActivityManager.isLowRamDeviceStatic() ? 25 : 300; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 71 | |
| 72 | final ActivityManagerService mService; |
| 73 | |
| 74 | /** |
| 75 | * Recognizable moniker for this queue |
| 76 | */ |
| 77 | final String mQueueName; |
| 78 | |
| 79 | /** |
| 80 | * Timeout period for this queue's broadcasts |
| 81 | */ |
| 82 | final long mTimeoutPeriod; |
| 83 | |
| 84 | /** |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 85 | * If true, we can delay broadcasts while waiting services to finish in the previous |
| 86 | * receiver's process. |
| 87 | */ |
| 88 | final boolean mDelayBehindServices; |
| 89 | |
| 90 | /** |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 91 | * Lists of all active broadcasts that are to be executed immediately |
| 92 | * (without waiting for another broadcast to finish). Currently this only |
| 93 | * contains broadcasts to registered receivers, to avoid spinning up |
| 94 | * a bunch of processes to execute IntentReceiver components. Background- |
| 95 | * and foreground-priority broadcasts are queued separately. |
| 96 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 97 | final ArrayList<BroadcastRecord> mParallelBroadcasts = new ArrayList<>(); |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 99 | /** |
| 100 | * List of all active broadcasts that are to be executed one at a time. |
| 101 | * The object at the top of the list is the currently activity broadcasts; |
| 102 | * those after it are waiting for the top to finish. As with parallel |
| 103 | * broadcasts, separate background- and foreground-priority queues are |
| 104 | * maintained. |
| 105 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 106 | final ArrayList<BroadcastRecord> mOrderedBroadcasts = new ArrayList<>(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 107 | |
| 108 | /** |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 109 | * Historical data of past broadcasts, for debugging. This is a ring buffer |
| 110 | * whose last element is at mHistoryNext. |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 111 | */ |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 112 | final BroadcastRecord[] mBroadcastHistory = new BroadcastRecord[MAX_BROADCAST_HISTORY]; |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 113 | int mHistoryNext = 0; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 114 | |
| 115 | /** |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 116 | * Summary of historical data of past broadcasts, for debugging. This is a |
| 117 | * ring buffer whose last element is at mSummaryHistoryNext. |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 118 | */ |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 119 | final Intent[] mBroadcastSummaryHistory = new Intent[MAX_BROADCAST_SUMMARY_HISTORY]; |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 120 | int mSummaryHistoryNext = 0; |
| 121 | |
| 122 | /** |
| 123 | * Various milestone timestamps of entries in the mBroadcastSummaryHistory ring |
| 124 | * buffer, also tracked via the mSummaryHistoryNext index. These are all in wall |
| 125 | * clock time, not elapsed. |
| 126 | */ |
| 127 | final long[] mSummaryHistoryEnqueueTime = new long[MAX_BROADCAST_SUMMARY_HISTORY]; |
| 128 | final long[] mSummaryHistoryDispatchTime = new long[MAX_BROADCAST_SUMMARY_HISTORY]; |
| 129 | final long[] mSummaryHistoryFinishTime = new long[MAX_BROADCAST_SUMMARY_HISTORY]; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 132 | * Set when we current have a BROADCAST_INTENT_MSG in flight. |
| 133 | */ |
| 134 | boolean mBroadcastsScheduled = false; |
| 135 | |
| 136 | /** |
| 137 | * True if we have a pending unexpired BROADCAST_TIMEOUT_MSG posted to our handler. |
| 138 | */ |
| 139 | boolean mPendingBroadcastTimeoutMessage; |
| 140 | |
| 141 | /** |
| 142 | * Intent broadcasts that we have tried to start, but are |
| 143 | * waiting for the application's process to be created. We only |
| 144 | * need one per scheduling class (instead of a list) because we always |
| 145 | * process broadcasts one at a time, so no others can be started while |
| 146 | * waiting for this one. |
| 147 | */ |
| 148 | BroadcastRecord mPendingBroadcast = null; |
| 149 | |
| 150 | /** |
| 151 | * The receiver index that is pending, to restart the broadcast if needed. |
| 152 | */ |
| 153 | int mPendingBroadcastRecvIndex; |
| 154 | |
| 155 | static final int BROADCAST_INTENT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG; |
| 156 | static final int BROADCAST_TIMEOUT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG + 1; |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 157 | static final int SCHEDULE_TEMP_WHITELIST_MSG |
| 158 | = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG + 2; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 159 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 160 | final BroadcastHandler mHandler; |
| 161 | |
| 162 | private final class BroadcastHandler extends Handler { |
| 163 | public BroadcastHandler(Looper looper) { |
| 164 | super(looper, null, true); |
| 165 | } |
| 166 | |
| 167 | @Override |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 168 | public void handleMessage(Message msg) { |
| 169 | switch (msg.what) { |
| 170 | case BROADCAST_INTENT_MSG: { |
| 171 | if (DEBUG_BROADCAST) Slog.v( |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 172 | TAG_BROADCAST, "Received BROADCAST_INTENT_MSG"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 173 | processNextBroadcast(true); |
| 174 | } break; |
| 175 | case BROADCAST_TIMEOUT_MSG: { |
| 176 | synchronized (mService) { |
| 177 | broadcastTimeoutLocked(true); |
| 178 | } |
| 179 | } break; |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 180 | case SCHEDULE_TEMP_WHITELIST_MSG: { |
| 181 | DeviceIdleController.LocalService dic = mService.mLocalDeviceIdleController; |
| 182 | if (dic != null) { |
| 183 | dic.addPowerSaveTempWhitelistAppDirect(UserHandle.getAppId(msg.arg1), |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 184 | msg.arg2, true, (String)msg.obj); |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 185 | } |
| 186 | } break; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 187 | } |
| 188 | } |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 189 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 190 | |
| 191 | private final class AppNotResponding implements Runnable { |
| 192 | private final ProcessRecord mApp; |
| 193 | private final String mAnnotation; |
| 194 | |
| 195 | public AppNotResponding(ProcessRecord app, String annotation) { |
| 196 | mApp = app; |
| 197 | mAnnotation = annotation; |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void run() { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 202 | mService.mAppErrors.appNotResponding(mApp, null, null, false, mAnnotation); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 206 | BroadcastQueue(ActivityManagerService service, Handler handler, |
| 207 | String name, long timeoutPeriod, boolean allowDelayBehindServices) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 208 | mService = service; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 209 | mHandler = new BroadcastHandler(handler.getLooper()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 210 | mQueueName = name; |
| 211 | mTimeoutPeriod = timeoutPeriod; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 212 | mDelayBehindServices = allowDelayBehindServices; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | public boolean isPendingBroadcastProcessLocked(int pid) { |
| 216 | return mPendingBroadcast != null && mPendingBroadcast.curApp.pid == pid; |
| 217 | } |
| 218 | |
| 219 | public void enqueueParallelBroadcastLocked(BroadcastRecord r) { |
| 220 | mParallelBroadcasts.add(r); |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 221 | r.enqueueClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | public void enqueueOrderedBroadcastLocked(BroadcastRecord r) { |
| 225 | mOrderedBroadcasts.add(r); |
Jeff Brown | 9fb3fd1 | 2014-09-29 15:32:12 -0700 | [diff] [blame] | 226 | r.enqueueClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | public final boolean replaceParallelBroadcastLocked(BroadcastRecord r) { |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 230 | for (int i = mParallelBroadcasts.size() - 1; i >= 0; i--) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 231 | if (r.intent.filterEquals(mParallelBroadcasts.get(i).intent)) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 232 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 233 | "***** DROPPING PARALLEL [" |
| 234 | + mQueueName + "]: " + r.intent); |
| 235 | mParallelBroadcasts.set(i, r); |
| 236 | return true; |
| 237 | } |
| 238 | } |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | public final boolean replaceOrderedBroadcastLocked(BroadcastRecord r) { |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 243 | for (int i = mOrderedBroadcasts.size() - 1; i > 0; i--) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 244 | if (r.intent.filterEquals(mOrderedBroadcasts.get(i).intent)) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 245 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 246 | "***** DROPPING ORDERED [" |
| 247 | + mQueueName + "]: " + r.intent); |
| 248 | mOrderedBroadcasts.set(i, r); |
| 249 | return true; |
| 250 | } |
| 251 | } |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | private final void processCurBroadcastLocked(BroadcastRecord r, |
| 256 | ProcessRecord app) throws RemoteException { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 257 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 258 | "Process cur broadcast " + r + " for app " + app); |
| 259 | if (app.thread == null) { |
| 260 | throw new RemoteException(); |
| 261 | } |
| 262 | r.receiver = app.thread.asBinder(); |
| 263 | r.curApp = app; |
| 264 | app.curReceiver = r; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 265 | app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 266 | mService.updateLruProcessLocked(app, false, null); |
| 267 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 268 | |
| 269 | // Tell the application to launch this receiver. |
| 270 | r.intent.setComponent(r.curComponent); |
| 271 | |
| 272 | boolean started = false; |
| 273 | try { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 274 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 275 | "Delivering to component " + r.curComponent |
| 276 | + ": " + r); |
Nicolas Geoffray | 27c0737 | 2015-11-05 16:54:09 +0000 | [diff] [blame] | 277 | mService.notifyPackageUse(r.intent.getComponent().getPackageName()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 278 | app.thread.scheduleReceiver(new Intent(r.intent), r.curReceiver, |
| 279 | mService.compatibilityInfoForPackageLocked(r.curReceiver.applicationInfo), |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 280 | r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId, |
| 281 | app.repProcState); |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 282 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 283 | "Process cur broadcast " + r + " DELIVERED for app " + app); |
| 284 | started = true; |
| 285 | } finally { |
| 286 | if (!started) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 287 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 288 | "Process cur broadcast " + r + ": NOT STARTED!"); |
| 289 | r.receiver = null; |
| 290 | r.curApp = null; |
| 291 | app.curReceiver = null; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | public boolean sendPendingBroadcastsLocked(ProcessRecord app) { |
| 297 | boolean didSomething = false; |
| 298 | final BroadcastRecord br = mPendingBroadcast; |
| 299 | if (br != null && br.curApp.pid == app.pid) { |
| 300 | try { |
| 301 | mPendingBroadcast = null; |
| 302 | processCurBroadcastLocked(br, app); |
| 303 | didSomething = true; |
| 304 | } catch (Exception e) { |
| 305 | Slog.w(TAG, "Exception in new application when starting receiver " |
| 306 | + br.curComponent.flattenToShortString(), e); |
| 307 | logBroadcastReceiverDiscardLocked(br); |
| 308 | finishReceiverLocked(br, br.resultCode, br.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 309 | br.resultExtras, br.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 310 | scheduleBroadcastsLocked(); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 311 | // 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] | 312 | br.state = BroadcastRecord.IDLE; |
| 313 | throw new RuntimeException(e.getMessage()); |
| 314 | } |
| 315 | } |
| 316 | return didSomething; |
| 317 | } |
| 318 | |
| 319 | public void skipPendingBroadcastLocked(int pid) { |
| 320 | final BroadcastRecord br = mPendingBroadcast; |
| 321 | if (br != null && br.curApp.pid == pid) { |
| 322 | br.state = BroadcastRecord.IDLE; |
| 323 | br.nextReceiver = mPendingBroadcastRecvIndex; |
| 324 | mPendingBroadcast = null; |
| 325 | scheduleBroadcastsLocked(); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | public void skipCurrentReceiverLocked(ProcessRecord app) { |
Wale Ogunwale | 24b243d | 2015-07-17 07:20:57 -0700 | [diff] [blame] | 330 | BroadcastRecord r = null; |
| 331 | if (mOrderedBroadcasts.size() > 0) { |
| 332 | BroadcastRecord br = mOrderedBroadcasts.get(0); |
| 333 | if (br.curApp == app) { |
| 334 | r = br; |
| 335 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 336 | } |
riddle_hsu | 01eb7fa | 2015-03-04 17:27:05 +0800 | [diff] [blame] | 337 | if (r == null && mPendingBroadcast != null && mPendingBroadcast.curApp == app) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 338 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 339 | "[" + mQueueName + "] skip & discard pending app " + r); |
riddle_hsu | 01eb7fa | 2015-03-04 17:27:05 +0800 | [diff] [blame] | 340 | r = mPendingBroadcast; |
| 341 | } |
| 342 | |
| 343 | if (r != null) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 344 | logBroadcastReceiverDiscardLocked(r); |
| 345 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 346 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 347 | scheduleBroadcastsLocked(); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | public void scheduleBroadcastsLocked() { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 352 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Schedule broadcasts [" |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 353 | + mQueueName + "]: current=" |
| 354 | + mBroadcastsScheduled); |
| 355 | |
| 356 | if (mBroadcastsScheduled) { |
| 357 | return; |
| 358 | } |
| 359 | mHandler.sendMessage(mHandler.obtainMessage(BROADCAST_INTENT_MSG, this)); |
| 360 | mBroadcastsScheduled = true; |
| 361 | } |
| 362 | |
| 363 | public BroadcastRecord getMatchingOrderedReceiver(IBinder receiver) { |
| 364 | if (mOrderedBroadcasts.size() > 0) { |
| 365 | final BroadcastRecord r = mOrderedBroadcasts.get(0); |
| 366 | if (r != null && r.receiver == receiver) { |
| 367 | return r; |
| 368 | } |
| 369 | } |
| 370 | return null; |
| 371 | } |
| 372 | |
| 373 | public boolean finishReceiverLocked(BroadcastRecord r, int resultCode, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 374 | String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices) { |
| 375 | final int state = r.state; |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 376 | final ActivityInfo receiver = r.curReceiver; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 377 | r.state = BroadcastRecord.IDLE; |
| 378 | if (state == BroadcastRecord.IDLE) { |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 379 | Slog.w(TAG, "finishReceiver [" + mQueueName + "] called but state is IDLE"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 380 | } |
| 381 | r.receiver = null; |
| 382 | r.intent.setComponent(null); |
Guobin Zhang | 04d0bb6 | 2014-03-07 17:47:10 +0800 | [diff] [blame] | 383 | if (r.curApp != null && r.curApp.curReceiver == r) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 384 | r.curApp.curReceiver = null; |
| 385 | } |
| 386 | if (r.curFilter != null) { |
| 387 | r.curFilter.receiverList.curBroadcast = null; |
| 388 | } |
| 389 | r.curFilter = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 390 | r.curReceiver = null; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 391 | r.curApp = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 392 | mPendingBroadcast = null; |
| 393 | |
| 394 | r.resultCode = resultCode; |
| 395 | r.resultData = resultData; |
| 396 | r.resultExtras = resultExtras; |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 397 | if (resultAbort && (r.intent.getFlags()&Intent.FLAG_RECEIVER_NO_ABORT) == 0) { |
| 398 | r.resultAbort = resultAbort; |
| 399 | } else { |
| 400 | r.resultAbort = false; |
| 401 | } |
| 402 | |
| 403 | if (waitForServices && r.curComponent != null && r.queue.mDelayBehindServices |
| 404 | && r.queue.mOrderedBroadcasts.size() > 0 |
| 405 | && r.queue.mOrderedBroadcasts.get(0) == r) { |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 406 | ActivityInfo nextReceiver; |
| 407 | if (r.nextReceiver < r.receivers.size()) { |
| 408 | Object obj = r.receivers.get(r.nextReceiver); |
| 409 | nextReceiver = (obj instanceof ActivityInfo) ? (ActivityInfo)obj : null; |
| 410 | } else { |
| 411 | nextReceiver = null; |
| 412 | } |
| 413 | // Don't do this if the next receive is in the same process as the current one. |
| 414 | if (receiver == null || nextReceiver == null |
| 415 | || receiver.applicationInfo.uid != nextReceiver.applicationInfo.uid |
| 416 | || !receiver.processName.equals(nextReceiver.processName)) { |
| 417 | // In this case, we are ready to process the next receiver for the current broadcast, |
| 418 | //Â but are on a queue that would like to wait for services to finish before moving |
| 419 | // on. If there are background services currently starting, then we will go into a |
| 420 | // special state where we hold off on continuing this broadcast until they are done. |
| 421 | if (mService.mServices.hasBackgroundServices(r.userId)) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 422 | Slog.i(TAG, "Delay finish: " + r.curComponent.flattenToShortString()); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 423 | r.state = BroadcastRecord.WAITING_SERVICES; |
| 424 | return false; |
| 425 | } |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | r.curComponent = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 430 | |
| 431 | // We will process the next receiver right now if this is finishing |
| 432 | // an app receiver (which is always asynchronous) or after we have |
| 433 | // come back from calling a receiver. |
| 434 | return state == BroadcastRecord.APP_RECEIVE |
| 435 | || state == BroadcastRecord.CALL_DONE_RECEIVE; |
| 436 | } |
| 437 | |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 438 | public void backgroundServicesFinishedLocked(int userId) { |
| 439 | if (mOrderedBroadcasts.size() > 0) { |
| 440 | BroadcastRecord br = mOrderedBroadcasts.get(0); |
| 441 | if (br.userId == userId && br.state == BroadcastRecord.WAITING_SERVICES) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 442 | Slog.i(TAG, "Resuming delayed broadcast"); |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 443 | br.curComponent = null; |
| 444 | br.state = BroadcastRecord.IDLE; |
| 445 | processNextBroadcast(false); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
Joe Onorato | 5869d1c | 2016-04-20 15:38:07 -0700 | [diff] [blame^] | 450 | private void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 451 | Intent intent, int resultCode, String data, Bundle extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 452 | boolean ordered, boolean sticky, int sendingUser) throws RemoteException { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 453 | // Send the intent to the receiver asynchronously using one-way binder calls. |
Craig Mautner | 38c1a5f | 2014-07-21 15:36:37 +0000 | [diff] [blame] | 454 | if (app != null) { |
| 455 | if (app.thread != null) { |
| 456 | // If we have an app thread, do the call through that so it is |
| 457 | // correctly ordered with other one-way calls. |
Joe Onorato | 5869d1c | 2016-04-20 15:38:07 -0700 | [diff] [blame^] | 458 | try { |
| 459 | app.thread.scheduleRegisteredReceiver(receiver, intent, resultCode, |
| 460 | data, extras, ordered, sticky, sendingUser, app.repProcState); |
| 461 | // TODO: Uncomment this when (b/28322359) is fixed and we aren't getting |
| 462 | // DeadObjectException when the process isn't actually dead. |
| 463 | //} catch (DeadObjectException ex) { |
| 464 | // Failed to call into the process. It's dying so just let it die and move on. |
| 465 | // throw ex; |
| 466 | } catch (RemoteException ex) { |
| 467 | // Failed to call into the process. It's either dying or wedged. Kill it gently. |
| 468 | synchronized (mService) { |
| 469 | Slog.w(TAG, "Can't deliver broadcast to " + app.processName |
| 470 | + " (pid " + app.pid + "). Crashing it."); |
| 471 | app.scheduleCrash("can't deliver broadcast"); |
| 472 | } |
| 473 | throw ex; |
| 474 | } |
Craig Mautner | 38c1a5f | 2014-07-21 15:36:37 +0000 | [diff] [blame] | 475 | } else { |
| 476 | // Application has died. Receiver doesn't exist. |
| 477 | throw new RemoteException("app.thread must not be null"); |
| 478 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 479 | } else { |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 480 | receiver.performReceive(intent, resultCode, data, extras, ordered, |
| 481 | sticky, sendingUser); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 485 | private void deliverToRegisteredReceiverLocked(BroadcastRecord r, |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 486 | BroadcastFilter filter, boolean ordered, int index) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 487 | boolean skip = false; |
Amith Yamasani | 8bf06ed | 2012-08-27 19:30:30 -0700 | [diff] [blame] | 488 | if (filter.requiredPermission != null) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 489 | int perm = mService.checkComponentPermission(filter.requiredPermission, |
| 490 | r.callingPid, r.callingUid, -1, true); |
| 491 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 492 | Slog.w(TAG, "Permission Denial: broadcasting " |
| 493 | + r.intent.toString() |
| 494 | + " from " + r.callerPackage + " (pid=" |
| 495 | + r.callingPid + ", uid=" + r.callingUid + ")" |
| 496 | + " requires " + filter.requiredPermission |
| 497 | + " due to registered receiver " + filter); |
| 498 | skip = true; |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 499 | } else { |
| 500 | final int opCode = AppOpsManager.permissionToOpCode(filter.requiredPermission); |
| 501 | if (opCode != AppOpsManager.OP_NONE |
| 502 | && mService.mAppOpsService.noteOperation(opCode, r.callingUid, |
| 503 | r.callerPackage) != AppOpsManager.MODE_ALLOWED) { |
| 504 | Slog.w(TAG, "Appop Denial: broadcasting " |
| 505 | + r.intent.toString() |
| 506 | + " from " + r.callerPackage + " (pid=" |
| 507 | + r.callingPid + ", uid=" + r.callingUid + ")" |
| 508 | + " requires appop " + AppOpsManager.permissionToOp( |
| 509 | filter.requiredPermission) |
| 510 | + " due to registered receiver " + filter); |
| 511 | skip = true; |
| 512 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 513 | } |
| 514 | } |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 515 | if (!skip && r.requiredPermissions != null && r.requiredPermissions.length > 0) { |
| 516 | for (int i = 0; i < r.requiredPermissions.length; i++) { |
| 517 | String requiredPermission = r.requiredPermissions[i]; |
| 518 | int perm = mService.checkComponentPermission(requiredPermission, |
| 519 | filter.receiverList.pid, filter.receiverList.uid, -1, true); |
| 520 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 521 | Slog.w(TAG, "Permission Denial: receiving " |
| 522 | + r.intent.toString() |
| 523 | + " to " + filter.receiverList.app |
| 524 | + " (pid=" + filter.receiverList.pid |
| 525 | + ", uid=" + filter.receiverList.uid + ")" |
| 526 | + " requires " + requiredPermission |
| 527 | + " due to sender " + r.callerPackage |
| 528 | + " (uid " + r.callingUid + ")"); |
| 529 | skip = true; |
| 530 | break; |
| 531 | } |
| 532 | int appOp = AppOpsManager.permissionToOpCode(requiredPermission); |
Svetoslav | fb9ec50 | 2015-09-01 14:45:18 -0700 | [diff] [blame] | 533 | if (appOp != AppOpsManager.OP_NONE && appOp != r.appOp |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 534 | && mService.mAppOpsService.noteOperation(appOp, |
| 535 | filter.receiverList.uid, filter.packageName) |
| 536 | != AppOpsManager.MODE_ALLOWED) { |
| 537 | Slog.w(TAG, "Appop Denial: receiving " |
| 538 | + r.intent.toString() |
| 539 | + " to " + filter.receiverList.app |
| 540 | + " (pid=" + filter.receiverList.pid |
| 541 | + ", uid=" + filter.receiverList.uid + ")" |
| 542 | + " requires appop " + AppOpsManager.permissionToOp( |
| 543 | requiredPermission) |
| 544 | + " due to sender " + r.callerPackage |
| 545 | + " (uid " + r.callingUid + ")"); |
| 546 | skip = true; |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | if (!skip && (r.requiredPermissions == null || r.requiredPermissions.length == 0)) { |
| 552 | int perm = mService.checkComponentPermission(null, |
Fyodor Kupolov | e37520b | 2015-07-14 22:29:21 +0000 | [diff] [blame] | 553 | filter.receiverList.pid, filter.receiverList.uid, -1, true); |
| 554 | if (perm != PackageManager.PERMISSION_GRANTED) { |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 555 | Slog.w(TAG, "Permission Denial: security check failed when receiving " |
Fyodor Kupolov | e37520b | 2015-07-14 22:29:21 +0000 | [diff] [blame] | 556 | + r.intent.toString() |
| 557 | + " to " + filter.receiverList.app |
| 558 | + " (pid=" + filter.receiverList.pid |
| 559 | + ", uid=" + filter.receiverList.uid + ")" |
Fyodor Kupolov | e37520b | 2015-07-14 22:29:21 +0000 | [diff] [blame] | 560 | + " due to sender " + r.callerPackage |
| 561 | + " (uid " + r.callingUid + ")"); |
| 562 | skip = true; |
| 563 | } |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 564 | } |
| 565 | if (!skip && r.appOp != AppOpsManager.OP_NONE |
| 566 | && mService.mAppOpsService.noteOperation(r.appOp, |
| 567 | filter.receiverList.uid, filter.packageName) |
| 568 | != AppOpsManager.MODE_ALLOWED) { |
| 569 | Slog.w(TAG, "Appop Denial: receiving " |
| 570 | + r.intent.toString() |
| 571 | + " to " + filter.receiverList.app |
| 572 | + " (pid=" + filter.receiverList.pid |
| 573 | + ", uid=" + filter.receiverList.uid + ")" |
| 574 | + " requires appop " + AppOpsManager.opToName(r.appOp) |
| 575 | + " due to sender " + r.callerPackage |
| 576 | + " (uid " + r.callingUid + ")"); |
| 577 | skip = true; |
Fyodor Kupolov | b4e7283 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 578 | } |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 579 | if (!skip) { |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 580 | final int allowed = mService.checkAllowBackgroundLocked(filter.receiverList.uid, |
Dianne Hackborn | e91f3e7 | 2016-03-25 18:48:15 -0700 | [diff] [blame] | 581 | filter.packageName, -1, true); |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 582 | if (allowed == ActivityManager.APP_START_MODE_DISABLED) { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 583 | Slog.w(TAG, "Background execution not allowed: receiving " |
| 584 | + r.intent |
| 585 | + " to " + filter.receiverList.app |
| 586 | + " (pid=" + filter.receiverList.pid |
| 587 | + ", uid=" + filter.receiverList.uid + ")"); |
| 588 | skip = true; |
| 589 | } |
| 590 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 591 | |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 592 | if (!mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, |
| 593 | r.callingPid, r.resolvedType, filter.receiverList.uid)) { |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 594 | skip = true; |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 595 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 596 | |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 597 | if (!skip && (filter.receiverList.app == null || filter.receiverList.app.crashing)) { |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 598 | Slog.w(TAG, "Skipping deliver [" + mQueueName + "] " + r |
| 599 | + " to " + filter.receiverList + ": process crashing"); |
| 600 | skip = true; |
| 601 | } |
| 602 | |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 603 | if (skip) { |
| 604 | r.delivery[index] = BroadcastRecord.DELIVERY_SKIPPED; |
| 605 | return; |
| 606 | } |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 607 | |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 608 | // If permissions need a review before any of the app components can run, we drop |
| 609 | // the broadcast and if the calling app is in the foreground and the broadcast is |
| 610 | // explicit we launch the review UI passing it a pending intent to send the skipped |
| 611 | // broadcast. |
| 612 | if (Build.PERMISSIONS_REVIEW_REQUIRED) { |
| 613 | if (!requestStartTargetPermissionsReviewIfNeededLocked(r, filter.packageName, |
| 614 | filter.owningUserId)) { |
| 615 | r.delivery[index] = BroadcastRecord.DELIVERY_SKIPPED; |
| 616 | return; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 617 | } |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | r.delivery[index] = BroadcastRecord.DELIVERY_DELIVERED; |
| 621 | |
| 622 | // If this is not being sent as an ordered broadcast, then we |
| 623 | // don't want to touch the fields that keep track of the current |
| 624 | // state of ordered broadcasts. |
| 625 | if (ordered) { |
| 626 | r.receiver = filter.receiverList.receiver.asBinder(); |
| 627 | r.curFilter = filter; |
| 628 | filter.receiverList.curBroadcast = r; |
| 629 | r.state = BroadcastRecord.CALL_IN_RECEIVE; |
| 630 | if (filter.receiverList.app != null) { |
| 631 | // Bump hosting application to no longer be in background |
| 632 | // scheduling class. Note that we can't do that if there |
| 633 | // isn't an app... but we can only be in that case for |
| 634 | // things that directly call the IActivityManager API, which |
| 635 | // are already core system stuff so don't matter for this. |
| 636 | r.curApp = filter.receiverList.app; |
| 637 | filter.receiverList.app.curReceiver = r; |
| 638 | mService.updateOomAdjLocked(r.curApp); |
| 639 | } |
| 640 | } |
| 641 | try { |
| 642 | if (DEBUG_BROADCAST_LIGHT) Slog.i(TAG_BROADCAST, |
| 643 | "Delivering to " + filter + " : " + r); |
| 644 | performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver, |
| 645 | new Intent(r.intent), r.resultCode, r.resultData, |
| 646 | r.resultExtras, r.ordered, r.initialSticky, r.userId); |
| 647 | if (ordered) { |
| 648 | r.state = BroadcastRecord.CALL_DONE_RECEIVE; |
| 649 | } |
| 650 | } catch (RemoteException e) { |
| 651 | Slog.w(TAG, "Failure sending broadcast " + r.intent, e); |
| 652 | if (ordered) { |
| 653 | r.receiver = null; |
| 654 | r.curFilter = null; |
| 655 | filter.receiverList.curBroadcast = null; |
| 656 | if (filter.receiverList.app != null) { |
| 657 | filter.receiverList.app.curReceiver = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 663 | private boolean requestStartTargetPermissionsReviewIfNeededLocked( |
| 664 | BroadcastRecord receiverRecord, String receivingPackageName, |
| 665 | final int receivingUserId) { |
| 666 | if (!mService.getPackageManagerInternalLocked().isPermissionsReviewRequired( |
| 667 | receivingPackageName, receivingUserId)) { |
| 668 | return true; |
| 669 | } |
| 670 | |
| 671 | final boolean callerForeground = receiverRecord.callerApp != null |
Dianne Hackborn | a49ad09 | 2016-03-03 13:39:10 -0800 | [diff] [blame] | 672 | ? receiverRecord.callerApp.setSchedGroup != ProcessList.SCHED_GROUP_BACKGROUND |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 673 | : true; |
| 674 | |
| 675 | // Show a permission review UI only for explicit broadcast from a foreground app |
| 676 | if (callerForeground && receiverRecord.intent.getComponent() != null) { |
| 677 | IIntentSender target = mService.getIntentSenderLocked( |
| 678 | ActivityManager.INTENT_SENDER_BROADCAST, receiverRecord.callerPackage, |
| 679 | receiverRecord.callingUid, receiverRecord.userId, null, null, 0, |
| 680 | new Intent[]{receiverRecord.intent}, |
| 681 | new String[]{receiverRecord.intent.resolveType(mService.mContext |
| 682 | .getContentResolver())}, |
| 683 | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT |
| 684 | | PendingIntent.FLAG_IMMUTABLE, null); |
| 685 | |
| 686 | final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSIONS); |
| 687 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 688 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 689 | intent.putExtra(Intent.EXTRA_PACKAGE_NAME, receivingPackageName); |
| 690 | intent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target)); |
| 691 | |
| 692 | if (DEBUG_PERMISSIONS_REVIEW) { |
| 693 | Slog.i(TAG, "u" + receivingUserId + " Launching permission review for package " |
| 694 | + receivingPackageName); |
| 695 | } |
| 696 | |
| 697 | mHandler.post(new Runnable() { |
| 698 | @Override |
| 699 | public void run() { |
| 700 | mService.mContext.startActivityAsUser(intent, new UserHandle(receivingUserId)); |
| 701 | } |
| 702 | }); |
| 703 | } else { |
| 704 | Slog.w(TAG, "u" + receivingUserId + " Receiving a broadcast in package" |
| 705 | + receivingPackageName + " requires a permissions review"); |
| 706 | } |
| 707 | |
| 708 | return false; |
| 709 | } |
| 710 | |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 711 | final void scheduleTempWhitelistLocked(int uid, long duration, BroadcastRecord r) { |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 712 | if (duration > Integer.MAX_VALUE) { |
| 713 | duration = Integer.MAX_VALUE; |
| 714 | } |
| 715 | // XXX ideally we should pause the broadcast until everything behind this is done, |
| 716 | // or else we will likely start dispatching the broadcast before we have opened |
| 717 | // access to the app (there is a lot of asynchronicity behind this). It is probably |
| 718 | // not that big a deal, however, because the main purpose here is to allow apps |
| 719 | // to hold wake locks, and they will be able to acquire their wake lock immediately |
| 720 | // it just won't be enabled until we get through this work. |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 721 | StringBuilder b = new StringBuilder(); |
| 722 | b.append("broadcast:"); |
| 723 | UserHandle.formatUid(b, r.callingUid); |
| 724 | b.append(":"); |
| 725 | if (r.intent.getAction() != null) { |
| 726 | b.append(r.intent.getAction()); |
| 727 | } else if (r.intent.getComponent() != null) { |
| 728 | b.append(r.intent.getComponent().flattenToShortString()); |
| 729 | } else if (r.intent.getData() != null) { |
| 730 | b.append(r.intent.getData()); |
| 731 | } |
| 732 | mHandler.obtainMessage(SCHEDULE_TEMP_WHITELIST_MSG, uid, (int)duration, b.toString()) |
| 733 | .sendToTarget(); |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 736 | final void processNextBroadcast(boolean fromMsg) { |
| 737 | synchronized(mService) { |
| 738 | BroadcastRecord r; |
| 739 | |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 740 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "processNextBroadcast [" |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 741 | + mQueueName + "]: " |
| 742 | + mParallelBroadcasts.size() + " broadcasts, " |
| 743 | + mOrderedBroadcasts.size() + " ordered broadcasts"); |
| 744 | |
| 745 | mService.updateCpuStats(); |
| 746 | |
| 747 | if (fromMsg) { |
| 748 | mBroadcastsScheduled = false; |
| 749 | } |
| 750 | |
| 751 | // First, deliver any non-serialized broadcasts right away. |
| 752 | while (mParallelBroadcasts.size() > 0) { |
| 753 | r = mParallelBroadcasts.remove(0); |
| 754 | r.dispatchTime = SystemClock.uptimeMillis(); |
| 755 | r.dispatchClockTime = System.currentTimeMillis(); |
| 756 | final int N = r.receivers.size(); |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 757 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, "Processing parallel broadcast [" |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 758 | + mQueueName + "] " + r); |
| 759 | for (int i=0; i<N; i++) { |
| 760 | Object target = r.receivers.get(i); |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 761 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 762 | "Delivering non-ordered on [" + mQueueName + "] to registered " |
| 763 | + target + ": " + r); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 764 | deliverToRegisteredReceiverLocked(r, (BroadcastFilter)target, false, i); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 765 | } |
| 766 | addBroadcastToHistoryLocked(r); |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 767 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, "Done with parallel broadcast [" |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 768 | + mQueueName + "] " + r); |
| 769 | } |
| 770 | |
| 771 | // Now take care of the next serialized one... |
| 772 | |
| 773 | // If we are waiting for a process to come up to handle the next |
| 774 | // broadcast, then do nothing at this point. Just in case, we |
| 775 | // check that the process we're waiting for still exists. |
| 776 | if (mPendingBroadcast != null) { |
Wale Ogunwale | 3c36b8e | 2015-03-09 10:18:51 -0700 | [diff] [blame] | 777 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, |
| 778 | "processNextBroadcast [" + mQueueName + "]: waiting for " |
| 779 | + mPendingBroadcast.curApp); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 780 | |
| 781 | boolean isDead; |
| 782 | synchronized (mService.mPidsSelfLocked) { |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 783 | ProcessRecord proc = mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid); |
| 784 | isDead = proc == null || proc.crashing; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 785 | } |
| 786 | if (!isDead) { |
| 787 | // It's still alive, so keep waiting |
| 788 | return; |
| 789 | } else { |
| 790 | Slog.w(TAG, "pending app [" |
| 791 | + mQueueName + "]" + mPendingBroadcast.curApp |
| 792 | + " died before responding to broadcast"); |
| 793 | mPendingBroadcast.state = BroadcastRecord.IDLE; |
| 794 | mPendingBroadcast.nextReceiver = mPendingBroadcastRecvIndex; |
| 795 | mPendingBroadcast = null; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | boolean looped = false; |
| 800 | |
| 801 | do { |
| 802 | if (mOrderedBroadcasts.size() == 0) { |
| 803 | // No more broadcasts pending, so all done! |
| 804 | mService.scheduleAppGcsLocked(); |
| 805 | if (looped) { |
| 806 | // If we had finished the last ordered broadcast, then |
| 807 | // make sure all processes have correct oom and sched |
| 808 | // adjustments. |
| 809 | mService.updateOomAdjLocked(); |
| 810 | } |
| 811 | return; |
| 812 | } |
| 813 | r = mOrderedBroadcasts.get(0); |
| 814 | boolean forceReceive = false; |
| 815 | |
| 816 | // Ensure that even if something goes awry with the timeout |
| 817 | // detection, we catch "hung" broadcasts here, discard them, |
| 818 | // and continue to make progress. |
| 819 | // |
| 820 | // This is only done if the system is ready so that PRE_BOOT_COMPLETED |
| 821 | // receivers don't get executed with timeouts. They're intended for |
| 822 | // one time heavy lifting after system upgrades and can take |
| 823 | // significant amounts of time. |
| 824 | int numReceivers = (r.receivers != null) ? r.receivers.size() : 0; |
| 825 | if (mService.mProcessesReady && r.dispatchTime > 0) { |
| 826 | long now = SystemClock.uptimeMillis(); |
| 827 | if ((numReceivers > 0) && |
| 828 | (now > r.dispatchTime + (2*mTimeoutPeriod*numReceivers))) { |
| 829 | Slog.w(TAG, "Hung broadcast [" |
| 830 | + mQueueName + "] discarded after timeout failure:" |
| 831 | + " now=" + now |
| 832 | + " dispatchTime=" + r.dispatchTime |
| 833 | + " startTime=" + r.receiverTime |
| 834 | + " intent=" + r.intent |
| 835 | + " numReceivers=" + numReceivers |
| 836 | + " nextReceiver=" + r.nextReceiver |
| 837 | + " state=" + r.state); |
| 838 | broadcastTimeoutLocked(false); // forcibly finish this broadcast |
| 839 | forceReceive = true; |
| 840 | r.state = BroadcastRecord.IDLE; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (r.state != BroadcastRecord.IDLE) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 845 | if (DEBUG_BROADCAST) Slog.d(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 846 | "processNextBroadcast(" |
| 847 | + mQueueName + ") called when not idle (state=" |
| 848 | + r.state + ")"); |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | if (r.receivers == null || r.nextReceiver >= numReceivers |
| 853 | || r.resultAbort || forceReceive) { |
| 854 | // No more receivers for this broadcast! Send the final |
| 855 | // result if requested... |
| 856 | if (r.resultTo != null) { |
| 857 | try { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 858 | if (DEBUG_BROADCAST) Slog.i(TAG_BROADCAST, |
Todd Kennedy | d2f1511 | 2015-01-21 15:25:56 -0800 | [diff] [blame] | 859 | "Finishing broadcast [" + mQueueName + "] " |
| 860 | + r.intent.getAction() + " app=" + r.callerApp); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 861 | performReceiveLocked(r.callerApp, r.resultTo, |
| 862 | new Intent(r.intent), r.resultCode, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 863 | r.resultData, r.resultExtras, false, false, r.userId); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 864 | // Set this to null so that the reference |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 865 | // (local and remote) isn't kept in the mBroadcastHistory. |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 866 | r.resultTo = null; |
| 867 | } catch (RemoteException e) { |
Craig Mautner | 38c1a5f | 2014-07-21 15:36:37 +0000 | [diff] [blame] | 868 | r.resultTo = null; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 869 | Slog.w(TAG, "Failure [" |
| 870 | + mQueueName + "] sending broadcast result of " |
| 871 | + r.intent, e); |
Joe Onorato | 5869d1c | 2016-04-20 15:38:07 -0700 | [diff] [blame^] | 872 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 876 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Cancelling BROADCAST_TIMEOUT_MSG"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 877 | cancelBroadcastTimeoutLocked(); |
| 878 | |
Wale Ogunwale | 3c36b8e | 2015-03-09 10:18:51 -0700 | [diff] [blame] | 879 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, |
| 880 | "Finished with ordered broadcast " + r); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 881 | |
| 882 | // ... and on to the next... |
| 883 | addBroadcastToHistoryLocked(r); |
| 884 | mOrderedBroadcasts.remove(0); |
| 885 | r = null; |
| 886 | looped = true; |
| 887 | continue; |
| 888 | } |
| 889 | } while (r == null); |
| 890 | |
| 891 | // Get the next receiver... |
| 892 | int recIdx = r.nextReceiver++; |
| 893 | |
| 894 | // Keep track of when this receiver started, and make sure there |
| 895 | // is a timeout message pending to kill it if need be. |
| 896 | r.receiverTime = SystemClock.uptimeMillis(); |
| 897 | if (recIdx == 0) { |
| 898 | r.dispatchTime = r.receiverTime; |
| 899 | r.dispatchClockTime = System.currentTimeMillis(); |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 900 | if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST, "Processing ordered broadcast [" |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 901 | + mQueueName + "] " + r); |
| 902 | } |
| 903 | if (! mPendingBroadcastTimeoutMessage) { |
| 904 | long timeoutTime = r.receiverTime + mTimeoutPeriod; |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 905 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 906 | "Submitting BROADCAST_TIMEOUT_MSG [" |
| 907 | + mQueueName + "] for " + r + " at " + timeoutTime); |
| 908 | setBroadcastTimeoutLocked(timeoutTime); |
| 909 | } |
| 910 | |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 911 | final BroadcastOptions brOptions = r.options; |
| 912 | final Object nextReceiver = r.receivers.get(recIdx); |
| 913 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 914 | if (nextReceiver instanceof BroadcastFilter) { |
| 915 | // Simple case: this is a registered receiver who gets |
| 916 | // a direct call. |
| 917 | BroadcastFilter filter = (BroadcastFilter)nextReceiver; |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 918 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 919 | "Delivering ordered [" |
| 920 | + mQueueName + "] to registered " |
| 921 | + filter + ": " + r); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 922 | deliverToRegisteredReceiverLocked(r, filter, r.ordered, recIdx); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 923 | if (r.receiver == null || !r.ordered) { |
| 924 | // The receiver has already finished, so schedule to |
| 925 | // process the next one. |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 926 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Quick finishing [" |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 927 | + mQueueName + "]: ordered=" |
| 928 | + r.ordered + " receiver=" + r.receiver); |
| 929 | r.state = BroadcastRecord.IDLE; |
| 930 | scheduleBroadcastsLocked(); |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 931 | } else { |
| 932 | if (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0) { |
| 933 | scheduleTempWhitelistLocked(filter.owningUid, |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 934 | brOptions.getTemporaryAppWhitelistDuration(), r); |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 935 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 936 | } |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | // Hard case: need to instantiate the receiver, possibly |
| 941 | // starting its application process to host it. |
| 942 | |
| 943 | ResolveInfo info = |
| 944 | (ResolveInfo)nextReceiver; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 945 | ComponentName component = new ComponentName( |
| 946 | info.activityInfo.applicationInfo.packageName, |
| 947 | info.activityInfo.name); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 948 | |
| 949 | boolean skip = false; |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 950 | if (brOptions != null && |
| 951 | (info.activityInfo.applicationInfo.targetSdkVersion |
| 952 | < brOptions.getMinManifestReceiverApiLevel() || |
| 953 | info.activityInfo.applicationInfo.targetSdkVersion |
| 954 | > brOptions.getMaxManifestReceiverApiLevel())) { |
| 955 | skip = true; |
| 956 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 957 | int perm = mService.checkComponentPermission(info.activityInfo.permission, |
| 958 | r.callingPid, r.callingUid, info.activityInfo.applicationInfo.uid, |
| 959 | info.activityInfo.exported); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 960 | if (!skip && perm != PackageManager.PERMISSION_GRANTED) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 961 | if (!info.activityInfo.exported) { |
| 962 | Slog.w(TAG, "Permission Denial: broadcasting " |
| 963 | + r.intent.toString() |
| 964 | + " from " + r.callerPackage + " (pid=" + r.callingPid |
| 965 | + ", uid=" + r.callingUid + ")" |
| 966 | + " is not exported from uid " + info.activityInfo.applicationInfo.uid |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 967 | + " due to receiver " + component.flattenToShortString()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 968 | } else { |
| 969 | Slog.w(TAG, "Permission Denial: broadcasting " |
| 970 | + r.intent.toString() |
| 971 | + " from " + r.callerPackage + " (pid=" + r.callingPid |
| 972 | + ", uid=" + r.callingUid + ")" |
| 973 | + " requires " + info.activityInfo.permission |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 974 | + " due to receiver " + component.flattenToShortString()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 975 | } |
| 976 | skip = true; |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 977 | } else if (!skip && info.activityInfo.permission != null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 978 | final int opCode = AppOpsManager.permissionToOpCode(info.activityInfo.permission); |
| 979 | if (opCode != AppOpsManager.OP_NONE |
| 980 | && mService.mAppOpsService.noteOperation(opCode, r.callingUid, |
| 981 | r.callerPackage) != AppOpsManager.MODE_ALLOWED) { |
| 982 | Slog.w(TAG, "Appop Denial: broadcasting " |
| 983 | + r.intent.toString() |
| 984 | + " from " + r.callerPackage + " (pid=" |
| 985 | + r.callingPid + ", uid=" + r.callingUid + ")" |
| 986 | + " requires appop " + AppOpsManager.permissionToOp( |
| 987 | info.activityInfo.permission) |
| 988 | + " due to registered receiver " |
| 989 | + component.flattenToShortString()); |
| 990 | skip = true; |
| 991 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 992 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 993 | if (!skip && info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID && |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 994 | r.requiredPermissions != null && r.requiredPermissions.length > 0) { |
| 995 | for (int i = 0; i < r.requiredPermissions.length; i++) { |
| 996 | String requiredPermission = r.requiredPermissions[i]; |
| 997 | try { |
| 998 | perm = AppGlobals.getPackageManager(). |
| 999 | checkPermission(requiredPermission, |
| 1000 | info.activityInfo.applicationInfo.packageName, |
| 1001 | UserHandle |
| 1002 | .getUserId(info.activityInfo.applicationInfo.uid)); |
| 1003 | } catch (RemoteException e) { |
| 1004 | perm = PackageManager.PERMISSION_DENIED; |
| 1005 | } |
| 1006 | if (perm != PackageManager.PERMISSION_GRANTED) { |
| 1007 | Slog.w(TAG, "Permission Denial: receiving " |
| 1008 | + r.intent + " to " |
| 1009 | + component.flattenToShortString() |
| 1010 | + " requires " + requiredPermission |
| 1011 | + " due to sender " + r.callerPackage |
| 1012 | + " (uid " + r.callingUid + ")"); |
| 1013 | skip = true; |
| 1014 | break; |
| 1015 | } |
| 1016 | int appOp = AppOpsManager.permissionToOpCode(requiredPermission); |
| 1017 | if (appOp != AppOpsManager.OP_NONE && appOp != r.appOp |
| 1018 | && mService.mAppOpsService.noteOperation(appOp, |
Fyodor Kupolov | e37520b | 2015-07-14 22:29:21 +0000 | [diff] [blame] | 1019 | info.activityInfo.applicationInfo.uid, info.activityInfo.packageName) |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 1020 | != AppOpsManager.MODE_ALLOWED) { |
| 1021 | Slog.w(TAG, "Appop Denial: receiving " |
| 1022 | + r.intent + " to " |
| 1023 | + component.flattenToShortString() |
| 1024 | + " requires appop " + AppOpsManager.permissionToOp( |
| 1025 | requiredPermission) |
| 1026 | + " due to sender " + r.callerPackage |
| 1027 | + " (uid " + r.callingUid + ")"); |
| 1028 | skip = true; |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | if (!skip && r.appOp != AppOpsManager.OP_NONE |
| 1034 | && mService.mAppOpsService.noteOperation(r.appOp, |
| 1035 | info.activityInfo.applicationInfo.uid, info.activityInfo.packageName) |
| 1036 | != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1037 | Slog.w(TAG, "Appop Denial: receiving " |
| 1038 | + r.intent + " to " |
| 1039 | + component.flattenToShortString() |
Fyodor Kupolov | d4fd8c7 | 2015-07-13 19:19:25 -0700 | [diff] [blame] | 1040 | + " requires appop " + AppOpsManager.opToName(r.appOp) |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1041 | + " due to sender " + r.callerPackage |
| 1042 | + " (uid " + r.callingUid + ")"); |
| 1043 | skip = true; |
| 1044 | } |
Ben Gruver | 49660c7 | 2013-08-06 19:54:08 -0700 | [diff] [blame] | 1045 | if (!skip) { |
| 1046 | skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid, |
| 1047 | r.callingPid, r.resolvedType, info.activityInfo.applicationInfo.uid); |
| 1048 | } |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 1049 | boolean isSingleton = false; |
| 1050 | try { |
| 1051 | isSingleton = mService.isSingleton(info.activityInfo.processName, |
| 1052 | info.activityInfo.applicationInfo, |
| 1053 | info.activityInfo.name, info.activityInfo.flags); |
| 1054 | } catch (SecurityException e) { |
| 1055 | Slog.w(TAG, e.getMessage()); |
| 1056 | skip = true; |
| 1057 | } |
| 1058 | if ((info.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) { |
| 1059 | if (ActivityManager.checkUidPermission( |
| 1060 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 1061 | info.activityInfo.applicationInfo.uid) |
| 1062 | != PackageManager.PERMISSION_GRANTED) { |
| 1063 | Slog.w(TAG, "Permission Denial: Receiver " + component.flattenToShortString() |
| 1064 | + " requests FLAG_SINGLE_USER, but app does not hold " |
| 1065 | + android.Manifest.permission.INTERACT_ACROSS_USERS); |
| 1066 | skip = true; |
| 1067 | } |
| 1068 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1069 | if (r.curApp != null && r.curApp.crashing) { |
| 1070 | // If the target process is crashing, just skip it. |
Dianne Hackborn | 9357b11 | 2013-10-03 18:27:48 -0700 | [diff] [blame] | 1071 | Slog.w(TAG, "Skipping deliver ordered [" + mQueueName + "] " + r |
| 1072 | + " to " + r.curApp + ": process crashing"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1073 | skip = true; |
| 1074 | } |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 1075 | if (!skip) { |
| 1076 | boolean isAvailable = false; |
| 1077 | try { |
| 1078 | isAvailable = AppGlobals.getPackageManager().isPackageAvailable( |
| 1079 | info.activityInfo.packageName, |
| 1080 | UserHandle.getUserId(info.activityInfo.applicationInfo.uid)); |
| 1081 | } catch (Exception e) { |
| 1082 | // all such failures mean we skip this receiver |
| 1083 | Slog.w(TAG, "Exception getting recipient info for " |
| 1084 | + info.activityInfo.packageName, e); |
| 1085 | } |
| 1086 | if (!isAvailable) { |
Wale Ogunwale | 3c36b8e | 2015-03-09 10:18:51 -0700 | [diff] [blame] | 1087 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
| 1088 | "Skipping delivery to " + info.activityInfo.packageName + " / " |
| 1089 | + info.activityInfo.applicationInfo.uid |
| 1090 | + " : package no longer available"); |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 1091 | skip = true; |
| 1092 | } |
| 1093 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1094 | |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 1095 | // If permissions need a review before any of the app components can run, we drop |
| 1096 | // the broadcast and if the calling app is in the foreground and the broadcast is |
| 1097 | // explicit we launch the review UI passing it a pending intent to send the skipped |
| 1098 | // broadcast. |
| 1099 | if (Build.PERMISSIONS_REVIEW_REQUIRED && !skip) { |
| 1100 | if (!requestStartTargetPermissionsReviewIfNeededLocked(r, |
| 1101 | info.activityInfo.packageName, UserHandle.getUserId( |
| 1102 | info.activityInfo.applicationInfo.uid))) { |
| 1103 | skip = true; |
| 1104 | } |
| 1105 | } |
| 1106 | |
Dianne Hackborn | 76e8009 | 2015-12-09 14:15:34 -0800 | [diff] [blame] | 1107 | // This is safe to do even if we are skipping the broadcast, and we need |
| 1108 | // this information now to evaluate whether it is going to be allowed to run. |
| 1109 | final int receiverUid = info.activityInfo.applicationInfo.uid; |
| 1110 | // If it's a singleton, it needs to be the same app or a special app |
| 1111 | if (r.callingUid != Process.SYSTEM_UID && isSingleton |
| 1112 | && mService.isValidSingletonCall(r.callingUid, receiverUid)) { |
| 1113 | info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0); |
| 1114 | } |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 1115 | String targetProcess = info.activityInfo.processName; |
| 1116 | ProcessRecord app = mService.getProcessRecordLocked(targetProcess, |
| 1117 | info.activityInfo.applicationInfo.uid, false); |
Dianne Hackborn | 76e8009 | 2015-12-09 14:15:34 -0800 | [diff] [blame] | 1118 | |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 1119 | if (!skip) { |
| 1120 | final int allowed = mService.checkAllowBackgroundLocked( |
Dianne Hackborn | e91f3e7 | 2016-03-25 18:48:15 -0700 | [diff] [blame] | 1121 | info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, -1, |
| 1122 | false); |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 1123 | if (allowed != ActivityManager.APP_START_MODE_NORMAL) { |
| 1124 | // We won't allow this receiver to be launched if the app has been |
Dianne Hackborn | e91f3e7 | 2016-03-25 18:48:15 -0700 | [diff] [blame] | 1125 | // completely disabled from launches, or it was not explicitly sent |
| 1126 | // to it and the app is in a state that should not receive it |
| 1127 | // (depending on how checkAllowBackgroundLocked has determined that). |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 1128 | if (allowed == ActivityManager.APP_START_MODE_DISABLED) { |
| 1129 | Slog.w(TAG, "Background execution disabled: receiving " |
| 1130 | + r.intent + " to " |
| 1131 | + component.flattenToShortString()); |
| 1132 | skip = true; |
Dianne Hackborn | e91f3e7 | 2016-03-25 18:48:15 -0700 | [diff] [blame] | 1133 | } else if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0) |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 1134 | || (r.intent.getComponent() == null |
Dianne Hackborn | e91f3e7 | 2016-03-25 18:48:15 -0700 | [diff] [blame] | 1135 | && r.intent.getPackage() == null |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 1136 | && ((r.intent.getFlags() |
| 1137 | & Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND) == 0))) { |
Dianne Hackborn | 2639c4b | 2015-12-04 13:11:09 -0800 | [diff] [blame] | 1138 | Slog.w(TAG, "Background execution not allowed: receiving " |
| 1139 | + r.intent + " to " |
| 1140 | + component.flattenToShortString()); |
| 1141 | skip = true; |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1146 | if (skip) { |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 1147 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Wale Ogunwale | 3c36b8e | 2015-03-09 10:18:51 -0700 | [diff] [blame] | 1148 | "Skipping delivery of ordered [" + mQueueName + "] " |
| 1149 | + r + " for whatever reason"); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 1150 | r.delivery[recIdx] = BroadcastRecord.DELIVERY_SKIPPED; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1151 | r.receiver = null; |
| 1152 | r.curFilter = null; |
| 1153 | r.state = BroadcastRecord.IDLE; |
| 1154 | scheduleBroadcastsLocked(); |
| 1155 | return; |
| 1156 | } |
| 1157 | |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 1158 | r.delivery[recIdx] = BroadcastRecord.DELIVERY_DELIVERED; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1159 | r.state = BroadcastRecord.APP_RECEIVE; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 1160 | r.curComponent = component; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1161 | r.curReceiver = info.activityInfo; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1162 | if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1163 | Slog.v(TAG_MU, "Updated broadcast record activity info for secondary user, " |
| 1164 | + info.activityInfo + ", callingUid = " + r.callingUid + ", uid = " |
| 1165 | + info.activityInfo.applicationInfo.uid); |
| 1166 | } |
| 1167 | |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 1168 | if (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0) { |
| 1169 | scheduleTempWhitelistLocked(receiverUid, |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1170 | brOptions.getTemporaryAppWhitelistDuration(), r); |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1173 | // Broadcast is being executed, its package can't be stopped. |
| 1174 | try { |
| 1175 | AppGlobals.getPackageManager().setPackageStoppedState( |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1176 | r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid)); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1177 | } catch (RemoteException e) { |
| 1178 | } catch (IllegalArgumentException e) { |
| 1179 | Slog.w(TAG, "Failed trying to unstop package " |
| 1180 | + r.curComponent.getPackageName() + ": " + e); |
| 1181 | } |
| 1182 | |
| 1183 | // Is this receiver's application already running? |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1184 | if (app != null && app.thread != null) { |
| 1185 | try { |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1186 | app.addPackage(info.activityInfo.packageName, |
| 1187 | info.activityInfo.applicationInfo.versionCode, mService.mProcessStats); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1188 | processCurBroadcastLocked(r, app); |
| 1189 | return; |
| 1190 | } catch (RemoteException e) { |
| 1191 | Slog.w(TAG, "Exception when sending broadcast to " |
| 1192 | + r.curComponent, e); |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 1193 | } catch (RuntimeException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1194 | Slog.wtf(TAG, "Failed sending broadcast to " |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 1195 | + r.curComponent + " with " + r.intent, e); |
| 1196 | // If some unexpected exception happened, just skip |
| 1197 | // this broadcast. At this point we are not in the call |
| 1198 | // from a client, so throwing an exception out from here |
| 1199 | // will crash the entire system instead of just whoever |
| 1200 | // sent the broadcast. |
| 1201 | logBroadcastReceiverDiscardLocked(r); |
| 1202 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 1203 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 1204 | scheduleBroadcastsLocked(); |
| 1205 | // We need to reset the state if we failed to start the receiver. |
| 1206 | r.state = BroadcastRecord.IDLE; |
| 1207 | return; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | // If a dead object exception was thrown -- fall through to |
| 1211 | // restart the application. |
| 1212 | } |
| 1213 | |
| 1214 | // Not running -- get it started, to be executed when the app comes up. |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 1215 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1216 | "Need to start app [" |
| 1217 | + mQueueName + "] " + targetProcess + " for broadcast " + r); |
| 1218 | if ((r.curApp=mService.startProcessLocked(targetProcess, |
| 1219 | info.activityInfo.applicationInfo, true, |
| 1220 | r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, |
| 1221 | "broadcast", r.curComponent, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1222 | (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false)) |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1223 | == null) { |
| 1224 | // Ah, this recipient is unavailable. Finish it if necessary, |
| 1225 | // and mark the broadcast record as ready for the next. |
| 1226 | Slog.w(TAG, "Unable to launch app " |
| 1227 | + info.activityInfo.applicationInfo.packageName + "/" |
| 1228 | + info.activityInfo.applicationInfo.uid + " for broadcast " |
| 1229 | + r.intent + ": process is bad"); |
| 1230 | logBroadcastReceiverDiscardLocked(r); |
| 1231 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 1232 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1233 | scheduleBroadcastsLocked(); |
| 1234 | r.state = BroadcastRecord.IDLE; |
| 1235 | return; |
| 1236 | } |
| 1237 | |
| 1238 | mPendingBroadcast = r; |
| 1239 | mPendingBroadcastRecvIndex = recIdx; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | final void setBroadcastTimeoutLocked(long timeoutTime) { |
| 1244 | if (! mPendingBroadcastTimeoutMessage) { |
| 1245 | Message msg = mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG, this); |
| 1246 | mHandler.sendMessageAtTime(msg, timeoutTime); |
| 1247 | mPendingBroadcastTimeoutMessage = true; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | final void cancelBroadcastTimeoutLocked() { |
| 1252 | if (mPendingBroadcastTimeoutMessage) { |
| 1253 | mHandler.removeMessages(BROADCAST_TIMEOUT_MSG, this); |
| 1254 | mPendingBroadcastTimeoutMessage = false; |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | final void broadcastTimeoutLocked(boolean fromMsg) { |
| 1259 | if (fromMsg) { |
| 1260 | mPendingBroadcastTimeoutMessage = false; |
| 1261 | } |
| 1262 | |
| 1263 | if (mOrderedBroadcasts.size() == 0) { |
| 1264 | return; |
| 1265 | } |
| 1266 | |
| 1267 | long now = SystemClock.uptimeMillis(); |
| 1268 | BroadcastRecord r = mOrderedBroadcasts.get(0); |
| 1269 | if (fromMsg) { |
| 1270 | if (mService.mDidDexOpt) { |
| 1271 | // Delay timeouts until dexopt finishes. |
| 1272 | mService.mDidDexOpt = false; |
| 1273 | long timeoutTime = SystemClock.uptimeMillis() + mTimeoutPeriod; |
| 1274 | setBroadcastTimeoutLocked(timeoutTime); |
| 1275 | return; |
| 1276 | } |
| 1277 | if (!mService.mProcessesReady) { |
| 1278 | // Only process broadcast timeouts if the system is ready. That way |
| 1279 | // PRE_BOOT_COMPLETED broadcasts can't timeout as they are intended |
| 1280 | // to do heavy lifting for system up. |
| 1281 | return; |
| 1282 | } |
| 1283 | |
| 1284 | long timeoutTime = r.receiverTime + mTimeoutPeriod; |
| 1285 | if (timeoutTime > now) { |
| 1286 | // We can observe premature timeouts because we do not cancel and reset the |
| 1287 | // broadcast timeout message after each receiver finishes. Instead, we set up |
| 1288 | // an initial timeout then kick it down the road a little further as needed |
| 1289 | // when it expires. |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 1290 | if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1291 | "Premature timeout [" |
| 1292 | + mQueueName + "] @ " + now + ": resetting BROADCAST_TIMEOUT_MSG for " |
| 1293 | + timeoutTime); |
| 1294 | setBroadcastTimeoutLocked(timeoutTime); |
| 1295 | return; |
| 1296 | } |
| 1297 | } |
| 1298 | |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 1299 | BroadcastRecord br = mOrderedBroadcasts.get(0); |
| 1300 | if (br.state == BroadcastRecord.WAITING_SERVICES) { |
| 1301 | // In this case the broadcast had already finished, but we had decided to wait |
| 1302 | // for started services to finish as well before going on. So if we have actually |
| 1303 | // waited long enough time timeout the broadcast, let's give up on the whole thing |
| 1304 | // and just move on to the next. |
Wale Ogunwale | d57969f | 2014-11-15 19:37:29 -0800 | [diff] [blame] | 1305 | Slog.i(TAG, "Waited long enough for: " + (br.curComponent != null |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 1306 | ? br.curComponent.flattenToShortString() : "(null)")); |
| 1307 | br.curComponent = null; |
| 1308 | br.state = BroadcastRecord.IDLE; |
| 1309 | processNextBroadcast(false); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | Slog.w(TAG, "Timeout of broadcast " + r + " - receiver=" + r. receiver |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1314 | + ", started " + (now - r.receiverTime) + "ms ago"); |
| 1315 | r.receiverTime = now; |
| 1316 | r.anrCount++; |
| 1317 | |
| 1318 | // Current receiver has passed its expiration date. |
| 1319 | if (r.nextReceiver <= 0) { |
| 1320 | Slog.w(TAG, "Timeout on receiver with nextReceiver <= 0"); |
| 1321 | return; |
| 1322 | } |
| 1323 | |
| 1324 | ProcessRecord app = null; |
| 1325 | String anrMessage = null; |
| 1326 | |
| 1327 | Object curReceiver = r.receivers.get(r.nextReceiver-1); |
Dianne Hackborn | e0e413e | 2015-12-09 17:22:26 -0800 | [diff] [blame] | 1328 | r.delivery[r.nextReceiver-1] = BroadcastRecord.DELIVERY_TIMEOUT; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1329 | Slog.w(TAG, "Receiver during timeout: " + curReceiver); |
| 1330 | logBroadcastReceiverDiscardLocked(r); |
| 1331 | if (curReceiver instanceof BroadcastFilter) { |
| 1332 | BroadcastFilter bf = (BroadcastFilter)curReceiver; |
| 1333 | if (bf.receiverList.pid != 0 |
| 1334 | && bf.receiverList.pid != ActivityManagerService.MY_PID) { |
| 1335 | synchronized (mService.mPidsSelfLocked) { |
| 1336 | app = mService.mPidsSelfLocked.get( |
| 1337 | bf.receiverList.pid); |
| 1338 | } |
| 1339 | } |
| 1340 | } else { |
| 1341 | app = r.curApp; |
| 1342 | } |
| 1343 | |
| 1344 | if (app != null) { |
| 1345 | anrMessage = "Broadcast of " + r.intent.toString(); |
| 1346 | } |
| 1347 | |
| 1348 | if (mPendingBroadcast == r) { |
| 1349 | mPendingBroadcast = null; |
| 1350 | } |
| 1351 | |
| 1352 | // Move on to the next receiver. |
| 1353 | finishReceiverLocked(r, r.resultCode, r.resultData, |
Dianne Hackborn | 6285a32 | 2013-09-18 12:09:47 -0700 | [diff] [blame] | 1354 | r.resultExtras, r.resultAbort, false); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1355 | scheduleBroadcastsLocked(); |
| 1356 | |
| 1357 | if (anrMessage != null) { |
| 1358 | // Post the ANR to the handler since we do not want to process ANRs while |
| 1359 | // potentially holding our lock. |
| 1360 | mHandler.post(new AppNotResponding(app, anrMessage)); |
| 1361 | } |
| 1362 | } |
| 1363 | |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1364 | private final int ringAdvance(int x, final int increment, final int ringSize) { |
| 1365 | x += increment; |
| 1366 | if (x < 0) return (ringSize - 1); |
| 1367 | else if (x >= ringSize) return 0; |
| 1368 | else return x; |
| 1369 | } |
| 1370 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1371 | private final void addBroadcastToHistoryLocked(BroadcastRecord r) { |
| 1372 | if (r.callingUid < 0) { |
| 1373 | // This was from a registerReceiver() call; ignore it. |
| 1374 | return; |
| 1375 | } |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1376 | r.finishTime = SystemClock.uptimeMillis(); |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1377 | |
| 1378 | mBroadcastHistory[mHistoryNext] = r; |
| 1379 | mHistoryNext = ringAdvance(mHistoryNext, 1, MAX_BROADCAST_HISTORY); |
| 1380 | |
| 1381 | mBroadcastSummaryHistory[mSummaryHistoryNext] = r.intent; |
| 1382 | mSummaryHistoryEnqueueTime[mSummaryHistoryNext] = r.enqueueClockTime; |
| 1383 | mSummaryHistoryDispatchTime[mSummaryHistoryNext] = r.dispatchClockTime; |
| 1384 | mSummaryHistoryFinishTime[mSummaryHistoryNext] = System.currentTimeMillis(); |
| 1385 | mSummaryHistoryNext = ringAdvance(mSummaryHistoryNext, 1, MAX_BROADCAST_SUMMARY_HISTORY); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 1388 | boolean cleanupDisabledPackageReceiversLocked( |
| 1389 | String packageName, Set<String> filterByClasses, int userId, boolean doit) { |
| 1390 | boolean didSomething = false; |
| 1391 | for (int i = mParallelBroadcasts.size() - 1; i >= 0; i--) { |
| 1392 | didSomething |= mParallelBroadcasts.get(i).cleanupDisabledPackageReceiversLocked( |
| 1393 | packageName, filterByClasses, userId, doit); |
| 1394 | if (!doit && didSomething) { |
| 1395 | return true; |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | for (int i = mOrderedBroadcasts.size() - 1; i >= 0; i--) { |
| 1400 | didSomething |= mOrderedBroadcasts.get(i).cleanupDisabledPackageReceiversLocked( |
| 1401 | packageName, filterByClasses, userId, doit); |
| 1402 | if (!doit && didSomething) { |
| 1403 | return true; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | return didSomething; |
| 1408 | } |
| 1409 | |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1410 | final void logBroadcastReceiverDiscardLocked(BroadcastRecord r) { |
Wale Ogunwale | a22c632 | 2015-06-03 09:59:45 -0700 | [diff] [blame] | 1411 | final int logIndex = r.nextReceiver - 1; |
| 1412 | if (logIndex >= 0 && logIndex < r.receivers.size()) { |
| 1413 | Object curReceiver = r.receivers.get(logIndex); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1414 | if (curReceiver instanceof BroadcastFilter) { |
| 1415 | BroadcastFilter bf = (BroadcastFilter) curReceiver; |
| 1416 | EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_FILTER, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1417 | bf.owningUserId, System.identityHashCode(r), |
Wale Ogunwale | a22c632 | 2015-06-03 09:59:45 -0700 | [diff] [blame] | 1418 | r.intent.getAction(), logIndex, System.identityHashCode(bf)); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1419 | } else { |
Wale Ogunwale | a22c632 | 2015-06-03 09:59:45 -0700 | [diff] [blame] | 1420 | ResolveInfo ri = (ResolveInfo) curReceiver; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1421 | EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1422 | UserHandle.getUserId(ri.activityInfo.applicationInfo.uid), |
Wale Ogunwale | a22c632 | 2015-06-03 09:59:45 -0700 | [diff] [blame] | 1423 | System.identityHashCode(r), r.intent.getAction(), logIndex, ri.toString()); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1424 | } |
| 1425 | } else { |
Wale Ogunwale | a22c632 | 2015-06-03 09:59:45 -0700 | [diff] [blame] | 1426 | if (logIndex < 0) Slog.w(TAG, |
| 1427 | "Discarding broadcast before first receiver is invoked: " + r); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1428 | EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1429 | -1, System.identityHashCode(r), |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1430 | r.intent.getAction(), |
| 1431 | r.nextReceiver, |
| 1432 | "NONE"); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | final boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 1437 | int opti, boolean dumpAll, String dumpPackage, boolean needSep) { |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 1438 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1439 | if (mParallelBroadcasts.size() > 0 || mOrderedBroadcasts.size() > 0 |
| 1440 | || mPendingBroadcast != null) { |
| 1441 | boolean printed = false; |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 1442 | for (int i = mParallelBroadcasts.size() - 1; i >= 0; i--) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1443 | BroadcastRecord br = mParallelBroadcasts.get(i); |
| 1444 | if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) { |
| 1445 | continue; |
| 1446 | } |
| 1447 | if (!printed) { |
| 1448 | if (needSep) { |
| 1449 | pw.println(); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1450 | } |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1451 | needSep = true; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1452 | printed = true; |
| 1453 | pw.println(" Active broadcasts [" + mQueueName + "]:"); |
| 1454 | } |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1455 | pw.println(" Active Broadcast " + mQueueName + " #" + i + ":"); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 1456 | br.dump(pw, " ", sdf); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1457 | } |
| 1458 | printed = false; |
| 1459 | needSep = true; |
Wale Ogunwale | ca1c125 | 2015-05-15 12:49:13 -0700 | [diff] [blame] | 1460 | for (int i = mOrderedBroadcasts.size() - 1; i >= 0; i--) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1461 | BroadcastRecord br = mOrderedBroadcasts.get(i); |
| 1462 | if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) { |
| 1463 | continue; |
| 1464 | } |
| 1465 | if (!printed) { |
| 1466 | if (needSep) { |
| 1467 | pw.println(); |
| 1468 | } |
| 1469 | needSep = true; |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1470 | printed = true; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1471 | pw.println(" Active ordered broadcasts [" + mQueueName + "]:"); |
| 1472 | } |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1473 | pw.println(" Active Ordered Broadcast " + mQueueName + " #" + i + ":"); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 1474 | mOrderedBroadcasts.get(i).dump(pw, " ", sdf); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1475 | } |
| 1476 | if (dumpPackage == null || (mPendingBroadcast != null |
| 1477 | && dumpPackage.equals(mPendingBroadcast.callerPackage))) { |
| 1478 | if (needSep) { |
| 1479 | pw.println(); |
| 1480 | } |
| 1481 | pw.println(" Pending broadcast [" + mQueueName + "]:"); |
| 1482 | if (mPendingBroadcast != null) { |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 1483 | mPendingBroadcast.dump(pw, " ", sdf); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1484 | } else { |
| 1485 | pw.println(" (null)"); |
| 1486 | } |
| 1487 | needSep = true; |
| 1488 | } |
| 1489 | } |
| 1490 | |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1491 | int i; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1492 | boolean printed = false; |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1493 | |
| 1494 | i = -1; |
| 1495 | int lastIndex = mHistoryNext; |
| 1496 | int ringIndex = lastIndex; |
| 1497 | do { |
| 1498 | // increasing index = more recent entry, and we want to print the most |
| 1499 | // recent first and work backwards, so we roll through the ring backwards. |
| 1500 | ringIndex = ringAdvance(ringIndex, -1, MAX_BROADCAST_HISTORY); |
| 1501 | BroadcastRecord r = mBroadcastHistory[ringIndex]; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1502 | if (r == null) { |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1503 | continue; |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1504 | } |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1505 | |
| 1506 | i++; // genuine record of some sort even if we're filtering it out |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1507 | if (dumpPackage != null && !dumpPackage.equals(r.callerPackage)) { |
| 1508 | continue; |
| 1509 | } |
| 1510 | if (!printed) { |
| 1511 | if (needSep) { |
| 1512 | pw.println(); |
| 1513 | } |
| 1514 | needSep = true; |
| 1515 | pw.println(" Historical broadcasts [" + mQueueName + "]:"); |
| 1516 | printed = true; |
| 1517 | } |
| 1518 | if (dumpAll) { |
Dianne Hackborn | 6cbd33f | 2012-09-17 18:28:24 -0700 | [diff] [blame] | 1519 | pw.print(" Historical Broadcast " + mQueueName + " #"); |
| 1520 | pw.print(i); pw.println(":"); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 1521 | r.dump(pw, " ", sdf); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1522 | } else { |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1523 | pw.print(" #"); pw.print(i); pw.print(": "); pw.println(r); |
| 1524 | pw.print(" "); |
| 1525 | pw.println(r.intent.toShortString(false, true, true, false)); |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 1526 | if (r.targetComp != null && r.targetComp != r.intent.getComponent()) { |
| 1527 | pw.print(" targetComp: "); pw.println(r.targetComp.toShortString()); |
| 1528 | } |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1529 | Bundle bundle = r.intent.getExtras(); |
| 1530 | if (bundle != null) { |
| 1531 | pw.print(" extras: "); pw.println(bundle.toString()); |
| 1532 | } |
| 1533 | } |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1534 | } while (ringIndex != lastIndex); |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1535 | |
| 1536 | if (dumpPackage == null) { |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1537 | lastIndex = ringIndex = mSummaryHistoryNext; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1538 | if (dumpAll) { |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1539 | printed = false; |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1540 | i = -1; |
| 1541 | } else { |
| 1542 | // roll over the 'i' full dumps that have already been issued |
| 1543 | for (int j = i; |
| 1544 | j > 0 && ringIndex != lastIndex;) { |
| 1545 | ringIndex = ringAdvance(ringIndex, -1, MAX_BROADCAST_SUMMARY_HISTORY); |
| 1546 | BroadcastRecord r = mBroadcastHistory[ringIndex]; |
| 1547 | if (r == null) { |
| 1548 | continue; |
| 1549 | } |
| 1550 | j--; |
| 1551 | } |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1552 | } |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1553 | // done skipping; dump the remainder of the ring. 'i' is still the ordinal within |
| 1554 | // the overall broadcast history. |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1555 | do { |
| 1556 | ringIndex = ringAdvance(ringIndex, -1, MAX_BROADCAST_SUMMARY_HISTORY); |
| 1557 | Intent intent = mBroadcastSummaryHistory[ringIndex]; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1558 | if (intent == null) { |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1559 | continue; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1560 | } |
| 1561 | if (!printed) { |
| 1562 | if (needSep) { |
| 1563 | pw.println(); |
| 1564 | } |
| 1565 | needSep = true; |
| 1566 | pw.println(" Historical broadcasts summary [" + mQueueName + "]:"); |
| 1567 | printed = true; |
| 1568 | } |
| 1569 | if (!dumpAll && i >= 50) { |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1570 | pw.println(" ..."); |
| 1571 | break; |
| 1572 | } |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1573 | i++; |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1574 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 1575 | pw.println(intent.toShortString(false, true, true, false)); |
Dianne Hackborn | 865907d | 2015-10-21 17:12:53 -0700 | [diff] [blame] | 1576 | pw.print(" "); |
| 1577 | TimeUtils.formatDuration(mSummaryHistoryDispatchTime[ringIndex] |
| 1578 | - mSummaryHistoryEnqueueTime[ringIndex], pw); |
| 1579 | pw.print(" dispatch "); |
| 1580 | TimeUtils.formatDuration(mSummaryHistoryFinishTime[ringIndex] |
| 1581 | - mSummaryHistoryDispatchTime[ringIndex], pw); |
| 1582 | pw.println(" finish"); |
| 1583 | pw.print(" enq="); |
| 1584 | pw.print(sdf.format(new Date(mSummaryHistoryEnqueueTime[ringIndex]))); |
| 1585 | pw.print(" disp="); |
| 1586 | pw.print(sdf.format(new Date(mSummaryHistoryDispatchTime[ringIndex]))); |
| 1587 | pw.print(" fin="); |
| 1588 | pw.println(sdf.format(new Date(mSummaryHistoryFinishTime[ringIndex]))); |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1589 | Bundle bundle = intent.getExtras(); |
| 1590 | if (bundle != null) { |
| 1591 | pw.print(" extras: "); pw.println(bundle.toString()); |
| 1592 | } |
Christopher Tate | f278f12 | 2015-04-22 13:12:01 -0700 | [diff] [blame] | 1593 | } while (ringIndex != lastIndex); |
Dianne Hackborn | 40c8db5 | 2012-02-10 18:59:48 -0800 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | return needSep; |
| 1597 | } |
| 1598 | } |