packages/apps/Settings
Revisão | b31f926061591bd0d2fab21150f2ac783d52b261 (tree) |
---|---|
Hora | 2016-05-05 19:08:31 |
Autor | Steve Kondik <shade@chem...> |
Commiter | Chih-Wei Huang |
Add preference for enabling root access (3/3)
Change-Id: I132a35a31c676511db954ff19120fa6d3c795b23
Conflicts:
res/values/arrays.xml
res/values/strings.xml
src/com/android/settings/DevelopmentSettings.java
Settings: Make CM developer options additions respect the on/off toggle
This commit fixes the problem where, when dev options are turned off, our
CM customizations don't turn off with the rest of the options and the
dangerous option (root access) does not reset to a safe setting.
Change-Id: I879756ea353ce2940c05b224998fc1a945f2ceff
DevSettings: Fix the root-access toggle in eng builds
It was being unconditionally removed, put it back
Change-Id: I8eecab7353c59b224d917cc1710124f57656cf47
@@ -0,0 +1,32 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<!-- | |
3 | +Copyright (C) 2012-2014 The CyanogenMod Project | |
4 | + | |
5 | +Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | +you may not use this file except in compliance with the License. | |
7 | +You may obtain a copy of the License at | |
8 | + | |
9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + | |
11 | +Unless required by applicable law or agreed to in writing, software | |
12 | +distributed under the License is distributed on an "AS IS" BASIS, | |
13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | +See the License for the specific language governing permissions and | |
15 | +limitations under the License. | |
16 | +--> | |
17 | +<resources> | |
18 | + <!-- Arrays for root access capability --> | |
19 | + <string-array name="root_access_entries"> | |
20 | + <item>@string/root_access_none</item> | |
21 | + <item>@string/root_access_apps</item> | |
22 | + <item>@string/root_access_adb</item> | |
23 | + <item>@string/root_access_all</item> | |
24 | + </string-array> | |
25 | + | |
26 | + <string-array name="root_access_values"> | |
27 | + <item>0</item> | |
28 | + <item>1</item> | |
29 | + <item>2</item> | |
30 | + <item>3</item> | |
31 | + </string-array> | |
32 | +</resources> | |
\ No newline at end of file |
@@ -0,0 +1,26 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<!-- | |
3 | + Copyright (C) 2012-2014 The CyanogenMod Project | |
4 | + | |
5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | + you may not use this file except in compliance with the License. | |
7 | + You may obtain a copy of the License at | |
8 | + | |
9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + | |
11 | + Unless required by applicable law or agreed to in writing, software | |
12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | + See the License for the specific language governing permissions and | |
15 | + limitations under the License. | |
16 | +--> | |
17 | +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
18 | + <!-- Setting checkbox title for root access --> | |
19 | + <string name="root_access">Root access</string> | |
20 | + <string name="root_access_warning_title">Allow root access?</string> | |
21 | + <string name="root_access_warning_message">Allowing applications to request root access is very dangerous and could compromise the security of your system!</string> | |
22 | + <string name="root_access_none">Disabled</string> | |
23 | + <string name="root_access_apps">Apps only</string> | |
24 | + <string name="root_access_adb">ADB only</string> | |
25 | + <string name="root_access_all">Apps and ADB</string> | |
26 | +</resources> |
@@ -66,6 +66,13 @@ | ||
66 | 66 | android:summary="@string/picture_color_mode_desc" |
67 | 67 | android:persistent="false" /> |
68 | 68 | |
69 | + <ListPreference | |
70 | + android:key="root_access" | |
71 | + android:title="@string/root_access" | |
72 | + android:persistent="false" | |
73 | + android:entries="@array/root_access_entries" | |
74 | + android:entryValues="@array/root_access_values" /> | |
75 | + | |
69 | 76 | <PreferenceCategory android:key="debug_debugging_category" |
70 | 77 | android:title="@string/debug_debugging_category"> |
71 | 78 |
@@ -162,6 +162,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
162 | 162 | |
163 | 163 | private static final String OPENGL_TRACES_KEY = "enable_opengl_traces"; |
164 | 164 | |
165 | + private static final String ROOT_ACCESS_KEY = "root_access"; | |
166 | + private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access"; | |
167 | + | |
165 | 168 | private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY |
166 | 169 | = "immediately_destroy_activities"; |
167 | 170 | private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit"; |
@@ -256,6 +259,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
256 | 259 | |
257 | 260 | private ColorModePreference mColorModePreference; |
258 | 261 | |
262 | + private PreferenceScreen mProcessStats; | |
263 | + private ListPreference mRootAccess; | |
264 | + private Object mSelectedRootValue; | |
265 | + | |
259 | 266 | private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>(); |
260 | 267 | |
261 | 268 | private final ArrayList<SwitchPreference> mResetSwitchPrefs |
@@ -269,6 +276,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
269 | 276 | |
270 | 277 | private Dialog mAdbKeysDialog; |
271 | 278 | private boolean mUnavailable; |
279 | + private Dialog mRootDialog; | |
272 | 280 | |
273 | 281 | @Override |
274 | 282 | protected int getMetricsCategory() { |
@@ -421,6 +429,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
421 | 429 | removePreference(KEY_COLOR_MODE); |
422 | 430 | mColorModePreference = null; |
423 | 431 | } |
432 | + | |
433 | + mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY); | |
434 | + mRootAccess.setOnPreferenceChangeListener(this); | |
435 | + if (!removeRootOptionsIfRequired()) { | |
436 | + mAllPrefs.add(mRootAccess); | |
437 | + } | |
424 | 438 | } |
425 | 439 | |
426 | 440 | private ListPreference addListPreference(String prefKey) { |
@@ -447,6 +461,18 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
447 | 461 | return pref; |
448 | 462 | } |
449 | 463 | |
464 | + private boolean removeRootOptionsIfRequired() { | |
465 | + // user builds don't get root, and eng always gets root | |
466 | + if (!(Build.IS_DEBUGGABLE || "eng".equals(Build.TYPE))) { | |
467 | + if (mRootAccess != null) { | |
468 | + getPreferenceScreen().removePreference(mRootAccess); | |
469 | + return true; | |
470 | + } | |
471 | + } | |
472 | + | |
473 | + return false; | |
474 | + } | |
475 | + | |
450 | 476 | @Override |
451 | 477 | public void onActivityCreated(Bundle savedInstanceState) { |
452 | 478 | super.onActivityCreated(savedInstanceState); |
@@ -628,6 +654,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
628 | 654 | updateMobileDataAlwaysOnOptions(); |
629 | 655 | updateSimulateColorSpace(); |
630 | 656 | updateUSBAudioOptions(); |
657 | + updateRootAccessOptions(); | |
631 | 658 | } |
632 | 659 | |
633 | 660 | private void resetDangerousOptions() { |
@@ -641,6 +668,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
641 | 668 | } |
642 | 669 | resetDebuggerOptions(); |
643 | 670 | writeLogdSizeOption(null); |
671 | + resetRootAccessOptions(); | |
644 | 672 | writeAnimationScaleOption(0, mWindowAnimationScale, null); |
645 | 673 | writeAnimationScaleOption(1, mTransitionAnimationScale, null); |
646 | 674 | writeAnimationScaleOption(2, mAnimatorDurationScale, null); |
@@ -656,6 +684,40 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
656 | 684 | pokeSystemProperties(); |
657 | 685 | } |
658 | 686 | |
687 | + private void updateRootAccessOptions() { | |
688 | + String value = SystemProperties.get(ROOT_ACCESS_PROPERTY, "1"); | |
689 | + mRootAccess.setValue(value); | |
690 | + mRootAccess.setSummary(getResources() | |
691 | + .getStringArray(R.array.root_access_entries)[Integer.valueOf(value)]); | |
692 | + } | |
693 | + | |
694 | + private void writeRootAccessOptions(Object newValue) { | |
695 | + String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "1"); | |
696 | + SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString()); | |
697 | + if (Integer.valueOf(newValue.toString()) < 2 && !oldValue.equals(newValue) | |
698 | + && "1".equals(SystemProperties.get("service.adb.root", "0"))) { | |
699 | + SystemProperties.set("service.adb.root", "0"); | |
700 | + Settings.Secure.putInt(getActivity().getContentResolver(), | |
701 | + Settings.Secure.ADB_ENABLED, 0); | |
702 | + Settings.Secure.putInt(getActivity().getContentResolver(), | |
703 | + Settings.Secure.ADB_ENABLED, 1); | |
704 | + } | |
705 | + updateRootAccessOptions(); | |
706 | + } | |
707 | + | |
708 | + private void resetRootAccessOptions() { | |
709 | + String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "1"); | |
710 | + SystemProperties.set(ROOT_ACCESS_PROPERTY, "1"); | |
711 | + if (!oldValue.equals("1") && "1".equals(SystemProperties.get("service.adb.root", "0"))) { | |
712 | + SystemProperties.set("service.adb.root", "0"); | |
713 | + Settings.Secure.putInt(getActivity().getContentResolver(), | |
714 | + Settings.Secure.ADB_ENABLED, 0); | |
715 | + Settings.Secure.putInt(getActivity().getContentResolver(), | |
716 | + Settings.Secure.ADB_ENABLED, 1); | |
717 | + } | |
718 | + updateRootAccessOptions(); | |
719 | + } | |
720 | + | |
659 | 721 | private void updateHdcpValues() { |
660 | 722 | ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY); |
661 | 723 | if (hdcpChecking != null) { |
@@ -1770,6 +1832,25 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
1770 | 1832 | } else if (preference == mSimulateColorSpace) { |
1771 | 1833 | writeSimulateColorSpace(newValue); |
1772 | 1834 | return true; |
1835 | + } else if (preference == mRootAccess) { | |
1836 | + if ("0".equals(SystemProperties.get(ROOT_ACCESS_PROPERTY, "1")) | |
1837 | + && !"0".equals(newValue)) { | |
1838 | + mSelectedRootValue = newValue; | |
1839 | + mDialogClicked = false; | |
1840 | + if (mRootDialog != null) { | |
1841 | + dismissDialogs(); | |
1842 | + } | |
1843 | + mRootDialog = new AlertDialog.Builder(getActivity()) | |
1844 | + .setMessage(getResources().getString(R.string.root_access_warning_message)) | |
1845 | + .setTitle(R.string.root_access_warning_title) | |
1846 | + .setIcon(android.R.drawable.ic_dialog_alert) | |
1847 | + .setPositiveButton(android.R.string.yes, this) | |
1848 | + .setNegativeButton(android.R.string.no, this).show(); | |
1849 | + mRootDialog.setOnDismissListener(this); | |
1850 | + } else { | |
1851 | + writeRootAccessOptions(newValue); | |
1852 | + } | |
1853 | + return true; | |
1773 | 1854 | } |
1774 | 1855 | return false; |
1775 | 1856 | } |
@@ -1787,6 +1868,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
1787 | 1868 | mEnableDialog.dismiss(); |
1788 | 1869 | mEnableDialog = null; |
1789 | 1870 | } |
1871 | + if (mRootDialog != null) { | |
1872 | + mRootDialog.dismiss(); | |
1873 | + mRootDialog = null; | |
1874 | + } | |
1790 | 1875 | } |
1791 | 1876 | |
1792 | 1877 | public void onClick(DialogInterface dialog, int which) { |
@@ -1823,6 +1908,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment | ||
1823 | 1908 | // Reset the toggle |
1824 | 1909 | mSwitchBar.setChecked(false); |
1825 | 1910 | } |
1911 | + } else if (dialog == mRootDialog) { | |
1912 | + if (which == DialogInterface.BUTTON_POSITIVE) { | |
1913 | + writeRootAccessOptions(mSelectedRootValue); | |
1914 | + } else { | |
1915 | + // Reset the option | |
1916 | + writeRootAccessOptions("0"); | |
1917 | + } | |
1826 | 1918 | } |
1827 | 1919 | } |
1828 | 1920 |