improve diagnostics apps

This commit is contained in:
Nathan Freitas 2014-04-17 10:16:25 -04:00
parent 2996fb2078
commit 1ea5281f82
1 changed files with 93 additions and 48 deletions

View File

@ -42,17 +42,6 @@ public class OrbotDiagnosticsActivity extends Activity {
mTextView = (TextView)findViewById(R.id.diaglog); mTextView = (TextView)findViewById(R.id.diaglog);
log("Hello, Orbot!");
log(android.os.Build.DEVICE);
log(android.os.Build.HARDWARE);
log(android.os.Build.MANUFACTURER);
log(android.os.Build.MODEL);
log(android.os.Build.VERSION.CODENAME);
log(android.os.Build.VERSION.RELEASE);
log("freemem: " + Runtime.getRuntime().freeMemory());
log("maxmem: " + Runtime.getRuntime().maxMemory());
log("storage: " + getFreeStorage());
} }
private String getFreeStorage () private String getFreeStorage ()
@ -90,6 +79,23 @@ public class OrbotDiagnosticsActivity extends Activity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
log("Hello, Orbot!");
try
{
log(android.os.Build.DEVICE);
log(android.os.Build.HARDWARE);
log(android.os.Build.MANUFACTURER);
log(android.os.Build.MODEL);
log(android.os.Build.VERSION.CODENAME);
log(android.os.Build.VERSION.RELEASE);
}
catch (Exception e)
{
log("error getting device info");
}
showFileTree (); showFileTree ();
runTorTest(); runTorTest();
@ -97,24 +103,36 @@ public class OrbotDiagnosticsActivity extends Activity {
private void killAllTor (File fileTor) throws IOException private void killAllTor (File fileTor) throws IOException
{ {
int maxTry = 5; try
int currTry = 0;
Shell shell = Shell.startShell();
Toolbox tb = new Toolbox(shell);
int procId;
while ((procId = TorServiceUtils.findProcessId(fileTor.getAbsolutePath())) != -1 && currTry++ < maxTry)
{ {
int maxTry = 5;
log ("Found existing orphan Tor process; Trying to shutdown now (device restart may be needed)..."); int currTry = 0;
log("Found Tor PID=" + procId + " - attempt to shutdown now...");
Shell shell = Shell.startShell();
SimpleCommand killCommand = new SimpleCommand("toolbox kill -9 " + procId); int procId;
shell.add(killCommand);
killCommand = new SimpleCommand("kill -9 " + procId); while ((procId = TorServiceUtils.findProcessId(fileTor.getAbsolutePath())) != -1 && currTry++ < maxTry)
shell.add(killCommand); {
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 () private void runTorTest ()
@ -145,17 +163,21 @@ public class OrbotDiagnosticsActivity extends Activity {
log ("Executing command> " + cmd); log ("Executing command> " + cmd);
Process process = Runtime.getRuntime().exec(cmd); Process process = Runtime.getRuntime().exec(cmd);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StreamGobbler sg = new StreamGobbler(); StreamGobbler sg = new StreamGobbler();
sg.reader = bufferedReader; sg.reader = bufferedReader;
sg.process = process; sg.process = process;
new Thread(sg).start(); new Thread(sg).start();
bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); if (process.getErrorStream() != null)
sg = new StreamGobbler(); {
sg.reader = bufferedReader; bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
sg.process = process; sg = new StreamGobbler();
new Thread(sg).start(); sg.reader = bufferedReader;
sg.process = process;
new Thread(sg).start();
}
} }
@ -215,14 +237,27 @@ public class OrbotDiagnosticsActivity extends Activity {
{ {
File fileDir = this.getDir("bin", Context.MODE_PRIVATE); File fileDir = this.getDir("bin", Context.MODE_PRIVATE);
log("checking file tree: " + fileDir.getAbsolutePath());
printDir (fileDir.getName(), fileDir); if (fileDir.exists())
{
log("checking file tree: " + fileDir.getAbsolutePath());
printDir (fileDir.getName(), fileDir);
}
else
{
log("app_bin does not exist");
}
fileDir = this.getDir("data", Context.MODE_PRIVATE); fileDir = this.getDir("data", Context.MODE_PRIVATE);
log("checking file tree: " + fileDir.getAbsolutePath()); if (fileDir.exists())
printDir (fileDir.getName(), fileDir); {
log("checking file tree: " + fileDir.getAbsolutePath());
printDir (fileDir.getName(), fileDir);
}
else
{
log ("app_data does not exist");
}
} }
@ -231,19 +266,29 @@ public class OrbotDiagnosticsActivity extends Activity {
{ {
File[] files = fileDir.listFiles(); File[] files = fileDir.listFiles();
for (File file : files) if (files != null && files.length > 0)
{ {
for (File file : files)
{
try
{
if (file.isDirectory())
{
printDir(path + '/' + file.getName(), file);
}
else
{
log(path + '/' + file.getName() + " len:" + file.length() + " exec:" + file.canExecute());
}
}
catch (Exception e)
{
log("problem printing out file information");
}
if (file.isDirectory())
{
printDir(path + '/' + file.getName(), file);
} }
else
{
log(path + '/' + file.getName() + " len:" + file.length() + " exec:" + file.canExecute());
}
} }
} }