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

Commit 259e6288 authored by SongFerngWang's avatar SongFerngWang
Browse files

EnabledNetworkModePreferenceController Remove AllowedNetworkType

Power manager decision do enable/disable NR by AllowedNetworkType,
and it will effect the PreferredNetworkMode UI. The
PreferredNetworkMode list no 5G item when AllowedNetworkType
disabled.

Bug: 156709797
Test: make RunSettingsRoboTests ROBOTEST_FILTER=\
EnabledNetworkModePreferenceControllerTest  (pass)

Change-Id: I3ab9eca0956c4cce1b79e518942063b681eb96cd
parent f5056a03
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -168,7 +168,6 @@ public class EnabledNetworkModePreferenceController extends
        private Context mContext;
        private TelephonyManager mTelephonyManager;

        private boolean mAllowed5gNetworkType;
        private boolean mIsGlobalCdma;
        private boolean mIs5gEntryDisplayed;
        private boolean mShow4gForLTE;
@@ -206,9 +205,6 @@ public class EnabledNetworkModePreferenceController extends
            final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
            final boolean isNrEnabledFromCarrierConfig = carrierConfig != null
                    && carrierConfig.getBoolean(CarrierConfigManager.KEY_NR_ENABLED_BOOL);
            mAllowed5gNetworkType = checkSupportedRadioBitmask(
                    mTelephonyManager.getAllowedNetworkTypes(),
                    TelephonyManager.NETWORK_TYPE_BITMASK_NR);
            mSupported5gRadioAccessFamily = isNrEnabledFromCarrierConfig
                    && checkSupportedRadioBitmask(mTelephonyManager.getSupportedRadioAccessFamily(),
                    TelephonyManager.NETWORK_TYPE_BITMASK_NR);
@@ -572,7 +568,7 @@ public class EnabledNetworkModePreferenceController extends
        }

        /**
         * Add 5G option. Only show the UI when device supported 5G and allowed 5G.
         * Add 5G option. Only show the UI when device supported 5G.
         */
        private void add5gEntry(int value) {
            boolean isNRValue = value >= TelephonyManagerConstants.NETWORK_MODE_NR_ONLY;
@@ -585,15 +581,13 @@ public class EnabledNetworkModePreferenceController extends
                mIs5gEntryDisplayed = false;
                Log.d(LOG_TAG, "Hide 5G option. "
                        + " supported5GRadioAccessFamily: " + mSupported5gRadioAccessFamily
                        + " allowed5GNetworkType: " + mAllowed5gNetworkType
                        + " isNRValue: " + isNRValue);
            }
        }

        private void addGlobalEntry() {
            Log.d(LOG_TAG, "addGlobalEntry. "
                    + " supported5GRadioAccessFamily: " + mSupported5gRadioAccessFamily
                    + " allowed5GNetworkType: " + mAllowed5gNetworkType);
                    + " supported5GRadioAccessFamily: " + mSupported5gRadioAccessFamily);
            mEntries.add(mContext.getString(R.string.network_global));
            if (showNrList()) {
                mEntriesValue.add(
@@ -605,7 +599,7 @@ public class EnabledNetworkModePreferenceController extends
        }

        private boolean showNrList() {
            return mSupported5gRadioAccessFamily && mAllowed5gNetworkType;
            return mSupported5gRadioAccessFamily;
        }

        /**
+0 −76
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ public class EnabledNetworkModePreferenceControllerTest {
    private static final int SUB_ID = 2;
    public static final String KEY = "enabled_network";

    private static final long ALLOWED_ALL_NETWORK_TYPE = -1;
    private static final long DISABLED_5G_NETWORK_TYPE = ~TelephonyManager.NETWORK_TYPE_BITMASK_NR;

    @Mock
@@ -98,7 +97,6 @@ public class EnabledNetworkModePreferenceControllerTest {
        doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
        mPreference = new ListPreference(mContext);
        mController = new EnabledNetworkModePreferenceController(mContext, KEY);
        mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
        mockAccessFamily(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
        mController.init(mLifecycle, SUB_ID);
        mPreference.setKey(mController.getPreferenceKey());
@@ -184,76 +182,6 @@ public class EnabledNetworkModePreferenceControllerTest {
                        TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
    }

    @Test
    public void updateState_disAllowed5g_5gOptionHidden() {
        mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
        mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
        mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
        mController.init(mLifecycle, SUB_ID);
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
                TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);

        mController.updateState(mPreference);

        assertThat(mPreference.getEntryValues())
                .asList()
                .doesNotContain(
                        String.valueOf(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
    }

    @Test
    public void updateState_disAllowed5g_selectOn4gOption() {
        mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
        mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
        mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
        mController.init(mLifecycle, SUB_ID);
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
                TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);

        mController.updateState(mPreference);

        assertThat(mPreference.getValue()).isEqualTo(
                String.valueOf(
                        TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
    }

    @Test
    public void updateState_GlobalDisAllowed5g_GlobalWithoutNR() {
        mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
        mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
        mController.init(mLifecycle, SUB_ID);
        mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
                TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);

        mController.updateState(mPreference);

        assertThat(mPreference.getEntryValues())
                .asList()
                .doesNotContain(
                        String.valueOf(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
    }

    @Test
    public void updateState_GlobalDisAllowed5g_SelectOnGlobal() {
        mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
        mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
        mController.init(mLifecycle, SUB_ID);
        mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
                TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);

        mController.updateState(mPreference);

        assertThat(mPreference.getValue()).isEqualTo(
                String.valueOf(
                        TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
    }

    @Test
    public void updateState_updateByNetworkMode() {
        mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
@@ -351,10 +279,6 @@ public class EnabledNetworkModePreferenceControllerTest {
        }
    }

    private void mockAllowedNetworkTypes(long allowedNetworkType) {
        doReturn(allowedNetworkType).when(mTelephonyManager).getAllowedNetworkTypes();
    }

    private void mockAccessFamily(int networkMode) {
        doReturn(MobileNetworkUtils.getRafFromNetworkType(networkMode))
                .when(mTelephonyManager)