LeOS-GSI/patches/leos/platform_packages_apps_Sett.../0003-OpenEUICC_Toggle.patch

148 lines
5.5 KiB
Diff

From 0ea0c42f5974018fa1f6732449c90c4d54b00c4e Mon Sep 17 00:00:00 2001
From: harvey186 <harvey186@hotmail.com>
Date: Sat, 21 Oct 2023 11:33:27 +0200
Subject: [PATCH] 0017-OpenEUICC_Toggle
Change-Id: I74ef245ba7a6e8f87fb52e4e73c8a190529701c1
---
0017-OpenEUICC_Toggle.patch | 44 +-------
res/values/arrays.xml | 21 ++++
res/values/strings.xml | 2 +
res/xml/security_dashboard_settings.xml | 6 +
.../OpenEuiccPreferenceController.java | 106 ++++++++++++++++++
.../settings/security/SecuritySettings.java | 1 +
6 files changed, 137 insertions(+), 43 deletions(-)
create mode 100644 src/com/android/settings/security/OpenEuiccPreferenceController.java
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e41c39cebf..bca428f730 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12124,6 +12124,8 @@
<string name="color_selector_dialog_done">Done</string>
<!-- Button to close the dialog without saving in screen flash color selection dialog. [CHAR LIMIT=20] -->
<string name="color_selector_dialog_cancel">Cancel</string>
+ <string name="openeuicc_title">Enable eUICC management</string>
+ <string name="openeuicc_summary">Enables the OpenEUICC app to allow management of virtual (eSIM) and physical eUICC cards. Reboot required after toggling.</string>
<!-- Title for the contrast preference fragment [CHAR LIMIT=35] -->
<string name="contrast_title">Contrast</string>
diff --git a/src/com/android/settings/security/OpenEuiccPreferenceController.java b/src/com/android/settings/security/OpenEuiccPreferenceController.java
new file mode 100644
index 0000000000..9ecfa96bfd
--- /dev/null
+++ b/src/com/android/settings/security/OpenEuiccPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings.security;
+
+import android.content.Context;
+
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.SystemProperties;
+
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class OpenEuiccPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
+
+ private static final String SYS_KEY_OPENEUICC_ENABLE = "persist.security.openeuicc";
+ private static final String PREF_KEY_OPENEUICC_ENABLE = "openeuicc";
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
+
+ private PreferenceCategory mSecurityCategory;
+ private SwitchPreference mOpenEuiccEnable;
+ private boolean mIsAdmin;
+ private UserManager mUm;
+
+ public OpenEuiccPreferenceController(Context context) {
+ super(context);
+ mUm = UserManager.get(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updatePreferenceState();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ mIsAdmin = mUm.isAdminUser();
+ return mIsAdmin;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_OPENEUICC_ENABLE;
+ }
+
+ // TODO: should we use onCreatePreferences() instead?
+ private void updatePreferenceState() {
+ if (mSecurityCategory == null) {
+ return;
+ }
+
+ if (mIsAdmin) {
+ mOpenEuiccEnable = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_OPENEUICC_ENABLE);
+ mOpenEuiccEnable.setChecked(SystemProperties.getInt(SYS_KEY_OPENEUICC_ENABLE, 0) == 1);
+ } else {
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_OPENEUICC_ENABLE));
+ }
+ }
+
+ @Override
+ public void onResume() {
+ updatePreferenceState();
+ if (mOpenEuiccEnable != null) {
+ boolean mode = mOpenEuiccEnable.isChecked();
+ SystemProperties.set(SYS_KEY_OPENEUICC_ENABLE, mode ? "1" : "0");
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ final String key = preference.getKey();
+ if (PREF_KEY_OPENEUICC_ENABLE.equals(key)) {
+ final boolean mode = !mOpenEuiccEnable.isChecked();
+ SystemProperties.set(SYS_KEY_OPENEUICC_ENABLE, mode ? "1" : "0");
+ }
+ return true;
+ }
+}
--
2.34.1