bug 672356 - plugin-container not set to background cgroup r=dougt

This commit is contained in:
Brad Lassey 2011-07-28 02:25:11 -04:00
parent f6e7ea13ac
commit 237262a45f
2 changed files with 49 additions and 0 deletions

View File

@ -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();
}

View File

@ -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) {