Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 580fa98f authored by Yu-Ting Tseng's avatar Yu-Ting Tseng
Browse files

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
parent 4fdea46e
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -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;