commit 4aa3cd6ea2ed43f76894d06d779640239f0dc0b0 Author: Nathan Freitas nathan@freitas.net Date: Fri Apr 18 06:22:10 2014 -0400
moved diagnotics to menu option (not launcher) --- res/menu/main.xml | 8 +++ res/raw/torrcdiag | 2 +- .../android/OrbotDiagnosticsActivity.java | 72 ++++++-------------- 3 files changed, 31 insertions(+), 51 deletions(-)
diff --git a/res/menu/main.xml b/res/menu/main.xml index 4cbee84..df929ab 100755 --- a/res/menu/main.xml +++ b/res/menu/main.xml @@ -72,6 +72,14 @@ yourapp:showAsAction="ifRoom"
/> + + + <item android:id="@+id/menu_diag" + android:title="Test Mode" + android:icon="@drawable/ic_menu_check" + yourapp:showAsAction="never" + + />
</menu> <!-- diff --git a/res/raw/torrcdiag b/res/raw/torrcdiag index 5463e29..2edd200 100644 --- a/res/raw/torrcdiag +++ b/res/raw/torrcdiag @@ -3,7 +3,7 @@ SOCKSListenAddress 127.0.0.1 SafeSocks 0 TestSocks 1 WarnUnsafeSocks 1 -Log debug stdout +Log info stdout ControlListenAddress 127.0.0.1 ControlPort 9051 CookieAuthentication 1 diff --git a/src/org/torproject/android/OrbotDiagnosticsActivity.java b/src/org/torproject/android/OrbotDiagnosticsActivity.java index f36d4c6..db7ab21 100644 --- a/src/org/torproject/android/OrbotDiagnosticsActivity.java +++ b/src/org/torproject/android/OrbotDiagnosticsActivity.java @@ -34,6 +34,7 @@ public class OrbotDiagnosticsActivity extends Activity { private TextView mTextView = null; private final static String TAG = "OrbotDiag"; private StringBuffer log = new StringBuffer(); + Process mProcess; @Override protected void onCreate(Bundle savedInstanceState) { @@ -64,17 +65,22 @@ public class OrbotDiagnosticsActivity extends Activity { protected void onDestroy() {
super.onDestroy(); + + } + + private void stopTor () + { File appBinHome = this.getDir("bin", Context.MODE_PRIVATE);
File fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY); - - try { - killAllTor (fileTor); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + if (mProcess != null) + mProcess.destroy(); + + } + +
@Override protected void onResume() { @@ -102,40 +108,6 @@ public class OrbotDiagnosticsActivity extends Activity { runTorTest(); }
- private void killAllTor (File fileTor) throws IOException - { - try - { - int maxTry = 5; - int currTry = 0; - - Shell shell = Shell.startShell(); - int procId; - - while ((procId = TorServiceUtils.findProcessId(fileTor.getAbsolutePath())) != -1 && currTry++ < maxTry) - { - - log ("Found existing orphan Tor process; Trying to shutdown now (device restart may be needed)..."); - log("Found Tor PID=" + procId + " - attempt to shutdown now..."); - - SimpleCommand killCommand = new SimpleCommand("toolbox kill -9 " + procId); - shell.add(killCommand); - killCommand.waitForFinish(); - log ("kill output: " + killCommand.getExitCode() + "; " + killCommand.getOutput()); - killCommand = new SimpleCommand("kill -9 " + procId); - shell.add(killCommand); - killCommand.waitForFinish(); - log ("kill output: " + killCommand.getExitCode() + "; " + killCommand.getOutput()); - } - } - catch (Exception e) - { - log("error killing Tor: " + e.getLocalizedMessage()); - Log.d(TAG, "error killing Tor", e); - } - - } - private void runTorTest () { try @@ -145,8 +117,7 @@ public class OrbotDiagnosticsActivity extends Activity { File fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY); enableBinExec (fileTor, appBinHome); - killAllTor (fileTor); - + InputStream is = getResources().openRawResource(R.raw.torrcdiag); File fileTorrc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY + "diag"); TorResourceInstaller.streamToFile(is,fileTorrc, false, false); @@ -163,20 +134,20 @@ public class OrbotDiagnosticsActivity extends Activity { log ("Executing command> " + cmd); - Process process = Runtime.getRuntime().exec(cmd); + mProcess = Runtime.getRuntime().exec(cmd); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream())); StreamGobbler sg = new StreamGobbler(); sg.reader = bufferedReader; - sg.process = process; + sg.process = mProcess; new Thread(sg).start(); - if (process.getErrorStream() != null) + if (mProcess.getErrorStream() != null) { - bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); + bufferedReader = new BufferedReader(new InputStreamReader(mProcess.getErrorStream())); sg = new StreamGobbler(); sg.reader = bufferedReader; - sg.process = process; + sg.process = mProcess; new Thread(sg).start(); } @@ -209,7 +180,8 @@ public class OrbotDiagnosticsActivity extends Activity { Log.d(TAG, "error reading line",e); } - log("Tor exit code=" + process.exitValue() + ";"); + //log("Tor exit code=" + process.exitValue() + ";"); + } }