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)
*/
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread (new TorStarter(intent)).start();
if (intent != null)
new Thread (new TorStarter(intent)).start();
else
Log.d(TAG, "Got null onStartCommand() intent");
return Service.START_STICKY;
}
private class TorStarter implements Runnable
@ -364,36 +365,27 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
mIntent = intent;
}
public void run (){
try{
//if this is a start on boot launch turn tor on
if (mIntent != null){
String action = mIntent.getAction();
public void run() {
String action = mIntent.getAction();
if (action!=null){
if(action.equals(Intent.ACTION_BOOT_COMPLETED)||action.equals(CMD_START)){
setTorProfile(STATUS_ON);
}else if (action.equals(CMD_STOP)){
setTorProfile(STATUS_OFF);
}else if (action.equals(CMD_NEWNYM)){
newIdentity();
}else if (action.equals(CMD_FLUSH)){
flushTransparentProxyRules();
}else if (action.equals(CMD_UPDATE)){
processSettings();
}else if (action.equals(CMD_VPN)){
enableVpnProxy();
}
else if (action.equals(CMD_VPN_CLEAR)){
clearVpnProxy();
}
}
}else{
Log.d(TAG, "Got null onStartCommand() intent");
if (action != null) {
if (action.equals(Intent.ACTION_BOOT_COMPLETED) || action.equals(CMD_START)) {
setTorProfile(STATUS_ON);
} else if (action.equals(CMD_STOP)) {
setTorProfile(STATUS_OFF);
} else if (action.equals(CMD_NEWNYM)) {
newIdentity();
} else if (action.equals(CMD_FLUSH)) {
flushTransparentProxyRules();
} else if (action.equals(CMD_UPDATE)) {
processSettings();
} else if (action.equals(CMD_VPN)) {
enableVpnProxy();
} else if (action.equals(CMD_VPN_CLEAR)) {
clearVpnProxy();
} else {
Log.w(TAG, "unhandled TorService Intent: " + action);
}
}catch (Exception e){
Log.e(TAG,"error onBind",e);
}
}
}
@ -879,19 +871,19 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
shellUser.close();
}
private boolean flushTransparentProxyRules () throws Exception
{
private boolean flushTransparentProxyRules () {
if (mHasRoot)
{
if (mTransProxy == null)
{
mTransProxy = new TorTransProxy(this, fileXtables);
try {
mTransProxy.flushTransproxyRules(this);
} catch (Exception e) {
e.printStackTrace();
return false;
}
mTransProxy.flushTransproxyRules(this);
return true;
}
else

View File

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