summaryrefslogtreecommitdiffstats
path: root/core/java/android/os
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2009-06-24 23:18:15 -0700
committerAmith Yamasani <yamasani@google.com>2009-06-24 23:26:29 -0700
commit819f928f6a9dc3fdf408236f33e17f03a7dfed2c (patch)
treee830a39404ad66b8a2bfc40ef7e96f0c2a85c014 /core/java/android/os
parentc6a482e778e7b5fc5790edf22e554c93f53b1112 (diff)
downloadframeworks_base-819f928f6a9dc3fdf408236f33e17f03a7dfed2c.zip
frameworks_base-819f928f6a9dc3fdf408236f33e17f03a7dfed2c.tar.gz
frameworks_base-819f928f6a9dc3fdf408236f33e17f03a7dfed2c.tar.bz2
Add a method to Process to get uid for a pid.
Use the uids to track native processes. Cache the uids to avoid checking /proc every time.
Diffstat (limited to 'core/java/android/os')
-rw-r--r--core/java/android/os/Process.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 333c7cb..1214abc 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -573,7 +573,21 @@ public class Process {
* directly to a gid.
*/
public static final native int getGidForName(String name);
-
+
+ /**
+ * Returns a uid for a currently running process.
+ * @param pid the process id
+ * @return the uid of the process, or -1 if the process is not running.
+ * @hide pending API council review
+ */
+ public static final int getUidForPid(int pid) {
+ String[] procStatusLabels = { "Uid:" };
+ long[] procStatusValues = new long[1];
+ procStatusValues[0] = -1;
+ Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues);
+ return (int) procStatusValues[0];
+ }
+
/**
* Set the priority of a thread, based on Linux priorities.
*