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

Commit 0251b272 authored by Gil Cukierman's avatar Gil Cukierman
Browse files

Change Toggle UX to "Require encryption"

Changes the UX of enable/disable null ciphers to
"Require encryption". The default value is off, making
the default behavior equivalent to the previous version
of the toggle.

Test: atest NullAlgorithmsPreferenceControllerTest
Test: Manual testing in cuttlefish
Bug: 264540492
Change-Id: Iaa0c9c259559a205aacad9fb9af8de6b54782c8d
parent c9e42d4d
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -11109,10 +11109,10 @@
    <!-- 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>
    <!-- Title for toggle if user wants to allow null cellular algorithms [CHAR LIMIT=40] -->
    <string name="allow_null_algorithms_title">Allow less secure connection</string>
    <!-- Summary for if the user wants to allow null cellular algorithms [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>
    <!-- Title for toggle if user wants to require cellular encryption [CHAR LIMIT=40] -->
    <string name="require_cellular_encryption_title">Require encryption</string>
    <!-- Summary for if the user wants to require cellular encryption [CHAR LIMIT=NONE] -->
    <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] -->
    <string name="app_info_all_services_label">All services</string>
+3 −3
Original line number Diff line number Diff line
@@ -251,9 +251,9 @@
            settings:userRestriction="no_cellular_2g"/>

        <SwitchPreference
            android:key="allow_null_algorithms"
            android:title="@string/allow_null_algorithms_title"
            android:summary="@string/allow_null_algorithms_summary"
            android:key="require_cellular_encryption"
            android:title="@string/require_cellular_encryption_title"
            android:summary="@string/require_cellular_encryption_summary"
            settings:controller=
                "com.android.settings.network.telephony.NullAlgorithmsPreferenceController" />

+10 −12
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import android.telephony.TelephonyManager;
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 {

@@ -33,7 +33,7 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
    private TelephonyManager mTelephonyManager;

    /**
     * Class constructor of "Allow Null Algorithms" toggle.
     * Class constructor of "Require Encryption" toggle.
     *
     * @param context of settings
     * @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
     * the parameter passed into {@link #setChecked(boolean)}, which is instead the requested future
@@ -90,7 +90,7 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
    @Override
    public boolean isChecked() {
        try {
            return mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled();
            return !mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled();
        } catch (Exception e) {
            Log.e(LOG_TAG,
                    "Failed isNullCipherAndIntegrityEnabled. Defaulting toggle to "
@@ -109,24 +109,22 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc
     * details.
     *
     * @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
     *                  function
     *                  completes, if it is not already.
     *                  true} denotes that null ciphers will be disabled by the modem after this
     *                  function completes, if it is not already.
     */
    @Override
    public boolean setChecked(boolean isChecked) {
        if (isChecked) {
            Log.i(LOG_TAG, "Enabling null algorithms");
            Log.i(LOG_TAG, "Encryption required. Disabling null algorithms.");
        } else {
            Log.i(LOG_TAG, "Disabling null algorithms");
            Log.i(LOG_TAG, "Encryption not required. Enabling null algorithms.");
        }
        try {
            mTelephonyManager.setNullCipherAndIntegrityEnabled(isChecked);
            mTelephonyManager.setNullCipherAndIntegrityEnabled(!isChecked);
        } catch (Exception e) {
            Log.e(LOG_TAG,
                    "Failed setNullCipherAndIntegrityEnabled. Setting not updated. Exception: "
                            + e.getMessage());
            // The underlying setting was not updated
            return false;
        }
        return true;
+5 −5
Original line number Diff line number Diff line
@@ -142,22 +142,22 @@ public final class NullAlgorithmsPreferenceControllerTest {
    }

    @Test
    public void setChecked_true() {
    public void setChecked_true_nullCiphersDisabled() {
        mController.setChecked(true);
        verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true);
        verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(false);
    }

    @Test
    public void setChecked_false() {
    public void setChecked_false_nullCiphersEnabled() {
        mController.setChecked(false);
        verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(false);
        verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true);
    }

    @Test
    public void setChecked_exceptionThrown() {
        doThrow(IllegalStateException.class).when(
                mTelephonyManager).setNullCipherAndIntegrityEnabled(true);
        assertFalse(mController.setChecked(true));
        assertFalse(mController.setChecked(false));
        verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true);
    }
}