Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1.  
  2.     public static boolean isRoot(Context context){
  3.         if (!Settings.Secure.getString(context.getContentResolver(),
  4.                 Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
  5.         {return true;}
  6.  
  7.         if(isDeviceRooted())
  8.         {
  9.             return true;
  10.         }
  11.  
  12.  
  13.  
  14.  
  15.         return false;
  16.  
  17.  
  18.     }
  19.  
  20.  
  21.     public static boolean isDeviceRooted() {
  22.         return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
  23.     }
  24.  
  25.     private static boolean checkRootMethod1() {
  26.         String buildTags = android.os.Build.TAGS;
  27.         return buildTags != null && buildTags.contains("test-keys");
  28.     }
  29.  
  30.     private static boolean checkRootMethod2() {
  31.         String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
  32.                 "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
  33.         for (String path : paths) {
  34.             if (new File(path).exists()) return true;
  35.         }
  36.         return false;
  37.     }
  38.  
  39.     private static boolean checkRootMethod3() {
  40.         Process process = null;
  41.         try {
  42.             process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
  43.             BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  44.             if (in.readLine() != null) return true;
  45.             return false;
  46.         } catch (Throwable t) {
  47.             return false;
  48.         } finally {
  49.             if (process != null) process.destroy();
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement