• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisãob31f926061591bd0d2fab21150f2ac783d52b261 (tree)
Hora2016-05-05 19:08:31
AutorSteve Kondik <shade@chem...>
CommiterChih-Wei Huang

Mensagem de Log

Add preference for enabling root access (3/3)

  • Root over ADB is now disabled by default on non-eng builds
  • Requires support in su binary and adbd
  • Root access can be configured to use ADB only, apps only, or all

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

Mudança Sumário

Diff

--- /dev/null
+++ b/res/values/cm_arrays.xml
@@ -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
--- /dev/null
+++ b/res/values/cm_strings.xml
@@ -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>
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -66,6 +66,13 @@
6666 android:summary="@string/picture_color_mode_desc"
6767 android:persistent="false" />
6868
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+
6976 <PreferenceCategory android:key="debug_debugging_category"
7077 android:title="@string/debug_debugging_category">
7178
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -162,6 +162,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
162162
163163 private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
164164
165+ private static final String ROOT_ACCESS_KEY = "root_access";
166+ private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
167+
165168 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
166169 = "immediately_destroy_activities";
167170 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
@@ -256,6 +259,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
256259
257260 private ColorModePreference mColorModePreference;
258261
262+ private PreferenceScreen mProcessStats;
263+ private ListPreference mRootAccess;
264+ private Object mSelectedRootValue;
265+
259266 private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
260267
261268 private final ArrayList<SwitchPreference> mResetSwitchPrefs
@@ -269,6 +276,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
269276
270277 private Dialog mAdbKeysDialog;
271278 private boolean mUnavailable;
279+ private Dialog mRootDialog;
272280
273281 @Override
274282 protected int getMetricsCategory() {
@@ -421,6 +429,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
421429 removePreference(KEY_COLOR_MODE);
422430 mColorModePreference = null;
423431 }
432+
433+ mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
434+ mRootAccess.setOnPreferenceChangeListener(this);
435+ if (!removeRootOptionsIfRequired()) {
436+ mAllPrefs.add(mRootAccess);
437+ }
424438 }
425439
426440 private ListPreference addListPreference(String prefKey) {
@@ -447,6 +461,18 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
447461 return pref;
448462 }
449463
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+
450476 @Override
451477 public void onActivityCreated(Bundle savedInstanceState) {
452478 super.onActivityCreated(savedInstanceState);
@@ -628,6 +654,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
628654 updateMobileDataAlwaysOnOptions();
629655 updateSimulateColorSpace();
630656 updateUSBAudioOptions();
657+ updateRootAccessOptions();
631658 }
632659
633660 private void resetDangerousOptions() {
@@ -641,6 +668,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
641668 }
642669 resetDebuggerOptions();
643670 writeLogdSizeOption(null);
671+ resetRootAccessOptions();
644672 writeAnimationScaleOption(0, mWindowAnimationScale, null);
645673 writeAnimationScaleOption(1, mTransitionAnimationScale, null);
646674 writeAnimationScaleOption(2, mAnimatorDurationScale, null);
@@ -656,6 +684,40 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
656684 pokeSystemProperties();
657685 }
658686
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+
659721 private void updateHdcpValues() {
660722 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
661723 if (hdcpChecking != null) {
@@ -1770,6 +1832,25 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
17701832 } else if (preference == mSimulateColorSpace) {
17711833 writeSimulateColorSpace(newValue);
17721834 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;
17731854 }
17741855 return false;
17751856 }
@@ -1787,6 +1868,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
17871868 mEnableDialog.dismiss();
17881869 mEnableDialog = null;
17891870 }
1871+ if (mRootDialog != null) {
1872+ mRootDialog.dismiss();
1873+ mRootDialog = null;
1874+ }
17901875 }
17911876
17921877 public void onClick(DialogInterface dialog, int which) {
@@ -1823,6 +1908,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
18231908 // Reset the toggle
18241909 mSwitchBar.setChecked(false);
18251910 }
1911+ } else if (dialog == mRootDialog) {
1912+ if (which == DialogInterface.BUTTON_POSITIVE) {
1913+ writeRootAccessOptions(mSelectedRootValue);
1914+ } else {
1915+ // Reset the option
1916+ writeRootAccessOptions("0");
1917+ }
18261918 }
18271919 }
18281920