diff options
| author | Marco Ballesio <balejs@google.com> | 2021-01-06 15:25:50 -0800 |
|---|---|---|
| committer | Marco Ballesio <balejs@google.com> | 2021-01-07 12:51:21 -0800 |
| commit | 770df97befaef78a5270de62ef6e7ecf603765cc (patch) | |
| tree | 255515db2da8312f0a3ce6393c3ca15ab266ca04 /core/java/android/os/Process.java | |
| parent | 565151c5641e737674037237ccfbf556a95f1454 (diff) | |
ActivityManager: don't freeze processes holding file locks
As a temporary measure waiting for the more robust b/176927978 to be
implemented, query the file lock status of processes prior freezing
them, and skip freeze if any locks are held.
Test: verified form the logs that processes holding file locks are not
frozen
Bug: 176928302
Change-Id: Ib7e1715effb63c1b304ce22a9451294fd9f7b10d
Diffstat (limited to 'core/java/android/os/Process.java')
| -rw-r--r-- | core/java/android/os/Process.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index 8048b9df6097..39e3e146f45b 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -31,9 +31,12 @@ 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; /** @@ -1430,4 +1433,38 @@ 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 IOException { + 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(); + if (i == 4 && Integer.parseInt(str) == pid) { + return true; + } + } + } + + return false; + } finally { + if (br != null) { + br.close(); + } + } + } } |
