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,18 +79,36 @@ 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();
} }
private void killAllTor (File fileTor) throws IOException private void killAllTor (File fileTor) throws IOException
{
try
{ {
int maxTry = 5; int maxTry = 5;
int currTry = 0; int currTry = 0;
Shell shell = Shell.startShell(); Shell shell = Shell.startShell();
Toolbox tb = new Toolbox(shell);
int procId; int procId;
while ((procId = TorServiceUtils.findProcessId(fileTor.getAbsolutePath())) != -1 && currTry++ < maxTry) while ((procId = TorServiceUtils.findProcessId(fileTor.getAbsolutePath())) != -1 && currTry++ < maxTry)
@ -112,10 +119,21 @@ public class OrbotDiagnosticsActivity extends Activity {
SimpleCommand killCommand = new SimpleCommand("toolbox kill -9 " + procId); SimpleCommand killCommand = new SimpleCommand("toolbox kill -9 " + procId);
shell.add(killCommand); shell.add(killCommand);
killCommand.waitForFinish();
log ("kill output: " + killCommand.getExitCode() + "; " + killCommand.getOutput());
killCommand = new SimpleCommand("kill -9 " + procId); killCommand = new SimpleCommand("kill -9 " + procId);
shell.add(killCommand); 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();
if (process.getErrorStream() != null)
{
bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
sg = new StreamGobbler(); sg = new StreamGobbler();
sg.reader = bufferedReader; sg.reader = bufferedReader;
sg.process = process; sg.process = process;
new Thread(sg).start(); 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);
if (fileDir.exists())
{
log("checking file tree: " + fileDir.getAbsolutePath()); log("checking file tree: " + fileDir.getAbsolutePath());
printDir (fileDir.getName(), fileDir); 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);
if (fileDir.exists())
{
log("checking file tree: " + fileDir.getAbsolutePath()); log("checking file tree: " + fileDir.getAbsolutePath());
printDir (fileDir.getName(), fileDir); printDir (fileDir.getName(), fileDir);
}
else
{
log ("app_data does not exist");
}
} }
@ -231,9 +266,13 @@ public class OrbotDiagnosticsActivity extends Activity {
{ {
File[] files = fileDir.listFiles(); File[] files = fileDir.listFiles();
if (files != null && files.length > 0)
{
for (File file : files) for (File file : files)
{ {
try
{
if (file.isDirectory()) if (file.isDirectory())
{ {
printDir(path + '/' + file.getName(), file); printDir(path + '/' + file.getName(), file);
@ -243,9 +282,15 @@ public class OrbotDiagnosticsActivity extends Activity {
log(path + '/' + file.getName() + " len:" + file.length() + " exec:" + file.canExecute()); log(path + '/' + file.getName() + " len:" + file.length() + " exec:" + file.canExecute());
} }
}
catch (Exception e)
{
log("problem printing out file information");
}
} }
} }
}
Handler mHandler = new Handler () Handler mHandler = new Handler ()
{ {