moved diagnotics to menu option (not launcher)

This commit is contained in:
Nathan Freitas 2014-04-18 06:22:10 -04:00
parent b6e7a02fb4
commit 4aa3cd6ea2
3 changed files with 31 additions and 51 deletions

View File

@ -73,6 +73,14 @@
/>
<item android:id="@+id/menu_diag"
android:title="Test Mode"
android:icon="@drawable/ic_menu_check"
yourapp:showAsAction="never"
/>
</menu>
<!--
MenuItem mItem = null;

View File

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

View File

@ -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,18 +65,23 @@ 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() {
super.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,7 +117,6 @@ 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");
@ -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() + ";");
}
}