diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0f92d31fa20..35612392a06 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13587,9 +13587,9 @@ Data usage charges may apply.
NOTE: 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; } diff --git a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java index 962a33b07ae..4b83bc72203 100644 --- a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java @@ -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