diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 42a731c952a1..7055efd38d6f 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -393,14 +393,17 @@ abstract public class GeckoApp // etc., and generally mark the profile as 'clean', and then // dirty it again if we get an onResume. + GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_STOPPING)); super.onStop(); + GeckoAppShell.putChildInBackground(); } @Override public void onRestart() { Log.i("GeckoApp", "restart"); + GeckoAppShell.putChildInForeground(); super.onRestart(); } diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index 0a7638ade555..306adc4492c7 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -1165,6 +1165,52 @@ public class GeckoAppShell return result; } + public static void putChildInBackground() { + try { + File cgroupFile = new File("/proc" + android.os.Process.myPid() + "/cgroup"); + BufferedReader br = new BufferedReader(new FileReader(cgroupFile)); + String[] cpuLine = br.readLine().split("/"); + br.close(); + final String backgroundGroup = cpuLine.length == 2 ? cpuLine[1] : ""; + GeckoProcessesVisitor visitor = new GeckoProcessesVisitor() { + public boolean callback(int pid) { + if (pid != android.os.Process.myPid()) { + try { + FileOutputStream fos = new FileOutputStream( + new File("/dev/cpuctl/" + backgroundGroup +"/tasks")); + fos.write(new Integer(pid).toString().getBytes()); + fos.close(); + } catch(Exception e) { + Log.e("GeckoAppShell", "error putting child in the background", e); + } + } + return true; + } + }; + EnumerateGeckoProcesses(visitor); + } catch (Exception e) { + Log.e("GeckoInputStream", "error reading cgroup", e); + } + } + + public static void putChildInForeground() { + GeckoProcessesVisitor visitor = new GeckoProcessesVisitor() { + public boolean callback(int pid) { + if (pid != android.os.Process.myPid()) { + try { + FileOutputStream fos = new FileOutputStream(new File("/dev/cpuctl/tasks")); + fos.write(new Integer(pid).toString().getBytes()); + fos.close(); + } catch(Exception e) { + Log.e("GeckoAppShell", "error putting child in the foreground", e); + } + } + return true; + } + }; + EnumerateGeckoProcesses(visitor); + } + public static void killAnyZombies() { GeckoProcessesVisitor visitor = new GeckoProcessesVisitor() { public boolean callback(int pid) {