summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/DevelopmentSettings.java
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2015-10-18 23:46:41 -0700
committerSteve Kondik <steve@cyngn.com>2015-10-18 23:47:07 -0700
commit587efed7f64c32d822baead8651c1f47067b59c1 (patch)
treea9de8890a44f43feacbc32985707862866445f02 /src/com/android/settings/DevelopmentSettings.java
parent584a7b64ad7468ae8f790d9d24cbf373dc869d38 (diff)
downloadpackages_apps_Settings-587efed7f64c32d822baead8651c1f47067b59c1.zip
packages_apps_Settings-587efed7f64c32d822baead8651c1f47067b59c1.tar.gz
packages_apps_Settings-587efed7f64c32d822baead8651c1f47067b59c1.tar.bz2
settings: Add developer setting for root access
Change-Id: If96219d893c0dfdcf4ad36e1cd8de3a413db0e8b
Diffstat (limited to 'src/com/android/settings/DevelopmentSettings.java')
-rw-r--r--src/com/android/settings/DevelopmentSettings.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 4a4c51d..5d1f417 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -161,6 +161,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
+ private static final String ROOT_ACCESS_KEY = "root_access";
+ private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
+
private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
= "immediately_destroy_activities";
private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
@@ -253,6 +256,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
private SwitchPreference mShowAllANRs;
+ private PreferenceScreen mProcessStats;
+ private ListPreference mRootAccess;
+ private Object mSelectedRootValue;
+
private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
private final ArrayList<SwitchPreference> mResetSwitchPrefs
@@ -266,6 +273,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
private Dialog mAdbKeysDialog;
private boolean mUnavailable;
+ private Dialog mRootDialog;
@Override
protected int getMetricsCategory() {
@@ -407,6 +415,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
mAllPrefs.add(hdcpChecking);
removePreferenceForProduction(hdcpChecking);
}
+
+ mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
+ mRootAccess.setOnPreferenceChangeListener(this);
+ if (!removeRootOptionsIfRequired()) {
+ mAllPrefs.add(mRootAccess);
+ }
}
private ListPreference addListPreference(String prefKey) {
@@ -433,6 +447,18 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
return pref;
}
+ private boolean removeRootOptionsIfRequired() {
+ // user builds don't get root, and eng always gets root
+ if (!(Build.IS_DEBUGGABLE || "eng".equals(Build.TYPE))) {
+ if (mRootAccess != null) {
+ getPreferenceScreen().removePreference(mRootAccess);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -601,6 +627,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
updateMobileDataAlwaysOnOptions();
updateSimulateColorSpace();
updateUSBAudioOptions();
+ updateUSBAudioOptions();
}
private void resetDangerousOptions() {
@@ -614,6 +641,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
}
resetDebuggerOptions();
writeLogdSizeOption(null);
+ resetRootAccessOptions();
writeAnimationScaleOption(0, mWindowAnimationScale, null);
writeAnimationScaleOption(1, mTransitionAnimationScale, null);
writeAnimationScaleOption(2, mAnimatorDurationScale, null);
@@ -629,6 +657,47 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
pokeSystemProperties();
}
+ private void updateRootAccessOptions() {
+ String value = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
+ mRootAccess.setValue(value);
+ mRootAccess.setSummary(getResources()
+ .getStringArray(R.array.root_access_entries)[Integer.valueOf(value)]);
+ }
+
+ public static boolean isRootForAppsEnabled() {
+ int value = SystemProperties.getInt(ROOT_ACCESS_PROPERTY, 0);
+ boolean daemonState =
+ SystemProperties.get("init.svc.su_daemon", "absent").equals("running");
+ return daemonState && (value == 1 || value == 3);
+ }
+
+ private void writeRootAccessOptions(Object newValue) {
+ String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
+ SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());
+ if (Integer.valueOf(newValue.toString()) < 2 && !oldValue.equals(newValue)
+ && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
+ SystemProperties.set("service.adb.root", "0");
+ Settings.Secure.putInt(getActivity().getContentResolver(),
+ Settings.Secure.ADB_ENABLED, 0);
+ Settings.Secure.putInt(getActivity().getContentResolver(),
+ Settings.Secure.ADB_ENABLED, 1);
+ }
+ updateRootAccessOptions();
+ }
+
+ private void resetRootAccessOptions() {
+ String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
+ SystemProperties.set(ROOT_ACCESS_PROPERTY, "0");
+ if (!oldValue.equals("0") && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
+ SystemProperties.set("service.adb.root", "0");
+ Settings.Secure.putInt(getActivity().getContentResolver(),
+ Settings.Secure.ADB_ENABLED, 0);
+ Settings.Secure.putInt(getActivity().getContentResolver(),
+ Settings.Secure.ADB_ENABLED, 1);
+ }
+ updateRootAccessOptions();
+ }
+
private void updateHdcpValues() {
ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
if (hdcpChecking != null) {
@@ -1743,6 +1812,24 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
} else if (preference == mSimulateColorSpace) {
writeSimulateColorSpace(newValue);
return true;
+ } else if (preference == mRootAccess) {
+ if ("0".equals(SystemProperties.get(ROOT_ACCESS_PROPERTY, "0"))
+ && !"0".equals(newValue)) {
+ mSelectedRootValue = newValue;
+ mDialogClicked = false;
+ if (mRootDialog != null) {
+ dismissDialogs();
+ }
+ mRootDialog = new AlertDialog.Builder(getActivity())
+ .setMessage(getResources().getString(R.string.root_access_warning_message))
+ .setTitle(R.string.root_access_warning_title)
+ .setPositiveButton(android.R.string.yes, this)
+ .setNegativeButton(android.R.string.no, this).show();
+ mRootDialog.setOnDismissListener(this);
+ } else {
+ writeRootAccessOptions(newValue);
+ }
+ return true;
}
return false;
}
@@ -1760,6 +1847,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
mEnableDialog.dismiss();
mEnableDialog = null;
}
+ if (mRootDialog != null) {
+ mRootDialog.dismiss();
+ mRootDialog = null;
+ }
}
public void onClick(DialogInterface dialog, int which) {
@@ -1796,6 +1887,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
// Reset the toggle
mSwitchBar.setChecked(false);
}
+ } else if (dialog == mRootDialog) {
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ writeRootAccessOptions(mSelectedRootValue);
+ } else {
+ // Reset the option
+ writeRootAccessOptions("0");
+ }
}
}
@@ -1811,6 +1909,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
mSwitchBar.setChecked(false);
}
mEnableDialog = null;
+ } else if (dialog == mRootDialog) {
+ updateRootAccessOptions();
+ mRootDialog = null;
}
}