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

Commit 1bbfec6e authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Update ApplicationStartInfo API

Match latest version, remove gating, and remove hide

Test: make

Bug: 247814855
Change-Id: Ibb25e1e2e0988f85f668b09f37a996b151174f2b
parent 0903f20e
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -4616,7 +4616,9 @@ package android.app {
  public class ActivityManager {
    method public int addAppTask(@NonNull android.app.Activity, @NonNull android.content.Intent, @Nullable android.app.ActivityManager.TaskDescription, @NonNull android.graphics.Bitmap);
    method public void addStartInfoTimestamp(@IntRange(from=android.app.ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER_START, to=android.app.ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER) int, long);
    method public void appNotResponding(@NonNull String);
    method public void clearApplicationStartInfoCompletionListener();
    method public boolean clearApplicationUserData();
    method public void clearWatchHeapLimit();
    method @RequiresPermission(android.Manifest.permission.DUMP) public void dumpPackageState(java.io.FileDescriptor, String);
@@ -4624,6 +4626,7 @@ package android.app {
    method public java.util.List<android.app.ActivityManager.AppTask> getAppTasks();
    method public android.content.pm.ConfigurationInfo getDeviceConfigurationInfo();
    method @NonNull public java.util.List<android.app.ApplicationExitInfo> getHistoricalProcessExitReasons(@Nullable String, @IntRange(from=0) int, @IntRange(from=0) int);
    method @NonNull public java.util.List<android.app.ApplicationStartInfo> getHistoricalProcessStartReasons(@IntRange(from=0) int);
    method public int getLargeMemoryClass();
    method public int getLauncherLargeIconDensity();
    method public int getLauncherLargeIconSize();
@@ -4650,6 +4653,7 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.REORDER_TASKS) public void moveTaskToFront(int, int);
    method @RequiresPermission(android.Manifest.permission.REORDER_TASKS) public void moveTaskToFront(int, int, android.os.Bundle);
    method @Deprecated public void restartPackage(String);
    method public void setApplicationStartInfoCompletionListener(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.app.ApplicationStartInfo>);
    method public void setProcessStateSummary(@Nullable byte[]);
    method public static void setVrThread(int);
    method public void setWatchHeapLimit(long);
@@ -5230,6 +5234,57 @@ package android.app {
    field public static final int REASON_USER_STOPPED = 11; // 0xb
  }
  public final class ApplicationStartInfo implements android.os.Parcelable {
    method public int describeContents();
    method public int getDefiningUid();
    method @Nullable public android.content.Intent getIntent();
    method public int getLaunchMode();
    method public int getPackageUid();
    method public int getPid();
    method @NonNull public String getProcessName();
    method public int getRealUid();
    method public int getReason();
    method public int getStartType();
    method public int getStartupState();
    method @NonNull public java.util.Map<java.lang.Integer,java.lang.Long> getStartupTimestamps();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.ApplicationStartInfo> CREATOR;
    field public static final int LAUNCH_MODE_SINGLE_INSTANCE = 2; // 0x2
    field public static final int LAUNCH_MODE_SINGLE_INSTANCE_PER_TASK = 4; // 0x4
    field public static final int LAUNCH_MODE_SINGLE_TASK = 3; // 0x3
    field public static final int LAUNCH_MODE_SINGLE_TOP = 1; // 0x1
    field public static final int LAUNCH_MODE_STANDARD = 0; // 0x0
    field public static final int STARTUP_STATE_ERROR = 1; // 0x1
    field public static final int STARTUP_STATE_FIRST_FRAME_DRAWN = 2; // 0x2
    field public static final int STARTUP_STATE_STARTED = 0; // 0x0
    field public static final int START_REASON_ALARM = 0; // 0x0
    field public static final int START_REASON_BACKUP = 1; // 0x1
    field public static final int START_REASON_BOOT_COMPLETE = 2; // 0x2
    field public static final int START_REASON_BROADCAST = 3; // 0x3
    field public static final int START_REASON_CONTENT_PROVIDER = 4; // 0x4
    field public static final int START_REASON_JOB = 5; // 0x5
    field public static final int START_REASON_LAUNCHER = 6; // 0x6
    field public static final int START_REASON_LAUNCHER_RECENTS = 7; // 0x7
    field public static final int START_REASON_OTHER = 8; // 0x8
    field public static final int START_REASON_PUSH = 9; // 0x9
    field public static final int START_REASON_SERVICE = 10; // 0xa
    field public static final int START_REASON_START_ACTIVITY = 11; // 0xb
    field public static final int START_TIMESTAMP_APPLICATION_ONCREATE = 2; // 0x2
    field public static final int START_TIMESTAMP_BIND_APPLICATION = 3; // 0x3
    field public static final int START_TIMESTAMP_FIRST_FRAME = 4; // 0x4
    field public static final int START_TIMESTAMP_FORK = 1; // 0x1
    field public static final int START_TIMESTAMP_FULLY_DRAWN = 5; // 0x5
    field public static final int START_TIMESTAMP_INITIAL_RENDERTHREAD_FRAME = 6; // 0x6
    field public static final int START_TIMESTAMP_LAUNCH = 0; // 0x0
    field public static final int START_TIMESTAMP_RESERVED_RANGE_DEVELOPER = 30; // 0x1e
    field public static final int START_TIMESTAMP_RESERVED_RANGE_DEVELOPER_START = 21; // 0x15
    field public static final int START_TIMESTAMP_RESERVED_RANGE_SYSTEM = 20; // 0x14
    field public static final int START_TIMESTAMP_SURFACEFLINGER_COMPOSITION_COMPLETE = 7; // 0x7
    field public static final int START_TYPE_COLD = 0; // 0x0
    field public static final int START_TYPE_HOT = 2; // 0x2
    field public static final int START_TYPE_WARM = 1; // 0x1
  }
  public final class AsyncNotedAppOp implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getAttributionTag();
+1 −0
Original line number Diff line number Diff line
@@ -535,6 +535,7 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public void addOnUidImportanceListener(android.app.ActivityManager.OnUidImportanceListener, int);
    method @RequiresPermission(android.Manifest.permission.FORCE_STOP_PACKAGES) public void forceStopPackage(String);
    method @RequiresPermission(anyOf={"android.permission.INTERACT_ACROSS_USERS", "android.permission.INTERACT_ACROSS_USERS_FULL"}) public static int getCurrentUser();
    method @NonNull @RequiresPermission(android.Manifest.permission.DUMP) public java.util.List<android.app.ApplicationStartInfo> getExternalHistoricalProcessStartReasons(@NonNull String, @IntRange(from=0) int);
    method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public int getPackageImportance(String);
    method @NonNull public java.util.Collection<java.util.Locale> getSupportedLocales();
    method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public int getUidImportance(int);
+39 −24
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.os.PowerExemptionManager.ReasonCode;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
@@ -107,6 +108,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * <p>
@@ -3978,8 +3980,6 @@ public class ActivityManager {
     *
     * @return a list of {@link ApplicationStartInfo} records matching the criteria, sorted in
     *         the order from most recent to least recent.
     *
     * @hide
     */
    @NonNull
    public List<ApplicationStartInfo> getHistoricalProcessStartReasons(
@@ -4011,6 +4011,7 @@ public class ActivityManager {
     * @hide
     */
    @NonNull
    @SystemApi
    @RequiresPermission(Manifest.permission.DUMP)
    public List<ApplicationStartInfo> getExternalHistoricalProcessStartReasons(
            @NonNull String packageName, @IntRange(from = 0) int maxNum) {
@@ -4023,18 +4024,6 @@ public class ActivityManager {
        }
    }

    /**
     * Callback to receive {@link ApplicationStartInfo} object once recording of startup related
     * metrics is complete.
     * Use with {@link #setApplicationStartInfoCompleteListener}.
     *
     * @hide
     */
    public interface ApplicationStartInfoCompleteListener {
        /** {@link ApplicationStartInfo} is complete, no more info will be added. */
        void onApplicationStartInfoComplete(@NonNull ApplicationStartInfo applicationStartInfo);
    }

    /**
     * Sets a callback to be notified when the {@link ApplicationStartInfo} records of this startup
     * are complete.
@@ -4054,19 +4043,16 @@ public class ActivityManager {
     *                    complete. Will replace existing listener if one is already attached.
     *
     * @throws IllegalArgumentException if executor or listener are null.
     *
     * @hide
     */
    public void setApplicationStartInfoCompleteListener(@NonNull final Executor executor,
            @NonNull final ApplicationStartInfoCompleteListener listener) {
    public void setApplicationStartInfoCompletionListener(@NonNull final Executor executor,
            @NonNull final Consumer<ApplicationStartInfo> listener) {
        Preconditions.checkNotNull(executor, "executor cannot be null");
        Preconditions.checkNotNull(listener, "listener cannot be null");
        IApplicationStartInfoCompleteListener callback =
                new IApplicationStartInfoCompleteListener.Stub() {
            @Override
            public void onApplicationStartInfoComplete(ApplicationStartInfo applicationStartInfo) {
                executor.execute(() ->
                        listener.onApplicationStartInfoComplete(applicationStartInfo));
                executor.execute(() -> listener.accept(applicationStartInfo));
            }
        };
        try {
@@ -4077,13 +4063,42 @@ public class ActivityManager {
    }

    /**
     * Removes the callback set by {@link #setApplicationStartInfoCompleteListener} if there is one.
     * Removes the callback set by {@link #setApplicationStartInfoCompletionListener} if there is one.
     */
    public void clearApplicationStartInfoCompletionListener() {
        try {
            getService().clearApplicationStartInfoCompleteListener(mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Adds an optional developer supplied timestamp to the calling apps most recent
     * {@link ApplicationStartInfo}. This is in addition to system recorded timestamps.
     *
     * @hide
     * <p class="note"> Note: timestamps added after {@link Activity#reportFullyDrawn} is called
     * will be discarded.</p>
     *
     * <p class="note"> Note: will overwrite existing timestamp if called with same key.</p>
     *
     * @param key         Unique key for timestamp. Must be greater than
     *                    {@link ApplicationStartInfo#START_TIMESTAMP_RESERVED_RANGE_SYSTEM} and
     *                    less than or equal to
     *                    {@link ApplicationStartInfo#START_TIMESTAMP_RESERVED_RANGE_DEVELOPER}.
     *                    Will thow {@link java.lang.IllegalArgumentException} if not in range.
     * @param timestampNs Clock monotonic time in nanoseconds of event to be recorded.
     */
    public void removeApplicationStartInfoCompleteListener() {
    public void addStartInfoTimestamp(@IntRange(
            from = ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER_START,
            to = ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER) int key,
            long timestampNs) {
        if (key <= ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_SYSTEM
                || key > ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER) {
            throw new IllegalArgumentException("Key not in allowed range.");
        }
        try {
            getService().removeApplicationStartInfoCompleteListener(mContext.getUserId());
            getService().addStartInfoTimestamp(key, timestampNs, mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+107 −37
Original line number Diff line number Diff line
@@ -21,20 +21,21 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.icu.text.SimpleDateFormat;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.util.ArrayMap;

import java.lang.annotation.ElementType;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Provide information related to a processes startup.
 *
 * @hide
 */
public final class ApplicationStartInfo implements Parcelable {

@@ -78,14 +79,14 @@ public final class ApplicationStartInfo implements Parcelable {
    /** Process started due to click app icon or widget from launcher. */
    public static final int START_REASON_LAUNCHER = 6;

    /** Process started from launcher recents. */
    public static final int START_REASON_LAUNCHER_RECENTS = 7;

    /** Process started not for any of the listed reasons. */
    public static final int START_REASON_OTHER = 7;
    public static final int START_REASON_OTHER = 8;

    /** Process started due to push message. */
    public static final int START_REASON_PUSH = 8;

    /** Process started to resume activity. */
    public static final int START_REASON_RESUMED_ACTIVITY = 9;
    public static final int START_REASON_PUSH = 9;

    /** Process service started. */
    public static final int START_REASON_SERVICE = 10;
@@ -136,11 +137,21 @@ public final class ApplicationStartInfo implements Parcelable {
     */
    public static final int LAUNCH_MODE_SINGLE_INSTANCE_PER_TASK = 4;

    /** The end of the range, beginning with 0, reserved for system timestamps.*/
    public static final int START_TIMESTAMP_RESERVED_RANGE_SYSTEM = 20;

    /** The beginning of the range reserved for developer supplied timestamps.*/
    public static final int START_TIMESTAMP_RESERVED_RANGE_DEVELOPER_START =
            START_TIMESTAMP_RESERVED_RANGE_SYSTEM + 1;

    /** The end of the range reserved for developer supplied timestamps.*/
    public static final int START_TIMESTAMP_RESERVED_RANGE_DEVELOPER = 30;

    /** Clock monotonic timestamp of launch started. */
    public static final int START_TIMESTAMP_LAUNCH = 0;

    /** Clock monotonic timestamp of finish java classloading. */
    public static final int START_TIMESTAMP_JAVA_CLASSLOADING_COMPLETE = 1;
    /** Clock monotonic timestamp of process fork. */
    public static final int START_TIMESTAMP_FORK = 1;

    /** Clock monotonic timestamp of Application onCreate called. */
    public static final int START_TIMESTAMP_APPLICATION_ONCREATE = 2;
@@ -154,6 +165,12 @@ public final class ApplicationStartInfo implements Parcelable {
    /** Clock monotonic timestamp of reportFullyDrawn called by application. */
    public static final int START_TIMESTAMP_FULLY_DRAWN = 5;

    /** Clock monotonic timestamp of initial renderthread frame. */
    public static final int START_TIMESTAMP_INITIAL_RENDERTHREAD_FRAME = 6;

    /** Clock monotonic timestamp of surfaceflinger composition complete. */
    public static final int START_TIMESTAMP_SURFACEFLINGER_COMPOSITION_COMPLETE = 7;

    /**
     * @see #getStartupState
     */
@@ -192,7 +209,7 @@ public final class ApplicationStartInfo implements Parcelable {
    /**
     * @see #getStartupTimestamps
     */
    private Map<@StartupTimestamp Integer, Long> mStartupTimestampsNs;
    private ArrayMap<Integer, Long> mStartupTimestampsNs;

    /**
     * @see #getStartType
@@ -235,9 +252,9 @@ public final class ApplicationStartInfo implements Parcelable {
                START_REASON_CONTENT_PROVIDER,
                START_REASON_JOB,
                START_REASON_LAUNCHER,
                START_REASON_LAUNCHER_RECENTS,
                START_REASON_OTHER,
                START_REASON_PUSH,
                START_REASON_RESUMED_ACTIVITY,
                START_REASON_SERVICE,
                START_REASON_START_ACTIVITY,
            })
@@ -272,22 +289,6 @@ public final class ApplicationStartInfo implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    public @interface LaunchMode {}

    /**
     * @hide *
     */
    @IntDef(
            prefix = {"START_TIMESTAMP_"},
            value = {
                START_TIMESTAMP_LAUNCH,
                START_TIMESTAMP_JAVA_CLASSLOADING_COMPLETE,
                START_TIMESTAMP_APPLICATION_ONCREATE,
                START_TIMESTAMP_BIND_APPLICATION,
                START_TIMESTAMP_FULLY_DRAWN,
            })
    @Retention(RetentionPolicy.SOURCE)
    @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
    public @interface StartupTimestamp {}

    /**
     * @see #getStartupState
     * @hide
@@ -348,9 +349,12 @@ public final class ApplicationStartInfo implements Parcelable {
     * @see #getStartupTimestamps
     * @hide
     */
    public void addStartupTimestamp(@StartupTimestamp int key, long timestampNs) {
    public void addStartupTimestamp(int key, long timestampNs) {
        if (key < 0 || key > START_TIMESTAMP_RESERVED_RANGE_DEVELOPER) {
            return;
        }
        if (mStartupTimestampsNs == null) {
            mStartupTimestampsNs = new HashMap<@StartupTimestamp Integer, Long>();
            mStartupTimestampsNs = new ArrayMap<Integer, Long>();
        }
        mStartupTimestampsNs.put(key, timestampNs);
    }
@@ -475,9 +479,9 @@ public final class ApplicationStartInfo implements Parcelable {
     * dependant on devloper calling {@link Activity#reportFullyDrawn}.
     * </p>
     */
    public @NonNull Map<@StartupTimestamp Integer, Long> getStartupTimestamps() {
    public @NonNull Map<Integer, Long> getStartupTimestamps() {
        if (mStartupTimestampsNs == null) {
            mStartupTimestampsNs = new HashMap<@StartupTimestamp Integer, Long>();
            mStartupTimestampsNs = new ArrayMap<Integer, Long>();
        }
        return mStartupTimestampsNs;
    }
@@ -536,9 +540,12 @@ public final class ApplicationStartInfo implements Parcelable {
        dest.writeString(mProcessName);
        dest.writeInt(mReason);
        dest.writeInt(mStartupTimestampsNs.size());
        for (@StartupTimestamp int key : mStartupTimestampsNs.keySet()) {
            dest.writeInt(key);
            dest.writeLong(mStartupTimestampsNs.get(key));
        Set<Map.Entry<Integer, Long>> timestampEntrySet = mStartupTimestampsNs.entrySet();
        Iterator<Map.Entry<Integer, Long>> iter = timestampEntrySet.iterator();
        while (iter.hasNext()) {
            Map.Entry<Integer, Long> entry = iter.next();
            dest.writeInt(entry.getKey());
            dest.writeLong(entry.getValue());
        }
        dest.writeInt(mStartType);
        dest.writeParcelable(mStartIntent, flags);
@@ -599,4 +606,67 @@ public final class ApplicationStartInfo implements Parcelable {
                    return new ApplicationStartInfo[size];
                }
            };

    /** @hide */
    public void dump(@NonNull PrintWriter pw, @Nullable String prefix, @Nullable String seqSuffix,
            @NonNull SimpleDateFormat sdf) {
        StringBuilder sb = new StringBuilder();
        sb.append(prefix)
                .append("ApplicationStartInfo ").append(seqSuffix).append(':')
                .append('\n')
                .append(" pid=").append(mPid)
                .append(" realUid=").append(mRealUid)
                .append(" packageUid=").append(mPackageUid)
                .append(" definingUid=").append(mDefiningUid)
                .append(" user=").append(UserHandle.getUserId(mPackageUid))
                .append('\n')
                .append(" process=").append(mProcessName)
                .append(" startupState=").append(mStartupState)
                .append(" reason=").append(reasonToString(mReason))
                .append(" startType=").append(startTypeToString(mStartType))
                .append(" launchMode=").append(mLaunchMode)
                .append('\n');
        if (mStartIntent != null) {
            sb.append(" intent=").append(mStartIntent.toString())
                .append('\n');
        }
        if (mStartupTimestampsNs.size() > 0) {
            sb.append(" timestamps: ");
            Set<Map.Entry<Integer, Long>> timestampEntrySet = mStartupTimestampsNs.entrySet();
            Iterator<Map.Entry<Integer, Long>> iter = timestampEntrySet.iterator();
            while (iter.hasNext()) {
                Map.Entry<Integer, Long> entry = iter.next();
                sb.append(entry.getKey()).append("=").append(entry.getValue()).append(" ");
            }
            sb.append('\n');
        }
        pw.print(sb.toString());
    }

    private static String reasonToString(@StartReason int reason) {
        return switch (reason) {
            case START_REASON_ALARM -> "ALARM";
            case START_REASON_BACKUP -> "BACKUP";
            case START_REASON_BOOT_COMPLETE -> "BOOT COMPLETE";
            case START_REASON_BROADCAST -> "BROADCAST";
            case START_REASON_CONTENT_PROVIDER -> "CONTENT PROVIDER";
            case START_REASON_JOB -> "JOB";
            case START_REASON_LAUNCHER -> "LAUNCHER";
            case START_REASON_LAUNCHER_RECENTS -> "LAUNCHER RECENTS";
            case START_REASON_OTHER -> "OTHER";
            case START_REASON_PUSH -> "PUSH";
            case START_REASON_SERVICE -> "SERVICE";
            case START_REASON_START_ACTIVITY -> "START ACTIVITY";
            default -> "";
        };
    }

    private static String startTypeToString(@StartType int startType) {
        return switch (startType) {
            case START_TYPE_COLD -> "COLD";
            case START_TYPE_WARM -> "WARM";
            case START_TYPE_HOT -> "HOT";
            default -> "";
        };
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -724,7 +724,20 @@ interface IActivityManager {
     *
     * @param userId      The userId in the multi-user environment.
     */
    void removeApplicationStartInfoCompleteListener(int userId);
    void clearApplicationStartInfoCompleteListener(int userId);


    /**
     * Adds a timestamp of the moment called to the calling apps most recent
     * {@link ApplicationStartInfo}.
     *
     *
     * @param key         Unique key for timestamp.
     * @param timestampNs Clock monotonic time in nanoseconds of event to be
     *                    recorded.
     * @param userId      The userId in the multi-user environment.
     */
    void addStartInfoTimestamp(int key, long timestampNs, int userId);

    /**
     * Return a list of {@link ApplicationExitInfo} records.
Loading