handle logging native process Exceptions closer to the source

Instead of passing Exceptions through many layers only to log them, just
log them where they are thrown.  Keeps things neater.
This commit is contained in:
Hans-Christoph Steiner 2015-06-08 20:42:18 -04:00
parent ae83f011b2
commit 12d92f48f5
2 changed files with 40 additions and 50 deletions

View File

@ -348,11 +348,12 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
* @see android.app.Service#onStart(android.content.Intent, int) * @see android.app.Service#onStart(android.content.Intent, int)
*/ */
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null)
new Thread (new TorStarter(intent)).start(); new Thread (new TorStarter(intent)).start();
else
Log.d(TAG, "Got null onStartCommand() intent");
return Service.START_STICKY; return Service.START_STICKY;
} }
private class TorStarter implements Runnable private class TorStarter implements Runnable
@ -365,9 +366,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} }
public void run() { public void run() {
try{
//if this is a start on boot launch turn tor on
if (mIntent != null){
String action = mIntent.getAction(); String action = mIntent.getAction();
if (action != null) { if (action != null) {
@ -383,17 +381,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
processSettings(); processSettings();
} else if (action.equals(CMD_VPN)) { } else if (action.equals(CMD_VPN)) {
enableVpnProxy(); enableVpnProxy();
} } else if (action.equals(CMD_VPN_CLEAR)) {
else if (action.equals(CMD_VPN_CLEAR)){
clearVpnProxy(); clearVpnProxy();
}
}
} else { } else {
Log.d(TAG, "Got null onStartCommand() intent"); Log.w(TAG, "unhandled TorService Intent: " + action);
} }
}catch (Exception e){
Log.e(TAG,"error onBind",e);
} }
} }
} }
@ -879,18 +871,18 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
shellUser.close(); shellUser.close();
} }
private boolean flushTransparentProxyRules () throws Exception private boolean flushTransparentProxyRules () {
{
if (mHasRoot) if (mHasRoot)
{ {
if (mTransProxy == null) if (mTransProxy == null)
{
mTransProxy = new TorTransProxy(this, fileXtables); mTransProxy = new TorTransProxy(this, fileXtables);
} try {
mTransProxy.flushTransproxyRules(this); mTransProxy.flushTransproxyRules(this);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true; return true;
} }

View File

@ -3,8 +3,6 @@ package org.torproject.android.service;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
import org.sufficientlysecure.rootcommands.Shell; import org.sufficientlysecure.rootcommands.Shell;
import org.sufficientlysecure.rootcommands.command.SimpleCommand; import org.sufficientlysecure.rootcommands.command.SimpleCommand;
import org.torproject.android.OrbotConstants; import org.torproject.android.OrbotConstants;
@ -12,7 +10,6 @@ import org.torproject.android.settings.TorifiedApp;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Log;
public class TorTransProxy implements TorServiceConstants { public class TorTransProxy implements TorServiceConstants {
@ -335,7 +332,7 @@ public class TorTransProxy implements TorServiceConstants {
return code; return code;
}*/ }*/
public int setTransparentProxyingByApp(Context context, ArrayList<TorifiedApp> apps, boolean enableRule, Shell shell) throws Exception public int setTransparentProxyingByApp(Context context, ArrayList<TorifiedApp> apps, boolean enableRule, Shell shell)
{ {
String ipTablesPath = getIpTablesPath(context); String ipTablesPath = getIpTablesPath(context);
@ -439,10 +436,13 @@ public class TorTransProxy implements TorServiceConstants {
return lastExit; return lastExit;
} }
private int executeCommand (Shell shell, String cmdString) throws IOException, TimeoutException private int executeCommand (Shell shell, String cmdString) {
{
SimpleCommand cmd = new SimpleCommand(cmdString); SimpleCommand cmd = new SimpleCommand(cmdString);
try {
shell.add(cmd); shell.add(cmd);
} catch (IOException e) {
e.printStackTrace();
}
int exitCode = cmd.getExitCode(); int exitCode = cmd.getExitCode();
String output = cmd.getOutput(); String output = cmd.getOutput();
@ -524,8 +524,7 @@ public class TorTransProxy implements TorServiceConstants {
} }
public int dropAllIPv6Traffic (Context context, int appUid, boolean enableDrop, Shell shell) throws Exception public int dropAllIPv6Traffic (Context context, int appUid, boolean enableDrop, Shell shell) {
{
String action = " -A "; String action = " -A ";
String chain = "OUTPUT"; String chain = "OUTPUT";
@ -575,8 +574,7 @@ public class TorTransProxy implements TorServiceConstants {
return lastExit; return lastExit;
}*/ }*/
public int flushTransproxyRules (Context context) throws Exception public int flushTransproxyRules (Context context) throws IOException {
{
int exit = -1; int exit = -1;
String ipTablesPath = getIpTablesPath(context); String ipTablesPath = getIpTablesPath(context);