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

Commit 13f2f6a5 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add new APIs to android.os.Process

- APIs the get the current process name
- APIs to get the process start "request" time

Fix: 205629074
Fix: 205337677
Test: atest CtsProcessTest

Change-Id: Id284fa169eb303011cdade6c3ab96e7026654612
parent 2ed83ecd
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -31957,8 +31957,10 @@ package android.os {
    method public static final long getElapsedCpuTime();
    method public static final long getElapsedCpuTime();
    method public static final int[] getExclusiveCores();
    method public static final int[] getExclusiveCores();
    method public static final int getGidForName(String);
    method public static final int getGidForName(String);
    method public static final long getStartElapsedRealtime();
    method public static long getStartElapsedRealtime();
    method public static final long getStartUptimeMillis();
    method public static long getStartRequestedElapsedRealtime();
    method public static long getStartRequestedUptimeMillis();
    method public static long getStartUptimeMillis();
    method public static final int getThreadPriority(int) throws java.lang.IllegalArgumentException;
    method public static final int getThreadPriority(int) throws java.lang.IllegalArgumentException;
    method public static final int getUidForName(String);
    method public static final int getUidForName(String);
    method public static final boolean is64Bit();
    method public static final boolean is64Bit();
@@ -31966,6 +31968,7 @@ package android.os {
    method public static final boolean isIsolated();
    method public static final boolean isIsolated();
    method public static final void killProcess(int);
    method public static final void killProcess(int);
    method public static final int myPid();
    method public static final int myPid();
    method @NonNull public static String myProcessName();
    method public static final int myTid();
    method public static final int myTid();
    method public static final int myUid();
    method public static final int myUid();
    method public static android.os.UserHandle myUserHandle();
    method public static android.os.UserHandle myUserHandle();
+11 −2
Original line number Original line Diff line number Diff line
@@ -37,8 +37,10 @@ import static android.window.ConfigurationHelper.shouldUpdateResources;


import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;


import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UptimeMillisLong;
import android.app.assist.AssistContent;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
import android.app.assist.AssistStructure;
import android.app.backup.BackupAgent;
import android.app.backup.BackupAgent;
@@ -888,6 +890,9 @@ public final class ActivityThread extends ClientTransactionHandler


        SharedMemory mSerializedSystemFontMap;
        SharedMemory mSerializedSystemFontMap;


        long startRequestedElapsedTime;
        long startRequestedUptime;

        @Override
        @Override
        public String toString() {
        public String toString() {
            return "AppBindData{appInfo=" + appInfo + "}";
            return "AppBindData{appInfo=" + appInfo + "}";
@@ -1099,7 +1104,8 @@ public final class ActivityThread extends ClientTransactionHandler
                CompatibilityInfo compatInfo, Map services, Bundle coreSettings,
                CompatibilityInfo compatInfo, Map services, Bundle coreSettings,
                String buildSerial, AutofillOptions autofillOptions,
                String buildSerial, AutofillOptions autofillOptions,
                ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges,
                ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges,
                SharedMemory serializedSystemFontMap) {
                SharedMemory serializedSystemFontMap,
                long startRequestedElapsedTime, long startRequestedUptime) {
            if (services != null) {
            if (services != null) {
                if (false) {
                if (false) {
                    // Test code to make sure the app could see the passed-in services.
                    // Test code to make sure the app could see the passed-in services.
@@ -1149,6 +1155,8 @@ public final class ActivityThread extends ClientTransactionHandler
            data.contentCaptureOptions = contentCaptureOptions;
            data.contentCaptureOptions = contentCaptureOptions;
            data.disabledCompatChanges = disabledCompatChanges;
            data.disabledCompatChanges = disabledCompatChanges;
            data.mSerializedSystemFontMap = serializedSystemFontMap;
            data.mSerializedSystemFontMap = serializedSystemFontMap;
            data.startRequestedElapsedTime = startRequestedElapsedTime;
            data.startRequestedUptime = startRequestedUptime;
            sendMessage(H.BIND_APPLICATION, data);
            sendMessage(H.BIND_APPLICATION, data);
        }
        }


@@ -6407,7 +6415,8 @@ public final class ActivityThread extends ClientTransactionHandler
            DdmVmInternal.setRecentAllocationsTrackingEnabled(true);
            DdmVmInternal.setRecentAllocationsTrackingEnabled(true);
        }
        }
        // Note when this process has started.
        // Note when this process has started.
        Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis());
        Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis(),
                data.startRequestedElapsedTime, data.startRequestedUptime);


        AppCompatCallbacks.install(data.disabledCompatChanges);
        AppCompatCallbacks.install(data.disabledCompatChanges);
        // Let libcore handle any compat changes after installing the list of compat changes.
        // Let libcore handle any compat changes after installing the list of compat changes.
+2 −1
Original line number Original line Diff line number Diff line
@@ -80,7 +80,8 @@ oneway interface IApplicationThread {
            in CompatibilityInfo compatInfo, in Map services,
            in CompatibilityInfo compatInfo, in Map services,
            in Bundle coreSettings, in String buildSerial, in AutofillOptions autofillOptions,
            in Bundle coreSettings, in String buildSerial, in AutofillOptions autofillOptions,
            in ContentCaptureOptions contentCaptureOptions, in long[] disabledCompatChanges,
            in ContentCaptureOptions contentCaptureOptions, in long[] disabledCompatChanges,
            in SharedMemory serializedSystemFontMap);
            in SharedMemory serializedSystemFontMap,
            long startRequestedElapsedTime, long startRequestedUptime);
    void runIsolatedEntryPoint(in String entryPoint, in String[] entryPointArgs);
    void runIsolatedEntryPoint(in String entryPoint, in String[] entryPointArgs);
    void scheduleExit();
    void scheduleExit();
    void scheduleServiceArgs(IBinder token, in ParceledListSlice args);
    void scheduleServiceArgs(IBinder token, in ParceledListSlice args);
+72 −5
Original line number Original line Diff line number Diff line
@@ -18,11 +18,14 @@ package android.os;


import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;


import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.annotation.UptimeMillisLong;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build.VERSION_CODES;
import android.system.ErrnoException;
import android.system.ErrnoException;
import android.system.Os;
import android.system.Os;
import android.system.OsConstants;
import android.system.OsConstants;
@@ -553,9 +556,26 @@ public class Process {
    public static final int SIGNAL_KILL = 9;
    public static final int SIGNAL_KILL = 9;
    public static final int SIGNAL_USR1 = 10;
    public static final int SIGNAL_USR1 = 10;


    /**
     * When the process started and ActivityThread.handleBindApplication() was executed.
     */
    private static long sStartElapsedRealtime;
    private static long sStartElapsedRealtime;

    /**
     * When the process started and ActivityThread.handleBindApplication() was executed.
     */
    private static long sStartUptimeMillis;
    private static long sStartUptimeMillis;


    /**
     * When the activity manager was about to ask zygote to fork.
     */
    private static long sStartRequestedElapsedRealtime;

    /**
     * When the activity manager was about to ask zygote to fork.
     */
    private static long sStartRequestedUptimeMillis;

    private static final int PIDFD_UNKNOWN = 0;
    private static final int PIDFD_UNKNOWN = 0;
    private static final int PIDFD_SUPPORTED = 1;
    private static final int PIDFD_SUPPORTED = 1;
    private static final int PIDFD_UNSUPPORTED = 2;
    private static final int PIDFD_UNSUPPORTED = 2;
@@ -605,6 +625,12 @@ public class Process {
     */
     */
    public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess();
    public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess();



    /**
     * The process name set via {@link #setArgV0(String)}.
     */
    private static String sArgV0;

    /**
    /**
     * Start a new process.
     * Start a new process.
     * 
     * 
@@ -718,21 +744,44 @@ public class Process {
    /**
    /**
     * Return the {@link SystemClock#elapsedRealtime()} at which this process was started.
     * Return the {@link SystemClock#elapsedRealtime()} at which this process was started.
     */
     */
    public static final long getStartElapsedRealtime() {
    @ElapsedRealtimeLong
    public static long getStartElapsedRealtime() {
        return sStartElapsedRealtime;
        return sStartElapsedRealtime;
    }
    }


    /**
    /**
     * Return the {@link SystemClock#uptimeMillis()} at which this process was started.
     * Return the {@link SystemClock#uptimeMillis()} at which this process was started.
     */
     */
    public static final long getStartUptimeMillis() {
    @UptimeMillisLong
    public static long getStartUptimeMillis() {
        return sStartUptimeMillis;
        return sStartUptimeMillis;
    }
    }


    /**
     * Return the {@link SystemClock#elapsedRealtime()} at which the system decides to start
     * this process.
     */
    @ElapsedRealtimeLong
    public static long getStartRequestedElapsedRealtime() {
        return sStartRequestedElapsedRealtime;
    }

    /**
     * Return the {@link SystemClock#uptimeMillis()} at which the system decides to start
     * this process.
     */
    @UptimeMillisLong
    public static long getStartRequestedUptimeMillis() {
        return sStartRequestedUptimeMillis;
    }

    /** @hide */
    /** @hide */
    public static final void setStartTimes(long elapsedRealtime, long uptimeMillis) {
    public static final void setStartTimes(long elapsedRealtime, long uptimeMillis,
            long startRequestedElapsedRealtime, long startRequestedUptime) {
        sStartElapsedRealtime = elapsedRealtime;
        sStartElapsedRealtime = elapsedRealtime;
        sStartUptimeMillis = uptimeMillis;
        sStartUptimeMillis = uptimeMillis;
        sStartRequestedElapsedRealtime = startRequestedElapsedRealtime;
        sStartRequestedUptimeMillis = startRequestedUptime;
    }
    }


    /**
    /**
@@ -1135,8 +1184,26 @@ public class Process {
     * 
     * 
     * {@hide}
     * {@hide}
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage(maxTargetSdk = VERSION_CODES.S, publicAlternatives = "Do not try to "
    public static final native void setArgV0(String text);
            + "change the process name. (If you must, you could use {@code pthread_setname_np(3)}, "
            + "but this could confuse the system)")
    public static void setArgV0(@NonNull String text) {
        sArgV0 = text;
        setArgV0Native(text);
    }

    private static native void setArgV0Native(String text);

    /**
     * Return the name of this process.
     */
    @NonNull
    public static String myProcessName() {
        // Note this could be different from the actual process name if someone changes the
        // process name using native code (using pthread_setname_np()). But sArgV0
        // is the name that the system thinks this process has.
        return sArgV0;
    }


    /**
    /**
     * Kill the process with the given PID.
     * Kill the process with the given PID.
+1 −1
Original line number Original line Diff line number Diff line
@@ -1346,7 +1346,7 @@ static const JNINativeMethod methods[] = {
        {"createProcessGroup", "(II)I", (void*)android_os_Process_createProcessGroup},
        {"createProcessGroup", "(II)I", (void*)android_os_Process_createProcessGroup},
        {"getExclusiveCores", "()[I", (void*)android_os_Process_getExclusiveCores},
        {"getExclusiveCores", "()[I", (void*)android_os_Process_getExclusiveCores},
        {"setSwappiness", "(IZ)Z", (void*)android_os_Process_setSwappiness},
        {"setSwappiness", "(IZ)Z", (void*)android_os_Process_setSwappiness},
        {"setArgV0", "(Ljava/lang/String;)V", (void*)android_os_Process_setArgV0},
        {"setArgV0Native", "(Ljava/lang/String;)V", (void*)android_os_Process_setArgV0},
        {"setUid", "(I)I", (void*)android_os_Process_setUid},
        {"setUid", "(I)I", (void*)android_os_Process_setUid},
        {"setGid", "(I)I", (void*)android_os_Process_setGid},
        {"setGid", "(I)I", (void*)android_os_Process_setGid},
        {"sendSignal", "(II)V", (void*)android_os_Process_sendSignal},
        {"sendSignal", "(II)V", (void*)android_os_Process_sendSignal},
Loading