mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
Bug 761301 - Make SUTAgent's kill command kill all app processes;r=jmaher
This commit is contained in:
parent
1d39230041
commit
fe8f195ed1
@ -2380,45 +2380,32 @@ private void CancelNotification()
|
||||
|
||||
public String KillProcess(String sProcName, OutputStream out)
|
||||
{
|
||||
String sTmp = "";
|
||||
String sCmd = "kill";
|
||||
|
||||
String sRet = sErrorPrefix + "Unable to kill " + sProcName + "\n";
|
||||
ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE);
|
||||
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses();
|
||||
int lcv = 0;
|
||||
String strProcName = "";
|
||||
int nPID = 0;
|
||||
String sFoundProcName = "";
|
||||
int nProcs = 0;
|
||||
boolean bFoundAppProcess = false;
|
||||
|
||||
if (lProcesses != null)
|
||||
if (lProcesses != null)
|
||||
nProcs = lProcesses.size();
|
||||
|
||||
for (lcv = 0; lcv < nProcs; lcv++)
|
||||
{
|
||||
if (lProcesses.get(lcv).processName.contains(sProcName))
|
||||
{
|
||||
strProcName = lProcesses.get(lcv).processName;
|
||||
nPID = lProcesses.get(lcv).pid;
|
||||
sRet = sErrorPrefix + "Failed to kill " + nPID + " " + strProcName + "\n";
|
||||
|
||||
sCmd += " " + nPID;
|
||||
sFoundProcName = lProcesses.get(lcv).processName;
|
||||
bFoundAppProcess = true;
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(this.getSuArgs(sCmd));
|
||||
pProc = Runtime.getRuntime().exec(this.getSuArgs("kill " + lProcesses.get(lcv).pid));
|
||||
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
|
||||
outThrd.start();
|
||||
outThrd.join(15000);
|
||||
sTmp = outThrd.strOutput;
|
||||
String sTmp = outThrd.strOutput;
|
||||
Log.e("KILLPROCESS", sTmp);
|
||||
if (outThrd.nExitCode == 0) {
|
||||
sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
|
||||
nPID = 0;
|
||||
break;
|
||||
} else {
|
||||
sRet = sErrorPrefix + "Failed to kill " + nPID + " " + strProcName + "\n";
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@ -2429,31 +2416,30 @@ private void CancelNotification()
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Give the messages a chance to be processed
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nPID > 0)
|
||||
if (bFoundAppProcess)
|
||||
{
|
||||
sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
|
||||
// Give the messages a chance to be processed
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
sRet = "Successfully killed " + sProcName + "\n";
|
||||
lProcesses = aMgr.getRunningAppProcesses();
|
||||
nProcs = 0;
|
||||
if (lProcesses != null)
|
||||
if (lProcesses != null)
|
||||
nProcs = lProcesses.size();
|
||||
for (lcv = 0; lcv < nProcs; lcv++)
|
||||
{
|
||||
if (lProcesses.get(lcv).processName.contains(sProcName))
|
||||
{
|
||||
sRet = sErrorPrefix + "Unable to kill " + nPID + " " + strProcName + "\n";
|
||||
sRet = sErrorPrefix + "Unable to kill " + sProcName + " (couldn't kill " + sFoundProcName +")\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2469,7 +2455,7 @@ private void CancelNotification()
|
||||
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
|
||||
outThrd.start();
|
||||
outThrd.join(10000);
|
||||
sTmp = outThrd.strOutput;
|
||||
String sTmp = outThrd.strOutput;
|
||||
StringTokenizer stokLines = new StringTokenizer(sTmp, "\n");
|
||||
while(stokLines.hasMoreTokens())
|
||||
{
|
||||
@ -2490,7 +2476,7 @@ private void CancelNotification()
|
||||
if (sName.contains(sProcName))
|
||||
{
|
||||
NewKillProc(sPid, out);
|
||||
sRet = "Successfully killed " + sPid + " " + sName + "\n";
|
||||
sRet = "Successfully killed " + sName + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user