Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package org.strongswan.android.utils;
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.io.File;
  5. /**
  6. * Created by amitapollo on 2/7/16.
  7. */
  8. public class RootUtil {
  9. public static boolean isDeviceRooted() {
  10. return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
  11. }
  12.  
  13. private static boolean checkRootMethod1() {
  14. String buildTags = android.os.Build.TAGS;
  15. return buildTags != null && buildTags.contains("test-keys");
  16. }
  17.  
  18. private static boolean checkRootMethod2() {
  19. 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",
  20. "/system/bin/failsafe/su", "/data/local/su" };
  21. for (String path : paths) {
  22. if (new File(path).exists()) return true;
  23. }
  24. return false;
  25. }
  26.  
  27. private static boolean checkRootMethod3() {
  28. Process process = null;
  29. try {
  30. process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
  31. BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  32. if (in.readLine() != null) return true;
  33. return false;
  34. } catch (Throwable t) {
  35. return false;
  36. } finally {
  37. if (process != null) process.destroy();
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement