[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] fulfilles the wishes of #12413 by support --default-torrc and -f



commit 2eb79a51856b05fc2636d81ed15bd75755646972
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Tue Jun 17 16:32:49 2014 -0400

    fulfilles the wishes of #12413 by support --default-torrc and -f
---
 .../android/service/TorResourceInstaller.java      |   29 +-------
 src/org/torproject/android/service/TorService.java |   73 ++++++++++++++++----
 2 files changed, 63 insertions(+), 39 deletions(-)

diff --git a/src/org/torproject/android/service/TorResourceInstaller.java b/src/org/torproject/android/service/TorResourceInstaller.java
index 9478384..3e91ea4 100644
--- a/src/org/torproject/android/service/TorResourceInstaller.java
+++ b/src/org/torproject/android/service/TorResourceInstaller.java
@@ -116,35 +116,12 @@ public class TorResourceInstaller implements TorServiceConstants {
 		return true;
 	}
 	
-	public boolean updateTorConfig (File fileTorRc, String extraLines) throws IOException, FileNotFoundException, TimeoutException
+	public boolean updateTorConfigCustom (File fileTorRcCustom, String extraLines) throws IOException, FileNotFoundException, TimeoutException
 	{
 		
-		InputStream is;
-        
-        Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getAbsolutePath());
-        
-		is = context.getResources().openRawResource(R.raw.torrc);		
-		shell.add(new SimpleCommand(COMMAND_RM_FORCE + fileTorRc.getAbsolutePath())).waitForFinish();
-		streamToFile(is,fileTorRc, false, false);
 
-		if (extraLines != null && extraLines.length() > 0)
-		{
-			StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
-			streamToFile(sbis,fileTorRc,true,false);
-		}
-		
-		is = context.getResources().openRawResource(R.raw.torrcdiag);
-		fileTorRc = new File(installFolder, TORRCDIAG_ASSET_KEY);
-		shell.add(new SimpleCommand(COMMAND_RM_FORCE + fileTorRc.getAbsolutePath())).waitForFinish();
-		streamToFile(is,fileTorRc, false, false);
-
-		if (extraLines != null && extraLines.length() > 0)
-		{
-			StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
-			streamToFile(sbis,fileTorRc,true,false);
-		}
-		
-		shell.close();
+		StringBufferInputStream sbis = new StringBufferInputStream(extraLines + '\n');
+		streamToFile(sbis,fileTorRcCustom,false,false);
 		
 		return true;
 	}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 5acb900..cca714c 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -23,8 +23,6 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
-import java.util.Timer;
-import java.util.TimerTask;
 import java.util.concurrent.TimeoutException;
 
 import net.freehaven.tor.control.ConfigEntry;
@@ -54,6 +52,7 @@ import android.graphics.Color;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.os.AsyncTask;
+import android.os.Handler;
 import android.os.IBinder;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
@@ -194,7 +193,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 
 	public int getTorStatus ()
     {
-    	
+		
     	return currentStatus;
     	
     }
@@ -236,10 +235,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		if (notifyId == ERROR_NOTIFY_ID)
 		{
 			mNotifyBuilder.setTicker(notifyMsg);
-			mNotifyBuilder.setOngoing(false);
 			mNotifyBuilder.setLights(Color.RED, 1000, 1000);
 			mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr);
 		}
+		else
+		{
+			mNotifyBuilder.setTicker("");
+			//mNotifyBuilder.setLights(Color.GREEN, 5000, 5000);
+		}
 		
 		if (isOngoing)
 		{
@@ -559,9 +562,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
     	extraLines.append('\n');
     	extraLines.append(prefs.getString("pref_custom_torrc", ""));
 
-		logNotice("updating torrc configuration...");
+		logNotice("updating torrc custom configuration...");
 
-    	boolean success = installer.updateTorConfig(fileTorRc, extraLines.toString());    
+		File fileTorRcCustom = new File(fileTorRc.getAbsolutePath() + ".custom");
+    	boolean success = installer.updateTorConfigCustom(fileTorRcCustom, extraLines.toString());    
     	
     	if (success)
     	{
@@ -765,7 +769,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		Shell shell = Shell.startShell();
 		
 		
-		SimpleCommand cmdTor = new SimpleCommand(fileTor.getCanonicalPath() + " DataDirectory " + appCacheHome.getCanonicalPath() + " -f " + torrcPath + " &");
+		SimpleCommand cmdTor = new SimpleCommand(fileTor.getCanonicalPath() 
+				+ " DataDirectory " + appCacheHome.getCanonicalPath() 
+				+ " --defaults-torrc " + torrcPath
+				+ " -f " + torrcPath + ".custom"
+				+ " &");
 		
 		shell.add(cmdTor);
 		
@@ -1110,7 +1118,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 			return PROFILE_ON;
 		}
 		
-		
 		public void setTorProfile(int profile)  {
 		
 			if (currentStatus == STATUS_OFF)
@@ -1123,6 +1130,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	   			   initTor();
 
 	        		currentStatus = STATUS_CONNECTING;
+	        		
 	   		     }
 	   		     catch (Exception e)
 	   		     {				
@@ -1159,6 +1167,48 @@ public class TorService extends Service implements TorServiceConstants, TorConst
       	
           
 	}
+	
+
+	
+	private Handler mHandlerStatusChecker = null;
+	
+	private void enableStatusChecker ()
+	{
+
+		if (mHandlerStatusChecker != null)
+			mHandlerStatusChecker = new Handler();
+		
+		mHandlerStatusChecker.postDelayed(new Runnable ()
+		{
+			public void run ()
+			{
+				if (conn != null)
+				{
+					try
+					{
+						String state = conn.getInfo("dormant");
+						if (state != null && Integer.parseInt(state) == 0)
+						{
+							currentStatus = STATUS_ON;
+							
+						}
+						else
+						{
+							currentStatus = STATUS_CONNECTING;
+							showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off,prefPersistNotifications);
+
+						}
+					}
+					catch (Exception e){}
+					
+
+    				mHandlerStatusChecker.postDelayed(this,1000);
+				}
+
+				
+			}
+		},1000);
+	}
 
 	public void newDescriptors(List<String> orList) {
 		
@@ -1233,9 +1283,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 			
 			sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead); 
 
-	//		if(++notificationCounter%10==0)
-		//	    startService(new Intent(ITorService.class.getName()));
-
 		}
 		
 		lastWritten = written;
@@ -1762,8 +1809,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 							logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_));
 							showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,prefPersistNotifications);
 
-							if (mHasRoot && mEnableTransparentProxy)
-								enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
+							//if (mHasRoot && mEnableTransparentProxy)
+								//enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
 							
 				        }
 					}

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits