[Provider model] Show no connection during out of service.

- When device out of service, show "No connection" on preference summary.
 - Modify the logic of icon and summary.

Bug: 183944316
Test: atest SubscriptionsPreferenceControllerTest passed
Change-Id: I179632918a9145f27cec7d9c08e1c0b675fd1ef6
This commit is contained in:
tom hsu
2021-04-15 20:38:15 +08:00
parent 089c56520d
commit f482c28423
2 changed files with 48 additions and 19 deletions

View File

@@ -257,15 +257,20 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
} }
private CharSequence getMobilePreferenceSummary(int subId) { private CharSequence getMobilePreferenceSummary(int subId) {
TelephonyManager tm = mTelephonyManager.createForSubscriptionId(subId); final TelephonyManager tmForSubId = mTelephonyManager.createForSubscriptionId(subId);
String result = mSubsPrefCtrlInjector.getNetworkType( if (!tmForSubId.isDataEnabled()) {
mContext, mConfig, mTelephonyDisplayInfo, subId);
if (!tm.isDataEnabled()) {
return mContext.getString(R.string.mobile_data_off_summary); return mContext.getString(R.string.mobile_data_off_summary);
} }
if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) {
final boolean isDataInService = tmForSubId.getDataState()
== TelephonyManager.DATA_CONNECTED;
String result = mSubsPrefCtrlInjector.getNetworkType(
mContext, mConfig, mTelephonyDisplayInfo, subId);
if (mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) {
result = mContext.getString(R.string.preference_summary_default_combination, result = mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.mobile_data_connection_active), result); mContext.getString(R.string.mobile_data_connection_active), result);
} else if (!isDataInService) {
result = mContext.getString(R.string.mobile_data_no_connection);
} }
return Html.fromHtml(result, Html.FROM_HTML_MODE_LEGACY); return Html.fromHtml(result, Html.FROM_HTML_MODE_LEGACY);
} }
@@ -274,31 +279,27 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
final TelephonyManager tmForSubId = mTelephonyManager.createForSubscriptionId(subId); final TelephonyManager tmForSubId = mTelephonyManager.createForSubscriptionId(subId);
final SignalStrength strength = tmForSubId.getSignalStrength(); final SignalStrength strength = tmForSubId.getSignalStrength();
int level = (strength == null) ? 0 : strength.getLevel(); int level = (strength == null) ? 0 : strength.getLevel();
int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
if (shouldInflateSignalStrength(subId)) { if (shouldInflateSignalStrength(subId)) {
level += 1; level += 1;
numLevels += 1; numLevels += 1;
} }
final boolean isMobileDataOn = tmForSubId.isDataEnabled(); Drawable icon = mSubsPrefCtrlInjector.getIcon(mContext, level, numLevels, false);
final boolean isActiveCellularNetwork = final boolean isActiveCellularNetwork =
mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext); mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext);
final boolean isMobileDataAccessible = tmForSubId.getDataState()
== TelephonyManager.DATA_CONNECTED;
final ServiceState serviceState = tmForSubId.getServiceState();
final boolean isVoiceOutOfService = (serviceState == null)
? true
: (serviceState.getState() == ServiceState.STATE_OUT_OF_SERVICE);
Drawable icon = mSubsPrefCtrlInjector.getIcon(mContext, level, numLevels, false);
if (isActiveCellularNetwork) { if (isActiveCellularNetwork) {
icon.setTint(Utils.getColorAccentDefaultColor(mContext)); icon.setTint(Utils.getColorAccentDefaultColor(mContext));
return icon; return icon;
} }
if ((isMobileDataOn && isMobileDataAccessible)
|| (!isMobileDataOn && !isVoiceOutOfService)) { final boolean isDataInService = tmForSubId.getDataState()
== TelephonyManager.DATA_CONNECTED;
final ServiceState serviceState = tmForSubId.getServiceState();
final boolean isVoiceInService = (serviceState == null)
? false
: (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
if (isDataInService || isVoiceInService) {
return icon; return icon;
} }
@@ -579,7 +580,8 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
String iconKey = getIconKey(telephonyDisplayInfo); String iconKey = getIconKey(telephonyDisplayInfo);
int resId = mapIconSets(config).get(iconKey).dataContentDescription; int resId = mapIconSets(config).get(iconKey).dataContentDescription;
return resId != 0 return resId != 0
? SubscriptionManager.getResourcesForSubId(context, subId).getString(resId) : ""; ? SubscriptionManager.getResourcesForSubId(context, subId).getString(resId)
: "";
} }
/** /**

View File

@@ -542,6 +542,33 @@ public class SubscriptionsPreferenceControllerTest {
assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary); assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary);
} }
@Test
@UiThreadTest
public void onTelephonyDisplayInfoChanged_providerAndHasMultiSimAndOutOfService_noConnection() {
final String noConnectionSummary =
ResourcesUtils.getResourcesString(mContext, "mobile_data_no_connection");
final CharSequence expectedSummary =
Html.fromHtml(noConnectionSummary, Html.FROM_HTML_MODE_LEGACY);
final String networkType = "LTE";
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
final TelephonyDisplayInfo telephonyDisplayInfo =
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true,
TelephonyManager.DATA_DISCONNECTED, ServiceState.STATE_OUT_OF_SERVICE);
doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
doReturn(networkType)
.when(sInjector).getNetworkType(any(), any(), any(), anyInt());
mController.onResume();
mController.displayPreference(mPreferenceScreen);
mController.onTelephonyDisplayInfoChanged(telephonyDisplayInfo);
assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary);
}
@Test @Test
@UiThreadTest @UiThreadTest
public void onAirplaneModeChanged_providerAndHasSim_noPreference() { public void onAirplaneModeChanged_providerAndHasSim_noPreference() {