diff options
| author | 2023-10-18 13:53:36 -0700 | |
|---|---|---|
| committer | 2023-10-20 15:15:03 -0700 | |
| commit | 580fa98fbff101238478ddb27083f097a62f382a (patch) | |
| tree | 874d2dc4e13f4a876a5e7ebe7b39c2c23f4fe67d | |
| parent | 4fdea46e9be396db4ae77ad82abc9379b121cf01 (diff) | |
Report mApp.uid instead of mApp.info.uid.
The two differ in the case of SDK sandbox process. The former would be
the uid of the actual app process hosting the SDK. The latter is a
generic uid for the sdksandbox package.
Test: atest ProcStatsTests
Bug=304599926
Change-Id: Ia29d088b909532319d5b17084a94f79090f86cff
| -rw-r--r-- | services/core/java/com/android/server/am/ProcessProfileRecord.java | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/am/ProcessProfileRecord.java b/services/core/java/com/android/server/am/ProcessProfileRecord.java index db74f1aed422..ae2670c880bf 100644 --- a/services/core/java/com/android/server/am/ProcessProfileRecord.java +++ b/services/core/java/com/android/server/am/ProcessProfileRecord.java @@ -23,6 +23,7 @@ import android.app.IApplicationThread; import android.app.ProcessMemoryState.HostingComponentType; import android.content.pm.ApplicationInfo; import android.os.Debug; +import android.os.Process; import android.os.SystemClock; import android.util.DebugUtils; import android.util.TimeUtils; @@ -266,15 +267,17 @@ final class ProcessProfileRecord { origBase.makeInactive(); } final ApplicationInfo info = mApp.info; + final int attributionUid = getUidForAttribution(mApp); final ProcessState baseProcessTracker = tracker.getProcessStateLocked( - info.packageName, info.uid, info.longVersionCode, mApp.processName); + info.packageName, attributionUid, info.longVersionCode, + mApp.processName); setBaseProcessTracker(baseProcessTracker); baseProcessTracker.makeActive(); pkgList.forEachPackage((pkgName, holder) -> { if (holder.state != null && holder.state != origBase) { holder.state.makeInactive(); } - tracker.updateProcessStateHolderLocked(holder, pkgName, mApp.info.uid, + tracker.updateProcessStateHolderLocked(holder, pkgName, attributionUid, mApp.info.longVersionCode, mApp.processName); if (holder.state != baseProcessTracker) { holder.state.makeActive(); @@ -531,7 +534,7 @@ final class ProcessProfileRecord { tracker.reportCachedKill(pkgList.getPackageListLocked(), mLastCachedPss); pkgList.forEachPackageProcessStats(holder -> FrameworkStatsLog.write(FrameworkStatsLog.CACHED_KILL_REPORTED, - mApp.info.uid, + getUidForAttribution(mApp), holder.state.getName(), holder.state.getPackage(), mLastCachedPss, @@ -586,6 +589,21 @@ final class ProcessProfileRecord { tracker.mPendingMemState = -1; } + /** + * Returns the uid that should be used for attribution purposes in profiling / stats. + * + * In most cases this returns the uid of the process itself. For isolated processes though, + * since the process uid is dynamically allocated and can't easily be traced back to the app, + * for attribution we use the app package uid. + */ + private static int getUidForAttribution(ProcessRecord processRecord) { + if (Process.isIsolatedUid(processRecord.uid)) { + return processRecord.info.uid; + } else { + return processRecord.uid; + } + } + @GuardedBy("mProfilerLock") int getPid() { return mPid; |