OSDN Git Service

Don't allow advanced mode if device is not rooted
authorjruesga <jorge@ruesga.com>
Sun, 21 Oct 2012 19:00:19 +0000 (21:00 +0200)
committerjruesga <jorge@ruesga.com>
Sun, 21 Oct 2012 19:00:19 +0000 (21:00 +0200)
src/com/cyanogenmod/explorer/ExplorerApplication.java
src/com/cyanogenmod/explorer/activities/preferences/SettingsPreferences.java

index 3629b5f..2544b5c 100644 (file)
@@ -60,8 +60,8 @@ public final class ExplorerApplication extends Application {
     private static ExplorerApplication sApp;
     private static ConsoleHolder sBackgroundConsole;
 
-    private static boolean sDebuggable = false;
-    private static boolean sRootedDevice = false;
+    private static boolean sIsDebuggable = false;
+    private static boolean sIsDeviceRooted = false;
 
     private final BroadcastReceiver mOnSettingChangeReceiver = new BroadcastReceiver() {
         @Override
@@ -179,10 +179,10 @@ public final class ExplorerApplication extends Application {
         sApp = this;
 
         // Check if the application is debuggable
-        sDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
+        sIsDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
         
         // Check if the device is rooted
-        sRootedDevice = new File(getString(R.string.su_binary)).exists();
+        sIsDeviceRooted = new File(getString(R.string.su_binary)).exists();
 
         // Register the broadcast receiver
         IntentFilter filter = new IntentFilter();
@@ -225,7 +225,7 @@ public final class ExplorerApplication extends Application {
      * @return boolean If the application is debuggable
      */
     public static boolean isDebuggable() {
-        return sDebuggable;
+        return sIsDebuggable;
     }
 
     /**
@@ -233,8 +233,8 @@ public final class ExplorerApplication extends Application {
      *
      * @return boolean If the device is rooted
      */
-    public static boolean isRooted() {
-        return sRootedDevice;
+    public static boolean isDeviceRooted() {
+        return sIsDeviceRooted;
     }
 
     /**
@@ -370,12 +370,15 @@ public final class ExplorerApplication extends Application {
      * @return boolean If the application is running in advanced mode
      */
     public static boolean isAdvancedMode() {
+        // If device is not rooted, don't allow advanced mode
+        if (isDeviceRooted()) return false;
+
         boolean defaultValue =
                 ((Boolean)ExplorerSettings.
                         SETTINGS_ADVANCE_MODE.
                             getDefaultValue()).booleanValue();
         String id = ExplorerSettings.SETTINGS_ADVANCE_MODE.getId();
-       return Preferences.getSharedPreferences().getBoolean(id, defaultValue);
+        return Preferences.getSharedPreferences().getBoolean(id, defaultValue);
     }
 
 }
index 21f1640..0bb6e43 100644 (file)
@@ -33,6 +33,7 @@ import android.view.View;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import com.cyanogenmod.explorer.ExplorerApplication;
 import com.cyanogenmod.explorer.R;
 import com.cyanogenmod.explorer.preferences.ExplorerSettings;
 import com.cyanogenmod.explorer.preferences.ObjectStringIdentifier;
@@ -120,7 +121,7 @@ public class SettingsPreferences extends PreferenceActivity {
         private ListPreference mDefaultLongClickAction;
         private ListPreference mFreeDiskSpaceWarningLevel;
         private CheckBoxPreference mComputeFolderStatistics;
-        private CheckBoxPreference mAllowConsoleSelection;
+        private CheckBoxPreference mAdvancedSettings;
 
         /**
          * @hide
@@ -218,11 +219,16 @@ public class SettingsPreferences extends PreferenceActivity {
                             ExplorerSettings.SETTINGS_COMPUTE_FOLDER_STATISTICS.getId());
             this.mComputeFolderStatistics.setOnPreferenceChangeListener(this.mOnChangeListener);
 
-            // Allow console selection
-            this.mAllowConsoleSelection =
+            // Advanced settings
+            this.mAdvancedSettings =
                     (CheckBoxPreference)findPreference(
                             ExplorerSettings.SETTINGS_ADVANCE_MODE.getId());
-            this.mAllowConsoleSelection.setOnPreferenceChangeListener(this.mOnChangeListener);
+            if (ExplorerApplication.isDeviceRooted()) {
+                this.mAdvancedSettings.setOnPreferenceChangeListener(this.mOnChangeListener);
+            } else {
+                // Disable the advanced mode
+                this.mAdvancedSettings.setEnabled(false);
+            }
 
             // Loaded
             this.mLoaded = true;