From a4fe1d80a49d89f288ac4f762ae677a948620c13 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Fri, 2 Jun 2023 18:01:02 -0700 Subject: [PATCH 1/2] Include intent flags in BroadcastDeliveryEventReported atom. Bug: 254521331 Test: statsd_testdrive 475 Change-Id: Iaaebedd7fa0efe4c955841a43e2f571338b5feef --- .../core/java/com/android/server/am/BroadcastQueueImpl.java | 5 +++-- .../java/com/android/server/am/BroadcastQueueModernImpl.java | 2 +- .../com/android/server/am/BroadcastQueueModernImplTest.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/am/BroadcastQueueImpl.java b/services/core/java/com/android/server/am/BroadcastQueueImpl.java index f6004d7d2b7fb..56717f5a2da52 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueImpl.java @@ -617,7 +617,8 @@ public class BroadcastQueueImpl extends BroadcastQueue { r.curApp.info.packageName, r.callerPackage, r.calculateTypeForLogging(), - r.getDeliveryGroupPolicy()); + r.getDeliveryGroupPolicy(), + r.intent.getFlags()); } if (state == BroadcastRecord.IDLE) { Slog.w(TAG_BROADCAST, "finishReceiver [" + mQueueName + "] called but state is IDLE"); @@ -798,7 +799,7 @@ public class BroadcastQueueImpl extends BroadcastQueue { dispatchDelay, receiveDelay, 0 /* finish_delay */, SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL, app != null ? app.info.packageName : null, callingPackage, - r.calculateTypeForLogging(), r.getDeliveryGroupPolicy()); + r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), r.intent.getFlags()); } } diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java index cbc75401f0b86..c1e6fc8261a9d 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java @@ -1932,7 +1932,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue { FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, uid, senderUid, actionName, receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState, app != null ? app.info.packageName : null, r.callerPackage, - r.calculateTypeForLogging(), r.getDeliveryGroupPolicy()); + r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), r.intent.getFlags()); } } diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java index 948687ae16453..6c133dda3569c 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java @@ -1407,7 +1407,7 @@ public final class BroadcastQueueModernImplTest { eq(BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST), eq(BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD), anyLong(), anyLong(), anyLong(), anyInt(), nullable(String.class), - anyString(), anyInt(), anyInt()), + anyString(), anyInt(), anyInt(), anyInt()), times(1)); } From 2379a4b857155162da38de302c643c181c866f39 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Mon, 5 Jun 2023 09:19:31 +0000 Subject: [PATCH 2/2] Log intent filter priority and broadcast sender priority. Bug: 254521331 Test: statsd_testdrive 475 Change-Id: Ic4618cbce839e73f7de7977075e12c1caebb12ca --- .../com/android/server/am/BroadcastQueueImpl.java | 15 +++++++++------ .../server/am/BroadcastQueueModernImpl.java | 3 ++- .../com/android/server/am/BroadcastRecord.java | 6 ++++++ .../java/com/android/server/am/ProcessRecord.java | 5 +++++ .../server/am/BroadcastQueueModernImplTest.java | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/am/BroadcastQueueImpl.java b/services/core/java/com/android/server/am/BroadcastQueueImpl.java index 56717f5a2da52..b6d9fd49f551c 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueImpl.java @@ -269,7 +269,7 @@ public class BroadcastQueueImpl extends BroadcastQueue { Activity.RESULT_CANCELED, null, null, false, false, oldRecord.shareIdentity, oldRecord.userId, oldRecord.callingUid, r.callingUid, r.callerPackage, - SystemClock.uptimeMillis() - oldRecord.enqueueTime, 0); + SystemClock.uptimeMillis() - oldRecord.enqueueTime, 0, 0); } catch (RemoteException e) { Slog.w(TAG, "Failure [" + mQueueName + "] sending broadcast result of " @@ -618,7 +618,9 @@ public class BroadcastQueueImpl extends BroadcastQueue { r.callerPackage, r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), - r.intent.getFlags()); + r.intent.getFlags(), + BroadcastRecord.getReceiverPriority(curReceiver), + r.callerProcState); } if (state == BroadcastRecord.IDLE) { Slog.w(TAG_BROADCAST, "finishReceiver [" + mQueueName + "] called but state is IDLE"); @@ -749,7 +751,7 @@ public class BroadcastQueueImpl extends BroadcastQueue { Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, boolean shareIdentity, int sendingUser, int receiverUid, int callingUid, String callingPackage, - long dispatchDelay, long receiveDelay) throws RemoteException { + long dispatchDelay, long receiveDelay, int priority) throws RemoteException { // If the broadcaster opted-in to sharing their identity, then expose package visibility for // the receiver. if (shareIdentity) { @@ -799,7 +801,8 @@ public class BroadcastQueueImpl extends BroadcastQueue { dispatchDelay, receiveDelay, 0 /* finish_delay */, SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL, app != null ? app.info.packageName : null, callingPackage, - r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), r.intent.getFlags()); + r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), r.intent.getFlags(), + priority, r.callerProcState); } } @@ -880,7 +883,7 @@ public class BroadcastQueueImpl extends BroadcastQueue { r.resultExtras, r.ordered, r.initialSticky, r.shareIdentity, r.userId, filter.receiverList.uid, r.callingUid, r.callerPackage, r.dispatchTime - r.enqueueTime, - r.receiverTime - r.dispatchTime); + r.receiverTime - r.dispatchTime, filter.getPriority()); // parallel broadcasts are fire-and-forget, not bookended by a call to // finishReceiverLocked(), so we manage their activity-start token here if (filter.receiverList.app != null @@ -1171,7 +1174,7 @@ public class BroadcastQueueImpl extends BroadcastQueue { r.resultData, r.resultExtras, false, false, r.shareIdentity, r.userId, r.callingUid, r.callingUid, r.callerPackage, r.dispatchTime - r.enqueueTime, - now - r.dispatchTime); + now - r.dispatchTime, 0); logBootCompletedBroadcastCompletionLatencyIfPossible(r); // Set this to null so that the reference // (local and remote) isn't kept in the mBroadcastHistory. diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java index c1e6fc8261a9d..7c227ff92fb61 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java @@ -1932,7 +1932,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue { FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, uid, senderUid, actionName, receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState, app != null ? app.info.packageName : null, r.callerPackage, - r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), r.intent.getFlags()); + r.calculateTypeForLogging(), r.getDeliveryGroupPolicy(), r.intent.getFlags(), + BroadcastRecord.getReceiverPriority(receiver), r.callerProcState); } } diff --git a/services/core/java/com/android/server/am/BroadcastRecord.java b/services/core/java/com/android/server/am/BroadcastRecord.java index cfdb13393e800..67d43fd30bade 100644 --- a/services/core/java/com/android/server/am/BroadcastRecord.java +++ b/services/core/java/com/android/server/am/BroadcastRecord.java @@ -44,6 +44,8 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UptimeMillisLong; +import android.app.ActivityManager; +import android.app.ActivityManager.ProcessState; import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.BackgroundStartPrivileges; @@ -93,6 +95,7 @@ final class BroadcastRecord extends Binder { final @Nullable String callerFeatureId; // which feature in the package sent this final int callingPid; // the pid of who sent this final int callingUid; // the uid of who sent this + final @ProcessState int callerProcState; // Procstate of the caller process at enqueue time. final int originalStickyCallingUid; // if this is a sticky broadcast, the Uid of the original sender @@ -462,6 +465,8 @@ final class BroadcastRecord extends Binder { callerFeatureId = _callerFeatureId; callingPid = _callingPid; callingUid = _callingUid; + callerProcState = callerApp == null ? ActivityManager.PROCESS_STATE_UNKNOWN + : callerApp.getCurProcState(); callerInstantApp = _callerInstantApp; callerInstrumented = isCallerInstrumented(_callerApp, _callingUid); resolvedType = _resolvedType; @@ -515,6 +520,7 @@ final class BroadcastRecord extends Binder { callerFeatureId = from.callerFeatureId; callingPid = from.callingPid; callingUid = from.callingUid; + callerProcState = from.callerProcState; callerInstantApp = from.callerInstantApp; callerInstrumented = from.callerInstrumented; ordered = from.ordered; diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java index d6495c78574ca..267d2464e0d52 100644 --- a/services/core/java/com/android/server/am/ProcessRecord.java +++ b/services/core/java/com/android/server/am/ProcessRecord.java @@ -669,6 +669,11 @@ class ProcessRecord implements WindowProcessListener { return mOnewayThread; } + @GuardedBy(anyOf = {"mService", "mProcLock"}) + int getCurProcState() { + return mState.getCurProcState(); + } + @GuardedBy({"mService", "mProcLock"}) public void makeActive(IApplicationThread thread, ProcessStatsService tracker) { mProfile.onProcessActive(thread, tracker); diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java index 6c133dda3569c..582685cf009ee 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java @@ -1407,7 +1407,7 @@ public final class BroadcastQueueModernImplTest { eq(BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST), eq(BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD), anyLong(), anyLong(), anyLong(), anyInt(), nullable(String.class), - anyString(), anyInt(), anyInt(), anyInt()), + anyString(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt()), times(1)); }