From 00798a5902e0042629a2f19c0ec7bc017d1ea658 Mon Sep 17 00:00:00 2001 From: tom hsu Date: Fri, 5 Feb 2021 22:42:58 +0800 Subject: [PATCH] [Provider model] Show a string on internet picker when mobile data off - https://screenshot.googleplex.com/6JE9ma6UZmGCNFQ Bug: 178680922 Test: Manual test passed Test: atest passed Change-Id: Id276e3f97b4380f648eb9e35ca7780a0ba32bdb2 --- .../SubscriptionsPreferenceController.java | 8 +++- ...SubscriptionsPreferenceControllerTest.java | 47 +++++++++++++++---- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java index d028c5835e2..392ccc6aba5 100644 --- a/src/com/android/settings/network/SubscriptionsPreferenceController.java +++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java @@ -35,6 +35,7 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; +import android.text.Html; import android.util.ArraySet; import androidx.annotation.VisibleForTesting; @@ -255,14 +256,17 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl mUpdateListener.onChildrenUpdated(); } - private String getMobilePreferenceSummary(int subId) { + private CharSequence getMobilePreferenceSummary(int subId) { String result = mSubsPrefCtrlInjector.getNetworkType( mContext, mConfig, mTelephonyDisplayInfo, subId); + if (!mTelephonyManager.isDataEnabled()) { + return mContext.getString(R.string.mobile_data_off_summary); + } if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) { result = mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.mobile_data_connection_active), result); } - return result; + return Html.fromHtml(result, Html.FROM_HTML_MODE_LEGACY); } private Drawable getIcon(int subId) { diff --git a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java index ef3f130911f..6b31342d31e 100644 --- a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java @@ -16,7 +16,6 @@ package com.android.settings.network; -import static android.telephony.SignalStrength.NUM_SIGNAL_STRENGTH_BINS; import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GOOD; import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GREAT; import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; @@ -24,6 +23,7 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq;; import static org.mockito.Mockito.doReturn; @@ -47,6 +47,7 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; +import android.text.Html; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleRegistry; @@ -371,14 +372,14 @@ public class SubscriptionsPreferenceControllerTest { final Preference pref = new Preference(mContext); final Drawable greatDrawWithoutCutOff = mock(Drawable.class); doReturn(greatDrawWithoutCutOff).when(sInjector) - .getIcon(mContext, 4, NUM_SIGNAL_STRENGTH_BINS, true); + .getIcon(any(), anyInt(), anyInt(), anyBoolean()); mController.setIcon(pref, 1, true /* isDefaultForData */); assertThat(pref.getIcon()).isEqualTo(greatDrawWithoutCutOff); final Drawable greatDrawWithCutOff = mock(Drawable.class); doReturn(greatDrawWithCutOff).when(sInjector) - .getIcon(mContext, 4, NUM_SIGNAL_STRENGTH_BINS, true); + .getIcon(any(), anyInt(), anyInt(), anyBoolean()); mController.setIcon(pref, 2, false /* isDefaultForData */); assertThat(pref.getIcon()).isEqualTo(greatDrawWithCutOff); } @@ -416,7 +417,8 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest public void displayPreference_providerAndHasMultiSimAndActive_connectedAndRat() { - final String expectedSummary = "Connected / 5G"; + final CharSequence expectedSummary = + Html.fromHtml("Connected / 5G", Html.FROM_HTML_MODE_LEGACY); final String networkType = "5G"; final List sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); @@ -426,6 +428,7 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen); @@ -435,8 +438,11 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest - public void displayPreference_providerAndHasMultiSimAndNotActive_showRatOnly() { - final String expectedSummary = "5G"; + public void displayPreference_providerAndHasMultiSimButMobileDataOff_notAutoConnect() { + final String dataOffSummary = + ResourcesUtils.getResourcesString(mContext, "mobile_data_off_summary"); + final CharSequence expectedSummary = + Html.fromHtml(dataOffSummary, Html.FROM_HTML_MODE_LEGACY); final String networkType = "5G"; final List sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); @@ -449,6 +455,27 @@ public class SubscriptionsPreferenceControllerTest { mController.onResume(); mController.displayPreference(mPreferenceScreen); + assertThat(mPreferenceCategory.getPreference(0).getSummary()) + .isEqualTo(expectedSummary.toString()); + } + + @Test + @UiThreadTest + public void displayPreference_providerAndHasMultiSimAndNotActive_showRatOnly() { + final CharSequence expectedSummary = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY); + final String networkType = "5G"; + final List sub = setupMockSubscriptions(2); + doReturn(true).when(sInjector).isProviderModelEnabled(mContext); + doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); + setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true, + TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE); + doReturn(networkType) + .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); + + mController.onResume(); + mController.displayPreference(mPreferenceScreen); + assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary); } @@ -467,7 +494,8 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest public void onTelephonyDisplayInfoChanged_providerAndHasMultiSimAndActive_connectedAndRat() { - final String expectedSummary = "Connected / LTE"; + final CharSequence expectedSummary = + Html.fromHtml("Connected / LTE", Html.FROM_HTML_MODE_LEGACY); final String networkType = "LTE"; final List sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = @@ -480,6 +508,7 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen); @@ -491,7 +520,8 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest public void onTelephonyDisplayInfoChanged_providerAndHasMultiSimAndNotActive_showRat() { - final String expectedSummary = "LTE"; + final CharSequence expectedSummary = + Html.fromHtml("LTE", Html.FROM_HTML_MODE_LEGACY); final String networkType = "LTE"; final List sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = @@ -504,6 +534,7 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen);