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

Commit ffcbdc81 authored by Gil Cukierman's avatar Gil Cukierman Committed by Android (Google) Code Review
Browse files

Merge "Track Modem Support for Null Cipher Disablement in Phone"

parents 5ac306b9 35f6f041
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -242,6 +242,8 @@ public class GsmCdmaPhone extends Phone {
    CellBroadcastConfigTracker mCellBroadcastConfigTracker =
            CellBroadcastConfigTracker.make(this, null);

    private boolean mIsNullCipherAndIntegritySupported = false;

    // Create Cfu (Call forward unconditional) so that dialing number &
    // mOnComplete (Message object passed by client) can be packed &
    // given as a single Cfu object as user data to RIL.
@@ -3440,6 +3442,14 @@ public class GsmCdmaPhone extends Phone {
                break;
            case 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;

            case EVENT_IMS_DEREGISTRATION_TRIGGERED:
@@ -5034,4 +5044,9 @@ public class GsmCdmaPhone extends Phone {
                getNullCipherAndIntegrityEnabledPreference(),
                obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE));
    }

    @Override
    public boolean isNullCipherAndIntegritySupported() {
        return mIsNullCipherAndIntegritySupported;
    }
}
+8 −0
Original line number 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 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
     * integrity preference.
+46 −1
Original line number 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_IMS_DEREGISTRATION_TRIGGERED;
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_UICC_APPS_ENABLEMENT_STATUS_CHANGED;
import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
@@ -2109,6 +2110,51 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        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
    public void testHandleNullCipherAndIntegrityEnabled_featureFlagOn() {
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
@@ -2137,7 +2183,6 @@ public class GsmCdmaPhoneTest extends TelephonyTest {

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

    }

    public void fdnCheckCleanup() {