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

Commit 35f6f041 authored by Gil Cukierman's avatar Gil Cukierman
Browse files

Track Modem Support for Null Cipher Disablement in Phone

Adds Phone.isNullCipherAndIntegritySupported which,
by default, is initialized to false in Phone (no support).

When the radio becomes available, it attempts to make
a request to set the user's null cipher and integrity
preferences. If the response is anything other than a
REQUEST_NOT_SUPPORTED exception, the phone then considers
the feature supported by the modem.

Bug: 264574296
Test: atest GsmCdmaPhoneTest
Change-Id: Ib3ba1aa28da35758dbdf585704d929c9bc45ff97
parent 905dca77
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -242,6 +242,8 @@ public class GsmCdmaPhone extends Phone {
    CellBroadcastConfigTracker mCellBroadcastConfigTracker =
    CellBroadcastConfigTracker mCellBroadcastConfigTracker =
            CellBroadcastConfigTracker.make(this, null);
            CellBroadcastConfigTracker.make(this, null);


    private boolean mIsNullCipherAndIntegritySupported = false;

    // Create Cfu (Call forward unconditional) so that dialing number &
    // Create Cfu (Call forward unconditional) so that dialing number &
    // mOnComplete (Message object passed by client) can be packed &
    // mOnComplete (Message object passed by client) can be packed &
    // given as a single Cfu object as user data to RIL.
    // given as a single Cfu object as user data to RIL.
@@ -3440,6 +3442,14 @@ public class GsmCdmaPhone extends Phone {
                break;
                break;
            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;
                if (ar == null || ar.exception == null) {
                    mIsNullCipherAndIntegritySupported = true;
                    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:
@@ -5034,4 +5044,9 @@ public class GsmCdmaPhone extends Phone {
                getNullCipherAndIntegrityEnabledPreference(),
                getNullCipherAndIntegrityEnabledPreference(),
                obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE));
                obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE));
    }
    }

    @Override
    public boolean isNullCipherAndIntegritySupported() {
        return mIsNullCipherAndIntegritySupported;
    }
}
}
+8 −0
Original line number Original line Diff line number Diff line
@@ -5157,6 +5157,14 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        return sp.getBoolean(PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, true);
        return sp.getBoolean(PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, true);
    }
    }


    /**
     * @return whether or not this Phone interacts with a modem that supports the null cipher
     * and integrity feature.
     */
    public boolean isNullCipherAndIntegritySupported() {
        return false;
    }

    /**
    /**
     * Override to implement handling of an update to the enablement of the null cipher and
     * Override to implement handling of an update to the enablement of the null cipher and
     * integrity preference.
     * integrity preference.
+46 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.internal.telephony.CommandsInterface.CF_REASON_UNCONDI
import static com.android.internal.telephony.Phone.EVENT_ICC_CHANGED;
import static com.android.internal.telephony.Phone.EVENT_ICC_CHANGED;
import static com.android.internal.telephony.Phone.EVENT_IMS_DEREGISTRATION_TRIGGERED;
import static com.android.internal.telephony.Phone.EVENT_IMS_DEREGISTRATION_TRIGGERED;
import static com.android.internal.telephony.Phone.EVENT_RADIO_AVAILABLE;
import static com.android.internal.telephony.Phone.EVENT_RADIO_AVAILABLE;
import static com.android.internal.telephony.Phone.EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE;
import static com.android.internal.telephony.Phone.EVENT_SRVCC_STATE_CHANGED;
import static com.android.internal.telephony.Phone.EVENT_SRVCC_STATE_CHANGED;
import static com.android.internal.telephony.Phone.EVENT_UICC_APPS_ENABLEMENT_STATUS_CHANGED;
import static com.android.internal.telephony.Phone.EVENT_UICC_APPS_ENABLEMENT_STATUS_CHANGED;
import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
@@ -2109,6 +2110,51 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        fdnCheckCleanup();
        fdnCheckCleanup();
    }
    }


    @Test
    public void testHandleNullCipherAndIntegrityEnabled_radioFeatureUnsupported() {
        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));

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

    @Test
    public void testHandleNullCipherAndIntegrityEnabled_radioSupportsFeature() {
        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));

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

    @Test
    @Test
    public void testHandleNullCipherAndIntegrityEnabled_featureFlagOn() {
    public void testHandleNullCipherAndIntegrityEnabled_featureFlagOn() {
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
@@ -2137,7 +2183,6 @@ public class GsmCdmaPhoneTest extends TelephonyTest {


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

    }
    }


    public void fdnCheckCleanup() {
    public void fdnCheckCleanup() {