commit 091037427af76f7bbb2c79e809bb77f8c42de323
Author: n8fr8 <[email protected]>
Date:   Wed Oct 25 11:41:55 2017 -0400

    clean up variables and improve how tor process is launched
---
 .../org/torproject/android/service/TorService.java |  47 +++----
 .../android/service/TorServiceConstants.java       | 140 ++++++++++-----------
 2 files changed, 95 insertions(+), 92 deletions(-)

diff --git 
a/orbotservice/src/main/java/org/torproject/android/service/TorService.java 
b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
index 36c1b229..8e5a7495 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -675,13 +675,7 @@ public class TorService extends Service implements 
TorServiceConstants, OrbotCon
        
        if (Prefs.useVpn())
                extraLines.append("DNSListenAddress 0.0.0.0").append('\n');
-       
-        if (Prefs.transparentTethering())
-        {
-            extraLines.append("TransListenAddress 0.0.0.0").append('\n');
-            extraLines.append("DNSListenAddress 0.0.0.0").append('\n');        
    
-        }
-       
+
         extraLines.append("VirtualAddrNetwork 10.192.0.0/10").append('\n');
         extraLines.append("AutomapHostsOnResolve 1").append('\n');
 
@@ -866,26 +860,32 @@ public class TorService extends Service implements 
TorServiceConstants, OrbotCon
                 + " -f " + torrcPath + ".custom";
     
         debug(torCmdString);
-        
-        int exitCode = exec(torCmdString + " --verify-config", true);
 
-        String output = "";
-       // String output = shellTorCommand.getOutput();
-        
-        if (exitCode != 0)
+
+        int exitCode = -1;
+
+        try {
+            exitCode = exec(torCmdString + " --verify-config", true);
+        }
+        catch (Exception e)
         {
-            logNotice("Tor (" + exitCode + "): " + output);
-            throw new Exception ("Torrc config did not verify");
-            
+            logNotice("Tor configuration did not verify: " + e.getMessage());
+            return false;
+        }
+
+
+        try {
+            exitCode = exec(torCmdString, true);
+        }
+        catch (Exception e)
+        {
+            logNotice("Tor was unable to start: " + e.getMessage());
+            return false;
         }
 
-        exitCode = exec(torCmdString, true);
-        output = "";// shellTorCommand.getOutput();
-        
         if (exitCode != 0)
         {
-            logNotice("Tor (" + exitCode + "): " + output);
-            //throw new Exception ("unable to start");
+            logNotice("Tor did not start. Exit:" + exitCode);
             return false;
         }
         
@@ -918,9 +918,12 @@ public class TorService extends Service implements 
TorServiceConstants, OrbotCon
     private int exec (String cmd, boolean wait) throws Exception
     {
         CommandResult shellResult = Shell.run(cmd);
-        shellResult.isSuccessful();
         debug("CMD: " + cmd + "; SUCCESS=" + shellResult.isSuccessful());
 
+        if (!shellResult.isSuccessful()) {
+            throw new Exception("Error: " + shellResult.exitCode + " ERR=" + 
shellResult.getStderr() + " OUT=" + shellResult.getStdout());
+        }
+
         /**
         SimpleCommand command = new SimpleCommand(cmd);
         mShell.add(command);
diff --git 
a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
 
b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
index d199eec6..b91f2b2d 100644
--- 
a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
+++ 
b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
@@ -7,150 +7,150 @@ import android.content.Intent;
 
 public interface TorServiceConstants {
 
-       public final static String TOR_APP_USERNAME = "org.torproject.android";
-       public final static String BROWSER_APP_USERNAME = 
"info.guardianproject.orfox";
+       String TOR_APP_USERNAME = "org.torproject.android";
+       String BROWSER_APP_USERNAME = "info.guardianproject.orfox";
        
-       public final static String DIRECTORY_TOR_BINARY = "bin";
-       public final static String DIRECTORY_TOR_DATA = "data";
+       String DIRECTORY_TOR_BINARY = "bin";
+       String DIRECTORY_TOR_DATA = "data";
        
        //name of the tor C binary
-       public final static String TOR_ASSET_KEY = "tor";       
+       String TOR_ASSET_KEY = "tor";   
        
        //torrc (tor config file)
-       public final static String TORRC_ASSET_KEY = "torrc";
-       public final static String TORRCDIAG_ASSET_KEY = "torrcdiag";
-       public final static String TORRC_TETHER_KEY = "torrctether";
+       String TORRC_ASSET_KEY = "torrc";
+       String TORRCDIAG_ASSET_KEY = "torrcdiag";
+       String TORRC_TETHER_KEY = "torrctether";
        
-       public final static String TOR_CONTROL_COOKIE = "control_auth_cookie";
+       String TOR_CONTROL_COOKIE = "control_auth_cookie";
        
        //privoxy
-       public final static String POLIPO_ASSET_KEY = "polipo";
+       String POLIPO_ASSET_KEY = "polipo";
        
        //privoxy.config
-       public final static String POLIPOCONFIG_ASSET_KEY = "torpolipo.conf";
+       String POLIPOCONFIG_ASSET_KEY = "torpolipo.conf";
        
        //geoip data file asset key
-       public final static String GEOIP_ASSET_KEY = "geoip";
-       public final static String GEOIP6_ASSET_KEY = "geoip6";
+       String GEOIP_ASSET_KEY = "geoip";
+       String GEOIP6_ASSET_KEY = "geoip6";
 
        //various console cmds
-       public final static String SHELL_CMD_CHMOD = "chmod";
-       public final static String SHELL_CMD_KILL = "kill -9";
-       public final static String SHELL_CMD_RM = "rm";
-       public final static String SHELL_CMD_PS = "toolbox ps";
-       public final static String SHELL_CMD_PS_ALT = "ps";
+       String SHELL_CMD_CHMOD = "chmod";
+       String SHELL_CMD_KILL = "kill -9";
+       String SHELL_CMD_RM = "rm";
+       String SHELL_CMD_PS = "toolbox ps";
+       String SHELL_CMD_PS_ALT = "ps";
     
     
-       //public final static String SHELL_CMD_PIDOF = "pidof";
-       public final static String SHELL_CMD_LINK = "ln -s";
-       public final static String SHELL_CMD_CP = "cp";
+       //String SHELL_CMD_PIDOF = "pidof";
+       String SHELL_CMD_LINK = "ln -s";
+       String SHELL_CMD_CP = "cp";
        
 
-       public final static String CHMOD_EXE_VALUE = "770";
+       String CHMOD_EXE_VALUE = "770";
 
-       public final static int FILE_WRITE_BUFFER_SIZE = 1024;
+       int FILE_WRITE_BUFFER_SIZE = 1024;
 
-       public final static String IP_LOCALHOST = "127.0.0.1";
-       public final static int UPDATE_TIMEOUT = 1000;
-       public final static int TOR_TRANSPROXY_PORT_DEFAULT = 9040;
+       String IP_LOCALHOST = "127.0.0.1";
+       int UPDATE_TIMEOUT = 1000;
+       int TOR_TRANSPROXY_PORT_DEFAULT = 9040;
        
-       public final static int STANDARD_DNS_PORT = 53;
-       public final static int TOR_DNS_PORT_DEFAULT = 5400;
-       public final static String TOR_VPN_DNS_LISTEN_ADDRESS = "127.0.0.1";
+       int STANDARD_DNS_PORT = 53;
+       int TOR_DNS_PORT_DEFAULT = 5400;
+       String TOR_VPN_DNS_LISTEN_ADDRESS = "127.0.0.1";
        
-       public final static int CONTROL_PORT_DEFAULT = 9051;
-    public final static int HTTP_PROXY_PORT_DEFAULT = 8118; // like Privoxy!
-    public final static int SOCKS_PROXY_PORT_DEFAULT = 9050;
+       int CONTROL_PORT_DEFAULT = 9051;
+    int HTTP_PROXY_PORT_DEFAULT = 8118; // like Privoxy!
+    int SOCKS_PROXY_PORT_DEFAULT = 9050;
 
     
        //path to check Tor against
-       public final static String URL_TOR_CHECK = 
"https://check.torproject.org";;
+       String URL_TOR_CHECK = "https://check.torproject.org";;
 
     //control port 
-    public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = 
"Bootstrapped 100%";
-    public final static String LOG_NOTICE_HEADER = "NOTICE";
-    public final static String LOG_NOTICE_BOOTSTRAPPED = "Bootstrapped";
+    String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
+    String LOG_NOTICE_HEADER = "NOTICE";
+    String LOG_NOTICE_BOOTSTRAPPED = "Bootstrapped";
     
     /**
      * A request to Orbot to transparently start Tor services
      */
-    public final static String ACTION_START = 
"org.torproject.android.intent.action.START";
+    String ACTION_START = "org.torproject.android.intent.action.START";
     /**
      * {@link Intent} send by Orbot with {@code ON/OFF/STARTING/STOPPING} 
status
      */
-    public final static String ACTION_STATUS = 
"org.torproject.android.intent.action.STATUS";
+    String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
     /**
      * {@code String} that contains a status constant: {@link #STATUS_ON},
      * {@link #STATUS_OFF}, {@link #STATUS_STARTING}, or
      * {@link #STATUS_STOPPING}
      */
-    public final static String EXTRA_STATUS = 
"org.torproject.android.intent.extra.STATUS";
+    String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
     /**
      * A {@link String} {@code packageName} for Orbot to direct its status 
reply
      * to, used in {@link #ACTION_START} {@link Intent}s sent to Orbot
      */
-    public final static String EXTRA_PACKAGE_NAME = 
"org.torproject.android.intent.extra.PACKAGE_NAME";
+    String EXTRA_PACKAGE_NAME = 
"org.torproject.android.intent.extra.PACKAGE_NAME";
     /**
      * The SOCKS proxy settings in URL form.
      */
-    public final static String EXTRA_SOCKS_PROXY = 
"org.torproject.android.intent.extra.SOCKS_PROXY";
-    public final static String EXTRA_SOCKS_PROXY_HOST = 
"org.torproject.android.intent.extra.SOCKS_PROXY_HOST";
-    public final static String EXTRA_SOCKS_PROXY_PORT = 
"org.torproject.android.intent.extra.SOCKS_PROXY_PORT";
+    String EXTRA_SOCKS_PROXY = 
"org.torproject.android.intent.extra.SOCKS_PROXY";
+    String EXTRA_SOCKS_PROXY_HOST = 
"org.torproject.android.intent.extra.SOCKS_PROXY_HOST";
+    String EXTRA_SOCKS_PROXY_PORT = 
"org.torproject.android.intent.extra.SOCKS_PROXY_PORT";
     /**
      * The HTTP proxy settings in URL form.
      */
-    public final static String EXTRA_HTTP_PROXY = 
"org.torproject.android.intent.extra.HTTP_PROXY";
-    public final static String EXTRA_HTTP_PROXY_HOST = 
"org.torproject.android.intent.extra.HTTP_PROXY_HOST";
-    public final static String EXTRA_HTTP_PROXY_PORT = 
"org.torproject.android.intent.extra.HTTP_PROXY_PORT";
+    String EXTRA_HTTP_PROXY = "org.torproject.android.intent.extra.HTTP_PROXY";
+    String EXTRA_HTTP_PROXY_HOST = 
"org.torproject.android.intent.extra.HTTP_PROXY_HOST";
+    String EXTRA_HTTP_PROXY_PORT = 
"org.torproject.android.intent.extra.HTTP_PROXY_PORT";
 
-    public final static String LOCAL_ACTION_LOG = "log";
-    public final static String LOCAL_ACTION_BANDWIDTH = "bandwidth";
-    public final static String LOCAL_EXTRA_LOG = "log";
+    String LOCAL_ACTION_LOG = "log";
+    String LOCAL_ACTION_BANDWIDTH = "bandwidth";
+    String LOCAL_EXTRA_LOG = "log";
 
     /**
      * All tor-related services and daemons are stopped
      */
-    public final static String STATUS_OFF = "OFF";
+    String STATUS_OFF = "OFF";
     /**
      * All tor-related services and daemons have completed starting
      */
-    public final static String STATUS_ON = "ON";
-    public final static String STATUS_STARTING = "STARTING";
-    public final static String STATUS_STOPPING = "STOPPING";
+    String STATUS_ON = "ON";
+    String STATUS_STARTING = "STARTING";
+    String STATUS_STOPPING = "STOPPING";
 
     /**
      * The user has disabled the ability for background starts triggered by
      * apps. Fallback to the old {@link Intent} action that brings up Orbot:
      * {@link 
org.torproject.android.OrbotMainActivity#INTENT_ACTION_REQUEST_START_TOR}
      */
-    public final static String STATUS_STARTS_DISABLED = "STARTS_DISABLED";
+    String STATUS_STARTS_DISABLED = "STARTS_DISABLED";
 
     // actions for internal command Intents
-    public static final String CMD_SIGNAL_HUP = "signal_hup";
-    public static final String CMD_STATUS = "status";
-    public static final String CMD_FLUSH = "flush";
-    public static final String CMD_NEWNYM = "newnym";
-    public static final String CMD_VPN = "vpn";
-    public static final String CMD_VPN_CLEAR = "vpnclear";
-    public static final String CMD_UPDATE_TRANS_PROXY = "update";
-    public static final String CMD_SET_EXIT = "setexit";
-
-    public static final String BINARY_TOR_VERSION = "0.3.1.8-openssl1.0.2k";
-    public static final String PREF_BINARY_TOR_VERSION_INSTALLED = 
"BINARY_TOR_VERSION_INSTALLED";
+     String CMD_SIGNAL_HUP = "signal_hup";
+     String CMD_STATUS = "status";
+     String CMD_FLUSH = "flush";
+     String CMD_NEWNYM = "newnym";
+     String CMD_VPN = "vpn";
+     String CMD_VPN_CLEAR = "vpnclear";
+     String CMD_UPDATE_TRANS_PROXY = "update";
+     String CMD_SET_EXIT = "setexit";
+
+     String BINARY_TOR_VERSION = "0.3.1.8-openssl1.0.2k";
+     String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";
     
     //obfsproxy 
-    public static final String OBFSCLIENT_ASSET_KEY = "obfs4proxy";
+     String OBFSCLIENT_ASSET_KEY = "obfs4proxy";
     
-   // public static final String MEEK_ASSET_KEY = "meek-client";
+   //  String MEEK_ASSET_KEY = "meek-client";
 
        //DNS daemon for TCP DNS over TOr
-       public final static String PDNSD_ASSET_KEY = "pdnsd";
+       String PDNSD_ASSET_KEY = "pdnsd";
 
        //EXIT COUNTRY CODES
-       public final static String[] COUNTRY_CODES = 
{"DE","AT","SE","CH","IS","CA","US","ES","FR","BG","PL","AU","BR","CZ","DK","FI","GB","HU","NL","JP","RO","RU","SG","SK"};
+       String[] COUNTRY_CODES = 
{"DE","AT","SE","CH","IS","CA","US","ES","FR","BG","PL","AU","BR","CZ","DK","FI","GB","HU","NL","JP","RO","RU","SG","SK"};
 
 
-       public static final String HIDDEN_SERVICES_DIR = "hidden_services";
+        String HIDDEN_SERVICES_DIR = "hidden_services";
 
 
 



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to