[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r23157: {projects} added LOG_OUTPUT_TO_DEBUG variable for compile time on/off o (projects/android/trunk/Orbot/src/org/torproject/android/service)
Author: n8fr8
Date: 2010-09-09 22:09:01 +0000 (Thu, 09 Sep 2010)
New Revision: 23157
Modified:
projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java
Log:
added LOG_OUTPUT_TO_DEBUG variable for compile time on/off of log output to Android stdout
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2010-09-09 21:47:06 UTC (rev 23156)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2010-09-09 22:09:01 UTC (rev 23157)
@@ -61,8 +61,7 @@
public void onCreate() {
super.onCreate();
- Log.d(TAG,"TorService: onCreate");
-
+
}
@@ -73,7 +72,7 @@
if (procId != -1)
{
- Log.d(TAG,"Found existing Tor process");
+ logNotice("Found existing Tor process");
sendCallbackLogMessage ("found existing Tor process...");
@@ -111,7 +110,7 @@
public void onLowMemory() {
super.onLowMemory();
- Log.d(TAG, "Low Memory Called");
+ logNotice( "Low Memory Warning!");
}
@@ -121,7 +120,7 @@
*/
public boolean onUnbind(Intent intent) {
- Log.d(TAG, "onUnbind Called: " + intent.getAction());
+ // logNotice( "onUnbind Called: " + intent.getAction());
isBound = false;
@@ -213,9 +212,6 @@
// Unregister all callbacks.
mCallbacks.kill();
-
- Log.d(TAG,"onDestroy called");
-
stopTor();
}
@@ -277,7 +273,6 @@
{
try {
logNotice("sending SHUTDOWN signal to Tor process");
- // conn.shutdownTor(arg0)
conn.signal("SHUTDOWN");
} catch (Exception e) {
Log.d(TAG,"error shutting down Tor via connection",e);
@@ -305,7 +300,7 @@
while (procId != -1)
{
- Log.d(TAG,"Found Privoxy PID=" + procId + " - killing now...");
+ logNotice("Found Privoxy PID=" + procId + " - killing now...");
String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
TorServiceUtils.doShellCommand(cmd,log, false, false);
@@ -317,10 +312,13 @@
private void logNotice (String msg)
{
-
- Log.d(TAG, msg);
- sendCallbackLogMessage(msg);
-
+ if (msg != null && msg.trim().length() > 0)
+ {
+ if (LOG_OUTPUT_TO_DEBUG)
+ Log.d(TAG, msg);
+
+ sendCallbackLogMessage(msg);
+ }
}
private String findAPK ()
@@ -333,7 +331,7 @@
int MAX_TRIES = 10;
String buildPath = apkBase + TOR_APP_USERNAME + APK_EXT;
- Log.d(TAG, "Checking APK location: " + buildPath);
+ logNotice("Checking APK location: " + buildPath);
File fileApk = new File(buildPath);
@@ -345,7 +343,7 @@
buildPath = apkBase + TOR_APP_USERNAME + '-' + i + APK_EXT;
fileApk = new File(buildPath);
- Log.d(TAG, "Checking APK location: " + buildPath);
+ logNotice( "Checking APK location: " + buildPath);
if (fileApk.exists())
return fileApk.getAbsolutePath();
@@ -357,7 +355,7 @@
buildPath = apkBaseExt + pkgFile;
fileApk = new File(buildPath);
- Log.d(TAG, "Checking external storage APK location: " + buildPath);
+ logNotice( "Checking external storage APK location: " + buildPath);
if (fileApk.exists())
return fileApk.getAbsolutePath();
@@ -367,7 +365,7 @@
buildPath = apkBaseExt + '-' + i + pkgFile;
fileApk = new File(buildPath);
- Log.d(TAG, "Checking external storage APK location: " + buildPath);
+ logNotice( "Checking external storage APK location: " + buildPath);
if (fileApk.exists())
return fileApk.getAbsolutePath();
@@ -381,16 +379,16 @@
{
- Log.d(TAG,"checking Tor binaries");
+ logNotice( "checking Tor binaries");
//appHome = getApplicationContext().getFilesDir().getAbsolutePath();
appHome = "/data/data/" + TOR_APP_USERNAME + "/";
- Log.d(TAG,"appHome=" + appHome);
+ logNotice( "appHome=" + appHome);
String apkPath = findAPK();
- Log.d(TAG,"found apk at: " + apkPath);
+ logNotice( "found apk at: " + apkPath);
boolean apkExists = new File(apkPath).exists();
@@ -522,7 +520,7 @@
String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"};
TorServiceUtils.doShellCommand(torCmd, log, false, false);
- Log.d(TAG,"Starting tor process: " + torCmd[0]);
+ logNotice( "Starting tor process: " + torCmd[0]);
Thread.sleep(1000);
int procId = TorServiceUtils.findProcessId(torBinaryPath);
@@ -568,7 +566,7 @@
private void runPrivoxyShellCmd () throws Exception
{
- Log.d(TAG,"Starting privoxy process");
+ logNotice( "Starting privoxy process");
int privoxyProcId = TorServiceUtils.findProcessId(privoxyPath);
@@ -630,7 +628,7 @@
{
try
{
- Log.d(TAG,"Connecting to control port: " + TOR_CONTROL_PORT);
+ logNotice( "Connecting to control port: " + TOR_CONTROL_PORT);
String baseMessage = getString(R.string.tor_process_connecting);
sendCallbackStatusMessage(baseMessage);
@@ -641,7 +639,7 @@
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2));
- Log.d(TAG,"SUCCESS connected to control port");
+ logNotice( "SUCCESS connected to control port");
String torAuthCookie = appHome + "data/control_auth_cookie";
@@ -650,7 +648,7 @@
new FileInputStream(new File(torAuthCookie)).read(cookie);
conn.authenticate(cookie);
- Log.d(TAG,"SUCCESS authenticated to control port");
+ logNotice( "SUCCESS authenticated to control port");
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3));
@@ -722,7 +720,7 @@
// We extend NullEventHandler so that we don't need to provide empty
// implementations for all the events we don't care about.
// ...
- Log.d(TAG,"adding control port event handler");
+ logNotice( "adding control port event handler");
conn.setEventHandler(this);
@@ -731,7 +729,7 @@
// conn.setEvents(Arrays.asList(new String[]{
// "DEBUG", "INFO", "NOTICE", "WARN", "ERR"}));
- Log.d(TAG,"SUCCESS added control port event handler");
+ logNotice( "SUCCESS added control port event handler");
@@ -783,7 +781,7 @@
public void message(String severity, String msg) {
- Log.d(TAG, "[Tor Control Port] " + severity + ": " + msg);
+ logNotice( "[Tor Control Port] " + severity + ": " + msg);
if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
{
@@ -813,41 +811,47 @@
public void orConnStatus(String status, String orName) {
- StringBuilder sb = new StringBuilder();
- sb.append("orConnStatus (");
- sb.append((orName) );
- sb.append("): ");
- sb.append(status);
-
- logNotice(sb.toString());
+ if (LOG_OUTPUT_TO_DEBUG)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("orConnStatus (");
+ sb.append((orName) );
+ sb.append("): ");
+ sb.append(status);
+
+ logNotice(sb.toString());
+ }
}
public void streamStatus(String status, String streamID, String target) {
- StringBuilder sb = new StringBuilder();
- sb.append("StreamStatus (");
- sb.append((streamID));
- sb.append("): ");
- sb.append(status);
-
- logNotice(sb.toString());
-
-
+ if (LOG_OUTPUT_TO_DEBUG)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("StreamStatus (");
+ sb.append((streamID));
+ sb.append("): ");
+ sb.append(status);
+
+ logNotice(sb.toString());
+ }
}
public void unrecognized(String type, String msg) {
- StringBuilder sb = new StringBuilder();
- sb.append("Message (");
- sb.append(type);
- sb.append("): ");
- sb.append(msg);
+ if (LOG_OUTPUT_TO_DEBUG)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Message (");
+ sb.append(type);
+ sb.append("): ");
+ sb.append(msg);
+
+ logNotice(sb.toString());
+ }
- logNotice(sb.toString());
-
-
}
public void bandwidthUsed(long read, long written) {
@@ -865,18 +869,19 @@
public void circuitStatus(String status, String circID, String path) {
- /*
- StringBuilder sb = new StringBuilder();
- sb.append("Circuit (");
- sb.append((circID));
- sb.append("): ");
- sb.append(status);
- sb.append("; ");
- sb.append(path);
+ if (LOG_OUTPUT_TO_DEBUG)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Circuit (");
+ sb.append((circID));
+ sb.append("): ");
+ sb.append(status);
+ sb.append("; ");
+ sb.append(path);
+
+ logNotice(sb.toString());
+ }
- logNotice(sb.toString());
- */
-
}
public IBinder onBind(Intent intent) {
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java 2010-09-09 21:47:06 UTC (rev 23156)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java 2010-09-09 22:09:01 UTC (rev 23157)
@@ -6,6 +6,8 @@
public final static String TAG = "ORBOT";
+ public static boolean LOG_OUTPUT_TO_DEBUG = false;
+
public final static String TOR_APP_USERNAME = "org.torproject.android";
public final static String ASSETS_BASE = "assets/";
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java 2010-09-09 21:47:06 UTC (rev 23156)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java 2010-09-09 22:09:01 UTC (rev 23157)
@@ -12,6 +12,11 @@
public class TorServiceUtils implements TorServiceConstants {
+ private static void logNotice (String msg)
+ {
+ if (LOG_OUTPUT_TO_DEBUG)
+ Log.d(TAG, msg);
+ }
public static int findProcessId(String command)
{
@@ -112,7 +117,7 @@
public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor) throws Exception
{
- Log.d(TAG,"executing shell cmds: " + cmds[0] + "; runAsRoot=" + runAsRoot);
+ logNotice("executing shell cmds: " + cmds[0] + "; runAsRoot=" + runAsRoot);
Process proc = null;
@@ -163,7 +168,7 @@
log.append(exitCode);
log.append("\n");
- Log.d(TAG,"command process exit value: " + exitCode);
+ logNotice("command process exit value: " + exitCode);
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2010-09-09 21:47:06 UTC (rev 23156)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2010-09-09 22:09:01 UTC (rev 23157)
@@ -5,27 +5,17 @@
import android.content.Context;
import android.util.Log;
-public class TorTransProxy {
+public class TorTransProxy implements TorServiceConstants {
private final static String TAG = TorServiceConstants.TAG;
-
-
+
//private static String BASE_DIR = "/data/data/" + TorServiceConstants.TOR_APP_USERNAME + "/";
-
- /*
- private final static String CMD_NAT_FLUSH = "iptables -t nat -F || exit\n";
- private final static String CMD_FILTER_FLUSH = "iptables -t filter -F || exit\n";
-
- private final static String CMD_DNS_PROXYING_ADD = "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5400 || exit\n";
-
- private final static String IPTABLES_ADD = " -A ";
- */
-
- //private final static String CMD_DNS_PROXYING_DELETE = "iptables -t nat -D PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5400 || exit\n";
- // - just calling a system wide flush of iptables rules
- //private final static String IPTABLES_DELETE = " -D "; //not deleting manually anymore - just calling a system wide flush of iptables rules
- // private final static String IPTABLES_DROP_ALL = " -j DROP ";
-
+
+ private static void logNotice (String msg)
+ {
+ if (LOG_OUTPUT_TO_DEBUG)
+ Log.d(TAG, msg);
+ }
/**
* Check if we have root access
* @return boolean true if we have root
@@ -48,7 +38,8 @@
} catch (Exception e) {
Log.w(TAG,"Error checking for root access: " + e.getMessage() ,e);
}
- Log.w(TAG, "Could not acquire root access: " + log.toString());
+
+ logNotice("Could not acquire root access: " + log.toString());
return false;
}
@@ -67,7 +58,7 @@
String[] cmd = {"iptables -v"};
int code = TorServiceUtils.doShellCommand(cmd, log, true, true);
String msg = log.toString();
- Log.d(TAG,cmd[0] + ";errCode=" + code + ";resp=" + msg);
+ logNotice(cmd[0] + ";errCode=" + code + ";resp=" + msg);
String out = log.toString();
@@ -85,7 +76,7 @@
Log.w(TAG,"Error checking iptables version: " + e.getMessage() ,e);
}
- Log.w(TAG, "Could not acquire check iptables: " + log.toString());
+ logNotice("Could not acquire check iptables: " + log.toString());
return null;
}
@@ -146,7 +137,7 @@
String[] cmd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String msg = res.toString();
- Log.d(TAG,cmd[0] + ";errCode=" + code + ";resp=" + msg);
+ logNotice(cmd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
@@ -163,7 +154,7 @@
String baseDir = findBaseDir();
String iptablesVersion = getIPTablesVersion();
- Log.d(TAG, "iptables version: " + iptablesVersion);
+ logNotice( "iptables version: " + iptablesVersion);
boolean ipTablesOld = false;
if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){
@@ -208,7 +199,7 @@
continue;
}
- Log.d(TAG,"enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")");
+ logNotice("enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")");
//TCP
script.append(baseDir);
@@ -285,7 +276,7 @@
String[] cmdAdd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmdAdd, res, true, true);
String msg = res.toString();
- Log.d(TAG,cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
+ logNotice(cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
}