123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package de.tudarmstadt.informatik.hostage.system;
- import java.io.IOException;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.preference.PreferenceManager;
- import android.util.Log;
- import de.tudarmstadt.informatik.hostage.Hostage;
- import de.tudarmstadt.informatik.hostage.R;
- public class Device {
- @SuppressWarnings("unused")
- // DO NOT REMOVE, NEEDED FOR SINGLETON INITIALIZATION
- private static final Device INSTANCE = new Device();
- private static boolean initialized = false;
- private static boolean root = false;
- private static boolean pp = false;
- private Device() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- String portBinder = "[ -e /data/local/bind ]";
- Process su = new ProcessBuilder("su", "-c", portBinder).start();
- switch (su.waitFor()) {
- case 0:
- root = true;
- pp = true;
- break;
- case 1:
- root = true;
- pp = false;
- break;
- case 127:
- root = false;
- pp = false;
- break;
- }
- } catch (InterruptedException e) {
- } catch (IOException e) {
- } finally {
- initialized = true;
- Log.d("hostage", "Root: " + Boolean.toString(root));
- Log.d("hostage", "PP: " + Boolean.toString(pp));
- }
- }
- }).start();
- }
- public static boolean isRooted() {
- while (!initialized)
- ;
- return root;
- }
- public static boolean isPorthackInstalled() {
- while (!initialized)
- ;
- return pp;
- }
- /**
- * Called after auto-loading porthack. To update the local variables.
- */
- public static boolean updatePorthack (){
- try {
- String portBinder = "[ -e /data/local/bind ]";
- Process su = new ProcessBuilder("su", "-c", portBinder).start();
- switch (su.waitFor()) {
- case 0:
- root = true;
- pp = true;
- break;
- case 1:
- root = true;
- pp = false;
- break;
- case 127:
- root = false;
- pp = false;
- break;
- }
- } catch (InterruptedException e) {
- } catch (IOException e) {
- } finally {
- initialized = true;
- Log.d("hostage", "Root: " + Boolean.toString(root));
- Log.d("hostage", "PP: " + Boolean.toString(pp));
- }
- return (pp && root);
- }
- }
|