Loading src/com/android/settings/network/telephony/NullAlgorithmsPreferenceController.java +25 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,12 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc } catch (UnsupportedOperationException e) { Log.i(LOG_TAG, "Null cipher enablement is unsupported: " + e.getMessage()); return UNSUPPORTED_ON_DEVICE; } catch (Exception e) { Log.e(LOG_TAG, "Failed isNullCipherAndIntegrityEnabled. Setting availability to " + "CONDITIONALLY_UNAVAILABLE. Exception: " + e.getMessage()); return CONDITIONALLY_UNAVAILABLE; } return AVAILABLE; Loading @@ -83,7 +89,16 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc */ @Override public boolean isChecked() { try { return mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled(); } catch (Exception e) { Log.e(LOG_TAG, "Failed isNullCipherAndIntegrityEnabled. Defaulting toggle to " + "checked = true. Exception: " + e.getMessage()); } // The default behavior for this toggle is enabled return true; } /** Loading @@ -105,7 +120,15 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc } else { Log.i(LOG_TAG, "Disabling null algorithms"); } try { 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; } } tests/unit/src/com/android/settings/network/telephony/NullAlgorithmsPreferenceControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading @@ -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); } } Loading
src/com/android/settings/network/telephony/NullAlgorithmsPreferenceController.java +25 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,12 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc } catch (UnsupportedOperationException e) { Log.i(LOG_TAG, "Null cipher enablement is unsupported: " + e.getMessage()); return UNSUPPORTED_ON_DEVICE; } catch (Exception e) { Log.e(LOG_TAG, "Failed isNullCipherAndIntegrityEnabled. Setting availability to " + "CONDITIONALLY_UNAVAILABLE. Exception: " + e.getMessage()); return CONDITIONALLY_UNAVAILABLE; } return AVAILABLE; Loading @@ -83,7 +89,16 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc */ @Override public boolean isChecked() { try { return mTelephonyManager.isNullCipherAndIntegrityPreferenceEnabled(); } catch (Exception e) { Log.e(LOG_TAG, "Failed isNullCipherAndIntegrityEnabled. Defaulting toggle to " + "checked = true. Exception: " + e.getMessage()); } // The default behavior for this toggle is enabled return true; } /** Loading @@ -105,7 +120,15 @@ public class NullAlgorithmsPreferenceController extends TelephonyTogglePreferenc } else { Log.i(LOG_TAG, "Disabling null algorithms"); } try { 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; } }
tests/unit/src/com/android/settings/network/telephony/NullAlgorithmsPreferenceControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading @@ -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); } }