[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] handle logging native process Exceptions closer to the source
commit 12d92f48f5f43ccb80da63698765478df46eb46e
Author: Hans-Christoph Steiner <hans@xxxxxxx>
Date: Mon Jun 8 20:42:18 2015 -0400
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.
---
src/org/torproject/android/service/TorService.java | 70 +++++++++-----------
.../torproject/android/service/TorTransProxy.java | 20 +++---
2 files changed, 40 insertions(+), 50 deletions(-)
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 4e23e72..23801f3 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -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) {
+ if (intent != null)
+ new Thread (new TorStarter(intent)).start();
+ else
+ Log.d(TAG, "Got null onStartCommand() intent");
- new Thread (new TorStarter(intent)).start();
-
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();
-
- 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");
+ 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.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();
}
- 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;
}
diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java
index 89663fb..d63abb2 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -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);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits