Merge "Change Toggle UX to "Require encryption""

This commit is contained in:
Gil Cukierman
2023-01-17 14:13:07 +00:00
committed by Android (Google) Code Review
4 changed files with 22 additions and 24 deletions

View File

@@ -11086,10 +11086,10 @@
<!-- Title for if toggle access is disabled by carrier [CHAR LIMIT=NONE] --> <!-- 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> <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>
<!-- Title for toggle if user wants to allow null cellular algorithms [CHAR LIMIT=40] --> <!-- Title for toggle if user wants to require cellular encryption [CHAR LIMIT=40] -->
<string name="allow_null_algorithms_title">Allow less secure connection</string> <string name="require_cellular_encryption_title">Require encryption</string>
<!-- Summary for if the user wants to allow null cellular algorithms [CHAR LIMIT=NONE] --> <!-- Summary for if the user wants to require cellular encryption [CHAR LIMIT=NONE] -->
<string name="allow_null_algorithms_summary">May improve your signal in some locations. For emergency calls, less secure connections are always allowed.</string> <string name="require_cellular_encryption_summary">Encryption is more secure, but you might not be able to connect in some locations. For emergency calls, encryption is never required</string>
<!-- Label for All services preference in App info settings [CHAR LIMIT=40] --> <!-- Label for All services preference in App info settings [CHAR LIMIT=40] -->
<string name="app_info_all_services_label">All services</string> <string name="app_info_all_services_label">All services</string>

View File

@@ -251,9 +251,9 @@
settings:userRestriction="no_cellular_2g"/> settings:userRestriction="no_cellular_2g"/>
<SwitchPreference <SwitchPreference
android:key="allow_null_algorithms" android:key="require_cellular_encryption"
android:title="@string/allow_null_algorithms_title" android:title="@string/require_cellular_encryption_title"
android:summary="@string/allow_null_algorithms_summary" android:summary="@string/require_cellular_encryption_summary"
settings:controller= settings:controller=
"com.android.settings.network.telephony.NullAlgorithmsPreferenceController" /> "com.android.settings.network.telephony.NullAlgorithmsPreferenceController" />

View File

@@ -21,9 +21,9 @@ import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
/** /**
* Preference controller for "Allow Null Algorithms" * Preference controller for "Require Encryption"
* *
* <p>This preference controller is toggling null algorithms is not a per-sim operation. * <p>This preference controller is toggling null algorithms. This applies to all active SIMs.
*/ */
public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenceController { public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenceController {
@@ -33,7 +33,7 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
/** /**
* Class constructor of "Allow Null Algorithms" toggle. * Class constructor of "Require Encryption" toggle.
* *
* @param context of settings * @param context of settings
* @param key assigned within UI entry of XML file * @param key assigned within UI entry of XML file
@@ -81,7 +81,7 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
} }
/** /**
* Return {@code true} if null algorithms are currently allowed. * Return {@code true} if encryption is required (null algorithms not allowed)
* *
* <p><b>NOTE:</b> This method returns the active state of the preference controller and is not * <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 * the parameter passed into {@link #setChecked(boolean)}, which is instead the requested future
@@ -90,7 +90,7 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
@Override @Override
public boolean isChecked() { public boolean isChecked() {
try { try {
return mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled(); return !mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled();
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, Log.e(LOG_TAG,
"Failed isNullCipherAndIntegrityEnabled. Defaulting toggle to " "Failed isNullCipherAndIntegrityEnabled. Defaulting toggle to "
@@ -109,24 +109,22 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
* details. * details.
* *
* @param isChecked The toggle value that we're being requested to enforce. A value of {@code * @param isChecked The toggle value that we're being requested to enforce. A value of {@code
* false} denotes that null ciphers will be disabled by the modem after this * true} denotes that null ciphers will be disabled by the modem after this
* function * function completes, if it is not already.
* completes, if it is not already.
*/ */
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
if (isChecked) { if (isChecked) {
Log.i(LOG_TAG, "Enabling null algorithms"); Log.i(LOG_TAG, "Encryption required. Disabling null algorithms.");
} else { } else {
Log.i(LOG_TAG, "Disabling null algorithms"); Log.i(LOG_TAG, "Encryption not required. Enabling null algorithms.");
} }
try { try {
mTelephonyManager.setNullCipherAndIntegrityEnabled(isChecked); mTelephonyManager.setNullCipherAndIntegrityEnabled(!isChecked);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, Log.e(LOG_TAG,
"Failed setNullCipherAndIntegrityEnabled. Setting not updated. Exception: " "Failed setNullCipherAndIntegrityEnabled. Setting not updated. Exception: "
+ e.getMessage()); + e.getMessage());
// The underlying setting was not updated
return false; return false;
} }
return true; return true;

View File

@@ -142,22 +142,22 @@ public final class NullAlgorithmsPreferenceControllerTest {
} }
@Test @Test
public void setChecked_true() { public void setChecked_true_nullCiphersDisabled() {
mController.setChecked(true); mController.setChecked(true);
verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true); verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(false);
} }
@Test @Test
public void setChecked_false() { public void setChecked_false_nullCiphersEnabled() {
mController.setChecked(false); mController.setChecked(false);
verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(false); verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true);
} }
@Test @Test
public void setChecked_exceptionThrown() { public void setChecked_exceptionThrown() {
doThrow(IllegalStateException.class).when( doThrow(IllegalStateException.class).when(
mTelephonyManager).setNullCipherAndIntegrityEnabled(true); mTelephonyManager).setNullCipherAndIntegrityEnabled(true);
assertFalse(mController.setChecked(true)); assertFalse(mController.setChecked(false));
verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true); verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true);
} }
} }