summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java25
-rw-r--r--services/core/java/com/android/server/am/BroadcastQueue.java13
-rw-r--r--services/core/java/com/android/server/am/BroadcastQueueModernImpl.java34
3 files changed, 55 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 2eaddb1c37f1..062afe93e63d 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -13874,6 +13874,29 @@ public class ActivityManagerService extends IActivityManager.Stub
@Nullable IBinder backgroundActivityStartsToken,
@Nullable int[] broadcastAllowList,
@Nullable BiFunction<Integer, Bundle, Bundle> filterExtrasForReceiver) {
+ final int cookie = BroadcastQueue.traceBegin("broadcastIntentLockedTraced");
+ final int res = broadcastIntentLockedTraced(callerApp, callerPackage, callerFeatureId,
+ intent, resolvedType, resultToApp, resultTo, resultCode, resultData, resultExtras,
+ requiredPermissions, excludedPermissions, excludedPackages, appOp, bOptions,
+ ordered, sticky, callingPid, callingUid, realCallingUid, realCallingPid, userId,
+ allowBackgroundActivityStarts, backgroundActivityStartsToken, broadcastAllowList,
+ filterExtrasForReceiver);
+ BroadcastQueue.traceEnd(cookie);
+ return res;
+ }
+
+ @GuardedBy("this")
+ final int broadcastIntentLockedTraced(ProcessRecord callerApp, String callerPackage,
+ @Nullable String callerFeatureId, Intent intent, String resolvedType,
+ ProcessRecord resultToApp, IIntentReceiver resultTo, int resultCode, String resultData,
+ Bundle resultExtras, String[] requiredPermissions,
+ String[] excludedPermissions, String[] excludedPackages, int appOp, Bundle bOptions,
+ boolean ordered, boolean sticky, int callingPid, int callingUid,
+ int realCallingUid, int realCallingPid, int userId,
+ boolean allowBackgroundActivityStarts,
+ @Nullable IBinder backgroundActivityStartsToken,
+ @Nullable int[] broadcastAllowList,
+ @Nullable BiFunction<Integer, Bundle, Bundle> filterExtrasForReceiver) {
// Ensure all internal loopers are registered for idle checks
BroadcastLoopers.addMyLooper();
@@ -14425,6 +14448,7 @@ public class ActivityManagerService extends IActivityManager.Stub
}
// Figure out who all will receive this broadcast.
+ final int cookie = BroadcastQueue.traceBegin("queryReceivers");
List receivers = null;
List<BroadcastFilter> registeredReceivers = null;
// Need to resolve the intent to interested receivers...
@@ -14455,6 +14479,7 @@ public class ActivityManagerService extends IActivityManager.Stub
resolvedType, false /*defaultOnly*/, userId);
}
}
+ BroadcastQueue.traceEnd(cookie);
final boolean replacePending =
(intent.getFlags()&Intent.FLAG_RECEIVER_REPLACE_PENDING) != 0;
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
index 1e172fc92f40..e0fab2cfec21 100644
--- a/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -24,6 +24,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.DropBoxManager;
import android.os.Handler;
+import android.os.Trace;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -76,6 +77,18 @@ public abstract class BroadcastQueue {
}
}
+ static int traceBegin(@NonNull String methodName) {
+ final int cookie = methodName.hashCode();
+ Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,
+ TAG, methodName, cookie);
+ return cookie;
+ }
+
+ static void traceEnd(int cookie) {
+ Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER,
+ TAG, cookie);
+ }
+
@Override
public String toString() {
return mQueueName;
diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
index a1686ad986fc..af2a97e62617 100644
--- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
+++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
@@ -64,7 +64,6 @@ import android.os.Message;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
-import android.os.Trace;
import android.os.UserHandle;
import android.text.format.DateUtils;
import android.util.IndentingPrintWriter;
@@ -322,6 +321,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
return;
}
+ final int cookie = traceBegin("updateRunnableList");
final boolean wantQueue = queue.isRunnable();
final boolean inQueue = (queue == mRunnableHead) || (queue.runnableAtPrev != null)
|| (queue.runnableAtNext != null);
@@ -348,6 +348,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
if (queue.isEmpty() && !queue.isActive() && !queue.isProcessWarm()) {
removeProcessQueue(queue.processName, queue.uid);
}
+
+ traceEnd(cookie);
}
/**
@@ -362,7 +364,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
int avail = mRunning.length - getRunningSize();
if (avail == 0) return;
- final int cookie = traceBegin(TAG, "updateRunningList");
+ final int cookie = traceBegin("updateRunningList");
final long now = SystemClock.uptimeMillis();
// If someone is waiting for a state, everything is runnable now
@@ -462,7 +464,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
});
}
- traceEnd(TAG, cookie);
+ traceEnd(cookie);
}
@Override
@@ -558,6 +560,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
public void enqueueBroadcastLocked(@NonNull BroadcastRecord r) {
if (DEBUG_BROADCAST) logv("Enqueuing " + r + " for " + r.receivers.size() + " receivers");
+ final int cookie = traceBegin("enqueueBroadcast");
r.applySingletonPolicy(mService);
final IntentFilter removeMatchingFilter = (r.options != null)
@@ -627,6 +630,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
if (r.receivers.isEmpty()) {
scheduleResultTo(r);
}
+
+ traceEnd(cookie);
}
private void applyDeliveryGroupPolicy(@NonNull BroadcastRecord r) {
@@ -912,6 +917,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
private boolean finishReceiverLocked(@NonNull BroadcastProcessQueue queue,
@DeliveryState int deliveryState, @NonNull String reason) {
+ final int cookie = traceBegin("finishReceiver");
checkState(queue.isActive(), "isActive");
final ProcessRecord app = queue.app;
@@ -938,11 +944,12 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
final boolean shouldRetire =
(queue.getActiveCountSinceIdle() >= mConstants.MAX_RUNNING_ACTIVE_BROADCASTS);
+ final boolean res;
if (queue.isRunnable() && queue.isProcessWarm() && !shouldRetire) {
// We're on a roll; move onto the next broadcast for this process
queue.makeActiveNextPending();
scheduleReceiverWarmLocked(queue);
- return true;
+ res = true;
} else {
// We've drained running broadcasts; maybe move back to runnable
queue.makeActiveIdle();
@@ -956,8 +963,10 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
// Tell other OS components that app is not actively running, giving
// a chance to update OOM adjustment
notifyStoppedRunning(queue);
- return false;
+ res = false;
}
+ traceEnd(cookie);
+ return res;
}
/**
@@ -967,6 +976,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
private void setDeliveryState(@Nullable BroadcastProcessQueue queue,
@Nullable ProcessRecord app, @NonNull BroadcastRecord r, int index,
@NonNull Object receiver, @DeliveryState int newDeliveryState, String reason) {
+ final int cookie = traceBegin("setDeliveryState");
final int oldDeliveryState = getDeliveryState(r, index);
// Only apply state when we haven't already reached a terminal state;
@@ -1024,6 +1034,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
enqueueUpdateRunningList();
}
}
+
+ traceEnd(cookie);
}
private @DeliveryState int getDeliveryState(@NonNull BroadcastRecord r, int index) {
@@ -1286,18 +1298,6 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
}
}
- private int traceBegin(String trackName, String methodName) {
- final int cookie = methodName.hashCode();
- Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,
- trackName, methodName, cookie);
- return cookie;
- }
-
- private void traceEnd(String trackName, int cookie) {
- Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER,
- trackName, cookie);
- }
-
private void updateWarmProcess(@NonNull BroadcastProcessQueue queue) {
if (!queue.isProcessWarm()) {
queue.setProcess(mService.getProcessRecordLocked(queue.processName, queue.uid));