summaryrefslogtreecommitdiff
path: root/core/java/android/os/Process.java
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2021-11-10 11:38:58 -0800
committerMakoto Onuki <omakoto@google.com>2021-11-15 15:37:37 -0800
commit13f2f6a5111824f88be09e5483e04187d1fff97b (patch)
treee84c60dc24fd0a1172fe6b7c04ee46265fa74b3b /core/java/android/os/Process.java
parent2ed83ecda6e5ecf009d90328792b34665266a5b9 (diff)
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
Diffstat (limited to 'core/java/android/os/Process.java')
-rw-r--r--core/java/android/os/Process.java77
1 files changed, 72 insertions, 5 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 9f37c4877199..c9670ff93f60 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -18,11 +18,14 @@ package android.os;
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
+import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
+import android.annotation.UptimeMillisLong;
import android.compat.annotation.UnsupportedAppUsage;
+import android.os.Build.VERSION_CODES;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
@@ -553,9 +556,26 @@ public class Process {
public static final int SIGNAL_KILL = 9;
public static final int SIGNAL_USR1 = 10;
+ /**
+ * When the process started and ActivityThread.handleBindApplication() was executed.
+ */
private static long sStartElapsedRealtime;
+
+ /**
+ * When the process started and ActivityThread.handleBindApplication() was executed.
+ */
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_SUPPORTED = 1;
private static final int PIDFD_UNSUPPORTED = 2;
@@ -605,6 +625,12 @@ public class Process {
*/
public static final ZygoteProcess ZYGOTE_PROCESS = new ZygoteProcess();
+
+ /**
+ * The process name set via {@link #setArgV0(String)}.
+ */
+ private static String sArgV0;
+
/**
* Start a new process.
*
@@ -718,21 +744,44 @@ public class Process {
/**
* Return the {@link SystemClock#elapsedRealtime()} at which this process was started.
*/
- public static final long getStartElapsedRealtime() {
+ @ElapsedRealtimeLong
+ public static long getStartElapsedRealtime() {
return sStartElapsedRealtime;
}
/**
* Return the {@link SystemClock#uptimeMillis()} at which this process was started.
*/
- public static final long getStartUptimeMillis() {
+ @UptimeMillisLong
+ public static long getStartUptimeMillis() {
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 */
- public static final void setStartTimes(long elapsedRealtime, long uptimeMillis) {
+ public static final void setStartTimes(long elapsedRealtime, long uptimeMillis,
+ long startRequestedElapsedRealtime, long startRequestedUptime) {
sStartElapsedRealtime = elapsedRealtime;
sStartUptimeMillis = uptimeMillis;
+ sStartRequestedElapsedRealtime = startRequestedElapsedRealtime;
+ sStartRequestedUptimeMillis = startRequestedUptime;
}
/**
@@ -1135,8 +1184,26 @@ public class Process {
*
* {@hide}
*/
- @UnsupportedAppUsage
- public static final native void setArgV0(String text);
+ @UnsupportedAppUsage(maxTargetSdk = VERSION_CODES.S, publicAlternatives = "Do not try to "
+ + "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.