Loading res/values/strings.xml +16 −0 Original line number Diff line number Diff line Loading @@ -13248,6 +13248,22 @@ <string name="carrier_wifi_offload_summary">Allow Google Fi to use W+ networks to improve speed and coverage</string> <!-- Title for merged carrier Wi-Fi network information. [CHAR LIMIT=NONE] --> <string name="carrier_wifi_network_title">W+ network</string> <!-- Provider Model: title of SIM category --> <string name="sim_category_title">SIM</string> <!-- Provider Model: title of Downloaded category. [CHAR LIMIT=50] --> <string name="downloaded_sim_category_title">DOWNLOADED SIM</string> <!-- Provider Model: summary of Active in SIM category. [CHAR LIMIT=50] --> <string name="sim_category_active_sim">Active</string> <!-- Provider Model: summary of Inactive in SIM category. [CHAR LIMIT=50] --> <string name="sim_category_inactive_sim">Inactive</string> <!-- Provider Model: summary of default config. [CHAR LIMIT=50] --> <string name="sim_category_default_active_sim">\u0020/ Default for <xliff:g name="default_sim_config" example=" / Default for calls">%1$s</xliff:g></string> <!-- Provider Model: summary of default call. [CHAR LIMIT=50] --> <string name="default_active_sim_calls">calls</string> <!-- Provider Model: summary of default SMS. [CHAR LIMIT=50] --> <string name="default_active_sim_sms">SMS</string> <!-- Provider Model: summary of default mobile data. [CHAR LIMIT=50] --> <string name="default_active_sim_mobile_data">mobile data</string> <!-- Summary text separator for preferences including a short description (eg. "Connected / 5G"). [CHAR LIMIT=50] --> res/xml/network_provider_sims_list.xml 0 → 100644 +50 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2021 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto" android:title="@string/provider_network_settings_title"> <PreferenceCategory android:key="provider_model_sim_category" android:title="@string/sim_category_title" android:order="20" settings:controller="com.android.settings.network.NetworkProviderSimsCategoryController"/> <PreferenceCategory android:key="provider_model_downloaded_sim_category" android:title="@string/downloaded_sim_category_title" android:order="25" settings:controller= "com.android.settings.network.NetworkProviderDownloadedSimsCategoryController" settings:allowDividerAbove="true"/> <com.android.settingslib.RestrictedPreference android:key="add_more" settings:isPreferenceVisible="false" settings:userRestriction="no_config_mobile_networks" settings:useAdminDisabledSummary="true" settings:searchable="false" android:title="@string/mobile_network_list_add_more" android:icon="@drawable/ic_menu_add_activated_tint" android:order="100"> <intent android:action="android.telephony.euicc.action.PROVISION_EMBEDDED_SUBSCRIPTION"> <extra android:name="android.telephony.euicc.extra.FORCE_PROVISION" android:value="true"/> </intent> </com.android.settingslib.RestrictedPreference> </PreferenceScreen> src/com/android/settings/network/MobileNetworkListFragment.java +41 −3 Original line number Diff line number Diff line Loading @@ -19,8 +19,12 @@ package com.android.settings.network; import android.app.settings.SettingsEnums; import android.content.Context; import android.os.UserManager; import android.provider.SearchIndexableResource; import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.core.AbstractPreferenceController; Loading @@ -33,9 +37,16 @@ import java.util.List; public class MobileNetworkListFragment extends DashboardFragment { private static final String LOG_TAG = "NetworkListFragment"; static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category"; @VisibleForTesting static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM = "provider_model_downloaded_sim_category"; @Override protected int getPreferenceScreenResId() { return R.xml.mobile_network_list; return Utils.isProviderModelEnabled(getContext()) ? R.xml.network_provider_sims_list : R.xml.mobile_network_list; } @Override Loading @@ -51,12 +62,39 @@ public class MobileNetworkListFragment extends DashboardFragment { @Override protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); if (Utils.isProviderModelEnabled(getContext())) { NetworkProviderSimsCategoryController simCategoryPrefCtrl = new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM); simCategoryPrefCtrl.init(getSettingsLifecycle()); controllers.add(simCategoryPrefCtrl); NetworkProviderDownloadedSimsCategoryController downloadedSimsCategoryCtrl = new NetworkProviderDownloadedSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM); downloadedSimsCategoryCtrl.init(getSettingsLifecycle()); controllers.add(downloadedSimsCategoryCtrl); } else { controllers.add(new MobileNetworkListController(getContext(), getLifecycle())); } return controllers; } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider(R.xml.mobile_network_list) { new BaseSearchIndexProvider() { @Override public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, boolean enabled) { final ArrayList<SearchIndexableResource> result = new ArrayList<>(); final SearchIndexableResource sir = new SearchIndexableResource(context); sir.xmlResId = Utils.isProviderModelEnabled(context) ? R.xml.network_provider_sims_list : R.xml.mobile_network_list; result.add(sir); return result; } @Override protected boolean isPageSearchEnabled(Context context) { Loading src/com/android/settings/network/NetworkProviderDownloadedSimListController.java 0 → 100644 +213 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.network; import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.ArrayMap; import androidx.annotation.VisibleForTesting; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.network.telephony.MobileNetworkUtils; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import java.util.ArrayList; import java.util.List; import java.util.Map; public class NetworkProviderDownloadedSimListController extends AbstractPreferenceController implements LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient { private static final String TAG = "NetworkProviderDownloadedSimListCtrl"; private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM = "provider_model_downloaded_sim_category"; private static final String KEY_PREFERENCE_DOWNLOADED_SIM = "provider_model_downloaded_sim_list"; private static final String KEY_ADD_MORE = "add_more"; private SubscriptionManager mSubscriptionManager; private SubscriptionsChangeListener mChangeListener; private PreferenceCategory mPreferenceCategory; private Map<Integer, Preference> mPreferences; public NetworkProviderDownloadedSimListController(Context context, Lifecycle lifecycle) { super(context); mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mChangeListener = new SubscriptionsChangeListener(context, this); mPreferences = new ArrayMap<>(); lifecycle.addObserver(this); } @OnLifecycleEvent(ON_RESUME) public void onResume() { mChangeListener.start(); IntentFilter filter = new IntentFilter(); filter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); mContext.registerReceiver(mDataSubscriptionChangedReceiver, filter); update(); } @OnLifecycleEvent(ON_PAUSE) public void onPause() { mChangeListener.stop(); if (mDataSubscriptionChangedReceiver != null) { mContext.unregisterReceiver(mDataSubscriptionChangedReceiver); } } @VisibleForTesting final BroadcastReceiver mDataSubscriptionChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { update(); } } }; @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM); screen.findPreference(KEY_ADD_MORE).setVisible( MobileNetworkUtils.showEuiccSettings(mContext)); update(); } private void update() { if (mPreferenceCategory == null) { return; } final Map<Integer, Preference> existingPreferences = mPreferences; mPreferences = new ArrayMap<>(); final List<SubscriptionInfo> subscriptions = getAvailableDownloadedSubscriptions(); for (SubscriptionInfo info : subscriptions) { final int subId = info.getSubscriptionId(); Preference pref = existingPreferences.remove(subId); if (pref == null) { pref = new Preference(mPreferenceCategory.getContext()); mPreferenceCategory.addPreference(pref); } final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName( info, mContext); pref.setTitle(displayName); pref.setSummary(getSummary(subId)); pref.setOnPreferenceClickListener(clickedPref -> { final Intent intent = new Intent(mContext, MobileNetworkActivity.class); intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId()); mContext.startActivity(intent); return true; }); mPreferences.put(subId, pref); } for (Preference pref : existingPreferences.values()) { mPreferenceCategory.removePreference(pref); } } public CharSequence getSummary(int subId) { if (mSubscriptionManager.isActiveSubscriptionId(subId)) { CharSequence config = SubscriptionUtil.getDefaultSimConfig(mContext, subId); CharSequence summary = mContext.getResources().getString( R.string.sim_category_active_sim); if (config == null) { return summary; } else { final StringBuilder activeSim = new StringBuilder(); activeSim.append(summary).append(config); return activeSim; } } else { return mContext.getString(R.string.sim_category_inactive_sim); } } @Override public boolean isAvailable() { if (!getAvailableDownloadedSubscriptions().isEmpty()) { return true; } return false; } @Override public String getPreferenceKey() { return KEY_PREFERENCE_DOWNLOADED_SIM; } private List<SubscriptionInfo> getAvailableDownloadedSubscriptions() { List<SubscriptionInfo> subList = new ArrayList<>(); for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) { if (info.isEmbedded()) { subList.add(info); } } return subList; } @Override public void updateState(Preference preference) { super.updateState(preference); refreshSummary(mPreferenceCategory); update(); } @Override public void onAirplaneModeChanged(boolean airplaneModeEnabled) { } @Override public void onSubscriptionsChanged() { update(); } @VisibleForTesting protected int getDefaultVoiceSubscriptionId() { return SubscriptionManager.getDefaultVoiceSubscriptionId(); } @VisibleForTesting protected int getDefaultSmsSubscriptionId() { return SubscriptionManager.getDefaultSmsSubscriptionId(); } @VisibleForTesting protected int getDefaultDataSubscriptionId() { return SubscriptionManager.getDefaultDataSubscriptionId(); } } src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryController.java 0 → 100644 +52 −0 Original line number Diff line number Diff line package com.android.settings.network; import android.content.Context; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.widget.PreferenceCategoryController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; public class NetworkProviderDownloadedSimsCategoryController extends PreferenceCategoryController implements LifecycleObserver { private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM = "provider_model_downloaded_sim_category"; private NetworkProviderDownloadedSimListController mNetworkProviderDownloadedSimListController; public NetworkProviderDownloadedSimsCategoryController(Context context, String key) { super(context, key); } public void init(Lifecycle lifecycle) { mNetworkProviderDownloadedSimListController = createDownloadedSimListController(lifecycle); } @VisibleForTesting protected NetworkProviderDownloadedSimListController createDownloadedSimListController( Lifecycle lifecycle) { return new NetworkProviderDownloadedSimListController(mContext, lifecycle); } @Override public int getAvailabilityStatus() { if (mNetworkProviderDownloadedSimListController == null || !mNetworkProviderDownloadedSimListController.isAvailable()) { return CONDITIONALLY_UNAVAILABLE; } else { return AVAILABLE; } } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); PreferenceCategory preferenceCategory = screen.findPreference( KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM); preferenceCategory.setVisible(isAvailable()); mNetworkProviderDownloadedSimListController.displayPreference(screen); } } Loading
res/values/strings.xml +16 −0 Original line number Diff line number Diff line Loading @@ -13248,6 +13248,22 @@ <string name="carrier_wifi_offload_summary">Allow Google Fi to use W+ networks to improve speed and coverage</string> <!-- Title for merged carrier Wi-Fi network information. [CHAR LIMIT=NONE] --> <string name="carrier_wifi_network_title">W+ network</string> <!-- Provider Model: title of SIM category --> <string name="sim_category_title">SIM</string> <!-- Provider Model: title of Downloaded category. [CHAR LIMIT=50] --> <string name="downloaded_sim_category_title">DOWNLOADED SIM</string> <!-- Provider Model: summary of Active in SIM category. [CHAR LIMIT=50] --> <string name="sim_category_active_sim">Active</string> <!-- Provider Model: summary of Inactive in SIM category. [CHAR LIMIT=50] --> <string name="sim_category_inactive_sim">Inactive</string> <!-- Provider Model: summary of default config. [CHAR LIMIT=50] --> <string name="sim_category_default_active_sim">\u0020/ Default for <xliff:g name="default_sim_config" example=" / Default for calls">%1$s</xliff:g></string> <!-- Provider Model: summary of default call. [CHAR LIMIT=50] --> <string name="default_active_sim_calls">calls</string> <!-- Provider Model: summary of default SMS. [CHAR LIMIT=50] --> <string name="default_active_sim_sms">SMS</string> <!-- Provider Model: summary of default mobile data. [CHAR LIMIT=50] --> <string name="default_active_sim_mobile_data">mobile data</string> <!-- Summary text separator for preferences including a short description (eg. "Connected / 5G"). [CHAR LIMIT=50] -->
res/xml/network_provider_sims_list.xml 0 → 100644 +50 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2021 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto" android:title="@string/provider_network_settings_title"> <PreferenceCategory android:key="provider_model_sim_category" android:title="@string/sim_category_title" android:order="20" settings:controller="com.android.settings.network.NetworkProviderSimsCategoryController"/> <PreferenceCategory android:key="provider_model_downloaded_sim_category" android:title="@string/downloaded_sim_category_title" android:order="25" settings:controller= "com.android.settings.network.NetworkProviderDownloadedSimsCategoryController" settings:allowDividerAbove="true"/> <com.android.settingslib.RestrictedPreference android:key="add_more" settings:isPreferenceVisible="false" settings:userRestriction="no_config_mobile_networks" settings:useAdminDisabledSummary="true" settings:searchable="false" android:title="@string/mobile_network_list_add_more" android:icon="@drawable/ic_menu_add_activated_tint" android:order="100"> <intent android:action="android.telephony.euicc.action.PROVISION_EMBEDDED_SUBSCRIPTION"> <extra android:name="android.telephony.euicc.extra.FORCE_PROVISION" android:value="true"/> </intent> </com.android.settingslib.RestrictedPreference> </PreferenceScreen>
src/com/android/settings/network/MobileNetworkListFragment.java +41 −3 Original line number Diff line number Diff line Loading @@ -19,8 +19,12 @@ package com.android.settings.network; import android.app.settings.SettingsEnums; import android.content.Context; import android.os.UserManager; import android.provider.SearchIndexableResource; import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.core.AbstractPreferenceController; Loading @@ -33,9 +37,16 @@ import java.util.List; public class MobileNetworkListFragment extends DashboardFragment { private static final String LOG_TAG = "NetworkListFragment"; static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category"; @VisibleForTesting static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM = "provider_model_downloaded_sim_category"; @Override protected int getPreferenceScreenResId() { return R.xml.mobile_network_list; return Utils.isProviderModelEnabled(getContext()) ? R.xml.network_provider_sims_list : R.xml.mobile_network_list; } @Override Loading @@ -51,12 +62,39 @@ public class MobileNetworkListFragment extends DashboardFragment { @Override protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); if (Utils.isProviderModelEnabled(getContext())) { NetworkProviderSimsCategoryController simCategoryPrefCtrl = new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM); simCategoryPrefCtrl.init(getSettingsLifecycle()); controllers.add(simCategoryPrefCtrl); NetworkProviderDownloadedSimsCategoryController downloadedSimsCategoryCtrl = new NetworkProviderDownloadedSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM); downloadedSimsCategoryCtrl.init(getSettingsLifecycle()); controllers.add(downloadedSimsCategoryCtrl); } else { controllers.add(new MobileNetworkListController(getContext(), getLifecycle())); } return controllers; } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider(R.xml.mobile_network_list) { new BaseSearchIndexProvider() { @Override public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, boolean enabled) { final ArrayList<SearchIndexableResource> result = new ArrayList<>(); final SearchIndexableResource sir = new SearchIndexableResource(context); sir.xmlResId = Utils.isProviderModelEnabled(context) ? R.xml.network_provider_sims_list : R.xml.mobile_network_list; result.add(sir); return result; } @Override protected boolean isPageSearchEnabled(Context context) { Loading
src/com/android/settings/network/NetworkProviderDownloadedSimListController.java 0 → 100644 +213 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.network; import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.ArrayMap; import androidx.annotation.VisibleForTesting; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.network.telephony.MobileNetworkUtils; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import java.util.ArrayList; import java.util.List; import java.util.Map; public class NetworkProviderDownloadedSimListController extends AbstractPreferenceController implements LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient { private static final String TAG = "NetworkProviderDownloadedSimListCtrl"; private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM = "provider_model_downloaded_sim_category"; private static final String KEY_PREFERENCE_DOWNLOADED_SIM = "provider_model_downloaded_sim_list"; private static final String KEY_ADD_MORE = "add_more"; private SubscriptionManager mSubscriptionManager; private SubscriptionsChangeListener mChangeListener; private PreferenceCategory mPreferenceCategory; private Map<Integer, Preference> mPreferences; public NetworkProviderDownloadedSimListController(Context context, Lifecycle lifecycle) { super(context); mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mChangeListener = new SubscriptionsChangeListener(context, this); mPreferences = new ArrayMap<>(); lifecycle.addObserver(this); } @OnLifecycleEvent(ON_RESUME) public void onResume() { mChangeListener.start(); IntentFilter filter = new IntentFilter(); filter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); mContext.registerReceiver(mDataSubscriptionChangedReceiver, filter); update(); } @OnLifecycleEvent(ON_PAUSE) public void onPause() { mChangeListener.stop(); if (mDataSubscriptionChangedReceiver != null) { mContext.unregisterReceiver(mDataSubscriptionChangedReceiver); } } @VisibleForTesting final BroadcastReceiver mDataSubscriptionChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { update(); } } }; @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM); screen.findPreference(KEY_ADD_MORE).setVisible( MobileNetworkUtils.showEuiccSettings(mContext)); update(); } private void update() { if (mPreferenceCategory == null) { return; } final Map<Integer, Preference> existingPreferences = mPreferences; mPreferences = new ArrayMap<>(); final List<SubscriptionInfo> subscriptions = getAvailableDownloadedSubscriptions(); for (SubscriptionInfo info : subscriptions) { final int subId = info.getSubscriptionId(); Preference pref = existingPreferences.remove(subId); if (pref == null) { pref = new Preference(mPreferenceCategory.getContext()); mPreferenceCategory.addPreference(pref); } final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName( info, mContext); pref.setTitle(displayName); pref.setSummary(getSummary(subId)); pref.setOnPreferenceClickListener(clickedPref -> { final Intent intent = new Intent(mContext, MobileNetworkActivity.class); intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId()); mContext.startActivity(intent); return true; }); mPreferences.put(subId, pref); } for (Preference pref : existingPreferences.values()) { mPreferenceCategory.removePreference(pref); } } public CharSequence getSummary(int subId) { if (mSubscriptionManager.isActiveSubscriptionId(subId)) { CharSequence config = SubscriptionUtil.getDefaultSimConfig(mContext, subId); CharSequence summary = mContext.getResources().getString( R.string.sim_category_active_sim); if (config == null) { return summary; } else { final StringBuilder activeSim = new StringBuilder(); activeSim.append(summary).append(config); return activeSim; } } else { return mContext.getString(R.string.sim_category_inactive_sim); } } @Override public boolean isAvailable() { if (!getAvailableDownloadedSubscriptions().isEmpty()) { return true; } return false; } @Override public String getPreferenceKey() { return KEY_PREFERENCE_DOWNLOADED_SIM; } private List<SubscriptionInfo> getAvailableDownloadedSubscriptions() { List<SubscriptionInfo> subList = new ArrayList<>(); for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) { if (info.isEmbedded()) { subList.add(info); } } return subList; } @Override public void updateState(Preference preference) { super.updateState(preference); refreshSummary(mPreferenceCategory); update(); } @Override public void onAirplaneModeChanged(boolean airplaneModeEnabled) { } @Override public void onSubscriptionsChanged() { update(); } @VisibleForTesting protected int getDefaultVoiceSubscriptionId() { return SubscriptionManager.getDefaultVoiceSubscriptionId(); } @VisibleForTesting protected int getDefaultSmsSubscriptionId() { return SubscriptionManager.getDefaultSmsSubscriptionId(); } @VisibleForTesting protected int getDefaultDataSubscriptionId() { return SubscriptionManager.getDefaultDataSubscriptionId(); } }
src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryController.java 0 → 100644 +52 −0 Original line number Diff line number Diff line package com.android.settings.network; import android.content.Context; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.widget.PreferenceCategoryController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; public class NetworkProviderDownloadedSimsCategoryController extends PreferenceCategoryController implements LifecycleObserver { private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM = "provider_model_downloaded_sim_category"; private NetworkProviderDownloadedSimListController mNetworkProviderDownloadedSimListController; public NetworkProviderDownloadedSimsCategoryController(Context context, String key) { super(context, key); } public void init(Lifecycle lifecycle) { mNetworkProviderDownloadedSimListController = createDownloadedSimListController(lifecycle); } @VisibleForTesting protected NetworkProviderDownloadedSimListController createDownloadedSimListController( Lifecycle lifecycle) { return new NetworkProviderDownloadedSimListController(mContext, lifecycle); } @Override public int getAvailabilityStatus() { if (mNetworkProviderDownloadedSimListController == null || !mNetworkProviderDownloadedSimListController.isAvailable()) { return CONDITIONALLY_UNAVAILABLE; } else { return AVAILABLE; } } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); PreferenceCategory preferenceCategory = screen.findPreference( KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM); preferenceCategory.setVisible(isAvailable()); mNetworkProviderDownloadedSimListController.displayPreference(screen); } }