Device.java 964 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package de.tudarmstadt.informatik.hostage.system;
  2. import java.io.IOException;
  3. public class Device {
  4. private static boolean initialized = false;
  5. private static boolean root = false;
  6. private static boolean pp = false;
  7. private Device() {
  8. new Thread(new Runnable() {
  9. @Override
  10. public void run() {
  11. try {
  12. String test = "[ -e /data/local/pp ]";
  13. Process su = new ProcessBuilder("su", "-c", test).start();
  14. switch (su.waitFor()) {
  15. case 0:
  16. root = true;
  17. pp = true;
  18. break;
  19. case 1:
  20. root = true;
  21. pp = false;
  22. break;
  23. case 127:
  24. root = false;
  25. pp = false;
  26. break;
  27. }
  28. } catch (InterruptedException e) {
  29. } catch (IOException e) {
  30. } finally {
  31. initialized = true;
  32. }
  33. }
  34. }).start();
  35. }
  36. public static boolean isRooted() {
  37. while (!initialized)
  38. ;
  39. return root;
  40. }
  41. public static boolean isPPInstalled() {
  42. while (!initialized)
  43. ;
  44. return pp;
  45. }
  46. }