[Settings] eSIM transfer: MobileNetworkListFragment

- Remove the eSIM/pSIM category and separators
 - Add pSIM/eSIM icon for SIMs

Screenshot: https://hsv.googleplex.com/5263071317590016

Bug: 261810065
Test: atest NetworkProviderSimListControllerTest
Change-Id: If4b8659c377698e682093e1508699bfc96855b29
This commit is contained in:
Zoey Chen
2022-12-09 16:21:48 +00:00
parent 9ca3255c2d
commit f1d040a0e4
13 changed files with 63 additions and 1117 deletions

View File

@@ -1,173 +0,0 @@
/*
* Copyright (C) 2019 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 com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.ArrayMap;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.List;
import java.util.Map;
/**
* This populates the entries on a page which lists all available mobile subscriptions. Each entry
* has the name of the subscription with some subtext giving additional detail, and clicking on the
* entry brings you to a details page for that network.
*
* @deprecated This class will be removed in Android U, use
* {@link NetworkProviderSimsCategoryController} and
* {@link NetworkProviderDownloadedSimsCategoryController} instead.
*/
@Deprecated
public class MobileNetworkListController extends AbstractPreferenceController implements
LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
private static final String TAG = "MobileNetworkListCtlr";
@VisibleForTesting
static final String KEY_ADD_MORE = "add_more";
private SubscriptionManager mSubscriptionManager;
private SubscriptionsChangeListener mChangeListener;
private PreferenceScreen mPreferenceScreen;
private Map<Integer, Preference> mPreferences;
public MobileNetworkListController(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();
update();
}
@OnLifecycleEvent(ON_PAUSE)
public void onPause() {
mChangeListener.stop();
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreferenceScreen = screen;
mPreferenceScreen.findPreference(KEY_ADD_MORE).setVisible(
MobileNetworkUtils.showEuiccSettings(mContext));
update();
}
private void update() {
if (mPreferenceScreen == null) {
return;
}
// Since we may already have created some preferences previously, we first grab the list of
// those, then go through the current available subscriptions making sure they are all
// present in the screen, and finally remove any now-outdated ones.
final Map<Integer, Preference> existingPreferences = mPreferences;
mPreferences = new ArrayMap<>();
final List<SubscriptionInfo> subscriptions = SubscriptionUtil.getAvailableSubscriptions(
mContext);
for (SubscriptionInfo info : subscriptions) {
final int subId = info.getSubscriptionId();
Preference pref = existingPreferences.remove(subId);
if (pref == null) {
pref = new Preference(mPreferenceScreen.getContext());
mPreferenceScreen.addPreference(pref);
}
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
info, mContext);
pref.setTitle(displayName);
if (info.isEmbedded()) {
if (mSubscriptionManager.isActiveSubscriptionId(subId)) {
pref.setSummary(R.string.mobile_network_active_esim);
} else {
pref.setSummary(R.string.mobile_network_inactive_esim);
}
} else {
if (mSubscriptionManager.isActiveSubscriptionId(subId)) {
pref.setSummary(R.string.mobile_network_active_sim);
} else if (SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
pref.setSummary(mContext.getString(R.string.mobile_network_inactive_sim));
} else {
pref.setSummary(mContext.getString(R.string.mobile_network_tap_to_activate,
displayName));
}
}
pref.setOnPreferenceClickListener(clickedPref -> {
if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)
&& !SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
SubscriptionUtil.startToggleSubscriptionDialogActivity(mContext, subId, true);
} else {
final Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
intent.setPackage(SETTINGS_PACKAGE_NAME);
intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
mContext.startActivity(intent);
}
return true;
});
mPreferences.put(subId, pref);
}
for (Preference pref : existingPreferences.values()) {
mPreferenceScreen.removePreference(pref);
}
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return null;
}
@Override
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
}
@Override
public void onSubscriptionsChanged() {
update();
}
}

View File

@@ -26,6 +26,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
@@ -38,9 +39,7 @@ 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";
private static final String KEY_ADD_SIM = "add_sim";
@Override
public void onResume() {
@@ -50,6 +49,8 @@ public class MobileNetworkListFragment extends DashboardFragment {
if (prefListView != null) {
prefListView.setItemAnimator(null);
}
findPreference(KEY_ADD_SIM).setVisible(MobileNetworkUtils.showEuiccSettings(getContext()));
}
@Override
@@ -79,10 +80,6 @@ public class MobileNetworkListFragment extends DashboardFragment {
new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM,
getSettingsLifecycle(), this);
controllers.add(simCategoryPrefCtrl);
NetworkProviderDownloadedSimsCategoryController downloadedSimsCategoryCtrl =
new NetworkProviderDownloadedSimsCategoryController(context,
KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM, getSettingsLifecycle(), this);
controllers.add(downloadedSimsCategoryCtrl);
return controllers;
}

