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

Commit a571b3d5 authored by Jing Ji's avatar Jing Ji Committed by Android (Google) Code Review
Browse files

Merge "Log the process hosting component types in ProcessMemorySnapshot" into udc-dev

parents 6db854c1 0284653e
Loading
Loading
Loading
Loading
+119 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app;

import android.annotation.IntDef;
import android.os.Parcel;
import android.os.Parcelable;

@@ -24,19 +25,132 @@ import android.os.Parcelable;
 * {@hide}
 */
public final class ProcessMemoryState implements Parcelable {
    /**
     * The type of the component this process is hosting;
     * this means not hosting any components (cached).
     */
    public static final int HOSTING_COMPONENT_TYPE_EMPTY =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_EMPTY;

    /**
     * The type of the component this process is hosting;
     * this means it's a system process.
     */
    public static final int HOSTING_COMPONENT_TYPE_SYSTEM =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_SYSTEM;

    /**
     * The type of the component this process is hosting;
     * this means it's a persistent process.
     */
    public static final int HOSTING_COMPONENT_TYPE_PERSISTENT =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_PERSISTENT;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a backup/restore agent.
     */
    public static final int HOSTING_COMPONENT_TYPE_BACKUP =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_BACKUP;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting an instrumentation.
     */
    public static final int HOSTING_COMPONENT_TYPE_INSTRUMENTATION =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_INSTRUMENTATION;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting an activity.
     */
    public static final int HOSTING_COMPONENT_TYPE_ACTIVITY =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_ACTIVITY;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a broadcast receiver.
     */
    public static final int HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a content provider.
     */
    public static final int HOSTING_COMPONENT_TYPE_PROVIDER =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_PROVIDER;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a started service.
     */
    public static final int HOSTING_COMPONENT_TYPE_STARTED_SERVICE =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_STARTED_SERVICE;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a foreground service.
     */
    public static final int HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE;

    /**
     * The type of the component this process is hosting;
     * this means it's being bound via a service binding.
     */
    public static final int HOSTING_COMPONENT_TYPE_BOUND_SERVICE =
            AppProtoEnums.HOSTING_COMPONENT_TYPE_BOUND_SERVICE;

    /**
     * The type of the component this process is hosting.
     * @hide
     */
    @IntDef(flag = true, prefix = { "HOSTING_COMPONENT_TYPE_" }, value = {
            HOSTING_COMPONENT_TYPE_EMPTY,
            HOSTING_COMPONENT_TYPE_SYSTEM,
            HOSTING_COMPONENT_TYPE_PERSISTENT,
            HOSTING_COMPONENT_TYPE_BACKUP,
            HOSTING_COMPONENT_TYPE_INSTRUMENTATION,
            HOSTING_COMPONENT_TYPE_ACTIVITY,
            HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER,
            HOSTING_COMPONENT_TYPE_PROVIDER,
            HOSTING_COMPONENT_TYPE_STARTED_SERVICE,
            HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE,
            HOSTING_COMPONENT_TYPE_BOUND_SERVICE,
    })
    public @interface HostingComponentType {}

    public final int uid;
    public final int pid;
    public final String processName;
    public final int oomScore;
    public final boolean hasForegroundServices;

    /**
     * The types of the components this process is hosting at the moment this snapshot is taken.
     *
     * Its value is the combination of {@link HostingComponentType}.
     */
    public final int mHostingComponentTypes;

    /**
     * The historical types of the components this process is or was hosting since it's born.
     *
     * Its value is the combination of {@link HostingComponentType}.
     */
    public final int mHistoricalHostingComponentTypes;

    public ProcessMemoryState(int uid, int pid, String processName, int oomScore,
            boolean hasForegroundServices) {
            boolean hasForegroundServices, int hostingComponentTypes,
            int historicalHostingComponentTypes) {
        this.uid = uid;
        this.pid = pid;
        this.processName = processName;
        this.oomScore = oomScore;
        this.hasForegroundServices = hasForegroundServices;
        this.mHostingComponentTypes = hostingComponentTypes;
        this.mHistoricalHostingComponentTypes = historicalHostingComponentTypes;
    }

