Device.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package de.tudarmstadt.informatik.hostage.system;
  2. import java.io.IOException;
  3. import android.util.Log;
  4. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  5. public class Device {
  6. private static String porthackFilepath = "/data/local/bind";
  7. private static boolean initialized = false;
  8. private static boolean root = false;
  9. private static boolean pp = false;
  10. private static void checkPorthack() {
  11. initialized = false;
  12. porthackFilepath = HelperUtils.getPorthackFilepath();
  13. Log.i("FILEPATH", porthackFilepath);
  14. String portBinder = "[ -e "+porthackFilepath+" ]";
  15. try {
  16. Process su = new ProcessBuilder("su", "-c", portBinder).start();
  17. switch (su.waitFor()) {
  18. case 0:
  19. root = true;
  20. pp = true;
  21. break;
  22. case 1:
  23. root = true;
  24. pp = false;
  25. break;
  26. case 127:
  27. root = false;
  28. pp = false;
  29. break;
  30. }
  31. } catch (InterruptedException e) {
  32. } catch (IOException e) {
  33. } finally {
  34. initialized = true;
  35. Log.d("hostage", "Root: " + Boolean.toString(root));
  36. Log.d("hostage", "PP: " + Boolean.toString(pp));
  37. }
  38. }
  39. public static boolean isRooted() {
  40. assert(initialized);
  41. return root;
  42. }
  43. public static boolean isPorthackInstalled() {
  44. assert(initialized);
  45. return pp;
  46. }
  47. /**
  48. * Called after auto-loading porthack. To update the local variables.
  49. */
  50. public static boolean updatePorthack(){
  51. checkPorthack();
  52. return (pp && root);
  53. }
  54. }