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

Commit f76d189a authored by Gil Cukierman's avatar Gil Cukierman
Browse files

Fix EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE Error Handling

The Require Encryption toggle was appearing in the Settings
app because `mIsNullCipherAndIntegritySupported` was being
set to `true` when an exception other than REQUEST_NOT_SUPPORTED
was returned. The code was operating under the false assumption
that the only exception returned when a modem operation is not
supported was REQUEST_NOT_SUPPORTED, but other exceptions are
possible, like RADIO_NOT_AVAILABLE.

This change enforces that the only way to set
`mIsNullCipherAndIntegritySupported` to `true` is by receiving
an error free response from the RIL.

Bug: 294037720
Test: atest GsmCdmaPhoneTest
Change-Id: Ic5ffb09e6a30c42e594ff3bfea29f6c04f8b949d
parent 2c0f49f8
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -3521,13 +3521,14 @@ public class GsmCdmaPhone extends Phone {
            case EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE:
            case EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE:
                logd("EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE");
                logd("EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE");
                ar = (AsyncResult) msg.obj;
                ar = (AsyncResult) msg.obj;
                // Only test for a success here in order to flip the support flag.
                // Testing for the negative case, e.g. REQUEST_NOT_SUPPORTED, is insufficient
                // because the modem or the RIL could still return exceptions for temporary
                // failures even when the feature is unsupported.
                if (ar == null || ar.exception == null) {
                if (ar == null || ar.exception == null) {
                    mIsNullCipherAndIntegritySupported = true;
                    mIsNullCipherAndIntegritySupported = true;
                    return;
                    return;
                }
                }
                CommandException.Error error = ((CommandException) ar.exception).getCommandError();
                mIsNullCipherAndIntegritySupported = !error.equals(
                        CommandException.Error.REQUEST_NOT_SUPPORTED);
                break;
                break;


            case EVENT_IMS_DEREGISTRATION_TRIGGERED:
            case EVENT_IMS_DEREGISTRATION_TRIGGERED:
+22 −2
Original line number Original line Diff line number Diff line
@@ -2211,7 +2211,6 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        verify(mMockCi, times(1)).setNullCipherAndIntegrityEnabled(anyBoolean(),
        verify(mMockCi, times(1)).setNullCipherAndIntegrityEnabled(anyBoolean(),
                any(Message.class));
                any(Message.class));


        // Some ephemeral error occurred in the modem, but the feature was supported
        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE,
        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE,
                new AsyncResult(null, null,
                new AsyncResult(null, null,
                        new CommandException(CommandException.Error.REQUEST_NOT_SUPPORTED))));
                        new CommandException(CommandException.Error.REQUEST_NOT_SUPPORTED))));
@@ -2219,6 +2218,28 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        assertFalse(mPhoneUT.isNullCipherAndIntegritySupported());
        assertFalse(mPhoneUT.isNullCipherAndIntegritySupported());
    }
    }


    @Test
    public void testHandleNullCipherAndIntegrityEnabled_radioUnavailable() {
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
                TelephonyManager.PROPERTY_ENABLE_NULL_CIPHER_TOGGLE, Boolean.TRUE.toString(),
                false);
        mPhoneUT.mCi = mMockCi;
        assertFalse(mPhoneUT.isNullCipherAndIntegritySupported());

        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(EVENT_RADIO_AVAILABLE,
                new AsyncResult(null, new int[]{ServiceState.RIL_RADIO_TECHNOLOGY_GSM}, null)));
        processAllMessages();

        verify(mMockCi, times(1)).setNullCipherAndIntegrityEnabled(anyBoolean(),
                any(Message.class));

        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE,
                new AsyncResult(null, null,
                        new CommandException(CommandException.Error.RADIO_NOT_AVAILABLE))));
        processAllMessages();
        assertFalse(mPhoneUT.isNullCipherAndIntegritySupported());
    }

    @Test
    @Test
    public void testHandleNullCipherAndIntegrityEnabled_radioSupportsFeature() {
    public void testHandleNullCipherAndIntegrityEnabled_radioSupportsFeature() {
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
@@ -2234,7 +2255,6 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        verify(mMockCi, times(1)).setNullCipherAndIntegrityEnabled(anyBoolean(),
        verify(mMockCi, times(1)).setNullCipherAndIntegrityEnabled(anyBoolean(),
                any(Message.class));
                any(Message.class));


        // Some ephemeral error occurred in the modem, but the feature was supported
        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE,
        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE,
                new AsyncResult(null, null, null)));
                new AsyncResult(null, null, null)));
        processAllMessages();
        processAllMessages();