put up error notification if Orbot cannot kill a process

There are a couple of different times when Orbot will be unable to kill the
running processes.  One example is when Orbot is running, then uninstalled,
then installed again.

closes #5254 https://dev.guardianproject.info/issues/5254
This commit is contained in:
Hans-Christoph Steiner 2015-06-04 11:59:22 -04:00
parent 81cf67f955
commit 2f1ad74538
2 changed files with 103 additions and 63 deletions

View File

@ -222,6 +222,7 @@
<string name="hidden_service_on">hidden service on:</string>
<string name="unable_to_read_hidden_service_name">unable to read hidden service name</string>
<string name="unable_to_start_tor">Unable to start Tor:</string>
<string name="unable_to_reset_tor">Reboot your device, unable to reset Tor!</string>
<string name="pref_use_sys_iptables_title">Use Default Iptables</string>
<string name="pref_use_sys_iptables_summary">use the built-in iptables binary instead of the one bundled with Orbot</string>

View File

@ -457,6 +457,14 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
sendCallbackLogMessage(getString(R.string.status_disabled));
}
catch (CannotKillException e)
{
Log.d(TAG, "An error occured stopping Tor", e);
logNotice("An error occured stopping Tor: " + e.getMessage());
sendCallbackLogMessage(getString(R.string.unable_to_reset_tor));
showToolbarNotification(getString(R.string.unable_to_reset_tor),
ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
}
catch (Exception e)
{
Log.d(TAG, "An error occured stopping Tor",e);
@ -560,27 +568,49 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
killProcess(filePolipo);
killProcess(fileObfsclient);
killProcess(fileMeekclient);
}
private void killProcess (File fileProcBin) throws IOException
{
int procId = -1;
Shell shell = Shell.startShell();
public class CannotKillException extends IllegalStateException {
private static final long serialVersionUID = -286877277562592501L;
while ((procId = TorServiceUtils.findProcessId(fileProcBin.getCanonicalPath())) != -1)
{
logNotice("Found " + fileProcBin.getName() + " PID=" + procId + " - killing now...");
SimpleCommand killCommand = new SimpleCommand("toolbox kill -9 " + procId);
shell.add(killCommand);
killCommand = new SimpleCommand("kill -9 " + procId);
shell.add(killCommand);
public CannotKillException(File f) {
super("Cannot kill " + f.getAbsolutePath());
}
}
shell.close();
private void killProcess(File fileProcBin) throws IOException {
int procId = -1;
int killAttempts = 0;
while ((procId = TorServiceUtils.findProcessId(fileProcBin.getCanonicalPath())) != -1) {
killAttempts++;
logNotice("Found " + fileProcBin.getName() + " PID=" + procId + " - killing now...");
String pidString = String.valueOf(procId);
/*
* first try as the normal app user to be safe, then if that fails,
* try root since the process might be left over from
* uninstall/reinstall with different UID.
*/
Shell shell;
if (mHasRoot && killAttempts > 2) {
shell = Shell.startRootShell();
Log.i(TAG, "using a root shell");
} else {
shell = Shell.startShell();
}
shell.add(new SimpleCommand("busybox killall " + fileProcBin.getName()));
shell.add(new SimpleCommand("toolbox kill -9 " + pidString));
shell.add(new SimpleCommand("busybox kill -9 " + pidString));
shell.add(new SimpleCommand("kill -9 " + pidString));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignored
}
shell.close();
if (killAttempts > 4)
throw new CannotKillException(fileProcBin);
}
}
private void logNotice (String msg)
@ -1420,6 +1450,15 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
startTor();
}
}
catch (CannotKillException e)
{
logException(e.getMessage(), e);
mCurrentStatus = STATUS_OFF;
sendCallbackStatus(mCurrentStatus);
showToolbarNotification(getString(R.string.unable_to_reset_tor),
ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
stopTor();
}
catch (Exception e)
{