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

Commit bfab8a80 authored by Amit Talreja (xWF)'s avatar Amit Talreja (xWF) Committed by Android (Google) Code Review
Browse files

Merge "Updated the 2G enable setting title. Bug:391709444 Test: atest...

Merge "Updated the 2G enable setting title. Bug:391709444 Test: atest Enable2gPreferenceControllerTest Flag: EXEMPT bugfix" into main
parents 5d09af06 86829930
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -13591,9 +13591,9 @@ Data usage charges may apply.</string>
    <string name="smart_forwarding_missing_alert_dialog_text">OK</string>
    <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=40] -->
    <string name="enable_2g_title">Allow 2G</string>
    <string name="enable_2g_title">2G network protection</string>
    <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] -->
    <string name="enable_2g_summary">2G is less secure, but may improve your connection in some locations. For emergency calls, 2G is always allowed.</string>
    <string name="enable_2g_summary">Avoids 2G networks, which are less secure. This may limit connectivity in some places. Emergency calling is always allowed.</string>
    <!-- Title for if toggle access is disabled by carrier [CHAR LIMIT=NONE] -->
    <string name="enable_2g_summary_disabled_carrier"><xliff:g id="carrier_name_2g" example="Google Fi">%1$s</xliff:g> requires 2G to be available</string>
+11 −11
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
    }

    /**
     * Return {@code true} if 2g is currently enabled.
     * Return {@code true} if only 3G and higher is currently enabled.
     *
     * <p><b>NOTE:</b> This method returns the active state of the preference controller and is not
     * the parameter passed into {@link #setChecked(boolean)}, which is instead the requested future
@@ -181,12 +181,12 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
     */
    @Override
    public boolean isChecked() {
        // If an enterprise admin has disabled 2g, we show the toggle as not checked to avoid
        // user confusion of seeing a checked toggle, but having 2g actually disabled.
        // If an enterprise admin has disabled 2g, we show the toggle as checked to avoid
        // user confusion of seeing a unchecked toggle, but having 3G and higher actually enable.
        // The RestrictedSwitchPreference will take care of transparently informing the user that
        // the setting was disabled by their admin
        if (isDisabledByAdmin()) {
            return false;
            return true;
        }

        if (mTelephonyManager == null) {
@@ -195,7 +195,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
        }
        long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
                mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
        return (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;
        return (currentlyAllowedNetworkTypes & BITMASK_2G) == 0;
    }

    /**
@@ -206,7 +206,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
     * details.
     *
     * @param isChecked The toggle value that we're being requested to enforce. A value of {@code
     *                  false} denotes that 2g will be disabled by the modem after this function
     *                  true} denotes that 2g will be disabled by the modem after this function
     *                  completes, if it is not already.
     */
    @Override
@@ -227,21 +227,21 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
        long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
                mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
        boolean enabled = (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;
        if (enabled == isChecked) {
        if (enabled != isChecked) {
            return false;
        }
        long newAllowedNetworkTypes = currentlyAllowedNetworkTypes;
        if (isChecked) {
            newAllowedNetworkTypes = currentlyAllowedNetworkTypes | BITMASK_2G;
            Log.i(LOG_TAG, "Enabling 2g. Allowed network types: " + newAllowedNetworkTypes);
        } else {
            newAllowedNetworkTypes = currentlyAllowedNetworkTypes & ~BITMASK_2G;
            Log.i(LOG_TAG, "Disabling 2g. Allowed network types: " + newAllowedNetworkTypes);
        } else {
            newAllowedNetworkTypes = currentlyAllowedNetworkTypes | BITMASK_2G;
            Log.i(LOG_TAG, "Enabling 2g. Allowed network types: " + newAllowedNetworkTypes);
        }
        mTelephonyManager.setAllowedNetworkTypesForReason(
                mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, newAllowedNetworkTypes);
        mMetricsFeatureProvider.action(
                mContext, SettingsEnums.ACTION_2G_ENABLED, isChecked);
                mContext, SettingsEnums.ACTION_2G_ENABLED, !isChecked);
        return true;
    }

+5 −5
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ public final class Enable2gPreferenceControllerTest {
        when2gIsEnabledForReasonEnable2g();

        // Disable 2G
        boolean changed = mController.setChecked(false);
        boolean changed = mController.setChecked(true);
        assertThat(changed).isEqualTo(true);

        verify(mTelephonyManager, times(1)).setAllowedNetworkTypesForReason(
@@ -159,7 +159,7 @@ public final class Enable2gPreferenceControllerTest {
    public void disabledByAdmin_toggleUnchecked() {
        when2gIsEnabledForReasonEnable2g();
        when2gIsDisabledByAdmin(true);
        assertThat(mController.isChecked()).isFalse();
        assertThat(mController.isChecked()).isTrue();
    }

    @Test
@@ -167,15 +167,15 @@ public final class Enable2gPreferenceControllerTest {
        // Initially, 2g is enabled
        when2gIsEnabledForReasonEnable2g();
        when2gIsDisabledByAdmin(false);
        assertThat(mController.isChecked()).isTrue();
        assertThat(mController.isChecked()).isFalse();

        // When we disable the preference by an admin, the preference should be unchecked
        when2gIsDisabledByAdmin(true);
        assertThat(mController.isChecked()).isFalse();
        assertThat(mController.isChecked()).isTrue();

        // If the preference is re-enabled by an admin, former state should hold
        when2gIsDisabledByAdmin(false);
        assertThat(mController.isChecked()).isTrue();
        assertThat(mController.isChecked()).isFalse();
    }

    @Test