[Settings] Allow disabled SIM to be controlled in UI
Disabled SIM are hidden from UI due to the API only check if there's a SIM with mobile data capability active within device. Right now, the UI design has been changed. The UI here should be accessible no mater with or without the support of mobile data. Bug: 193820245 Bug: 194761536 Test: local Change-Id: I9c8b8fa16e74cd0fe4419966cc97ad55b5b87b17 (cherry picked from commit847f326cd4
) (cherry picked from commita8ce9abde7
)
This commit is contained in:
@@ -23,7 +23,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.euicc.EuiccManager;
|
||||
|
||||
@@ -36,8 +35,9 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.network.helper.SelectableSubscriptions;
|
||||
import com.android.settings.network.helper.SubscriptionAnnotation;
|
||||
import com.android.settings.network.telephony.MobileNetworkActivity;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.AddPreference;
|
||||
import com.android.settingslib.Utils;
|
||||
@@ -61,6 +61,8 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
private SubscriptionsChangeListener mChangeListener;
|
||||
private AddPreference mPreference;
|
||||
|
||||
private MobileNetworkSummaryStatus mStatusCache = new MobileNetworkSummaryStatus();
|
||||
|
||||
/**
|
||||
* This controls the summary text and click behavior of the "Mobile network" item on the
|
||||
* Network & internet page. There are 3 separate cases depending on the number of mobile network
|
||||
@@ -82,8 +84,8 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
if (lifecycle != null) {
|
||||
mChangeListener = new SubscriptionsChangeListener(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
mChangeListener = new SubscriptionsChangeListener(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,25 +108,24 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions(
|
||||
mContext);
|
||||
mStatusCache.update(mContext, null);
|
||||
List<SubscriptionAnnotation> subs = mStatusCache.getSubscriptionList();
|
||||
|
||||
if (subs.isEmpty()) {
|
||||
if (MobileNetworkUtils.showEuiccSettings(mContext)) {
|
||||
if (mStatusCache.isEuiccConfigSupport()) {
|
||||
return mContext.getResources().getString(
|
||||
R.string.mobile_network_summary_add_a_network);
|
||||
}
|
||||
return null;
|
||||
// set empty string to override previous text for carrier when SIM available
|
||||
return "";
|
||||
} else if (subs.size() == 1) {
|
||||
final SubscriptionInfo info = subs.get(0);
|
||||
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
||||
info, mContext);
|
||||
final int subId = info.getSubscriptionId();
|
||||
if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)
|
||||
&& !SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
|
||||
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
|
||||
} else {
|
||||
SubscriptionAnnotation info = subs.get(0);
|
||||
CharSequence displayName = mStatusCache.getDisplayName(info.getSubscriptionId());
|
||||
if (info.getSubInfo().isEmbedded() || info.isActive()
|
||||
|| mStatusCache.isPhysicalSimDisableSupport()) {
|
||||
return displayName;
|
||||
}
|
||||
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
|
||||
} else {
|
||||
if (com.android.settings.Utils.isProviderModelEnabled(mContext)) {
|
||||
return getSummaryForProviderModel(subs);
|
||||
@@ -135,10 +136,16 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getSummaryForProviderModel(List<SubscriptionInfo> subs) {
|
||||
return String.join(", ", subs.stream().map(subInfo -> {
|
||||
return SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext);
|
||||
}).collect(Collectors.toList()));
|
||||
private CharSequence getSummaryForProviderModel(List<SubscriptionAnnotation> subs) {
|
||||
return subs.stream()
|
||||
.mapToInt(SubscriptionAnnotation::getSubscriptionId)
|
||||
.mapToObj(subId -> mStatusCache.getDisplayName(subId))
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private void logPreferenceClick(Preference preference) {
|
||||
mMetricsFeatureProvider.logClickedPreference(preference,
|
||||
preference.getExtras().getInt(DashboardFragment.CATEGORY));
|
||||
}
|
||||
|
||||
private void startAddSimFlow() {
|
||||
@@ -147,62 +154,64 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (mPreference == null || mPreference.isDisabledByAdmin()) {
|
||||
return;
|
||||
}
|
||||
private void initPreference() {
|
||||
refreshSummary(mPreference);
|
||||
mPreference.setOnPreferenceClickListener(null);
|
||||
mPreference.setOnAddClickListener(null);
|
||||
mPreference.setFragment(null);
|
||||
mPreference.setEnabled(!mChangeListener.isAirplaneModeOn());
|
||||
}
|
||||
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions(
|
||||
mContext);
|
||||
private void update() {
|
||||
if (mPreference == null || mPreference.isDisabledByAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mStatusCache.update(mContext, statusCache -> initPreference());
|
||||
|
||||
List<SubscriptionAnnotation> subs = mStatusCache.getSubscriptionList();
|
||||
if (subs.isEmpty()) {
|
||||
if (MobileNetworkUtils.showEuiccSettings(mContext)) {
|
||||
if (mStatusCache.isEuiccConfigSupport()) {
|
||||
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
||||
mMetricsFeatureProvider.logClickedPreference(pref,
|
||||
pref.getExtras().getInt(DashboardFragment.CATEGORY));
|
||||
logPreferenceClick(pref);
|
||||
startAddSimFlow();
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
mPreference.setEnabled(false);
|
||||
}
|
||||
} else {
|
||||
// We have one or more existing subscriptions, so we want the plus button if eSIM is
|
||||
// supported.
|
||||
if (MobileNetworkUtils.showEuiccSettings(mContext)) {
|
||||
mPreference.setAddWidgetEnabled(!mChangeListener.isAirplaneModeOn());
|
||||
mPreference.setOnAddClickListener(p -> {
|
||||
mMetricsFeatureProvider.logClickedPreference(p,
|
||||
p.getExtras().getInt(DashboardFragment.CATEGORY));
|
||||
startAddSimFlow();
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (subs.size() == 1) {
|
||||
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
||||
mMetricsFeatureProvider.logClickedPreference(pref,
|
||||
pref.getExtras().getInt(DashboardFragment.CATEGORY));
|
||||
final SubscriptionInfo info = subs.get(0);
|
||||
final int subId = info.getSubscriptionId();
|
||||
if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)
|
||||
&& !SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)) {
|
||||
SubscriptionUtil.startToggleSubscriptionDialogActivity(
|
||||
mContext, subId, true);
|
||||
} else {
|
||||
final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
|
||||
intent.putExtra(Settings.EXTRA_SUB_ID, subs.get(0).getSubscriptionId());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
// We have one or more existing subscriptions, so we want the plus button if eSIM is
|
||||
// supported.
|
||||
if (mStatusCache.isEuiccConfigSupport()) {
|
||||
mPreference.setAddWidgetEnabled(!mChangeListener.isAirplaneModeOn());
|
||||
mPreference.setOnAddClickListener(p -> {
|
||||
logPreferenceClick(p);
|
||||
startAddSimFlow();
|
||||
});
|
||||
}
|
||||
|
||||
if (subs.size() == 1) {
|
||||
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
||||
logPreferenceClick(pref);
|
||||
|
||||
SubscriptionAnnotation info = subs.get(0);
|
||||
if (info.getSubInfo().isEmbedded() || info.isActive()
|
||||
|| mStatusCache.isPhysicalSimDisableSupport()) {
|
||||
final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
|
||||
intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
mPreference.setFragment(MobileNetworkListFragment.class.getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
SubscriptionUtil.startToggleSubscriptionDialogActivity(
|
||||
mContext, info.getSubscriptionId(), true);
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
mPreference.setFragment(MobileNetworkListFragment.class.getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,12 +227,14 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
|
||||
update();
|
||||
mStatusCache.update(mContext, statusCache -> update());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
refreshSummary(mPreference);
|
||||
update();
|
||||
mStatusCache.update(mContext, statusCache -> {
|
||||
refreshSummary(mPreference);
|
||||
update();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user