Loading src/java/com/android/internal/telephony/GsmCdmaPhone.java +5 −1 Original line number Diff line number Diff line Loading @@ -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)); Loading src/java/com/android/internal/telephony/security/NullCipherNotifier.java +26 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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; } } tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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, Loading Loading
src/java/com/android/internal/telephony/GsmCdmaPhone.java +5 −1 Original line number Diff line number Diff line Loading @@ -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)); Loading
src/java/com/android/internal/telephony/security/NullCipherNotifier.java +26 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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; } }
tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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, Loading