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

Commit 24bbe58d authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add package information to association sources.

This is often known by the system, though not always.  But when
we do know it, it is really useful to maintain that info so we can
do queries like "give me all of the associations that package X is
involved with".

Bug: 121146315
Test: manual
Change-Id: I0dd7aeb9147ecfd65a510d3b2a8bb4a0fbab57e3
parent 00b10eff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6155,7 +6155,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        try {
            synchronized (getGetProviderLock(auth, userId)) {
                holder = ActivityManager.getService().getContentProvider(
                        getApplicationThread(), auth, userId, stable);
                        getApplicationThread(), c.getOpPackageName(), auth, userId, stable);
            }
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ interface IActivityManager {
            int ignoreWindowingMode);
    void moveTaskToFront(int task, int flags, in Bundle options);
    int getTaskForActivity(in IBinder token, in boolean onlyRoot);
    ContentProviderHolder getContentProvider(in IApplicationThread caller,
    ContentProviderHolder getContentProvider(in IApplicationThread caller, in String callingPackage,
            in String name, int userId, boolean stable);
    void publishContentProviders(in IApplicationThread caller,
            in List<ContentProviderHolder> providers);
+34 −11
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.app.procstats;


import android.annotation.Nullable;
import android.os.Parcel;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -192,9 +193,16 @@ public final class AssociationState {
         */
        String mProcess;

        SourceKey(int uid, String process) {
        /**
         * Optional package name, or null; consider this final.  Not final just to avoid a
         * temporary object during lookup.
         */
        @Nullable String mPackage;

        SourceKey(int uid, String process, String pkg) {
            mUid = uid;
            mProcess = process;
            mPackage = pkg;
        }

        public boolean equals(Object o) {
@@ -202,12 +210,14 @@ public final class AssociationState {
                return false;
            }
            SourceKey s = (SourceKey) o;
            return s.mUid == mUid && Objects.equals(s.mProcess, mProcess);
            return s.mUid == mUid && Objects.equals(s.mProcess, mProcess)
                    && Objects.equals(s.mPackage, mPackage);
        }

        @Override
        public int hashCode() {
            return Integer.hashCode(mUid) ^ (mProcess == null ? 0 : mProcess.hashCode());
            return Integer.hashCode(mUid) ^ (mProcess == null ? 0 : mProcess.hashCode())
                    ^ (mPackage == null ? 0 : (mPackage.hashCode() * 33));
        }

        @Override
@@ -217,6 +227,8 @@ public final class AssociationState {
            UserHandle.formatUid(sb, mUid);
            sb.append(' ');
            sb.append(mProcess);
            sb.append(' ');
            sb.append(mPackage);
            sb.append('}');
            return sb.toString();
        }
@@ -227,7 +239,7 @@ public final class AssociationState {
     */
    private final ArrayMap<SourceKey, SourceState> mSources = new ArrayMap<>();

    private final SourceKey mTmpSourceKey = new SourceKey(0, null);
    private final SourceKey mTmpSourceKey = new SourceKey(0, null, null);

    private ProcessState mProc;

@@ -266,12 +278,13 @@ public final class AssociationState {
        mProc = proc;
    }

    public SourceState startSource(int uid, String processName) {
    public SourceState startSource(int uid, String processName, String packageName) {
        mTmpSourceKey.mUid = uid;
        mTmpSourceKey.mProcess = processName;
        mTmpSourceKey.mPackage = packageName;
        SourceState src = mSources.get(mTmpSourceKey);
        if (src == null) {
            SourceKey key = new SourceKey(uid, processName);
            SourceKey key = new SourceKey(uid, processName, packageName);
            src = new SourceState(key);
            mSources.put(key, src);
        }
@@ -379,6 +392,7 @@ public final class AssociationState {
            final SourceState src = mSources.valueAt(isrc);
            out.writeInt(key.mUid);
            stats.writeCommonString(out, key.mProcess);
            stats.writeCommonString(out, key.mPackage);
            out.writeInt(src.mCount);
            out.writeLong(src.mDuration);
            out.writeInt(src.mActiveCount);
@@ -405,7 +419,8 @@ public final class AssociationState {
        for (int isrc = 0; isrc < NSRC; isrc++) {
            final int uid = in.readInt();
            final String procName = stats.readCommonString(in, parcelVersion);
            final SourceKey key = new SourceKey(uid, procName);
            final String pkgName = stats.readCommonString(in, parcelVersion);
            final SourceKey key = new SourceKey(uid, procName, pkgName);
            final SourceState src = new SourceState(key);
            src.mCount = in.readInt();
            src.mDuration = in.readLong();
@@ -445,10 +460,11 @@ public final class AssociationState {
        }
    }

    public boolean hasProcess(String procName) {
    public boolean hasProcessOrPackage(String procName) {
        final int NSRC = mSources.size();
        for (int isrc = 0; isrc < NSRC; isrc++) {
            if (mSources.keyAt(isrc).mProcess.equals(procName)) {
            final SourceKey key = mSources.keyAt(isrc);
            if (procName.equals(key.mProcess) || procName.equals(key.mPackage)) {
                return true;
            }
        }
@@ -466,7 +482,8 @@ public final class AssociationState {
        for (int isrc = 0; isrc < NSRC; isrc++) {
            final SourceKey key = mSources.keyAt(isrc);
            final SourceState src = mSources.valueAt(isrc);
            if (reqPackage != null && !reqPackage.equals(key.mProcess)) {
            if (reqPackage != null && !reqPackage.equals(key.mProcess)
                    && !reqPackage.equals(key.mPackage)) {
                continue;
            }
            pw.print(prefixInner);
@@ -474,6 +491,11 @@ public final class AssociationState {
            pw.print(key.mProcess);
            pw.print("/");
            UserHandle.formatUid(pw, key.mUid);
            if (key.mPackage != null) {
                pw.print(" (");
                pw.print(key.mPackage);
                pw.print(")");
            }
            pw.println(":");
            pw.print(prefixInner);
            pw.print("   Total count ");
@@ -683,6 +705,7 @@ public final class AssociationState {
            final SourceState src = mSources.valueAt(isrc);
            final long sourceToken = proto.start(PackageAssociationProcessStatsProto.SOURCES);
            proto.write(PackageAssociationSourceProcessStatsProto.PROCESS_NAME, key.mProcess);
            proto.write(PackageAssociationSourceProcessStatsProto.PACKAGE_NAME, key.mPackage);
            proto.write(PackageAssociationSourceProcessStatsProto.PROCESS_UID, key.mUid);
            proto.write(PackageAssociationSourceProcessStatsProto.TOTAL_COUNT, src.mCount);
            long duration = src.mDuration;
+3 −3
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ public final class ProcessStats implements Parcelable {
            {"proc", "pkg-proc", "pkg-svc", "pkg-asc", "pkg-all", "all"};

    // Current version of the parcel format.
    private static final int PARCEL_VERSION = 34;
    private static final int PARCEL_VERSION = 35;
    // In-memory Parcel magic number, used to detect attempts to unmarshall bad data
    private static final int MAGIC = 0x50535454;

@@ -1490,7 +1490,7 @@ public final class ProcessStats implements Parcelable {
                                // package, so that if so we print those.
                                for (int iasc = 0; iasc < NASCS; iasc++) {
                                    AssociationState asc = pkgState.mAssociations.valueAt(iasc);
                                    if (asc.hasProcess(reqPackage)) {
                                    if (asc.hasProcessOrPackage(reqPackage)) {
                                        onlyAssociations = true;
                                        break;
                                    }
@@ -1591,7 +1591,7 @@ public final class ProcessStats implements Parcelable {
                            for (int iasc = 0; iasc < NASCS; iasc++) {
                                AssociationState asc = pkgState.mAssociations.valueAt(iasc);
                                if (!pkgMatch && !reqPackage.equals(asc.getProcessName())) {
                                    if (!onlyAssociations || !asc.hasProcess(reqPackage)) {
                                    if (!onlyAssociations || !asc.hasProcessOrPackage(reqPackage)) {
                                        continue;
                                    }
                                }
+3 −1
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ message PackageServiceStatsProto {
    repeated PackageServiceOperationStatsProto operation_stats = 2;
}

// Next Tag: 7
// Next Tag: 8
message PackageAssociationSourceProcessStatsProto {
    option (android.msg_privacy).dest = DEST_AUTOMATIC;

@@ -194,6 +194,8 @@ message PackageAssociationSourceProcessStatsProto {
    optional int32 process_uid = 1;
    // Process name.
    optional string process_name = 2;
    // Package name.
    optional string package_name = 7;

    // Total count of the times this association appeared.
    optional int32 total_count = 3;
Loading