Provider model CarrierItem's subtitle show no connection

CarrierItem's subtitle show no connection when Wi-Fi
off + no service

Bug: 182433548
Test: atest ProviderModelSliceTest
atest ProviderModelSliceHelperTest
atest NetworkProviderWorkerTest
atest InternetConnectivityPanelTest
make RunSettingsRoboTests -j

Change-Id: I04778cf2b184c0a75dc6999ffde011a9ad5e0690
This commit is contained in:
SongFerngWang
2021-03-19 11:25:36 +08:00
parent 48cc107acd
commit fb2a1d9db9
3 changed files with 68 additions and 61 deletions

View File

@@ -12789,6 +12789,9 @@
<!-- Provider Model: <!-- Provider Model:
Summary indicating that a SIM has an active mobile data connection [CHAR LIMIT=50] --> Summary indicating that a SIM has an active mobile data connection [CHAR LIMIT=50] -->
<string name="mobile_data_connection_active">Connected</string> <string name="mobile_data_connection_active">Connected</string>
<!-- Provider Model:
Summary indicating that a active SIM and no network available [CHAR LIMIT=50] -->
<string name="mobile_data_no_connection">No connection</string>
<!-- Provider Model: <!-- Provider Model:
Summary indicating that a SIM has no mobile data connection [CHAR LIMIT=50] --> Summary indicating that a SIM has no mobile data connection [CHAR LIMIT=50] -->
<string name="mobile_data_off_summary">Internet won\u0027t auto\u2011connect</string> <string name="mobile_data_off_summary">Internet won\u0027t auto\u2011connect</string>

View File

