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

Commit a444fd99 authored by Lei Yu's avatar Lei Yu Committed by android-build-merger
Browse files

Merge "Hide network select in some situations" into qt-dev

am: 2bdf358c

Change-Id: Ie188d11a05692d49e8fb154e348aa1789098a0c9
parents 8fa5f720 2bdf358c
Loading
Loading
Loading
Loading
+47 −13
Original line number Diff line number Diff line
@@ -277,8 +277,7 @@ public class MobileNetworkUtils {
                return true;
            }

            if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA
                    && !isTdscdmaSupported(context, telephonyManager)) {
            if (shouldSpeciallyUpdateGsmCdma(context, subId)) {
                return true;
            }
        }
@@ -296,16 +295,15 @@ public class MobileNetworkUtils {
        if (isGsmBasicOptions(context, subId)) {
            return true;
        }
        final int settingsNetworkMode = android.provider.Settings.Global.getInt(
        final int networkMode = android.provider.Settings.Global.getInt(
                context.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
                Phone.PREFERRED_NT_MODE);
        if (isWorldMode(context, subId)) {
            if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO
                    || settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA) {
            if (networkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO
                    || networkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA) {
                return true;
            } else if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA
                    && !MobileNetworkUtils.isTdscdmaSupported(context, subId)) {
            } else if (shouldSpeciallyUpdateGsmCdma(context, subId)) {
                return true;
            }
        }
@@ -362,16 +360,24 @@ public class MobileNetworkUtils {
            return false;
        }

        final int networkMode = android.provider.Settings.Global.getInt(
                context.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
                Phone.PREFERRED_NT_MODE);
        if (networkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO
                && isWorldMode(context, subId)) {
            return false;
        }
        if (shouldSpeciallyUpdateGsmCdma(context, subId)) {
            return false;
        }

        if (isGsmBasicOptions(context, subId)) {
            return true;
        }

        final int settingsNetworkMode = android.provider.Settings.Global.getInt(
                context.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
                Phone.PREFERRED_NT_MODE);
        if (isWorldMode(context, subId)) {
            if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA) {
            if (networkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA) {
                return true;
            }
        }
@@ -414,7 +420,6 @@ public class MobileNetworkUtils {
        return false;
    }


    /**
     * Return subId that supported by search. If there are more than one, return first one,
     * otherwise return {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}
@@ -461,4 +466,33 @@ public class MobileNetworkUtils {
            }
        }
    }

    /**
     * This method is migrated from {@link com.android.phone.MobileNetworkSettings} and we should
     * use it carefully. This code snippet doesn't have very clear meaning however we should
     * update GSM or CDMA differently based on what it returns.
     *
     * 1. For all CDMA settings, make them visible if it return {@code true}
     * 2. For GSM settings, make them visible if it return {@code true} unless 3
     * 3. For network select settings, make it invisible if it return {@code true}
     */
    @VisibleForTesting
    static boolean shouldSpeciallyUpdateGsmCdma(Context context, int subId) {
        final int networkMode = android.provider.Settings.Global.getInt(
                context.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
                Phone.PREFERRED_NT_MODE);
        if (networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM
                || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA
                || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA
                || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA
                || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA
                || networkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA) {
            if (!isTdscdmaSupported(context, subId) && isWorldMode(context, subId)) {
                return true;
            }
        }

        return false;
    }
}
+82 −0
Original line number Diff line number Diff line
@@ -219,4 +219,86 @@ public class MobileNetworkUtilsTest {
        assertThat(MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, SUB_ID_1))
                .isTrue();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_notWorldMode_returnFalse() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, false);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isFalse();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_supportTdscdma_returnFalse() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, true);

        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isFalse();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_ModeLteTdscdmaGsm_returnTrue() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        Settings.Global.putInt(mContext.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
                TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM);
        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_ModeLteTdscdmaGsmWcdma_returnTrue() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        Settings.Global.putInt(mContext.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
                TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA);
        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_ModeLteTdscdma_returnTrue() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        Settings.Global.putInt(mContext.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
                TelephonyManager.NETWORK_MODE_LTE_TDSCDMA);
        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_ModeLteTdscdmaWcdma_returnTrue() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        Settings.Global.putInt(mContext.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
                TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA);
        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_ModeLteTdscdmaCdmaEvdoGsmWcdma_returnTrue() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        Settings.Global.putInt(mContext.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
                TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA);
        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
    }

    @Test
    public void shouldSpeciallyUpdateGsmCdma_ModeLteCdmaEvdoGsmWcdma_returnTrue() {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, false);

        Settings.Global.putInt(mContext.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
                TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
        assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
    }
}