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

[tor-commits] [orbot/master] updated impl of torified apps logic



commit 4ae52261cf2abad0e49d8b001b31b3e48ab37e70
Author: n8fr8 <nathan@xxxxxxxxxxx>
Date:   Tue Jun 19 20:45:25 2012 -0400

    updated impl of torified apps logic
---
 src/org/torproject/android/service/TorService.java |   29 +++++++-
 .../android/service/TorServiceUtils.java           |   15 +++-
 .../torproject/android/service/TorTransProxy.java  |   29 ++++----
 .../torproject/android/settings/AppManager.java    |   81 +++++++++++++++-----
 .../torproject/android/settings/TorifiedApp.java   |    7 ++
 5 files changed, 124 insertions(+), 37 deletions(-)

diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 071b680..0a4ab44 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -7,6 +7,7 @@
 
 package org.torproject.android.service;
 
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -1012,6 +1013,28 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		}
 
 
+		private void startNotification ()
+		{
+			
+			Notification notice = new Notification(R.drawable.tornotificationon, getString(R.string.status_activated), System.currentTimeMillis());
+			
+			//This constructor is deprecated. Use Notification.Builder instead
+			//Notification notice = new Notification(R.drawable.iocipher, "Active: " + mIpAddress, System.currentTimeMillis());
+
+			Intent intent = new Intent(TorService.this, Orbot.class);
+
+			PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
+
+			//This method is deprecated. Use Notification.Builder instead.
+			notice.setLatestEventInfo(TorService.this,getString(R.string.app_name), getString(R.string.status_activated), pendIntent);
+
+			notice.flags |= Notification.FLAG_NO_CLEAR;
+			notice.flags |= Notification.FLAG_ONGOING_EVENT;
+			
+			startForeground(NOTIFY_ID,notice);
+		
+		}
+		
 
 	public void message(String severity, String msg) {
 		
@@ -1021,8 +1044,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
           if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
           {
         	  currentStatus = STATUS_ON;
-        	  showToolbarNotification (getString(R.string.status_activated),NOTIFY_ID,R.drawable.tornotificationon, Notification.FLAG_ONGOING_EVENT);
+        	//  showToolbarNotification (getString(R.string.status_activated),NOTIFY_ID,R.drawable.tornotificationon, Notification.FLAG_ONGOING_EVENT);
 
+        //	  TorService.this.set
+        	  
+        	  startNotification();
+        	  
    		   	getHiddenServiceHostname ();
    		   
           }
diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java
index 08517d0..a226861 100644
--- a/src/org/torproject/android/service/TorServiceUtils.java
+++ b/src/org/torproject/android/service/TorServiceUtils.java
@@ -28,16 +28,27 @@ public class TorServiceUtils implements TorServiceConstants {
 			if (fileSU.exists())
 				return true;
 			
-			fileSU = new File("/system/bin/su");
+			fileSU = new File("/system/app/superuser.apk");
 			if (fileSU.exists())
 				return true;
 			
+			fileSU = new File("/system/bin/su");
+			if (fileSU.exists())
+			{
+				String[] cmd = {"su"};
+				int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
+				if (exitCode != 0)
+					return false;
+				else
+					return true;
+			}
+			
 			//Check for 'su' binary 
 			String[] cmd = {"which su"};
 			int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
 			
 			if (exitCode == 0) {
-				TorService.logMessage("Can acquire root permissions");
+				TorService.logMessage("root exists, but not sure about permissions");
 		    	 return true;
 		     
 		    }
diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java
index dbb955b..2571123 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -1,6 +1,7 @@
 package org.torproject.android.service;
 
 import java.io.File;
+import java.util.ArrayList;
 
 import org.torproject.android.TorConstants;
 import org.torproject.android.settings.TorifiedApp;
@@ -100,12 +101,12 @@ public class TorTransProxy implements TorServiceConstants {
 			//flush nat for every app
 			script.append(ipTablesPath);
 			script.append(" -t nat -m owner --uid-owner ");
-			script.append(apps[i].getUid());
+			script.append(tApp.getUid());
 			script.append(" -F || exit\n");
 		
 			script.append(ipTablesPath);
 			script.append(" -t filter -m owner --uid-owner ");
-			script.append(apps[i].getUid());
+			script.append(tApp.getUid());
 			script.append(" -F || exit\n");
 				
 		}
@@ -204,7 +205,7 @@ public class TorTransProxy implements TorServiceConstants {
 	
 	
 	
-	public int setTransparentProxyingByApp(Context context, TorifiedApp[] apps) throws Exception
+	public int setTransparentProxyingByApp(Context context, ArrayList<TorifiedApp> apps) throws Exception
 	{
 
 		boolean runRoot = true;
@@ -224,16 +225,16 @@ public class TorTransProxy implements TorServiceConstants {
     	int torUid = context.getApplicationInfo().uid;
 
 		//build up array of shell cmds to execute under one root context
-		for (int i = 0; i < apps.length; i++)
+		for (TorifiedApp tApp:apps)
 		{
 
-			if (apps[i].isTorified()
-					&& (!apps[i].getUsername().equals(TorServiceConstants.TOR_APP_USERNAME))
-					&& (!apps[i].getUsername().equals(TorServiceConstants.ORWEB_APP_USERNAME))
+			if (tApp.isTorified()
+					&& (!tApp.getUsername().equals(TorServiceConstants.TOR_APP_USERNAME))
+					&& (!tApp.getUsername().equals(TorServiceConstants.ORWEB_APP_USERNAME))
 					) //if app is set to true
 			{
 				
-				TorService.logMessage("enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")");
+				TorService.logMessage("enabling transproxy for app: " + tApp.getUsername() + "(" + tApp.getUid() + ")");
 			 
 				// Set up port redirection
 		    	script.append(ipTablesPath);
@@ -241,7 +242,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(" -A OUTPUT -p tcp");
 				script.append(" ! -d 127.0.0.1"); //allow access to localhost
 				script.append(" -m owner --uid-owner ");
-				script.append(apps[i].getUid());
+				script.append(tApp.getUid());
 				script.append(" -m tcp --syn");
 				script.append(" -j REDIRECT --to-ports ");
 				script.append(TOR_TRANSPROXY_PORT);
@@ -251,7 +252,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(ipTablesPath);
 				script.append(" -t nat");
 				script.append(" -A OUTPUT -p udp -m owner --uid-owner ");
-				script.append(apps[i].getUid());
+				script.append(tApp.getUid());
 				script.append(" -m udp --dport "); 
 				script.append(STANDARD_DNS_PORT);
 				script.append(" -j REDIRECT --to-ports ");
@@ -267,7 +268,7 @@ public class TorTransProxy implements TorServiceConstants {
 					script.append(" -t filter");
 					script.append(" -A OUTPUT");
 					script.append(" -m owner --uid-owner ");
-					script.append(apps[i].getUid());
+					script.append(tApp.getUid());
 					script.append(" -p tcp");
 					script.append(" -d 127.0.0.1");
 					script.append(" --dport ");
@@ -281,7 +282,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(" -t filter");
 				script.append(" -A OUTPUT");
 				script.append(" -m owner --uid-owner ");
-				script.append(apps[i].getUid());
+				script.append(tApp.getUid());
 				script.append(" -p tcp");
 				script.append(" -o lo");
 				script.append(" -j ACCEPT");
@@ -292,7 +293,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(" -t filter");
 				script.append(" -A OUTPUT");
 				script.append(" -m owner --uid-owner ");
-				script.append(apps[i].getUid());
+				script.append(tApp.getUid());
 				script.append(" -p udp");
 				script.append(" --dport ");
 				script.append(STANDARD_DNS_PORT);
@@ -304,7 +305,7 @@ public class TorTransProxy implements TorServiceConstants {
 				script.append(" -t filter");
 				script.append(" -A OUTPUT");
 				script.append(" -m owner --uid-owner ");
-				script.append(apps[i].getUid());
+				script.append(tApp.getUid());
 				script.append(" -p tcp");
 				script.append(" -j REJECT");
 				script.append(" || exit\n");
diff --git a/src/org/torproject/android/settings/AppManager.java b/src/org/torproject/android/settings/AppManager.java
index 2e10ed7..a88a4d7 100644
--- a/src/org/torproject/android/settings/AppManager.java
+++ b/src/org/torproject/android/settings/AppManager.java
@@ -3,6 +3,7 @@
 
 package org.torproject.android.settings;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -19,7 +20,10 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PermissionInfo;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
@@ -40,7 +44,7 @@ import android.widget.TextView;
 
 public class AppManager extends Activity implements OnCheckedChangeListener, OnClickListener, TorConstants {
 
-	private static TorifiedApp[] apps = null;
+	private static ArrayList<TorifiedApp> apps = null;
 
 	private ListView listApps;
 	
@@ -83,8 +87,9 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 	private void loadApps ()
 	{
 		resetApps(this);
-        final TorifiedApp[] apps = getApps(this);
+        final ArrayList<TorifiedApp> apps = getApps(this);
         
+        /*
         Arrays.sort(apps, new Comparator<TorifiedApp>() {
 			public int compare(TorifiedApp o1, TorifiedApp o2) {
 				if (o1.isTorified() == o2.isTorified()) return o1.getName().compareTo(o2.getName());
@@ -92,6 +97,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 				return 1;
 			}
         });
+        */
         
         final LayoutInflater inflater = getLayoutInflater();
 		
@@ -118,7 +124,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
         		}
         		
         		
-        		final TorifiedApp app = apps[position];
+        		final TorifiedApp app = apps.get(position);
         		
         	
         		entry.icon.setImageDrawable(app.getIcon());
@@ -156,7 +162,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 		
 	}
 
-	public static TorifiedApp[] getApps (Context context)
+	public static ArrayList<TorifiedApp> getApps (Context context)
 	{
 		if (apps == null)
 			resetApps(context);
@@ -164,7 +170,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 		return apps;
 	}
 	
-	public static TorifiedApp[] resetApps (Context context)
+	public static ArrayList<TorifiedApp> resetApps (Context context)
 	{
 
 		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -187,36 +193,71 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 		
 		List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0);
 		
-		
 		Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
 		
-		apps = new TorifiedApp[lAppInfo.size()];
+		apps = new ArrayList<TorifiedApp>();
 		
 		ApplicationInfo aInfo = null;
 		
 		int appIdx = 0;
+		TorifiedApp app = null;
 		
 		while (itAppInfo.hasNext())
 		{
 			aInfo = itAppInfo.next();
 			
-			apps[appIdx] = new TorifiedApp();
+			app = new TorifiedApp();
+			
+			try {
+				PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);
+				
+				if (pInfo != null && pInfo.permissions != null)
+				{
+					for (String permInfo:pInfo.requestedPermissions)
+					{
+						if (permInfo.equals("android.permission.INTERNET"))
+						{
+							app.setUsesInternet(true);
+							
+						}
+					}
+					
+				}
+				
+				
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			
+			if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
+		    {
+		         //System app
+				app.setUsesInternet(true);
+		   }
 			
 			
-			apps[appIdx].setEnabled(aInfo.enabled);
-			apps[appIdx].setUid(aInfo.uid);
-			apps[appIdx].setUsername(pMgr.getNameForUid(apps[appIdx].getUid()));
-			apps[appIdx].setProcname(aInfo.processName);
-			apps[appIdx].setName(pMgr.getApplicationLabel(aInfo).toString());
-			apps[appIdx].setIcon(pMgr.getApplicationIcon(aInfo));
+			if (!app.usesInternet())
+				continue;
+			else
+			{
+				apps.add(app);
+			}
+			
+			app.setEnabled(aInfo.enabled);
+			app.setUid(aInfo.uid);
+			app.setUsername(pMgr.getNameForUid(app.getUid()));
+			app.setProcname(aInfo.processName);
+			app.setName(pMgr.getApplicationLabel(aInfo).toString());
+			app.setIcon(pMgr.getApplicationIcon(aInfo));
 			
 			// check if this application is allowed
-			if (Arrays.binarySearch(tordApps, apps[appIdx].getUsername()) >= 0) {
-				apps[appIdx].setTorified(true);
+			if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) {
+				app.setTorified(true);
 			}
 			else
 			{
-				apps[appIdx].setTorified(false);
+				app.setTorified(false);
 			}
 			
 			appIdx++;
@@ -238,11 +279,11 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 
 		StringBuilder tordApps = new StringBuilder();
 		
-		for (int i = 0; i < apps.length; i++)
+		for (TorifiedApp tApp:apps)
 		{
-			if (apps[i].isTorified())
+			if (tApp.isTorified())
 			{
-				tordApps.append(apps[i].getUsername());
+				tordApps.append(tApp.getUsername());
 				tordApps.append("|");
 			}
 		}
diff --git a/src/org/torproject/android/settings/TorifiedApp.java b/src/org/torproject/android/settings/TorifiedApp.java
index 4f7fb2d..8e53321 100644
--- a/src/org/torproject/android/settings/TorifiedApp.java
+++ b/src/org/torproject/android/settings/TorifiedApp.java
@@ -12,7 +12,14 @@ public class TorifiedApp {
 	private Drawable icon;
 	
 	private boolean torified = false;
+	private boolean usesInternet = false;
 	
+	public boolean usesInternet() {
+		return usesInternet;
+	}
+	public void setUsesInternet(boolean usesInternet) {
+		this.usesInternet = usesInternet;
+	}
 	/**
 	 * @return the torified
 	 */



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