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

Commit 5194c025 authored by Yu-Ting Tseng's avatar Yu-Ting Tseng Committed by Android (Google) Code Review
Browse files

Merge "Make a few AM APIs available to native callers." into main

parents a2ba06b7 d88863d7
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -419,6 +419,20 @@ filegroup {
    ],
    ],
}
}


filegroup {
    name: "activity_manager_iprocessobserver_aidl",
    srcs: [
        "android/app/IProcessObserver.aidl",
    ],
}

filegroup {
    name: "activity_manager_runningappprocessinfo_aidl",
    srcs: [
        "android/app/RunningAppProcessInfo.aidl",
    ],
}

filegroup {
filegroup {
    name: "hwbinder-stubs-srcs",
    name: "hwbinder-stubs-srcs",
    srcs: [
    srcs: [
+47 −57
Original line number Original line Diff line number Diff line
@@ -3747,6 +3747,9 @@ public class ActivityManager {
     * Information you can retrieve about a running process.
     * Information you can retrieve about a running process.
     */
     */
    public static class RunningAppProcessInfo implements Parcelable {
    public static class RunningAppProcessInfo implements Parcelable {
        // The list of fields must be kept in sync with RunningAppProcessInfo.aidl.
        // LINT.IfChange

        /**
        /**
         * The name of the process that this object is associated with
         * The name of the process that this object is associated with
         */
         */
@@ -3773,33 +3776,9 @@ public class ActivityManager {
         */
         */
        public String[] pkgDeps;
        public String[] pkgDeps;


        /**
         * Constant for {@link #flags}: this is an app that is unable to
         * correctly save its state when going to the background,
         * so it can not be killed while in the background.
         * @hide
         */
        public static final int FLAG_CANT_SAVE_STATE = 1<<0;

        /**
         * Constant for {@link #flags}: this process is associated with a
         * persistent system app.
         * @hide
         */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
        public static final int FLAG_PERSISTENT = 1<<1;

        /**
         * Constant for {@link #flags}: this process is associated with a
         * persistent system app.
         * @hide
         */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
        public static final int FLAG_HAS_ACTIVITIES = 1<<2;

        /**
        /**
         * Flags of information.  May be any of
         * Flags of information.  May be any of
         * {@link #FLAG_CANT_SAVE_STATE}.
         * {@link android.app.RunningAppProcessInfo#FLAG_CANT_SAVE_STATE}.
         * @hide
         * @hide
         */
         */
        @UnsupportedAppUsage
        @UnsupportedAppUsage
@@ -4127,6 +4106,8 @@ public class ActivityManager {
         */
         */
        public long lastActivityTime;
        public long lastActivityTime;


        // LINT.ThenChange(frameworks/base/core/java/android/app/RunningAppProcessInfo.aidl)

        public RunningAppProcessInfo() {
        public RunningAppProcessInfo() {
            importance = IMPORTANCE_FOREGROUND;
            importance = IMPORTANCE_FOREGROUND;
            importanceReasonCode = REASON_UNKNOWN;
            importanceReasonCode = REASON_UNKNOWN;
@@ -4148,41 +4129,50 @@ public class ActivityManager {
        }
        }


        public void writeToParcel(Parcel dest, int flags) {
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(processName);
            final android.app.RunningAppProcessInfo info = new android.app.RunningAppProcessInfo();
            dest.writeInt(pid);
            info.processName = TextUtils.emptyIfNull(processName);
            dest.writeInt(uid);
            info.pid = pid;
            dest.writeStringArray(pkgList);
            info.uid = uid;
            dest.writeStringArray(pkgDeps);
            info.pkgList = pkgList;
            dest.writeInt(this.flags);
            info.pkgDeps = pkgDeps;
            dest.writeInt(lastTrimLevel);
            info.flags = this.flags;
            dest.writeInt(importance);
            info.lastTrimLevel = lastTrimLevel;
            dest.writeInt(lru);
            info.importance = importance;
            dest.writeInt(importanceReasonCode);
            info.lru = lru;
            dest.writeInt(importanceReasonPid);
            info.importanceReasonCode = importanceReasonCode;
            ComponentName.writeToParcel(importanceReasonComponent, dest);
            info.importanceReasonPid = importanceReasonPid;
            dest.writeInt(importanceReasonImportance);
            info.importanceReasonComponent = importanceReasonComponent != null
            dest.writeInt(processState);
                    ? importanceReasonComponent.flattenToString()
            dest.writeInt(isFocused ? 1 : 0);
                    : null;
            dest.writeLong(lastActivityTime);
            info.importanceReasonImportance = importanceReasonImportance;
            info.processState = processState;
            info.isFocused = isFocused;
            info.lastActivityTime = lastActivityTime;

            info.writeToParcel(dest, flags);
        }
        }


        public void readFromParcel(Parcel source) {
        public void readFromParcel(Parcel source) {
            processName = source.readString();
            final android.app.RunningAppProcessInfo info = new android.app.RunningAppProcessInfo();
            pid = source.readInt();
            info.readFromParcel(source);
            uid = source.readInt();
            processName = info.processName;
            pkgList = source.readStringArray();
            pid = info.pid;
            pkgDeps = source.readStringArray();
            uid = info.uid;
            flags = source.readInt();
            pkgList = info.pkgList;
            lastTrimLevel = source.readInt();
            pkgDeps = info.pkgDeps;
            importance = source.readInt();
            flags = info.flags;
            lru = source.readInt();
            lastTrimLevel = info.lastTrimLevel;
            importanceReasonCode = source.readInt();
            importance = info.importance;
            importanceReasonPid = source.readInt();
            lru = info.lru;
            importanceReasonComponent = ComponentName.readFromParcel(source);
            importanceReasonCode = info.importanceReasonCode;
            importanceReasonImportance = source.readInt();
            importanceReasonPid = info.importanceReasonPid;
            processState = source.readInt();
            importanceReasonComponent = info.importanceReasonComponent != null
            isFocused = source.readInt() != 0;
                    ? ComponentName.unflattenFromString(info.importanceReasonComponent)
            lastActivityTime = source.readLong();
                    : null;
            importanceReasonImportance = info.importanceReasonImportance;
            processState = info.processState;
            isFocused = info.isFocused;
            lastActivityTime = info.lastActivityTime;
        }
        }


        /**
        /**
+7 −6
Original line number Original line Diff line number Diff line
@@ -154,6 +154,13 @@ interface IActivityManager {


    /** Logs API state change to associate with an FGS, used for FGS Type Metrics */
    /** Logs API state change to associate with an FGS, used for FGS Type Metrics */
    oneway void logFgsApiStateChanged(int apiType, int state, int appUid, int appPid);
    oneway void logFgsApiStateChanged(int apiType, int state, int appUid, int appPid);

    @UnsupportedAppUsage
    void registerProcessObserver(in IProcessObserver observer);
    @UnsupportedAppUsage
    void unregisterProcessObserver(in IProcessObserver observer);
    @UnsupportedAppUsage
    List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses();
    // =============== End of transactions used on native side as well ============================
    // =============== End of transactions used on native side as well ============================


    // Special low-level communication with activity manager.
    // Special low-level communication with activity manager.
@@ -344,8 +351,6 @@ interface IActivityManager {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    List<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags);
    List<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags);
    // Retrieve running application processes in the system
    // Retrieve running application processes in the system
    @UnsupportedAppUsage
    List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses();
    IBinder peekService(in Intent service, in String resolvedType, in String callingPackage);
    IBinder peekService(in Intent service, in String resolvedType, in String callingPackage);
    // Turn on/off profiling in a particular process.
    // Turn on/off profiling in a particular process.
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
@@ -410,10 +415,6 @@ interface IActivityManager {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    void setStopUserOnSwitch(int value);
    void setStopUserOnSwitch(int value);
    boolean removeTask(int taskId);
    boolean removeTask(int taskId);
    @UnsupportedAppUsage
    void registerProcessObserver(in IProcessObserver observer);
    @UnsupportedAppUsage
    void unregisterProcessObserver(in IProcessObserver observer);
    boolean isIntentSenderTargetedToPackage(in IIntentSender sender);
    boolean isIntentSenderTargetedToPackage(in IIntentSender sender);
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    void updatePersistentConfiguration(in Configuration values);
    void updatePersistentConfiguration(in Configuration values);
+275 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

/**
 * Information about an app process.
 *
 * For historical reasons, there is also an identical struct defined in Java
 * (android.app.ActivityManager.RunningAppProcessInfo), which existed
 * before this AIDL struct is created. The existing Java class exposes public
 * APIs in a way that can not be directly replaced with this new AIDL struct.
 * Therefore both the Java class and this AIDL struct would continue to
 * co-exist. The Java class continues to provide a public API, and internally
 * uses this AIDL struct for parceling / unparceling.
 *
 * {@hide}
 */
parcelable RunningAppProcessInfo {
    /**
     * The name of the process that this object is associated with
     */
    @utf8InCpp String processName;

    /**
     * The pid of this process; 0 if none
     */
    int pid;

    /**
     * The user id of this process.
     */
    int uid;

    /**
     * All packages that have been loaded into the process.
     */
    @utf8InCpp String[] pkgList;

    /**
     * Additional packages loaded into the process as dependency.
     */
    @utf8InCpp String[] pkgDeps;

    /**
     * Constant for {@link #flags}: this is an app that is unable to
     * correctly save its state when going to the background,
     * so it can not be killed while in the background.
     */
    const int FLAG_CANT_SAVE_STATE = 1<<0;

    /**
     * Constant for {@link #flags}: this process is associated with a
     * persistent system app.
     */
    const int FLAG_PERSISTENT = 1<<1;

    /**
     * Constant for {@link #flags}: this process is associated with a
     * persistent system app.
     */
    const int FLAG_HAS_ACTIVITIES = 1<<2;

    /**
     * Flags of information.  May be any of
     * {@link #FLAG_CANT_SAVE_STATE}.
     */
    int flags;

    /**
     * Last memory trim level reported to the process: corresponds to
     * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
     * ComponentCallbacks2.onTrimMemory(int)}.
     */
    int lastTrimLevel;

    /**
     * Constant for {@link #importance}: This process is running the
     * foreground UI; that is, it is the thing currently at the top of the screen
     * that the user is interacting with.
     */
    const int IMPORTANCE_FOREGROUND = 100;

    /**
     * Constant for {@link #importance}: This process is running a foreground
     * service, for example to perform music playback even while the user is
     * not immediately in the app.  This generally indicates that the process
     * is doing something the user actively cares about.
     */
    const int IMPORTANCE_FOREGROUND_SERVICE = 125;

    /**
     * Constant for {@link #importance}: This process is running something
     * that is actively visible to the user, though not in the immediate
     * foreground.  This may be running a window that is behind the current
     * foreground (so paused and with its state saved, not interacting with
     * the user, but visible to them to some degree); it may also be running
     * other services under the system's control that it inconsiders important.
     */
    const int IMPORTANCE_VISIBLE = 200;

    /**
     * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
     * before {@link Build.VERSION_CODES#O}.  Since the {@link Build.VERSION_CODES#O} SDK,
     * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
     *
     * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
     * on Android versions below {@link Build.VERSION_CODES#O}.
     *
     * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
     * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
     * For apps targeting version {@link Build.VERSION_CODES#O} and later,
     * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
     */
    const int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;

    /**
     * Constant for {@link #importance}: This process is not something the user
     * is directly aware of, but is otherwise perceptible to them to some degree.
     */
    const int IMPORTANCE_PERCEPTIBLE = 230;

    /**
     * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
     * this wrong value
     * before {@link Build.VERSION_CODES#O}.  Since the {@link Build.VERSION_CODES#O} SDK,
     * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
     *
     * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
     * on Android versions below {@link Build.VERSION_CODES#O}.
     *
     * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
     * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
     * For apps targeting version {@link Build.VERSION_CODES#O} and later,
     * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
     */
    const int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;

    /**
     * Constant for {@link #importance}: This process contains services
     * that should remain running.  These are background services apps have
     * started, not something the user is aware of, so they may be killed by
     * the system relatively freely (though it is generally desired that they
     * stay running as long as they want to).
     */
    const int IMPORTANCE_SERVICE = 300;

    /**
     * Constant for {@link #importance}: This process is running the foreground
     * UI, but the device is asleep so it is not visible to the user.  Though the
     * system will try hard to keep its process from being killed, in all other
     * ways we consider it a kind of cached process, with the limitations that go
     * along with that state: network access, running background services, etc.
     */
    const int IMPORTANCE_TOP_SLEEPING = 325;

    /**
     * Constant for {@link #importance}: This process is running an
     * application that can not save its state, and thus can't be killed
     * while in the background.  This will be used with apps that have
     * {@link android.R.attr#cantSaveState} set on their application tag.
     */
    const int IMPORTANCE_CANT_SAVE_STATE = 350;

    /**
     * Constant for {@link #importance}: This process process contains
     * cached code that is expendable, not actively running any app components
     * we care about.
     */
    const int IMPORTANCE_CACHED = 400;

    /**
     * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
     */
    const int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;

    /**
     * Constant for {@link #importance}: This process does not exist.
     */
    const int IMPORTANCE_GONE = 1000;

    /**
     * The relative importance level that the system places on this process.
     * These constants are numbered so that "more important" values are
     * always smaller than "less important" values.
     */
    int importance;

    /**
     * An additional ordering within a particular {@link #importance}
     * category, providing finer-grained information about the relative
     * utility of processes within a category.  This number means nothing
     * except that a smaller values are more recently used (and thus
     * more important).  Currently an LRU value is only maintained for
     * the {@link #IMPORTANCE_CACHED} category, though others may
     * be maintained in the future.
     */
    int lru;

    /**
     * Constant for {@link #importanceReasonCode}: nothing special has
     * been specified for the reason for this level.
     */
    const int REASON_UNKNOWN = 0;

    /**
     * Constant for {@link #importanceReasonCode}: one of the application's
     * content providers is being used by another process.  The pid of
     * the client process is in {@link #importanceReasonPid} and the
     * target provider in this process is in
     * {@link #importanceReasonComponent}.
     */
    const int REASON_PROVIDER_IN_USE = 1;

    /**
     * Constant for {@link #importanceReasonCode}: one of the application's
     * content providers is being used by another process.  The pid of
     * the client process is in {@link #importanceReasonPid} and the
     * target provider in this process is in
     * {@link #importanceReasonComponent}.
     */
    const int REASON_SERVICE_IN_USE = 2;

    /**
     * The reason for {@link #importance}, if any.
     */
    int importanceReasonCode;

    /**
     * For the specified values of {@link #importanceReasonCode}, this
     * is the process ID of the other process that is a client of this
     * process.  This will be 0 if no other process is using this one.
     */
    int importanceReasonPid;

    /**
     * For the specified values of {@link #importanceReasonCode}, this
     * is the name of the component that is being used in this process.
     */
    @nullable @utf8InCpp String importanceReasonComponent;

    /**
     * When {@link #importanceReasonPid} is non-0, this is the importance
     * of the other pid.
     */
    int importanceReasonImportance;

    /**
     * Current process state, as per PROCESS_STATE_* constants.
     */
    int processState;

    /**
     * Whether the app is focused in multi-window environment.
     */
    boolean isFocused;

    /**
     * Copy of {@link com.android.server.am.ProcessRecord#lastActivityTime} of the process.
     */
    long lastActivityTime;
}
 No newline at end of file
+3 −3
Original line number Original line Diff line number Diff line
@@ -4183,13 +4183,13 @@ public final class ProcessList {
        outInfo.pid = app.getPid();
        outInfo.pid = app.getPid();
        outInfo.uid = app.info.uid;
        outInfo.uid = app.info.uid;
        if (app.getWindowProcessController().isHeavyWeightProcess()) {
        if (app.getWindowProcessController().isHeavyWeightProcess()) {
            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE;
            outInfo.flags |= android.app.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE;
        }
        }
        if (app.isPersistent()) {
        if (app.isPersistent()) {
            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT;
            outInfo.flags |= android.app.RunningAppProcessInfo.FLAG_PERSISTENT;
        }
        }
        if (app.hasActivities()) {
        if (app.hasActivities()) {
            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES;
            outInfo.flags |= android.app.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES;
        }
        }
        outInfo.lastTrimLevel = app.mProfile.getTrimMemoryLevel();
        outInfo.lastTrimLevel = app.mProfile.getTrimMemoryLevel();
        final ProcessStateRecord state = app.mState;
        final ProcessStateRecord state = app.mState;