diff options
| author | 2023-03-16 23:44:36 -0700 | |
|---|---|---|
| committer | 2023-03-17 16:49:32 -0700 | |
| commit | 0b774f93c32d401094bff02641b226ae237bf74c (patch) | |
| tree | 6ee18e21ebf0b8d47544fca5aa9b95369aab9cbc | |
| parent | 46d80767e64d0463a36f659dbd851399bea101dd (diff) | |
Log the package name of the broadcast/service/provider requests
Bug: 273390508
Test: statsd_testdrive 475 476 477
Change-Id: I421ec5c9e3ca08be8adb88e1ccf06cae1a0e0170
6 files changed, 40 insertions, 24 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 4a0a228ce645..c129938ea7b1 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -602,7 +602,7 @@ public final class ActiveServices { try { final ServiceRecord.StartItem si = r.pendingStarts.get(0); startServiceInnerLocked(this, si.intent, r, false, true, si.callingId, - si.mCallingProcessName, r.startRequested); + si.mCallingProcessName, r.startRequested, si.mCallingPackageName); } catch (TransactionTooLargeException e) { // Ignore, nobody upstack cares. } @@ -969,7 +969,7 @@ public final class ActiveServices { startServiceInnerLocked(r, service, callingUid, callingPid, getCallingProcessNameLocked(callingUid, callingPid, callingPackage), fgRequired, callerFg, - backgroundStartPrivileges); + backgroundStartPrivileges, callingPackage); if (res.aliasComponent != null && !realResult.getPackageName().startsWith("!") && !realResult.getPackageName().startsWith("?")) { @@ -990,7 +990,7 @@ public final class ActiveServices { private ComponentName startServiceInnerLocked(ServiceRecord r, Intent service, int callingUid, int callingPid, String callingProcessName, boolean fgRequired, boolean callerFg, - BackgroundStartPrivileges backgroundStartPrivileges) + BackgroundStartPrivileges backgroundStartPrivileges, String callingPackage) throws TransactionTooLargeException { NeededUriGrants neededGrants = mAm.mUgmInternal.checkGrantUriPermissionFromIntent( service, callingUid, r.packageName, r.userId); @@ -1003,7 +1003,7 @@ public final class ActiveServices { r.delayedStop = false; r.fgRequired = fgRequired; r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(), - service, neededGrants, callingUid, callingProcessName)); + service, neededGrants, callingUid, callingProcessName, callingPackage)); if (fgRequired) { // We are now effectively running a foreground service. @@ -1088,7 +1088,7 @@ public final class ActiveServices { r.allowBgActivityStartsOnServiceStart(backgroundStartPrivileges); } ComponentName cmp = startServiceInnerLocked(smap, service, r, callerFg, addToStarting, - callingUid, callingProcessName, wasStartRequested); + callingUid, callingProcessName, wasStartRequested, callingPackage); return cmp; } @@ -1241,7 +1241,7 @@ public final class ActiveServices { try { startServiceInnerLocked(s, serviceIntent, callingUid, callingPid, callingProcessName, fgRequired, callerFg, - backgroundStartPrivileges); + backgroundStartPrivileges, callingPackage); } catch (TransactionTooLargeException e) { /* ignore - local call */ } @@ -1287,7 +1287,7 @@ public final class ActiveServices { ComponentName startServiceInnerLocked(ServiceMap smap, Intent service, ServiceRecord r, boolean callerFg, boolean addToStarting, int callingUid, String callingProcessName, - boolean wasStartRequested) throws TransactionTooLargeException { + boolean wasStartRequested, String callingPackage) throws TransactionTooLargeException { synchronized (mAm.mProcessStats.mLock) { final ServiceState stracker = r.getTracker(); if (stracker != null) { @@ -1328,7 +1328,9 @@ public final class ActiveServices { : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM), getShortProcessNameForStats(callingUid, callingProcessName), getShortServiceNameForStats(r), - packageState); + packageState, + packageName, + callingPackage); if (r.startRequested && addToStarting) { boolean first = smap.mStartingBackground.size() == 0; @@ -3661,7 +3663,9 @@ public final class ActiveServices { : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM), getShortProcessNameForStats(callingUid, callerApp.processName), getShortServiceNameForStats(s), - packageState); + packageState, + s.packageName, + callerApp.info.packageName); if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "Bind " + s + " with " + b + ": received=" + b.intent.received @@ -5253,7 +5257,7 @@ public final class ActiveServices { // be called. if (r.startRequested && r.callStart && r.pendingStarts.size() == 0) { r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(), - null, null, 0, null)); + null, null, 0, null, null)); } sendServiceArgsLocked(r, execInFg, true); @@ -6247,7 +6251,7 @@ public final class ActiveServices { stopServiceLocked(sr, true); } else { sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true, - sr.getLastStartId(), baseIntent, null, 0, null)); + sr.getLastStartId(), baseIntent, null, 0, null, null)); if (sr.app != null && sr.app.getThread() != null) { // We always run in the foreground, since this is called as // part of the "remove task" UI operation. diff --git a/services/core/java/com/android/server/am/BroadcastQueueImpl.java b/services/core/java/com/android/server/am/BroadcastQueueImpl.java index c08570684aec..fcddff0e5ebc 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueImpl.java @@ -601,7 +601,9 @@ public class BroadcastQueueImpl extends BroadcastQueue { r.dispatchTime - r.enqueueTime, r.receiverTime - r.dispatchTime, finishTime - r.receiverTime, - packageState); + packageState, + r.curApp.info.packageName, + r.callerPackage); } if (state == BroadcastRecord.IDLE) { Slog.w(TAG_BROADCAST, "finishReceiver [" + mQueueName + "] called but state is IDLE"); @@ -780,7 +782,8 @@ public class BroadcastQueueImpl extends BroadcastQueue { BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__RUNTIME, BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM, dispatchDelay, receiveDelay, 0 /* finish_delay */, - SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL); + SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL, + app != null ? app.info.packageName : null, callingPackage); } } diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java index bef16b6f081c..c785a60846cb 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java @@ -1122,7 +1122,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue { } r.terminalCount++; - notifyFinishReceiver(queue, r, index, receiver); + notifyFinishReceiver(queue, app, r, index, receiver); checkFinished = true; } // When entire ordered broadcast finished, deliver final result @@ -1593,9 +1593,10 @@ class BroadcastQueueModernImpl extends BroadcastQueue { * typically for internal bookkeeping. */ private void notifyFinishReceiver(@Nullable BroadcastProcessQueue queue, - @NonNull BroadcastRecord r, int index, @NonNull Object receiver) { + @Nullable ProcessRecord app, @NonNull BroadcastRecord r, int index, + @NonNull Object receiver) { if (r.wasDeliveryAttempted(index)) { - logBroadcastDeliveryEventReported(queue, r, index, receiver); + logBroadcastDeliveryEventReported(queue, app, r, index, receiver); } final boolean recordFinished = (r.terminalCount == r.receivers.size()); @@ -1605,7 +1606,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue { } private void logBroadcastDeliveryEventReported(@Nullable BroadcastProcessQueue queue, - @NonNull BroadcastRecord r, int index, @NonNull Object receiver) { + @Nullable ProcessRecord app, @NonNull BroadcastRecord r, int index, + @NonNull Object receiver) { // Report statistics for each individual receiver final int uid = getReceiverUid(receiver); final int senderUid = (r.callingUid == -1) ? Process.SYSTEM_UID : r.callingUid; @@ -1631,7 +1633,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue { ? SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL; FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, uid, senderUid, actionName, - receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState); + receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState, + app != null ? app.info.packageName : null, r.callerPackage); } } diff --git a/services/core/java/com/android/server/am/ContentProviderHelper.java b/services/core/java/com/android/server/am/ContentProviderHelper.java index 48df1494fbe8..a1fcd424f8c1 100644 --- a/services/core/java/com/android/server/am/ContentProviderHelper.java +++ b/services/core/java/com/android/server/am/ContentProviderHelper.java @@ -263,7 +263,8 @@ public class ContentProviderHelper { PROVIDER_ACQUISITION_EVENT_REPORTED, r.uid, callingUid, PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM, - PROVIDER_ACQUISITION_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL); + PROVIDER_ACQUISITION_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL, + cpi.packageName, callingPackage); return holder; } @@ -334,7 +335,8 @@ public class ContentProviderHelper { PROVIDER_ACQUISITION_EVENT_REPORTED, cpr.proc.uid, callingUid, PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM, - PROVIDER_ACQUISITION_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL); + PROVIDER_ACQUISITION_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL, + cpi.packageName, callingPackage); } } finally { Binder.restoreCallingIdentity(origId); @@ -511,7 +513,8 @@ public class ContentProviderHelper { PROVIDER_ACQUISITION_EVENT_REPORTED, proc.uid, callingUid, PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM, - PROVIDER_ACQUISITION_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL); + PROVIDER_ACQUISITION_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL, + cpi.packageName, callingPackage); } else { final int packageState = ((cpr.appInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) @@ -536,7 +539,7 @@ public class ContentProviderHelper { PROVIDER_ACQUISITION_EVENT_REPORTED, proc.uid, callingUid, PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD, - packageState); + packageState, cpi.packageName, callingPackage); } cpr.launchingApp = proc; mLaunchingProviders.add(cpr); diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index 663121ea3212..4defdc6976e1 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -249,6 +249,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN final String mCallingProcessName; final Intent intent; final NeededUriGrants neededGrants; + final @Nullable String mCallingPackageName; long deliveredTime; int deliveryCount; int doneExecutingCount; @@ -258,7 +259,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent, NeededUriGrants _neededGrants, int _callingId, - String callingProcessName) { + String callingProcessName, @Nullable String callingPackageName) { sr = _sr; taskRemoved = _taskRemoved; id = _id; @@ -266,6 +267,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN neededGrants = _neededGrants; callingId = _callingId; mCallingProcessName = callingProcessName; + mCallingPackageName = callingPackageName; } UriPermissionOwner getUriPermissionsLocked() { 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 8a5d3a6772a5..63e8e56d09b2 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java @@ -50,6 +50,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -1078,7 +1079,7 @@ public final class BroadcastQueueModernImplTest { eq(getUidForPackage(PACKAGE_GREEN)), anyInt(), eq(Intent.ACTION_TIME_TICK), eq(BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST), eq(BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD), - anyLong(), anyLong(), anyLong(), anyInt()), times(1)); + anyLong(), anyLong(), anyLong(), anyInt(), anyString(), anyString()), times(1)); } private Intent createPackageChangedIntent(int uid, List<String> componentNameList) { |