Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7429fd13 authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "Change the condition for showing "no connection"" into sc-dev

parents bc7e4bcd 5f8f44c7
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.telephony.AccessNetworkConstants;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
@@ -106,7 +108,12 @@ public class ProviderModelSliceHelper {
     * @return whether the ServiceState's data state is in-service.
     */
    public boolean isDataStateInService() {
        return mTelephonyManager.getDataState() == mTelephonyManager.DATA_CONNECTED;
        final ServiceState serviceState = mTelephonyManager.getServiceState();
        NetworkRegistrationInfo regInfo =
                (serviceState == null) ? null : serviceState.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        return (regInfo == null) ? false : regInfo.isRegistered();
    }

    /**
+20 −4
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import android.graphics.drawable.Drawable;
import android.net.wifi.WifiManager;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.AccessNetworkConstants;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
@@ -274,9 +276,16 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
        if (!tmForSubId.isDataEnabled()) {
            return mContext.getString(R.string.mobile_data_off_summary);
        }
        final ServiceState serviceState = tmForSubId.getServiceState();
        final NetworkRegistrationInfo regInfo = (serviceState == null)
                ? null
                : serviceState.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);

        final boolean isDataInService = tmForSubId.getDataState()
                == TelephonyManager.DATA_CONNECTED;
        final boolean isDataInService = (regInfo == null)
                ? false
                : regInfo.isRegistered();
        final boolean isCarrierNetworkActive =
                (mWifiPickerTrackerHelper != null)
                        && mWifiPickerTrackerHelper.isCarrierNetworkActive();
@@ -311,9 +320,16 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
            return icon;
        }

        final boolean isDataInService = tmForSubId.getDataState()
                == TelephonyManager.DATA_CONNECTED;
        final ServiceState serviceState = tmForSubId.getServiceState();
        final NetworkRegistrationInfo regInfo = (serviceState == null)
                ? null
                : serviceState.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);

        final boolean isDataInService = (regInfo == null)
                ? false
                : regInfo.isRegistered();
        final boolean isVoiceInService = (serviceState == null)
                ? false
                : (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
+20 −8
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ import android.net.NetworkCapabilities;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.PersistableBundle;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
@@ -169,7 +171,7 @@ public class ProviderModelSliceHelperTest {
        CharSequence expectedSubtitle = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY);
        String networkType = "5G";
        mockConnections(true, ServiceState.STATE_IN_SERVICE, expectDisplayName,
                mTelephonyManager.DATA_CONNECTED, true);
                true, true);
        addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI);

        ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
@@ -189,7 +191,7 @@ public class ProviderModelSliceHelperTest {
                "preference_summary_default_combination", connectedText, networkType),
                Html.FROM_HTML_MODE_LEGACY);
        mockConnections(true, ServiceState.STATE_IN_SERVICE, expectDisplayName,
                mTelephonyManager.DATA_CONNECTED, true);
                true, true);
        addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);

        ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
@@ -208,7 +210,7 @@ public class ProviderModelSliceHelperTest {
        String networkType = "";

        mockConnections(true, ServiceState.STATE_OUT_OF_SERVICE, expectDisplayName,
                mTelephonyManager.DATA_DISCONNECTED, false);
                false, false);
        addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);

        ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
@@ -221,7 +223,7 @@ public class ProviderModelSliceHelperTest {
    @Test
    public void getMobileDrawable_noCarrierData_getMobileDrawable() throws Throwable {
        mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "",
                mTelephonyManager.DATA_DISCONNECTED, true);
                false, true);
        when(mConnectivityManager.getActiveNetwork()).thenReturn(null);
        Drawable expectDrawable = mock(Drawable.class);

@@ -232,7 +234,7 @@ public class ProviderModelSliceHelperTest {
    @Test
    public void getMobileDrawable_hasCarrierDataAndDataIsOnCellular_getMobileDrawable()
            throws Throwable {
        mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED,
        mockConnections(true, ServiceState.STATE_IN_SERVICE, "", true,
                true);
        addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
        Drawable drawable = mock(Drawable.class);
@@ -246,7 +248,7 @@ public class ProviderModelSliceHelperTest {
    @Test
    public void getMobileDrawable_hasCarrierDataAndDataIsOnWifi_getMobileDrawable()
            throws Throwable {
        mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED,
        mockConnections(true, ServiceState.STATE_IN_SERVICE, "", true,
                true);
        Drawable drawable = mock(Drawable.class);
        addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI);
@@ -263,12 +265,22 @@ public class ProviderModelSliceHelperTest {
    }

    private void mockConnections(boolean isDataEnabled, int serviceState, String expectDisplayName,
            int getDataState, boolean isWifiEnabled) {
            boolean dataRegState, boolean isWifiEnabled) {
        when(mTelephonyManager.isDataEnabled()).thenReturn(isDataEnabled);
        when(mWifiManager.isWifiEnabled()).thenReturn(isWifiEnabled);
        when(mTelephonyManager.getDataState()).thenReturn(getDataState);

        when(mServiceState.getState()).thenReturn(serviceState);

        NetworkRegistrationInfo regInfo = new NetworkRegistrationInfo.Builder()
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setRegistrationState(dataRegState ? NetworkRegistrationInfo.REGISTRATION_STATE_HOME
                        : NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING)
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
                .build();
        when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS,
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(regInfo);

        when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
    }

+34 −13
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.net.NetworkCapabilities;
import android.os.Looper;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.AccessNetworkConstants;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
@@ -430,7 +432,7 @@ public class SubscriptionsPreferenceControllerTest {
        doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
        doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
        setupGetIconConditions(sub.get(0).getSubscriptionId(), true, true,
                TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE);
                true, ServiceState.STATE_IN_SERVICE);
        doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(false));
@@ -451,7 +453,7 @@ public class SubscriptionsPreferenceControllerTest {
        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);
                true, ServiceState.STATE_IN_SERVICE);
        doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(true));
@@ -476,7 +478,7 @@ public class SubscriptionsPreferenceControllerTest {
        doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
        doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
        setupGetIconConditions(sub.get(0).getSubscriptionId(), false, false,
                TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE);
                true, ServiceState.STATE_IN_SERVICE);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(false));

@@ -496,7 +498,7 @@ public class SubscriptionsPreferenceControllerTest {
        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);
                true, ServiceState.STATE_IN_SERVICE);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(false));
        when(mTelephonyManager.isDataEnabled()).thenReturn(true);
@@ -532,7 +534,7 @@ public class SubscriptionsPreferenceControllerTest {
        doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
        doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
        setupGetIconConditions(sub.get(0).getSubscriptionId(), true, true,
                TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE);
                true, ServiceState.STATE_IN_SERVICE);
        doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(false));
@@ -558,7 +560,7 @@ public class SubscriptionsPreferenceControllerTest {
        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);
                true, ServiceState.STATE_IN_SERVICE);
        doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(false));
@@ -585,7 +587,7 @@ public class SubscriptionsPreferenceControllerTest {
        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);
                false, ServiceState.STATE_OUT_OF_SERVICE);
        doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
        doReturn(networkType)
                .when(sInjector).getNetworkType(any(), any(), any(), anyInt(), eq(false));
@@ -665,7 +667,7 @@ public class SubscriptionsPreferenceControllerTest {
        Drawable icon = mock(Drawable.class);
        doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));
        setupGetIconConditions(sub.get(0).getSubscriptionId(), true, true,
                TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE);
                true, ServiceState.STATE_IN_SERVICE);

        mController.onResume();
        mController.displayPreference(mPreferenceScreen);
@@ -683,7 +685,7 @@ public class SubscriptionsPreferenceControllerTest {
        Drawable icon = mock(Drawable.class);
        doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));
        setupGetIconConditions(subId, false, true,
                TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE);
                true, ServiceState.STATE_IN_SERVICE);
        mController.onResume();
        mController.displayPreference(mPreferenceScreen);
        Drawable actualIcon = mPreferenceCategory.getPreference(0).getIcon();
@@ -702,12 +704,22 @@ public class SubscriptionsPreferenceControllerTest {
        doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));

        setupGetIconConditions(subId, false, false,
                TelephonyManager.DATA_DISCONNECTED, ServiceState.STATE_IN_SERVICE);
                false, ServiceState.STATE_IN_SERVICE);

        mController.onResume();
        mController.displayPreference(mPreferenceScreen);
        Drawable actualIcon = mPreferenceCategory.getPreference(0).getIcon();
        doReturn(TelephonyManager.DATA_CONNECTED).when(mTelephonyManagerForSub).getDataState();
        ServiceState ss = mock(ServiceState.class);
        NetworkRegistrationInfo regInfo = new NetworkRegistrationInfo.Builder()
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
                .build();
        doReturn(ss).when(mTelephonyManagerForSub).getServiceState();
        doReturn(regInfo).when(ss).getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS,
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN);

        assertThat(icon).isEqualTo(actualIcon);
    }
@@ -733,14 +745,23 @@ public class SubscriptionsPreferenceControllerTest {
    }

    private void setupGetIconConditions(int subId, boolean isActiveCellularNetwork,
            boolean isDataEnable, int dataState, int servicestate) {
            boolean isDataEnable, boolean dataState, int servicestate) {
        doReturn(mTelephonyManagerForSub).when(mTelephonyManager).createForSubscriptionId(subId);
        doReturn(isActiveCellularNetwork).when(sInjector).isActiveCellularNetwork(mContext);
        doReturn(isDataEnable).when(mTelephonyManagerForSub).isDataEnabled();
        doReturn(dataState).when(mTelephonyManagerForSub).getDataState();
        ServiceState ss = mock(ServiceState.class);
        NetworkRegistrationInfo regInfo = new NetworkRegistrationInfo.Builder()
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setRegistrationState(dataState ? NetworkRegistrationInfo.REGISTRATION_STATE_HOME
                        : NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_SEARCHING)
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
                .build();
        doReturn(ss).when(mTelephonyManagerForSub).getServiceState();
        doReturn(servicestate).when(ss).getState();
        doReturn(regInfo).when(ss).getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS,
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
    }

    private List<SubscriptionInfo> setupMockSubscriptions(int count) {