Bug 761301 - Make SUTAgent's kill command kill all app processes

This commit is contained in:
William Lachance 2012-06-05 11:07:42 -04:00
parent b0c53ad019
commit c6bbc3a759

View File

@ -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";
}
}
}