summaryrefslogtreecommitdiff
path: root/core/java/android/os/Process.java
diff options
context:
space:
mode:
authorLi Li <dualli@google.com>2021-07-28 11:27:26 -0700
committerLi Li <dualli@google.com>2021-07-29 09:18:53 -0700
commitbbe06e7b598e5249e40c06b6bf2c563ad94e00f5 (patch)
tree7a17bc5dd53f0559048d98e765e652e63a67d549 /core/java/android/os/Process.java
parent92145ddf77aac1f6cf9816b99086be89ff69f4ab (diff)
Freezer: fix exception when parsing /proc/locks
The original code is based on /proc/locks manpage. Unfortunately, that manpage is never correctly updated to include the new field for blocked locks. The new code detects the extra field. As StringTokenizer is too heavy, ProcFileReader is used for better performance. Bug: 194756340 Test: FrameworksUtilTests com.android.internal.util.ProcFileReaderTest Test: FrameworksCoreTests com.android.internal.os.ProcLocksReaderTest Test: No /proc/locks parsing exception with blocked locks Change-Id: I4c9763f9d3091f7d84d2e4b672d7e5cb78b33f59
Diffstat (limited to 'core/java/android/os/Process.java')
-rw-r--r--core/java/android/os/Process.java42
1 files changed, 0 insertions, 42 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 6bca336dae91..9f37c4877199 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -34,12 +34,9 @@ import dalvik.system.VMRuntime;
import libcore.io.IoUtils;
-import java.io.BufferedReader;
import java.io.FileDescriptor;
-import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
-import java.util.StringTokenizer;
import java.util.concurrent.TimeoutException;
/**
@@ -1472,43 +1469,4 @@ public class Process {
}
private static native int nativePidFdOpen(int pid, int flags) throws ErrnoException;
-
- /**
- * Checks if a process corresponding to a specific pid owns any file locks.
- * @param pid The process ID for which we want to know the existence of file locks.
- * @return true If the process holds any file locks, false otherwise.
- * @throws IOException if /proc/locks can't be accessed.
- *
- * @hide
- */
- public static boolean hasFileLocks(int pid) throws Exception {
- BufferedReader br = null;
-
- try {
- br = new BufferedReader(new FileReader("/proc/locks"));
- String line;
-
- while ((line = br.readLine()) != null) {
- StringTokenizer st = new StringTokenizer(line);
-
- for (int i = 0; i < 5 && st.hasMoreTokens(); i++) {
- String str = st.nextToken();
- try {
- if (i == 4 && Integer.parseInt(str) == pid) {
- return true;
- }
- } catch (NumberFormatException nfe) {
- throw new Exception("Exception parsing /proc/locks at \" "
- + line + " \", token #" + i);
- }
- }
- }
-
- return false;
- } finally {
- if (br != null) {
- br.close();
- }
- }
- }
}