@@ -24,6 +24,7 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.net.wifi.WifiManager;
import android.telephony.ServiceState; import android.telephony.ServiceState;
import android.telephony.SignalStrength; import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
@@ -231,6 +232,7 @@ public class ProviderModelSliceHelper {
} }
private String getMobileSummary(String networkTypeDescription) { private String getMobileSummary(String networkTypeDescription) {
final WifiManager wifiManager = mContext.getSystemService(WifiManager.class);
String summary = networkTypeDescription; String summary = networkTypeDescription;
if (isDataSimActive()) { if (isDataSimActive()) {
summary = mContext.getString(R.string.preference_summary_default_combination, summary = mContext.getString(R.string.preference_summary_default_combination,
@@ -238,6 +240,8 @@ public class ProviderModelSliceHelper {
networkTypeDescription); networkTypeDescription);
} else if (!isMobileDataEnabled()) { } else if (!isMobileDataEnabled()) {
summary = mContext.getString(R.string.mobile_data_off_summary); summary = mContext.getString(R.string.mobile_data_off_summary);
} else if (!wifiManager.isWifiEnabled() && !isDataSimActive()) {
summary = mContext.getString(R.string.mobile_data_no_connection);
} }
return summary; return summary;
} }

View File

@@ -33,6 +33,7 @@ import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.Uri; import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.ServiceState; import android.telephony.ServiceState;
@@ -90,6 +91,8 @@ public class ProviderModelSliceHelperTest {
private SubscriptionInfo mDefaultDataSubscriptionInfo; private SubscriptionInfo mDefaultDataSubscriptionInfo;
@Mock @Mock
private Drawable mDrawableWithSignalStrength; private Drawable mDrawableWithSignalStrength;
@Mock
private WifiManager mWifiManager;
@Before @Before
public void setUp() { public void setUp() {
@@ -102,13 +105,23 @@ public class ProviderModelSliceHelperTest {
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn( when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
mCarrierConfigManager); mCarrierConfigManager);
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle);
mBundle.putBoolean(CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL, false);
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager); when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
when(mConnectivityManager.getActiveNetwork()).thenReturn(mNetwork); when(mConnectivityManager.getActiveNetwork()).thenReturn(mNetwork);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
TestCustomSliceable testCustomSliceable = new TestCustomSliceable(); TestCustomSliceable testCustomSliceable = new TestCustomSliceable();
mProviderModelSliceHelper = new MockProviderModelSliceHelper(mContext, testCustomSliceable); mProviderModelSliceHelper = new MockProviderModelSliceHelper(mContext, testCustomSliceable);
final int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
when(mDefaultDataSubscriptionInfo.getSubscriptionId()).thenReturn(defaultDataSubId);
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(mDefaultDataSubscriptionInfo));
} }
@Test @Test
@@ -155,20 +168,9 @@ public class ProviderModelSliceHelperTest {
String expectDisplayName = "Name1"; String expectDisplayName = "Name1";
CharSequence expectedSubtitle = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY); CharSequence expectedSubtitle = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY);
String networkType = "5G"; String networkType = "5G";
mockConnections(true, ServiceState.STATE_IN_SERVICE, expectDisplayName,
final int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId(); mTelephonyManager.DATA_CONNECTED, true);
when(mDefaultDataSubscriptionInfo.getSubscriptionId()).thenReturn(defaultDataSubId);
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(mDefaultDataSubscriptionInfo));
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
mBundle.putBoolean(CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL, false);
addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI); addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI);
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow( ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
networkType); networkType);
@@ -178,7 +180,7 @@ public class ProviderModelSliceHelperTest {
} }
@Test @Test
public void createCarrierRow_hasDdsAndActiveNetworkIsCellular_verifyTitleAndSummary() { public void createCarrierRow_wifiOnhasDdsAndActiveNetworkIsCellular_verifyTitleAndSummary() {
String expectDisplayName = "Name1"; String expectDisplayName = "Name1";
String networkType = "5G"; String networkType = "5G";
String connectedText = ResourcesUtils.getResourcesString(mContext, String connectedText = ResourcesUtils.getResourcesString(mContext,
@@ -186,16 +188,27 @@ public class ProviderModelSliceHelperTest {
CharSequence expectedSubtitle = Html.fromHtml(ResourcesUtils.getResourcesString(mContext, CharSequence expectedSubtitle = Html.fromHtml(ResourcesUtils.getResourcesString(mContext,
"preference_summary_default_combination", connectedText, networkType), "preference_summary_default_combination", connectedText, networkType),
Html.FROM_HTML_MODE_LEGACY); Html.FROM_HTML_MODE_LEGACY);
mockConnections(true, ServiceState.STATE_IN_SERVICE, expectDisplayName,
mTelephonyManager.DATA_CONNECTED, true);
addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
final int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId(); ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
when(mDefaultDataSubscriptionInfo.getSubscriptionId()).thenReturn(defaultDataSubId); networkType);
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn( assertThat(testRowBuild.getTitle()).isEqualTo(expectDisplayName);
mDefaultDataSubscriptionInfo); assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle);
when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn( }
Arrays.asList(mDefaultDataSubscriptionInfo));
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); @Test
mBundle.putBoolean(CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL, false); public void createCarrierRow_noNetworkAvailable_verifyTitleAndSummary() {
String expectDisplayName = "Name1";
CharSequence expectedSubtitle = Html.fromHtml(
ResourcesUtils.getResourcesString(mContext, "mobile_data_no_connection"),
Html.FROM_HTML_MODE_LEGACY);
String networkType = "";
mockConnections(true, ServiceState.STATE_OUT_OF_SERVICE, expectDisplayName,
mTelephonyManager.DATA_DISCONNECTED, false);
addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR); addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow( ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
@@ -207,53 +220,40 @@ public class ProviderModelSliceHelperTest {
@Test @Test
public void isNoCarrierData_mobileDataOnAndNoData_returnTrue() { public void isNoCarrierData_mobileDataOnAndNoData_returnTrue() {
when(mTelephonyManager.isDataEnabled()).thenReturn(true); mockConnections(true, ServiceState.STATE_IN_SERVICE, "",
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_DISCONNECTED); mTelephonyManager.DATA_DISCONNECTED, true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue(); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue();
} }
@Test @Test
public void isNoCarrierData_mobileDataOffAndOutOfService_returnTrue() { public void isNoCarrierData_mobileDataOffAndOutOfService_returnTrue() {
when(mTelephonyManager.isDataEnabled()).thenReturn(false); mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "",
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_DISCONNECTED); mTelephonyManager.DATA_DISCONNECTED, true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue(); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue();
} }
@Test @Test
public void isNoCarrierData_mobileDataOnAndDataConnected_returnFalse() { public void isNoCarrierData_mobileDataOnAndDataConnected_returnFalse() {
when(mTelephonyManager.isDataEnabled()).thenReturn(true); mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED,
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_CONNECTED); true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse(); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse();
} }
@Test @Test
public void isNoCarrierData_mobileDataOffAndVoiceIsInService_returnFalse() { public void isNoCarrierData_mobileDataOffAndVoiceIsInService_returnFalse() {
when(mTelephonyManager.isDataEnabled()).thenReturn(false); mockConnections(false, ServiceState.STATE_IN_SERVICE, "",
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_DISCONNECTED); mTelephonyManager.DATA_DISCONNECTED, true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse(); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse();
} }
@Test @Test
public void getMobileDrawable_noCarrierData_getMobileDrawable() throws Throwable { public void getMobileDrawable_noCarrierData_getMobileDrawable() throws Throwable {
when(mTelephonyManager.isDataEnabled()).thenReturn(false); mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "",
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_DISCONNECTED); mTelephonyManager.DATA_DISCONNECTED, true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
when(mConnectivityManager.getActiveNetwork()).thenReturn(null); when(mConnectivityManager.getActiveNetwork()).thenReturn(null);
Drawable expectDrawable = mock(Drawable.class); Drawable expectDrawable = mock(Drawable.class);
@@ -264,15 +264,10 @@ public class ProviderModelSliceHelperTest {
@Test @Test
public void getMobileDrawable_hasCarrierDataAndDataIsOnCellular_getMobileDrawable() public void getMobileDrawable_hasCarrierDataAndDataIsOnCellular_getMobileDrawable()
throws Throwable { throws Throwable {
when(mTelephonyManager.isDataEnabled()).thenReturn(true); mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED,
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_CONNECTED); true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
Drawable drawable = mock(Drawable.class);
int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR); addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
Drawable drawable = mock(Drawable.class);
assertThat(mProviderModelSliceHelper.getMobileDrawable(drawable)).isEqualTo( assertThat(mProviderModelSliceHelper.getMobileDrawable(drawable)).isEqualTo(
mDrawableWithSignalStrength); mDrawableWithSignalStrength);
@@ -283,14 +278,9 @@ public class ProviderModelSliceHelperTest {
@Test @Test
public void getMobileDrawable_hasCarrierDataAndDataIsOnWifi_getMobileDrawable() public void getMobileDrawable_hasCarrierDataAndDataIsOnWifi_getMobileDrawable()
throws Throwable { throws Throwable {
when(mTelephonyManager.isDataEnabled()).thenReturn(true); mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED,
when(mTelephonyManager.getDataState()).thenReturn(mTelephonyManager.DATA_CONNECTED); true);
when(mTelephonyManager.getServiceState()).thenReturn(mServiceState);
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
Drawable drawable = mock(Drawable.class); Drawable drawable = mock(Drawable.class);
int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI); addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI);
assertThat(mProviderModelSliceHelper.getMobileDrawable(drawable)).isEqualTo( assertThat(mProviderModelSliceHelper.getMobileDrawable(drawable)).isEqualTo(
@@ -303,6 +293,16 @@ public class ProviderModelSliceHelperTest {
mNetworkCapabilities); mNetworkCapabilities);
} }
private void mockConnections(boolean isDataEnabled, int serviceState, String expectDisplayName,
int getDataState, boolean isWifiEnabled) {
when(mTelephonyManager.isDataEnabled()).thenReturn(isDataEnabled);
when(mWifiManager.isWifiEnabled()).thenReturn(isWifiEnabled);
when(mTelephonyManager.getDataState()).thenReturn(getDataState);
when(mServiceState.getState()).thenReturn(serviceState);
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
}
private class TestCustomSliceable implements CustomSliceable { private class TestCustomSliceable implements CustomSliceable {
TestCustomSliceable() { TestCustomSliceable() {
} }