Add Extra Exception Checks to Null Cipher Toggle

Adds broad exception safety to all TelephonyManager calls.
Without these extra catch blocks, the entire Settings app would
crash if a TelephonyManager API were to throw an exception.

Bug: 262914591
Test: atest NullAlgorithmsPreferenceControllerTest
Change-Id: I997a37fe71bf007d67989c89b3abe3e520d79d3c
This commit is contained in:
Gil Cukierman
2023-01-03 18:21:34 +00:00
parent 238b7b4620
commit 58f946072d
2 changed files with 44 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
@@ -119,6 +120,16 @@ public final class NullAlgorithmsPreferenceControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
public void getAvailabilityStatus_telephonyManagerException_conditionallyUnavailable() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
TelephonyManager.PROPERTY_ENABLE_NULL_CIPHER_TOGGLE, Boolean.TRUE.toString(),
false);
doThrow(IllegalStateException.class).when(
mTelephonyManager).isNullCipherAndIntegrityPreferenceEnabled();
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
public void getAvailabilityStatus_returnAvailable() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
@@ -141,4 +152,12 @@ public final class NullAlgorithmsPreferenceControllerTest {
mController.setChecked(false);
verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(false);
}
@Test
public void setChecked_exceptionThrown() {
doThrow(IllegalStateException.class).when(
mTelephonyManager).setNullCipherAndIntegrityEnabled(true);
assertFalse(mController.setChecked(true));
verify(mTelephonyManager, times(1)).setNullCipherAndIntegrityEnabled(true);
}
}