Device.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package de.tudarmstadt.informatik.hostage.system;
  2. import java.io.IOException;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.preference.PreferenceManager;
  7. import android.util.Log;
  8. import de.tudarmstadt.informatik.hostage.Hostage;
  9. import de.tudarmstadt.informatik.hostage.R;
  10. public class Device {
  11. @SuppressWarnings("unused")
  12. // DO NOT REMOVE, NEEDED FOR SINGLETON INITIALIZATION
  13. private static final Device INSTANCE = new Device();
  14. private static boolean initialized = false;
  15. private static boolean root = false;
  16. private static boolean pp = false;
  17. private Device() {
  18. new Thread(new Runnable() {
  19. @Override
  20. public void run() {
  21. try {
  22. String portBinder = "[ -e /data/local/bind ]";
  23. Process su = new ProcessBuilder("su", "-c", portBinder).start();
  24. switch (su.waitFor()) {
  25. case 0:
  26. root = true;
  27. pp = true;
  28. break;
  29. case 1:
  30. root = true;
  31. pp = false;
  32. break;
  33. case 127:
  34. root = false;
  35. pp = false;
  36. break;
  37. }
  38. } catch (InterruptedException e) {
  39. } catch (IOException e) {
  40. } finally {
  41. initialized = true;
  42. Log.d("hostage", "Root: " + Boolean.toString(root));
  43. Log.d("hostage", "PP: " + Boolean.toString(pp));
  44. }
  45. }
  46. }).start();
  47. }
  48. public static boolean isRooted() {
  49. while (!initialized)
  50. ;
  51. return root;
  52. }
  53. public static boolean isPorthackInstalled() {
  54. while (!initialized)
  55. ;
  56. return pp;
  57. }
  58. /**
  59. * Called after auto-loading porthack. To update the local variables.
  60. */
  61. public static boolean updatePorthack (){
  62. try {
  63. String portBinder = "[ -e /data/local/bind ]";
  64. Process su = new ProcessBuilder("su", "-c", portBinder).start();
  65. switch (su.waitFor()) {
  66. case 0:
  67. root = true;
  68. pp = true;
  69. break;
  70. case 1:
  71. root = true;
  72. pp = false;
  73. break;
  74. case 127:
  75. root = false;
  76. pp = false;
  77. break;
  78. }
  79. } catch (InterruptedException e) {
  80. } catch (IOException e) {
  81. } finally {
  82. initialized = true;
  83. Log.d("hostage", "Root: " + Boolean.toString(root));
  84. Log.d("hostage", "PP: " + Boolean.toString(pp));
  85. }
  86. return (pp && root);
  87. }
  88. }