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

Commit abe64604 authored by Michael Groover's avatar Michael Groover
Browse files

Enable null cipher notification updates on preference change

This commit updates the NullCipherNotifier to handle security
algorithm updates from the modem based on the preference update.

Bug: 316592273
Test: atest GsmCdmaPhoneTest
Change-Id: I73aa92ba3346a809b751ba705620e14f803a22e6
parent 9b6396e3
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -5373,7 +5373,11 @@ public class GsmCdmaPhone extends Phone {
        }
        boolean prefEnabled = getNullCipherNotificationsPreferenceEnabled();

        // TODO(b/316592273): Enable / disable in NullCipherNotifier once the class is available.
        if (prefEnabled) {
            mNullCipherNotifier.enable();
        } else {
            mNullCipherNotifier.disable();
        }

        mCi.setSecurityAlgorithmsUpdatedEnabled(prefEnabled,
                obtainMessage(EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE));
+26 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ public class NullCipherNotifier {
    private static final String TAG = "NullCipherNotifier";
    private static NullCipherNotifier sInstance;

    private boolean mEnabled = false;

    /**
     * Gets a singleton NullCipherNotifier.
     */
@@ -55,4 +57,28 @@ public class NullCipherNotifier {
        // from here.
        Rlog.d(TAG, "Security algorithm update: phoneId = " + phoneId + " " + update);
    }

    /**
     * Enables null cipher notification; {@code onSecurityAlgorithmUpdate} will start handling
     * security algorithm updates and send notifications to the user when required.
     */
    public void enable() {
        Rlog.d(TAG, "enabled");
        mEnabled = true;
    }

    /**
     * Clear all internal state and prevent further notifications until re-enabled. This can be
     * used in response to a user disabling the feature for null cipher notifications. If
     * {@code onSecurityAlgorithmUpdate} is called while in a disabled state, security algorithm
     * updates will be dropped.
     */
    public void disable() {
        Rlog.d(TAG, "disabled");
        mEnabled = false;
    }

    public boolean isEnabled() {
        return mEnabled;
    }
}
+33 −0
Original line number Diff line number Diff line
@@ -3019,6 +3019,31 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        assertTrue(phoneUT.isNullCipherNotificationSupported());
    }

    @Test
    public void testNullCipherNotification_preferenceEnabled() {
        when(mFeatureFlags.enableModemCipherTransparency()).thenReturn(true);
        GsmCdmaPhone phoneUT = makeNewPhoneUT();

        setNullCipherNotificationPreferenceEnabled(true);
        phoneUT.handleNullCipherNotificationPreferenceChanged();

        verify(mNullCipherNotifier, times(1)).enable();
        verify(mMockCi, times(1)).setSecurityAlgorithmsUpdatedEnabled(eq(true),
                any(Message.class));
    }

    @Test
    public void testNullCipherNotification_preferenceDisabled() {
        when(mFeatureFlags.enableModemCipherTransparency()).thenReturn(true);
        GsmCdmaPhone phoneUT = makeNewPhoneUT();

        setNullCipherNotificationPreferenceEnabled(false);
        phoneUT.handleNullCipherNotificationPreferenceChanged();

        verify(mNullCipherNotifier, times(1)).disable();
        verify(mMockCi, times(1)).setSecurityAlgorithmsUpdatedEnabled(eq(false),
                any(Message.class));
    }

    private void sendRadioAvailableToPhone(GsmCdmaPhone phone) {
        phone.sendMessage(phone.obtainMessage(EVENT_RADIO_AVAILABLE,
@@ -3037,6 +3062,14 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        processAllMessages();
    }

    private void setNullCipherNotificationPreferenceEnabled(boolean enabled) {
        SharedPreferences sharedPreferences =
                PreferenceManager.getDefaultSharedPreferences(mContext);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enabled);
        editor.apply();
    }

    private GsmCdmaPhone makeNewPhoneUT() {
        return new GsmCdmaPhone(
                mContext,