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

[tor-commits] [orbot/master] Updated TorServiceUtils.checkRootAccess()



commit e63c745808ac9020983e872c5deac190d4f884de
Author: Sathyanarayanan Gunasekaran <gsathya.ceg@xxxxxxxxx>
Date:   Tue Jun 28 09:12:52 2011 +0530

    Updated TorServiceUtils.checkRootAccess()
    
    checkRootAccess() now checks if 'su' binary and
    Superuser.apk exist to check if the phone has
    root access
---
 .../android/service/TorServiceUtils.java           |   37 +++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java
index 2aa58e6..657d525 100644
--- a/src/org/torproject/android/service/TorServiceUtils.java
+++ b/src/org/torproject/android/service/TorServiceUtils.java
@@ -17,7 +17,9 @@ public class TorServiceUtils implements TorServiceConstants {
 	 * Check if we have root access
 	 * @return boolean true if we have root
 	 */
-	public static boolean checkRootAccess() {
+	/*
+	  public static boolean checkRootAccess() {
+	 
 	
 
 		StringBuilder log = new StringBuilder();
@@ -45,7 +47,40 @@ public class TorServiceUtils implements TorServiceConstants {
 		TorService.logMessage("Could not acquire root permissions");
 		return false;
 	}
+	*/
 	
+	public static boolean checkRootAccess(){
+		
+		StringBuilder log = new StringBuilder();
+		
+		try {
+			
+			// Check if Superuser.apk exists
+			File file = new File("/system/app/Superuser.apk");
+			
+			//Check for 'su' binary 
+			String[] cmd = {"which su"};
+			int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
+			
+			if (file.exists() && exitCode == 0) {
+				TorService.logMessage("Can acquire root permissions");
+		    	 return true;
+		     
+		    }
+		      
+		} catch (IOException e) {
+			//this means that there is no root to be had (normally) so we won't log anything
+			TorService.logException("Error checking for root access",e);
+			
+		}
+		catch (Exception e) {
+			TorService.logException("Error checking for root access",e);
+			//this means that there is no root to be had (normally)
+		}
+		
+		TorService.logMessage("Could not acquire root permissions");
+		return false;
+	}
 	
 	
 	public static int findProcessId(String command) 



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