Device.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package de.tudarmstadt.informatik.hostage.system;
  2. import java.io.IOException;
  3. import android.util.Log;
  4. public class Device {
  5. @SuppressWarnings("unused")
  6. // DO NOT REMOVE, NEEDED FOR SINGLETON INITIALIZATION
  7. private static final Device INSTANCE = new Device();
  8. private static boolean initialized = false;
  9. private static boolean root = false;
  10. private static boolean pp = false;
  11. private Device() {
  12. new Thread(new Runnable() {
  13. @Override
  14. public void run() {
  15. try {
  16. String test = "[ -e /data/local/bind ]";
  17. Process su = new ProcessBuilder("su", "-c", test).start();
  18. switch (su.waitFor()) {
  19. case 0:
  20. root = true;
  21. pp = true;
  22. break;
  23. case 1:
  24. root = true;
  25. pp = false;
  26. break;
  27. case 127:
  28. root = false;
  29. pp = false;
  30. break;
  31. }
  32. } catch (InterruptedException e) {
  33. } catch (IOException e) {
  34. } finally {
  35. initialized = true;
  36. Log.d("hostage", "Root: " + Boolean.toString(root));
  37. Log.d("hostage", "PP: " + Boolean.toString(pp));
  38. }
  39. }
  40. }).start();
  41. }
  42. public static boolean isRooted() {
  43. while (!initialized)
  44. ;
  45. return root;
  46. }
  47. public static boolean isPorthackInstalled() {
  48. while (!initialized)
  49. ;
  50. return pp;
  51. }
  52. }