    private ProcessMemoryState(Parcel in) {
@@ -45,6 +159,8 @@ public final class ProcessMemoryState implements Parcelable {
        processName = in.readString();
        oomScore = in.readInt();
        hasForegroundServices = in.readInt() == 1;
        mHostingComponentTypes = in.readInt();
        mHistoricalHostingComponentTypes = in.readInt();
    }

    public static final @android.annotation.NonNull Creator<ProcessMemoryState> CREATOR = new Creator<ProcessMemoryState>() {
@@ -71,5 +187,7 @@ public final class ProcessMemoryState implements Parcelable {
        parcel.writeString(processName);
        parcel.writeInt(oomScore);
        parcel.writeInt(hasForegroundServices ? 1 : 0);
        parcel.writeInt(mHostingComponentTypes);
        parcel.writeInt(mHistoricalHostingComponentTypes);
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_SYSTEM_INIT;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_UI_VISIBILITY;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.OP_NONE;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_BACKUP;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_INSTRUMENTATION;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_PERSISTENT;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_SYSTEM;
import static android.content.pm.ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT;
import static android.content.pm.PackageManager.GET_SHARED_LIBRARY_FILES;
import static android.content.pm.PackageManager.MATCH_ALL;
@@ -158,10 +162,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.MemoryStatUtil.hasMemcg;
import static com.android.server.am.ProcessList.ProcStartHandler;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BACKUP;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_INSTRUMENTATION;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_PERSISTENT;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_SYSTEM;
import static com.android.server.net.NetworkPolicyManagerInternal.updateBlockedReasonsWithProcState;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND;
@@ -17696,7 +17696,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                    final ProcessRecord r = mPidsSelfLocked.valueAt(i);
                    processMemoryStates.add(new ProcessMemoryState(
                            r.uid, r.getPid(), r.processName, r.mState.getCurAdj(),
                            r.mServices.hasForegroundServices()));
                            r.mServices.hasForegroundServices(),
                            r.mProfile.getCurrentHostingComponentTypes(),
                            r.mProfile.getHistoricalHostingComponentTypes()));
                }
            }
            return processMemoryStates;
+1 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.am;
import static android.Manifest.permission.GET_ANY_PROVIDER_TYPE;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_GET_PROVIDER;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_REMOVE_PROVIDER;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_PROVIDER;
import static android.content.ContentProvider.isAuthorityRedirectedForCloneProfile;
import static android.os.Process.PROC_CHAR;
import static android.os.Process.PROC_OUT_LONG;
@@ -34,7 +35,6 @@ import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_E
import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU;
import static com.android.server.am.ActivityManagerService.TAG_MU;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_PROVIDER;

import android.annotation.Nullable;
import android.annotation.UserIdInt;
+2 −83
Original line number Diff line number Diff line
@@ -17,9 +17,10 @@
package com.android.server.am;

import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_EMPTY;

import android.annotation.IntDef;
import android.app.IApplicationThread;
import android.app.ProcessMemoryState.HostingComponentType;
import android.content.pm.ApplicationInfo;
import android.os.Debug;
import android.os.SystemClock;
@@ -42,88 +43,6 @@ import java.util.concurrent.atomic.AtomicLong;
 * Profiling info of the process, such as PSS, cpu, etc.
 */
final class ProcessProfileRecord {
    // Keep below types in sync with the HostingComponentType in the atoms.proto.
    /**
     * The type of the component this process is hosting;
     * this means not hosting any components (cached).
     */
    static final int HOSTING_COMPONENT_TYPE_EMPTY = 0x0;

    /**
     * The type of the component this process is hosting;
     * this means it's a system process.
     */
    static final int HOSTING_COMPONENT_TYPE_SYSTEM = 0x00000001;

    /**
     * The type of the component this process is hosting;
     * this means it's a persistent process.
     */
    static final int HOSTING_COMPONENT_TYPE_PERSISTENT = 0x00000002;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a backup/restore agent.
     */
    static final int HOSTING_COMPONENT_TYPE_BACKUP = 0x00000004;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting an instrumentation.
     */
    static final int HOSTING_COMPONENT_TYPE_INSTRUMENTATION = 0x00000008;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting an activity.
     */
    static final int HOSTING_COMPONENT_TYPE_ACTIVITY = 0x00000010;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a broadcast receiver.
     */
    static final int HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER = 0x00000020;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a content provider.
     */
    static final int HOSTING_COMPONENT_TYPE_PROVIDER = 0x00000040;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a started service.
     */
    static final int HOSTING_COMPONENT_TYPE_STARTED_SERVICE = 0x00000080;

    /**
     * The type of the component this process is hosting;
     * this means it's hosting a foreground service.
     */
    static final int HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE = 0x00000100;

    /**
     * The type of the component this process is hosting;
     * this means it's being bound via a service binding.
     */
    static final int HOSTING_COMPONENT_TYPE_BOUND_SERVICE = 0x00000200;

    @IntDef(flag = true, prefix = { "HOSTING_COMPONENT_TYPE_" }, value = {
            HOSTING_COMPONENT_TYPE_EMPTY,
            HOSTING_COMPONENT_TYPE_SYSTEM,
            HOSTING_COMPONENT_TYPE_PERSISTENT,
            HOSTING_COMPONENT_TYPE_BACKUP,
            HOSTING_COMPONENT_TYPE_INSTRUMENTATION,
            HOSTING_COMPONENT_TYPE_ACTIVITY,
            HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER,
            HOSTING_COMPONENT_TYPE_PROVIDER,
            HOSTING_COMPONENT_TYPE_STARTED_SERVICE,
            HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE,
            HOSTING_COMPONENT_TYPE_BOUND_SERVICE,
    })
    @interface HostingComponentType {}

    final ProcessRecord mApp;

    private final ActivityManagerService mService;
+2 −2
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package com.android.server.am;

import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_BOUND_SERVICE;
import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_BOUND_SERVICE;
import static android.app.ProcessMemoryState.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE;

import android.app.ActivityManager;
import android.content.Context;
Loading