Loading src/com/android/settings/network/SubscriptionsPreferenceController.java +6 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +38 −7 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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<SubscriptionInfo> sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); Loading @@ -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); Loading @@ -433,10 +436,33 @@ public class SubscriptionsPreferenceControllerTest { assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary); } @Test @UiThreadTest 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<SubscriptionInfo> 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()); mController.onResume(); mController.displayPreference(mPreferenceScreen); assertThat(mPreferenceCategory.getPreference(0).getSummary()) .isEqualTo(expectedSummary.toString()); } @Test @UiThreadTest public void displayPreference_providerAndHasMultiSimAndNotActive_showRatOnly() { final String expectedSummary = "5G"; final CharSequence expectedSummary = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY); final String networkType = "5G"; final List<SubscriptionInfo> sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); Loading @@ -445,6 +471,7 @@ public class SubscriptionsPreferenceControllerTest { 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); Loading @@ -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<SubscriptionInfo> sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = Loading @@ -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); Loading @@ -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<SubscriptionInfo> sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = Loading @@ -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); Loading Loading
src/com/android/settings/network/SubscriptionsPreferenceController.java +6 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading
tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +38 −7 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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<SubscriptionInfo> sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); Loading @@ -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); Loading @@ -433,10 +436,33 @@ public class SubscriptionsPreferenceControllerTest { assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary); } @Test @UiThreadTest 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<SubscriptionInfo> 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()); mController.onResume(); mController.displayPreference(mPreferenceScreen); assertThat(mPreferenceCategory.getPreference(0).getSummary()) .isEqualTo(expectedSummary.toString()); } @Test @UiThreadTest public void displayPreference_providerAndHasMultiSimAndNotActive_showRatOnly() { final String expectedSummary = "5G"; final CharSequence expectedSummary = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY); final String networkType = "5G"; final List<SubscriptionInfo> sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); Loading @@ -445,6 +471,7 @@ public class SubscriptionsPreferenceControllerTest { 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); Loading @@ -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<SubscriptionInfo> sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = Loading @@ -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); Loading @@ -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<SubscriptionInfo> sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = Loading @@ -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); Loading