From 48711d3efcdbf27ae8b644155d0c48e1d8472ee8 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Thu, 9 Sep 2010 20:39:52 +0000 Subject: [PATCH] alpha-1.0.3 RC1: cleaned up unnecessary log output; improved iptables handling for transproxy svn:r23154 --- AndroidManifest.xml | 10 +- CHANGELOG | 13 ++ assets/torrc | 1 - res/layout/layout_log.xml | 7 +- res/values/strings.xml | 3 + res/xml-es/preferences.xml | 76 -------- src/org/torproject/android/AppManager.java | 2 +- src/org/torproject/android/Orbot.java | 19 +- .../android/SettingsPreferences.java | 2 +- src/org/torproject/android/Utils.java | 2 +- .../android/net/ModSSLSocketFactory.java | 11 -- .../torproject/android/net/SocksClient.java | 6 +- .../android/net/SocksSocketFactory.java | 4 +- .../android/service/TorBinaryInstaller.java | 12 +- .../android/service/TorService.java | 169 +++++++++++------- .../android/service/TorServiceConstants.java | 2 +- .../android/service/TorServiceUtils.java | 17 +- .../android/service/TorTransProxy.java | 89 +++++---- 18 files changed, 201 insertions(+), 244 deletions(-) delete mode 100644 res/xml-es/preferences.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e8e430be..471b1213 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,15 +1,14 @@ + package="org.torproject.android" android:versionName="0.2.2.14-orbot-alpha-1.0.3" android:versionCode="9"> - + + android:theme="@android:style/Theme.NoTitleBar"> @@ -34,7 +33,8 @@ - + + diff --git a/CHANGELOG b/CHANGELOG index eb70de7c..7da70a6b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,18 @@ NOTE: Specific #s below correspond to Trac tickets logged and maintained at https://trac.torproject.org/projects/tor/ +1.0.3 +- fixed spanish language issues with settings screen +- cleaned up logging, and moved most of it to debug output only +- small changes to iptables, transproxy settings to handle iptables 1.3 and 1.4 variations + +1.0.2 +- added "check" yes/no dialog prompt +- debugged iptables/transprox settings on Android 1.6 and 2.2 +- added proxy settings help screen and fixed processSettings() NPE + +1.0.1 +- found and fixed major bug in per-app trans proxying; list of apps was being cached and iptables rules were not properly updated as the user changed the selection in the list + 1.0.0 - 2010-08-10 - Added "Proxy Settings" help screen - Handle potential null pointers on process settings where service not yet active diff --git a/assets/torrc b/assets/torrc index 1c687a09..b381fe7b 100644 --- a/assets/torrc +++ b/assets/torrc @@ -2,7 +2,6 @@ SocksPort 9050 SocksListenAddress 127.0.0.1 SafeSocks 1 Log notice stdout -##Log debug syslog DataDirectory /data/data/org.torproject.android/data ControlPort 9051 CookieAuthentication 1 diff --git a/res/layout/layout_log.xml b/res/layout/layout_log.xml index 872c0509..41cc9fe9 100644 --- a/res/layout/layout_log.xml +++ b/res/layout/layout_log.xml @@ -32,8 +32,9 @@ android:layout_toLeftOf="@+id/radioModeImage" android:textColor="#333333" /> + @@ -45,8 +46,8 @@ android:textSize="12px" android:background="#A0222222" /> - - + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 795fa1c4..36ed6407 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -35,6 +35,9 @@ Close About +Clear Log + + Orbot requires different configuration depending on the Android operating system version it is used on. Please visit https://www.torproject.org/docs/android.html for the latest information. diff --git a/res/xml-es/preferences.xml b/res/xml-es/preferences.xml deleted file mode 100644 index 55974d05..00000000 --- a/res/xml-es/preferences.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/org/torproject/android/AppManager.java b/src/org/torproject/android/AppManager.java index c2fa5b25..bec96b66 100644 --- a/src/org/torproject/android/AppManager.java +++ b/src/org/torproject/android/AppManager.java @@ -140,7 +140,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC protected void onStop() { super.onStop(); - //Log.i(getClass().getName(),"Exiting Preferences"); + //Log.d(getClass().getName(),"Exiting Preferences"); } diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 304d40b4..ccf1ef82 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -306,8 +306,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants setResult(RESULT_OK, nResult); } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Log.e(TAG, "error accessing hidden service", e); } @@ -478,6 +477,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants txtMessageLog.setClickable(true); txtMessageLog.setText(logBuffer.toString()); + } @@ -684,7 +684,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants String onionHostname = Utils.readString(new FileInputStream(file)); return onionHostname.trim(); } catch (FileNotFoundException e) { - Log.i(TAG, "unable to read onion hostname file",e); + Log.d(TAG, "unable to read onion hostname file",e); return null; } } @@ -820,6 +820,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG); mHandler.sendMessage(msg); + logBuffer = new StringBuffer(); } private void stopTor () throws RemoteException @@ -862,7 +863,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants } catch (Exception e) { - Log.i(TAG,"error onclick",e); + Log.d(TAG,"error onclick",e); } return super.onTouchEvent(event); @@ -900,7 +901,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants } catch (Exception e) { - Log.i(TAG,"error onclick",e); + Log.d(TAG,"error onclick",e); } // } @@ -954,7 +955,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants logBuffer.append('\n'); - if (torServiceMsg.length() > 0 && torServiceMsg.charAt(0)!='>') + if (torServiceMsg.length() > 0) updateStatus(torServiceMsg); break; @@ -965,6 +966,10 @@ public class Orbot extends Activity implements OnClickListener, TorConstants logBuffer.append(torLogMsg); logBuffer.append('\n'); + if (txtMessageLog != null) + { + txtMessageLog.append(torLogMsg + '\n'); + } break; case ENABLE_TOR_MSG: @@ -1017,7 +1022,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants // do anything with it; we can count on soon being // disconnected (and then reconnected if it can be restarted) // so there is no need to do anything here. - Log.i(TAG,"error registering callback to service",e); + Log.d(TAG,"error registering callback to service",e); } diff --git a/src/org/torproject/android/SettingsPreferences.java b/src/org/torproject/android/SettingsPreferences.java index aa92c30b..e6173fa6 100644 --- a/src/org/torproject/android/SettingsPreferences.java +++ b/src/org/torproject/android/SettingsPreferences.java @@ -78,7 +78,7 @@ public class SettingsPreferences protected void onStop() { super.onStop(); - //Log.i(getClass().getName(),"Exiting Preferences"); + //Log.d(getClass().getName(),"Exiting Preferences"); } @Override diff --git a/src/org/torproject/android/Utils.java b/src/org/torproject/android/Utils.java index cd48ebf0..1a0082fd 100644 --- a/src/org/torproject/android/Utils.java +++ b/src/org/torproject/android/Utils.java @@ -84,7 +84,7 @@ public class Utils { return true; } catch (IOException e) { - // Log.i(TAG, "error writing file: " + path, e); + // Log.d(TAG, "error writing file: " + path, e); e.printStackTrace(); return false; } diff --git a/src/org/torproject/android/net/ModSSLSocketFactory.java b/src/org/torproject/android/net/ModSSLSocketFactory.java index 924d3b0b..7edea6c2 100644 --- a/src/org/torproject/android/net/ModSSLSocketFactory.java +++ b/src/org/torproject/android/net/ModSSLSocketFactory.java @@ -60,8 +60,6 @@ import org.apache.http.conn.ssl.X509HostnameVerifier; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; -import android.util.Log; - /** @@ -255,8 +253,6 @@ public class ModSSLSocketFactory implements LayeredSocketFactory { this.socketfactory = SSLSocketFactory.getSocketFactory(); //this.nameResolver = null; - //Log.i("TOR_SERVICE","ModSSLSocketFactory: proxied via " + host + ":" + port); - this.mSocksSocketFactory = new SocksSocketFactory("127.0.0.1",9050); } @@ -325,16 +321,11 @@ public class ModSSLSocketFactory implements LayeredSocketFactory { }*/ - Log.i("TOR_SERVICE","connecting socks factory"); Socket sSocket = mSocksSocketFactory.connectSocket(underlying, host, port, localAddress, localPort, params); - Log.i("TOR_SERVICE","creating SSL Socket"); // SSLSocket sslsock = (SSLSocket) socketfactory.connectSocket(sSocket, host, port, localAddress, localPort, params); SSLSocket sslsock = (SSLSocket)socketfactory.createSocket(sSocket, host, port, true); - - Log.i("TOR_SERVICE","created SSL Socket!"); - if ((localAddress != null) || (localPort > 0)) { // we need to bind explicitly @@ -343,8 +334,6 @@ public class ModSSLSocketFactory implements LayeredSocketFactory { InetSocketAddress isa = new InetSocketAddress(localAddress, localPort); - - Log.i("TOR_SERVICE","binding SSL Socket!"); sslsock.bind(isa); } diff --git a/src/org/torproject/android/net/SocksClient.java b/src/org/torproject/android/net/SocksClient.java index 4113a292..bf8fd49d 100644 --- a/src/org/torproject/android/net/SocksClient.java +++ b/src/org/torproject/android/net/SocksClient.java @@ -47,9 +47,9 @@ private static final int BUF_SIZE = 1024; ss = new SocksSocket(host, port); out = ss.getOutputStream(); in = ss.getInputStream(); - Log.i(getClass().getName(),"Connected..."); - Log.i(getClass().getName(),"TO: "+host+":"+port); - Log.i(getClass().getName(),"ViaProxy: "+ss.getLocalAddress().getHostAddress() + Log.d(getClass().getName(),"Connected..."); + Log.d(getClass().getName(),"TO: "+host+":"+port); + Log.d(getClass().getName(),"ViaProxy: "+ss.getLocalAddress().getHostAddress() +":"+ss.getLocalPort()); } diff --git a/src/org/torproject/android/net/SocksSocketFactory.java b/src/org/torproject/android/net/SocksSocketFactory.java index 96674075..fa2ca4f7 100644 --- a/src/org/torproject/android/net/SocksSocketFactory.java +++ b/src/org/torproject/android/net/SocksSocketFactory.java @@ -65,7 +65,7 @@ public class SocksSocketFactory implements SocketFactory { sProxy = new Socks5Proxy(proxyaddress, proxyport); } catch (UnknownHostException e) { // TODO Auto-generated catch block - Log.i("TOR_SERVICE","SocksSF couldn't connect",e); + Log.d("TOR_SERVICE","SocksSF couldn't connect",e); } sProxy.resolveAddrLocally(false); @@ -77,7 +77,7 @@ public class SocksSocketFactory implements SocketFactory { InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { - Log.i("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port); + Log.d("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port); if (host == null) { throw new IllegalArgumentException("Target host may not be null."); diff --git a/src/org/torproject/android/service/TorBinaryInstaller.java b/src/org/torproject/android/service/TorBinaryInstaller.java index e48c4fd4..c88e3781 100644 --- a/src/org/torproject/android/service/TorBinaryInstaller.java +++ b/src/org/torproject/android/service/TorBinaryInstaller.java @@ -33,10 +33,10 @@ public class TorBinaryInstaller implements TorServiceConstants { { boolean torBinaryExists = new File(installPath + TOR_BINARY_ASSET_KEY).exists(); - Log.i(TAG,"Tor binary exists=" + torBinaryExists); + Log.d(TAG,"Tor binary exists=" + torBinaryExists); boolean privoxyBinaryExists = new File(installPath + PRIVOXY_ASSET_KEY).exists(); - Log.i(TAG,"Privoxy binary exists=" + privoxyBinaryExists); + Log.d(TAG,"Privoxy binary exists=" + privoxyBinaryExists); if (!(torBinaryExists && privoxyBinaryExists) || force) installFromZip (); @@ -72,12 +72,12 @@ public class TorBinaryInstaller implements TorServiceConstants { zip.close(); - Log.i(TAG,"SUCCESS: unzipped tor, privoxy, iptables binaries from apk"); + Log.d(TAG,"SUCCESS: unzipped tor, privoxy, iptables binaries from apk"); } catch (IOException ioe) { - Log.i(TAG,"FAIL: unable to unzip binaries from apk",ioe); + Log.d(TAG,"FAIL: unable to unzip binaries from apk",ioe); } } @@ -108,7 +108,7 @@ public class TorBinaryInstaller implements TorServiceConstants { { - Log.i(TAG,"Error opening output file " + targetFilename,e); + Log.d(TAG,"Error opening output file " + targetFilename,e); return; } @@ -135,7 +135,7 @@ public class TorBinaryInstaller implements TorServiceConstants { { - Log.i(TAG,"Error writing output file '" + targetFilename + "': " + e.toString()); + Log.d(TAG,"Error writing output file '" + targetFilename + "': " + e.toString()); return; diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 43277bca..ca7faf85 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -51,6 +51,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable private ArrayList configBuffer = null; + private boolean isBound = false; private String appHome = null; private String torBinaryPath = null; @@ -60,7 +61,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable public void onCreate() { super.onCreate(); - Log.i(TAG,"TorService: onCreate"); + Log.d(TAG,"TorService: onCreate"); } @@ -72,9 +73,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable if (procId != -1) { - Log.i(TAG,"Found existing Tor process"); + Log.d(TAG,"Found existing Tor process"); - sendCallbackMessage ("found existing Tor process..."); + sendCallbackLogMessage ("found existing Tor process..."); try { currentStatus = STATUS_CONNECTING; @@ -87,12 +88,12 @@ public class TorService extends Service implements TorServiceConstants, Runnable return true; } catch (RuntimeException e) { - Log.i(TAG,"Unable to connect to existing Tor instance,",e); + Log.d(TAG,"Unable to connect to existing Tor instance,",e); currentStatus = STATUS_OFF; this.stopTor(); } catch (Exception e) { - Log.i(TAG,"Unable to connect to existing Tor instance,",e); + Log.d(TAG,"Unable to connect to existing Tor instance,",e); currentStatus = STATUS_OFF; this.stopTor(); @@ -110,7 +111,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable public void onLowMemory() { super.onLowMemory(); - Log.i(TAG, "Low Memory Called"); + Log.d(TAG, "Low Memory Called"); } @@ -120,8 +121,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable */ public boolean onUnbind(Intent intent) { - Log.i(TAG, "onUnbind Called: " + intent.getAction()); + Log.d(TAG, "onUnbind Called: " + intent.getAction()); + isBound = false; return super.onUnbind(intent); @@ -138,6 +140,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable private void showToolbarNotification (String notifyMsg, int icon) { + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); @@ -168,7 +171,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable public void onRebind(Intent intent) { super.onRebind(intent); - Log.i(TAG,"on rebind"); + isBound = true; + } @@ -196,7 +200,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable { currentStatus = STATUS_OFF; this.showToolbarNotification(getString(R.string.status_disabled), R.drawable.tornotification); - Log.i(TAG,"Unable to start Tor: " + e.getMessage(),e); + Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e); } } } @@ -210,7 +214,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable mCallbacks.kill(); - Log.i(TAG,"onDestroy called"); + Log.d(TAG,"onDestroy called"); stopTor(); } @@ -220,7 +224,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable currentStatus = STATUS_OFF; - sendCallbackMessage("Web proxy shutdown"); + sendCallbackLogMessage("Web proxy shutdown"); try { @@ -230,15 +234,15 @@ public class TorService extends Service implements TorServiceConstants, Runnable showToolbarNotification (getString(R.string.status_disabled),R.drawable.tornotificationoff); - sendCallbackMessage(getString(R.string.status_disabled)); + sendCallbackStatusMessage(getString(R.string.status_disabled)); setupTransProxy(false); } catch (Exception e) { - Log.i(TAG, "An error occured stopping Tor",e); + Log.d(TAG, "An error occured stopping Tor",e); logNotice("An error occured stopping Tor: " + e.getMessage()); - sendCallbackMessage("Something bad happened. Check the log"); + sendCallbackStatusMessage("Something bad happened. Check the log"); } } @@ -262,7 +266,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable } catch (Exception e) { - Log.i(TAG,"Unable to reload configuration",e); + Log.d(TAG,"Unable to reload configuration",e); } } @@ -276,7 +280,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable // conn.shutdownTor(arg0) conn.signal("SHUTDOWN"); } catch (Exception e) { - Log.i(TAG,"error shutting down Tor via connection",e); + Log.d(TAG,"error shutting down Tor via connection",e); } conn = null; } @@ -301,7 +305,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable while (procId != -1) { - Log.i(TAG,"Found Privoxy PID=" + procId + " - killing now..."); + Log.d(TAG,"Found Privoxy PID=" + procId + " - killing now..."); String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" }; TorServiceUtils.doShellCommand(cmd,log, false, false); @@ -314,9 +318,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable private void logNotice (String msg) { - Log.i(TAG, msg); + Log.d(TAG, msg); - sendCallbackMessage('>' + msg); + sendCallbackLogMessage(msg); } @@ -330,7 +334,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable int MAX_TRIES = 10; String buildPath = apkBase + TOR_APP_USERNAME + APK_EXT; - Log.i(TAG, "Checking APK location: " + buildPath); + Log.d(TAG, "Checking APK location: " + buildPath); File fileApk = new File(buildPath); @@ -342,7 +346,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable buildPath = apkBase + TOR_APP_USERNAME + '-' + i + APK_EXT; fileApk = new File(buildPath); - Log.i(TAG, "Checking APK location: " + buildPath); + Log.d(TAG, "Checking APK location: " + buildPath); if (fileApk.exists()) return fileApk.getAbsolutePath(); @@ -354,7 +358,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable buildPath = apkBaseExt + pkgFile; fileApk = new File(buildPath); - Log.i(TAG, "Checking external storage APK location: " + buildPath); + Log.d(TAG, "Checking external storage APK location: " + buildPath); if (fileApk.exists()) return fileApk.getAbsolutePath(); @@ -364,7 +368,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable buildPath = apkBaseExt + '-' + i + pkgFile; fileApk = new File(buildPath); - Log.i(TAG, "Checking external storage APK location: " + buildPath); + Log.d(TAG, "Checking external storage APK location: " + buildPath); if (fileApk.exists()) return fileApk.getAbsolutePath(); @@ -376,19 +380,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable private boolean checkTorBinaries () throws Exception { - //android.os.Debug.waitForDebugger(); - Log.i(TAG,"checking Tor binaries"); + Log.d(TAG,"checking Tor binaries"); //appHome = getApplicationContext().getFilesDir().getAbsolutePath(); appHome = "/data/data/" + TOR_APP_USERNAME + "/"; - Log.i(TAG,"appHome=" + appHome); + Log.d(TAG,"appHome=" + appHome); String apkPath = findAPK(); - Log.i(TAG,"found apk at: " + apkPath); + Log.d(TAG,"found apk at: " + apkPath); boolean apkExists = new File(apkPath).exists(); @@ -427,7 +430,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable logNotice(getString(R.string.status_install_fail)); - sendCallbackMessage(getString(R.string.status_install_fail)); + sendCallbackStatusMessage(getString(R.string.status_install_fail)); return false; } @@ -458,16 +461,13 @@ public class TorService extends Service implements TorServiceConstants, Runnable public void initTor () throws Exception { - // android.os.Debug.waitForDebugger(); - - currentStatus = STATUS_CONNECTING; logNotice(getString(R.string.status_starting_up)); - sendCallbackMessage(getString(R.string.status_starting_up)); + sendCallbackStatusMessage(getString(R.string.status_starting_up)); killTorProcess (); @@ -484,8 +484,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable } catch (Exception e) { currentStatus = STATUS_OFF; - Log.i(TAG,"Unable to start Privoxy: " + e.getMessage(),e); - sendCallbackMessage("Unable to start Privoxy: " + e.getMessage()); + Log.d(TAG,"Unable to start Privoxy: " + e.getMessage(),e); + sendCallbackLogMessage("Unable to start Privoxy: " + e.getMessage()); } } @@ -501,8 +501,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable setupTransProxy(true); } catch (Exception e) { - Log.i(TAG,"Unable to start Tor: " + e.getMessage(),e); - sendCallbackMessage("Unable to start Tor: " + e.getMessage()); + Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e); + sendCallbackStatusMessage("Unable to start Tor: " + e.getMessage()); stopTor(); } } @@ -513,15 +513,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable private void runTorShellCmd() throws Exception { + + StringBuilder log = new StringBuilder(); - Log.i(TAG,"Starting tor process"); String torrcPath = appHome + TORRC_ASSET_KEY; String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"}; TorServiceUtils.doShellCommand(torCmd, log, false, false); + Log.d(TAG,"Starting tor process: " + torCmd[0]); + Thread.sleep(1000); int procId = TorServiceUtils.findProcessId(torBinaryPath); @@ -538,9 +541,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable if (procId == -1) { - sendCallbackMessage("Couldn't start Tor process...\n" + log.toString()); + sendCallbackStatusMessage("Couldn't start Tor process...\n" + log.toString()); Thread.sleep(1000); - sendCallbackMessage(getString(R.string.status_starting_up)); + sendCallbackStatusMessage(getString(R.string.status_starting_up)); Thread.sleep(3000); attempts++; } @@ -566,7 +569,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable private void runPrivoxyShellCmd () throws Exception { - Log.i(TAG,"Starting privoxy process"); + Log.d(TAG,"Starting privoxy process"); int privoxyProcId = TorServiceUtils.findProcessId(privoxyPath); @@ -602,7 +605,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable logNotice(log.toString()); } - sendCallbackMessage("Privoxy is running on port: " + PORT_HTTP); + sendCallbackLogMessage("Privoxy is running on port: " + PORT_HTTP); Thread.sleep(100); logNotice("Privoxy process id=" + privoxyProcId); @@ -628,18 +631,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable { try { - Log.i(TAG,"Connecting to control port: " + TOR_CONTROL_PORT); + Log.d(TAG,"Connecting to control port: " + TOR_CONTROL_PORT); String baseMessage = getString(R.string.tor_process_connecting); - sendCallbackMessage(baseMessage); + sendCallbackStatusMessage(baseMessage); Socket s = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT); conn = TorControlConnection.getConnection(s); // conn.authenticate(new byte[0]); // See section 3.2 - sendCallbackMessage(getString(R.string.tor_process_connecting_step2)); + sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2)); - Log.i(TAG,"SUCCESS connected to control port"); + Log.d(TAG,"SUCCESS connected to control port"); String torAuthCookie = appHome + "data/control_auth_cookie"; @@ -648,9 +651,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable new FileInputStream(new File(torAuthCookie)).read(cookie); conn.authenticate(cookie); - Log.i(TAG,"SUCCESS authenticated to control port"); + Log.d(TAG,"SUCCESS authenticated to control port"); - sendCallbackMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3)); + sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3)); addEventHandler(); @@ -662,9 +665,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable catch (Exception ce) { conn = null; - Log.i(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce); + Log.d(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce); - sendCallbackMessage(getString(R.string.tor_process_connecting_step4)); + sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step4)); Thread.sleep(1000); @@ -695,20 +698,20 @@ public class TorService extends Service implements TorServiceConstants, Runnable // "status/bootstrap-phase", "status","version"})); String bsPhase = conn.getInfo("status/bootstrap-phase"); - Log.i(TAG, "bootstrap-phase: " + bsPhase); + Log.d(TAG, "bootstrap-phase: " + bsPhase); } else { // String status = conn.getInfo("status/circuit-established"); - // Log.i(TAG, "status/circuit-established=" + status); + // Log.d(TAG, "status/circuit-established=" + status); } } } catch (Exception e) { - Log.i(TAG, "Unable to get Tor status from control port"); + Log.d(TAG, "Unable to get Tor status from control port"); currentStatus = STATUS_UNAVAILABLE; } @@ -720,7 +723,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable // We extend NullEventHandler so that we don't need to provide empty // implementations for all the events we don't care about. // ... - Log.i(TAG,"adding control port event handler"); + Log.d(TAG,"adding control port event handler"); conn.setEventHandler(this); @@ -729,7 +732,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable // conn.setEvents(Arrays.asList(new String[]{ // "DEBUG", "INFO", "NOTICE", "WARN", "ERR"})); - Log.i(TAG,"SUCCESS added control port event handler"); + Log.d(TAG,"SUCCESS added control port event handler"); @@ -762,7 +765,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable if (profile == PROFILE_ON) { currentStatus = STATUS_CONNECTING; - sendCallbackMessage ("starting..."); + sendCallbackStatusMessage ("starting..."); new Thread(_torInstance).start(); @@ -770,7 +773,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable else { currentStatus = STATUS_OFF; - sendCallbackMessage ("shutting down..."); + sendCallbackStatusMessage ("shutting down..."); _torInstance.stopTor(); @@ -781,7 +784,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable public void message(String severity, String msg) { - Log.i(TAG, "[Tor Control Port] " + severity + ": " + msg); + Log.d(TAG, "[Tor Control Port] " + severity + ": " + msg); if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1) { @@ -790,8 +793,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable } - sendCallbackMessage (msg); - + sendCallbackStatusMessage (msg); + } private void showAlert(String title, String msg) @@ -849,7 +852,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable } public void bandwidthUsed(long read, long written) { - sendCallbackMessage ("bandwidth used: read=" + read + " written=" + written); StringBuilder sb = new StringBuilder(); sb.append("Bandwidth used: "); @@ -864,6 +866,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable public void circuitStatus(String status, String circID, String path) { + /* StringBuilder sb = new StringBuilder(); sb.append("Circuit ("); sb.append((circID)); @@ -873,7 +876,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable sb.append(path); logNotice(sb.toString()); - + */ } @@ -894,7 +897,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable } catch (Exception e) { - Log.i(TAG,"Unable to check for Tor binaries",e); + Log.d(TAG,"Unable to check for Tor binaries",e); return null; } } @@ -948,7 +951,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable } catch (Exception e) { - Log.i(TAG, "error enabling transproxy",e); + Log.d(TAG, "error enabling transproxy",e); return false; } @@ -1045,8 +1048,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable private ArrayList callbackBuffer = new ArrayList(); - private void sendCallbackMessage (String newStatus) + private void sendCallbackStatusMessage (String newStatus) { + sendCallbackLogMessage (newStatus); //we want everything to go to the log! // Broadcast to all clients the new value. final int N = mCallbacks.beginBroadcast(); @@ -1082,6 +1086,43 @@ public class TorService extends Service implements TorServiceConstants, Runnable mCallbacks.finishBroadcast(); } + private void sendCallbackLogMessage (String logMessage) + { + + // Broadcast to all clients the new value. + final int N = mCallbacks.beginBroadcast(); + + + callbackBuffer.add(logMessage); + + if (N > 0) + { + + Iterator it = callbackBuffer.iterator(); + String status = null; + + while (it.hasNext()) + { + status = it.next(); + + for (int i=0; i