diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 96df80f1d9a7..908e6718ffd0 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -1502,12 +1502,11 @@ public class GeckoAppShell boolean callback(int pid); } - static int sPidColumn = -1; - static int sUserColumn = -1; private static void EnumerateGeckoProcesses(GeckoProcessesVisitor visiter) { + int pidColumn = -1; + int userColumn = -1; try { - // run ps and parse its output java.lang.Process ps = Runtime.getRuntime().exec("ps"); BufferedReader in = new BufferedReader(new InputStreamReader(ps.getInputStream()), @@ -1516,30 +1515,28 @@ public class GeckoAppShell String headerOutput = in.readLine(); // figure out the column offsets. We only care about the pid and user fields - if (sPidColumn == -1 || sUserColumn == -1) { - StringTokenizer st = new StringTokenizer(headerOutput); - - int tokenSoFar = 0; - while(st.hasMoreTokens()) { - String next = st.nextToken(); - if (next.equalsIgnoreCase("PID")) - sPidColumn = tokenSoFar; - else if (next.equalsIgnoreCase("USER")) - sUserColumn = tokenSoFar; - tokenSoFar++; - } + StringTokenizer st = new StringTokenizer(headerOutput); + + int tokenSoFar = 0; + while (st.hasMoreTokens()) { + String next = st.nextToken(); + if (next.equalsIgnoreCase("PID")) + pidColumn = tokenSoFar; + else if (next.equalsIgnoreCase("USER")) + userColumn = tokenSoFar; + tokenSoFar++; } // alright, the rest are process entries. String psOutput = null; while ((psOutput = in.readLine()) != null) { String[] split = psOutput.split("\\s+"); - if (split.length <= sPidColumn || split.length <= sUserColumn) + if (split.length <= pidColumn || split.length <= userColumn) continue; - int uid = android.os.Process.getUidForName(split[sUserColumn]); + int uid = android.os.Process.getUidForName(split[userColumn]); if (uid == android.os.Process.myUid() && !split[split.length - 1].equalsIgnoreCase("ps")) { - int pid = Integer.parseInt(split[sPidColumn]); + int pid = Integer.parseInt(split[pidColumn]); boolean keepGoing = visiter.callback(pid); if (keepGoing == false) break;