Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 2850ff6

Browse files
Runtime control of CarrierConfig2
Signed-off-by: Tavi <[email protected]>
1 parent 4328ec6 commit 2850ff6

File tree

4 files changed

+218
-2
lines changed

4 files changed

+218
-2
lines changed

Patches/LineageOS-20.0/android_packages_apps_Settings/0017-OpenEUICC_Toggle.patch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Date: Wed, 20 Apr 2022 01:04:27 -0400
44
Subject: [PATCH] Add a toggle for OpenEUICC enablement
55

66
Copy and pasted from the GrapheneOS exec spawning toggle patch
7+
TODO: MOVE OUT OF SECURITY CATEGORY
78

89
Change-Id: Ibea6ea9bed1c2ae3491f403d9e5c17c1d1c403f1
910
Signed-off-by: Tad <[email protected]>
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Tad <[email protected]>
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 &amp; 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);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Tavi <[email protected]>
3+
Date: Tue, 25 Jun 2024 02:39:28 -0400
4+
Subject: [PATCH] Runtime control of platform carrier config package
5+
6+
Change-Id: I8cc8f2bda264bd42fe83d5c96fa6382e63a88410
7+
Signed-off-by: Tavi <[email protected]>
8+
---
9+
src/com/android/phone/CarrierConfigLoader.java | 11 +++++++++--
10+
1 file changed, 9 insertions(+), 2 deletions(-)
11+
12+
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
13+
index 9a0da4bee..749df35f7 100644
14+
--- a/src/com/android/phone/CarrierConfigLoader.java
15+
+++ b/src/com/android/phone/CarrierConfigLoader.java
16+
@@ -43,6 +43,7 @@ import android.os.PersistableBundle;
17+
import android.os.Process;
18+
import android.os.RemoteException;
19+
import android.os.ResultReceiver;
20+
+import android.os.SystemProperties;
21+
import android.os.UserHandle;
22+
import android.preference.PreferenceManager;
23+
import android.service.carrier.CarrierIdentifier;
24+
@@ -688,8 +689,14 @@ public class CarrierConfigLoader extends ICarrierConfigLoader.Stub {
25+
/* package */ CarrierConfigLoader(@NonNull Context context,
26+
@NonNull SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
27+
mContext = context;
28+
- mPlatformCarrierConfigPackage =
29+
- mContext.getString(R.string.platform_carrier_config_package);
30+
+ if (SystemProperties.getBoolean("persist.security.carrierconfig2", false)) {
31+
+ mPlatformCarrierConfigPackage = "app.grapheneos.carrierconfig2";
32+
+ } else {
33+
+ //mPlatformCarrierConfigPackage = "com.android.carrierconfig";
34+
+ mPlatformCarrierConfigPackage =
35+
+ mContext.getString(R.string.platform_carrier_config_package);
36+
+ }
37+
+ Log.d("CarrierConfigPackageOverride", "Provider: " + mPlatformCarrierConfigPackage);
38+
mHandler = new ConfigHandler(looper);
39+
40+
IntentFilter systemEventsFilter = new IntentFilter();

Scripts/LineageOS-20.0/Patch.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ git revert --no-edit 09577521a65e1cef0560a84085fca46b1cf53803; #Fix invisible bu
264264
fi;
265265

266266
if enterAndClear "packages/apps/CarrierConfig2"; then
267+
awk -i inplace '!/overrides/' Android.bp; #Don't replace CarrierConfig
267268
sed -i -e '31,35d;' AndroidManifest.xml; #Fixups
268269
rm src/app/grapheneos/carrierconfig2/TestActivity.java src/app/grapheneos/carrierconfig2/loader/CmpTest.java;
269270
if [ -d "$DOS_BUILD_BASE"/vendor/divested-carriersettings ]; then sed -i 's|etc/CarrierSettings|etc/CarrierSettings2|' src/app/grapheneos/carrierconfig2/loader/CSettingsDir.java; fi; #Alter the search path
@@ -320,6 +321,7 @@ applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0014-LTE_Only_Mode-2.pat
320321
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0015-SUPL_Toggle.patch"; #Add a toggle for forcibly disabling SUPL (GrapheneOS)
321322
applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0016-microG_Toggle.patch"; #Add a toggle for microG enablement (heavily based off of a GrapheneOS patch)
322323
if [ "$DOS_DEBLOBBER_REMOVE_EUICC_FULL" = false ]; then applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0017-OpenEUICC_Toggle.patch"; fi; #Add a toggle for OpenEUICC enablement (heavily based off of a GrapheneOS patch)
324+
if [ -d "$DOS_BUILD_BASE"/vendor/divested-carriersettings ]; then applyPatch "$DOS_PATCHES/android_packages_apps_Settings/0018-CC2_Toggle.patch"; fi; #Add a toggle for CarrierConfig2 enablement (heavily based off of a GrapheneOS patch)
323325
applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Settings/0001-disable_apps.patch"; #Add an ability to disable non-system apps from the "App info" screen (GrapheneOS)
324326
fi;
325327

@@ -384,7 +386,7 @@ applyPatch "$DOS_PATCHES/android_packages_providers_DownloadProvider/0001-Networ
384386
fi;
385387

386388
if enterAndClear "packages/services/Telephony"; then
387-
if [ -d "$DOS_BUILD_BASE"/vendor/divested-carriersettings ]; then sed -i 's|com.android.carrierconfig|app.grapheneos.carrierconfig2|' res/values/config.xml; fi; #Alter the provider
389+
if [ -d "$DOS_BUILD_BASE"/vendor/divested-carriersettings ]; then applyPatch "$DOS_PATCHES/android_packages_services_Telephony/0001-CC2.patch"; fi; #Runtime control of platform carrier config package (DivestOS)
388390
fi;
389391

390392

@@ -457,7 +459,7 @@ sed -i 's/wifi,cell/internet/' overlay/common/frameworks/base/packages/SystemUI/
457459
sed -i 's|system/etc|$(TARGET_COPY_OUT_PRODUCT)/etc|' divestos.mk;
458460
if [ -d "$DOS_BUILD_BASE"/vendor/divested-carriersettings ]; then
459461
echo "Including CarrierConfig2 & CarrierSettings2";
460-
echo "ifneq ($(BOARD_WITHOUT_RADIO),true)" >> divestos.mk;
462+
echo 'ifneq ($(BOARD_WITHOUT_RADIO),true)' >> divestos.mk;
461463
echo "PRODUCT_PACKAGES += CarrierConfig2" >> divestos.mk;
462464
echo "include vendor/divested-carriersettings/CarrierSettings2.mk" >> divestos.mk;
463465
echo "endif" >> divestos.mk;

0 commit comments

Comments
 (0)