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:
parent
ae83f011b2
commit
12d92f48f5
|
@ -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
|
||||||
|
@ -364,36 +365,27 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
mIntent = intent;
|
mIntent = intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run (){
|
public void run() {
|
||||||
try{
|
String action = mIntent.getAction();
|
||||||
//if this is a start on boot launch turn tor on
|
|
||||||
if (mIntent != null){
|
|
||||||
String action = mIntent.getAction();
|
|
||||||
|
|
||||||
if (action!=null){
|
if (action != null) {
|
||||||
if(action.equals(Intent.ACTION_BOOT_COMPLETED)||action.equals(CMD_START)){
|
if (action.equals(Intent.ACTION_BOOT_COMPLETED) || action.equals(CMD_START)) {
|
||||||
setTorProfile(STATUS_ON);
|
setTorProfile(STATUS_ON);
|
||||||
}else if (action.equals(CMD_STOP)){
|
} else if (action.equals(CMD_STOP)) {
|
||||||
setTorProfile(STATUS_OFF);
|
setTorProfile(STATUS_OFF);
|
||||||
}else if (action.equals(CMD_NEWNYM)){
|
} else if (action.equals(CMD_NEWNYM)) {
|
||||||
newIdentity();
|
newIdentity();
|
||||||
}else if (action.equals(CMD_FLUSH)){
|
} else if (action.equals(CMD_FLUSH)) {
|
||||||
flushTransparentProxyRules();
|
flushTransparentProxyRules();
|
||||||
}else if (action.equals(CMD_UPDATE)){
|
} else if (action.equals(CMD_UPDATE)) {
|
||||||
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 {
|
||||||
}
|
Log.w(TAG, "unhandled TorService Intent: " + action);
|
||||||
}
|
|
||||||
}else{
|
|
||||||
Log.d(TAG, "Got null onStartCommand() intent");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
Log.e(TAG,"error onBind",e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -879,19 +871,19 @@ 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);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTransProxy.flushTransproxyRules(this);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -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);
|
||||||
shell.add(cmd);
|
try {
|
||||||
|
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);
|
||||||
|
|
Loading…
Reference in New Issue