|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Wed, 20 Apr 2022 01:04:27 -0400 |
| 4 | +Subject: [PATCH] Add a toggle for CarrierConfig2 enablement |
| 5 | + |
| 6 | +Copy and pasted from the GrapheneOS exec spawning toggle patch |
| 7 | +TODO: MOVE OUT OF SECURITY CATEGORY |
| 8 | + |
| 9 | +Change-Id: Ibea6ea9bed1c2ae3491f403d9e5c17c1d1c403f1 |
| 10 | +Signed-off-by: Tad < [email protected]> |
| 11 | +--- |
| 12 | + res/values/strings.xml | 3 + |
| 13 | + res/xml/security_dashboard_settings.xml | 6 + |
| 14 | + .../CarrierConfig2PreferenceController.java | 106 ++++++++++++++++++ |
| 15 | + .../settings/security/SecuritySettings.java | 1 + |
| 16 | + 4 files changed, 116 insertions(+) |
| 17 | + create mode 100644 src/com/android/settings/security/CarrierConfig2PreferenceController.java |
| 18 | + |
| 19 | +diff --git a/res/values/strings.xml b/res/values/strings.xml |
| 20 | +index 751f4a4037..d8f4ed191a 100644 |
| 21 | +--- a/res/values/strings.xml |
| 22 | ++++ b/res/values/strings.xml |
| 23 | +@@ -762,6 +762,9 @@ |
| 24 | + <string name="openeuicc_title">Enable eUICC management</string> |
| 25 | + <string name="openeuicc_summary">Enables the OpenEUICC app to allow management of virtual (eSIM) and physical eUICC cards. Reboot required after toggling.</string> |
| 26 | + |
| 27 | ++ <string name="carrierconfig2_title">Enable CarrierConfig2</string> |
| 28 | ++ <string name="carrierconfig2_summary">Use a larger Google database instead of the AOSP database for carrier specific configurations. May improve cellular network compatibility & functionality.</string> |
| 29 | ++ |
| 30 | + <!-- Text shown for the title of the lock when trust lost option [CHAR LIMIT=40] --> |
| 31 | + <string name="trust_lost_locks_screen_title">Lock screen when trust is lost</string> |
| 32 | + <!-- Text shown for the description of the lock when trust lost option [CHAR LIMIT=NONE --> |
| 33 | +diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml |
| 34 | +index de90cec5bc..d8766ab41a 100644 |
| 35 | +--- a/res/xml/security_dashboard_settings.xml |
| 36 | ++++ b/res/xml/security_dashboard_settings.xml |
| 37 | +@@ -98,6 +98,12 @@ |
| 38 | + android:title="@string/openeuicc_title" |
| 39 | + android:summary="@string/openeuicc_summary" |
| 40 | + android:persistent="false" /> |
| 41 | ++ |
| 42 | ++ <SwitchPreference |
| 43 | ++ android:key="carrierconfig2" |
| 44 | ++ android:title="@string/carrierconfig2_title" |
| 45 | ++ android:summary="@string/carrierconfig2_summary" |
| 46 | ++ android:persistent="false" /> |
| 47 | + </PreferenceCategory> |
| 48 | + |
| 49 | + <Preference |
| 50 | +diff --git a/src/com/android/settings/security/CarrierConfig2PreferenceController.java b/src/com/android/settings/security/CarrierConfig2PreferenceController.java |
| 51 | +new file mode 100644 |
| 52 | +index 0000000000..a3e5aa1759 |
| 53 | +--- /dev/null |
| 54 | ++++ b/src/com/android/settings/security/CarrierConfig2PreferenceController.java |
| 55 | +@@ -0,0 +1,106 @@ |
| 56 | ++/* |
| 57 | ++ * Copyright (C) 2022 The Android Open Source Project |
| 58 | ++ * |
| 59 | ++ * Licensed under the Apache License, Version 2.0 (the "License"); |
| 60 | ++ * you may not use this file except in compliance with the License. |
| 61 | ++ * You may obtain a copy of the License at |
| 62 | ++ * |
| 63 | ++ * http://www.apache.org/licenses/LICENSE-2.0 |
| 64 | ++ * |
| 65 | ++ * Unless required by applicable law or agreed to in writing, software |
| 66 | ++ * distributed under the License is distributed on an "AS IS" BASIS, |
| 67 | ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 68 | ++ * See the License for the specific language governing permissions and |
| 69 | ++ * limitations under the License |
| 70 | ++ */ |
| 71 | ++ |
| 72 | ++package com.android.settings.security; |
| 73 | ++ |
| 74 | ++import android.content.Context; |
| 75 | ++ |
| 76 | ++import android.os.UserHandle; |
| 77 | ++import android.os.UserManager; |
| 78 | ++import android.os.SystemProperties; |
| 79 | ++ |
| 80 | ++import android.provider.Settings; |
| 81 | ++ |
| 82 | ++import androidx.preference.Preference; |
| 83 | ++import androidx.preference.PreferenceCategory; |
| 84 | ++import androidx.preference.PreferenceGroup; |
| 85 | ++import androidx.preference.PreferenceScreen; |
| 86 | ++import androidx.preference.TwoStatePreference; |
| 87 | ++import androidx.preference.SwitchPreference; |
| 88 | ++ |
| 89 | ++import com.android.internal.widget.LockPatternUtils; |
| 90 | ++import com.android.settings.core.PreferenceControllerMixin; |
| 91 | ++import com.android.settingslib.core.AbstractPreferenceController; |
| 92 | ++import com.android.settingslib.core.lifecycle.events.OnResume; |
| 93 | ++ |
| 94 | ++public class CarrierConfig2PreferenceController extends AbstractPreferenceController |
| 95 | ++ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener { |
| 96 | ++ |
| 97 | ++ private static final String SYS_KEY_CARRIERCONFIG2_ENABLE = "persist.security.carrierconfig2"; |
| 98 | ++ private static final String PREF_KEY_CARRIERCONFIG2_ENABLE = "carrierconfig2"; |
| 99 | ++ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category"; |
| 100 | ++ |
| 101 | ++ private PreferenceCategory mSecurityCategory; |
| 102 | ++ private SwitchPreference mCarrierConfig2Enable; |
| 103 | ++ private boolean mIsAdmin; |
| 104 | ++ private UserManager mUm; |
| 105 | ++ |
| 106 | ++ public CarrierConfig2PreferenceController(Context context) { |
| 107 | ++ super(context); |
| 108 | ++ mUm = UserManager.get(context); |
| 109 | ++ } |
| 110 | ++ |
| 111 | ++ @Override |
| 112 | ++ public void displayPreference(PreferenceScreen screen) { |
| 113 | ++ super.displayPreference(screen); |
| 114 | ++ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY); |
| 115 | ++ updatePreferenceState(); |
| 116 | ++ } |
| 117 | ++ |
| 118 | ++ @Override |
| 119 | ++ public boolean isAvailable() { |
| 120 | ++ mIsAdmin = mUm.isAdminUser(); |
| 121 | ++ return mIsAdmin; |
| 122 | ++ } |
| 123 | ++ |
| 124 | ++ @Override |
| 125 | ++ public String getPreferenceKey() { |
| 126 | ++ return PREF_KEY_CARRIERCONFIG2_ENABLE; |
| 127 | ++ } |
| 128 | ++ |
| 129 | ++ // TODO: should we use onCreatePreferences() instead? |
| 130 | ++ private void updatePreferenceState() { |
| 131 | ++ if (mSecurityCategory == null) { |
| 132 | ++ return; |
| 133 | ++ } |
| 134 | ++ |
| 135 | ++ if (mIsAdmin) { |
| 136 | ++ mCarrierConfig2Enable = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_CARRIERCONFIG2_ENABLE); |
| 137 | ++ mCarrierConfig2Enable.setChecked(SystemProperties.getInt(SYS_KEY_CARRIERCONFIG2_ENABLE, 0) == 1); |
| 138 | ++ } else { |
| 139 | ++ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_CARRIERCONFIG2_ENABLE)); |
| 140 | ++ } |
| 141 | ++ } |
| 142 | ++ |
| 143 | ++ @Override |
| 144 | ++ public void onResume() { |
| 145 | ++ updatePreferenceState(); |
| 146 | ++ if (mCarrierConfig2Enable != null) { |
| 147 | ++ boolean mode = mCarrierConfig2Enable.isChecked(); |
| 148 | ++ SystemProperties.set(SYS_KEY_CARRIERCONFIG2_ENABLE, mode ? "1" : "0"); |
| 149 | ++ } |
| 150 | ++ } |
| 151 | ++ |
| 152 | ++ @Override |
| 153 | ++ public boolean onPreferenceChange(Preference preference, Object value) { |
| 154 | ++ final String key = preference.getKey(); |
| 155 | ++ if (PREF_KEY_CARRIERCONFIG2_ENABLE.equals(key)) { |
| 156 | ++ final boolean mode = !mCarrierConfig2Enable.isChecked(); |
| 157 | ++ SystemProperties.set(SYS_KEY_CARRIERCONFIG2_ENABLE, mode ? "1" : "0"); |
| 158 | ++ } |
| 159 | ++ return true; |
| 160 | ++ } |
| 161 | ++} |
| 162 | +diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java |
| 163 | +index ef92897f88..b1e27f6ce2 100644 |
| 164 | +--- a/src/com/android/settings/security/SecuritySettings.java |
| 165 | ++++ b/src/com/android/settings/security/SecuritySettings.java |
| 166 | +@@ -111,6 +111,7 @@ public class SecuritySettings extends DashboardFragment { |
| 167 | + securityPreferenceControllers.add(new HostsPreferenceController(context)); |
| 168 | + securityPreferenceControllers.add(new SigSpoofPreferenceController(context)); |
| 169 | + securityPreferenceControllers.add(new OpenEuiccPreferenceController(context)); |
| 170 | ++ securityPreferenceControllers.add(new CarrierConfig2PreferenceController(context)); |
| 171 | + controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY) |
| 172 | + .setChildren(securityPreferenceControllers)); |
| 173 | + controllers.addAll(securityPreferenceControllers); |
0 commit comments