View File

@@ -1,204 +0,0 @@
/*
* 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.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleOwner;
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.MobileNetworkUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.mobile.dataservice.DataServiceUtils;
import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity;
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
import com.android.settingslib.mobile.dataservice.UiccInfoEntity;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class NetworkProviderDownloadedSimListController extends
AbstractPreferenceController implements
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback {
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 PreferenceCategory mPreferenceCategory;
private Map<Integer, Preference> mPreferences;
private LifecycleOwner mLifecycleOwner;
private MobileNetworkRepository mMobileNetworkRepository;
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
public NetworkProviderDownloadedSimListController(Context context, Lifecycle lifecycle,
LifecycleOwner lifecycleOwner) {
super(context);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mPreferences = new ArrayMap<>();
mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
lifecycle.addObserver(this);
}
@OnLifecycleEvent(ON_RESUME)
public void onResume() {
mMobileNetworkRepository.addRegister(mLifecycleOwner);
update();
}
@OnLifecycleEvent(ON_PAUSE)
public void onPause() {
mMobileNetworkRepository.removeRegister();
}
@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<SubscriptionInfoEntity> subscriptions = getAvailableDownloadedSubscriptions();
for (SubscriptionInfoEntity info : subscriptions) {
final int subId = Integer.parseInt(info.subId);
Preference pref = existingPreferences.remove(subId);
if (pref == null) {
pref = new Preference(mPreferenceCategory.getContext());
mPreferenceCategory.addPreference(pref);
}
final CharSequence displayName = info.uniqueName;
pref.setTitle(displayName);
pref.setSummary(getSummary(info));
pref.setOnPreferenceClickListener(clickedPref -> {
MobileNetworkUtils.launchMobileNetworkSettings(mContext, info);
return true;
});
mPreferences.put(subId, pref);
}
for (Preference pref : existingPreferences.values()) {
mPreferenceCategory.removePreference(pref);
}
}
public CharSequence getSummary(SubscriptionInfoEntity subInfo) {
if (subInfo.isActiveSubscriptionId) {
CharSequence config = subInfo.defaultSimConfig;
CharSequence summary = mContext.getResources().getString(
R.string.sim_category_active_sim);
if (config == "") {
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;
}
@VisibleForTesting
protected List<SubscriptionInfoEntity> getAvailableDownloadedSubscriptions() {
List<SubscriptionInfoEntity> subList = new ArrayList<>();
for (SubscriptionInfoEntity info : mSubInfoEntityList) {
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 onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
if (DataServiceUtils.shouldUpdateEntityList(mSubInfoEntityList, subInfoEntityList)) {
mSubInfoEntityList = subInfoEntityList;
mPreferenceCategory.setVisible(isAvailable());
update();
}
}
@Override
public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> activeSubInfoList) {
}
@Override
public void onAllUiccInfoChanged(List<UiccInfoEntity> uiccInfoEntityList) {
}
@Override
public void onAllMobileNetworkInfoChanged(
List<MobileNetworkInfoEntity> mobileNetworkInfoEntityList) {
}
}

View File

@@ -1,68 +0,0 @@
package com.android.settings.network;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
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 LOG_TAG = "NetworkProviderDownloadedSimsCategoryController";
private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM =
"provider_model_downloaded_sim_category";
private PreferenceCategory mPreferenceCategory;
private NetworkProviderDownloadedSimListController mNetworkProviderDownloadedSimListController;
public NetworkProviderDownloadedSimsCategoryController(Context context, String key,
Lifecycle lifecycle, LifecycleOwner lifecycleOwner) {
super(context, key);
mNetworkProviderDownloadedSimListController =
new NetworkProviderDownloadedSimListController(mContext, lifecycle, lifecycleOwner);
}
@Override
public int getAvailabilityStatus() {
if (mNetworkProviderDownloadedSimListController == null
|| !mNetworkProviderDownloadedSimListController.isAvailable()) {
return CONDITIONALLY_UNAVAILABLE;
} else {
return AVAILABLE;
}
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mNetworkProviderDownloadedSimListController.displayPreference(screen);
mPreferenceCategory = screen.findPreference(
KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM);
if (mPreferenceCategory == null) {
Log.d(LOG_TAG, "displayPreference(), Can not find the category.");
return;
}
mPreferenceCategory.setVisible(isAvailable());
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mPreferenceCategory == null) {
Log.d(LOG_TAG, "updateState(), Can not find the category.");
return;
}
int count = mPreferenceCategory.getPreferenceCount();
String title = mContext.getString(count > 1
? R.string.downloaded_sims_category_title
: R.string.downloaded_sim_category_title);
mPreferenceCategory.setTitle(title);
}
}

View File

@@ -19,13 +19,9 @@ 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.graphics.drawable.Drawable;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
import android.util.Log;
@@ -38,6 +34,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -58,7 +55,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
private SubscriptionManager mSubscriptionManager;
private PreferenceCategory mPreferenceCategory;
private Map<Integer, Preference> mPreferences;
private Map<Integer, RestrictedPreference> mPreferences;
private LifecycleOwner mLifecycleOwner;
private MobileNetworkRepository mMobileNetworkRepository;
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
@@ -96,25 +93,27 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
return;
}
final Map<Integer, Preference> existingPreferences = mPreferences;
final Map<Integer, RestrictedPreference> existingPreferences = mPreferences;
mPreferences = new ArrayMap<>();
final List<SubscriptionInfoEntity> subscriptions = getAvailablePhysicalSubscriptions();
for (SubscriptionInfoEntity info : subscriptions) {
final int subId = Integer.parseInt(info.subId);
Preference pref = existingPreferences.remove(subId);
RestrictedPreference pref = existingPreferences.remove(subId);
if (pref == null) {
pref = new Preference(mPreferenceCategory.getContext());
pref = new RestrictedPreference(mPreferenceCategory.getContext());
mPreferenceCategory.addPreference(pref);
}
final CharSequence displayName = info.uniqueName;
pref.setTitle(displayName);
boolean isActiveSubscriptionId = info.isActiveSubscriptionId;
pref.setSummary(getSummary(info, displayName));
final Drawable drawable = mContext.getDrawable(
info.isEmbedded ? R.drawable.ic_sim_card_download : R.drawable.ic_sim_card);
pref.setIcon(drawable);
pref.setOnPreferenceClickListener(clickedPref -> {
if (!isActiveSubscriptionId && !SubscriptionUtil.showToggleForPhysicalSim(
mSubscriptionManager)) {
if (!info.isEmbedded && !isActiveSubscriptionId
&& !SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
SubscriptionUtil.startToggleSubscriptionDialogActivity(mContext, subId,
true);
} else {
@@ -124,7 +123,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
});
mPreferences.put(subId, pref);
}
for (Preference pref : existingPreferences.values()) {
for (RestrictedPreference pref : existingPreferences.values()) {
mPreferenceCategory.removePreference(pref);
}
}
@@ -141,10 +140,13 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
activeSim.append(summary).append(config);
return activeSim;
}
} else if (SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
return mContext.getString(R.string.sim_category_inactive_sim);
} else {
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
if (!subInfo.isEmbedded && !SubscriptionUtil.showToggleForPhysicalSim(
mSubscriptionManager)) {
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
} else {
return mContext.getString(R.string.sim_category_inactive_sim);
}
}
}
@@ -160,9 +162,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
protected List<SubscriptionInfoEntity> getAvailablePhysicalSubscriptions() {
List<SubscriptionInfoEntity> subList = new ArrayList<>();
for (SubscriptionInfoEntity info : mSubInfoEntityList) {
if (!info.isEmbedded) {
subList.add(info);
}
subList.add(info);
}
return subList;
}

View File

@@ -64,18 +64,4 @@ public class NetworkProviderSimsCategoryController extends PreferenceCategoryCon
}
mPreferenceCategory.setVisible(isAvailable());
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mPreferenceCategory == null) {
Log.d(LOG_TAG, "updateState(), Can not find the category.");
return;
}
int count = mPreferenceCategory.getPreferenceCount();
String title = mContext.getString(count > 1
? R.string.provider_network_settings_title
: R.string.sim_category_title);
mPreferenceCategory.setTitle(title);
}
}