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

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

Update Null Cipher Enabled on Radio Available

Adds a new handling method on Phone that is overriden
by GsmCdmaPhone to handle requests for updates to the
SharedPreference that backs the null cipher enablement API.

The GsmCdmaPhone handles calling the handler on modem availability
which covers a reboot of the device or a restart of the modem after
crashes.

Test: atest GsmCdmaPhoneTest
Bug: 260844152
Change-Id: Ifaa70998d551c9fb7545211f725c51fad06ea80a
parent 1fdeecd1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2946,9 +2946,9 @@ public interface CommandsInterface {
     * Set the UE's ability to accept/reject null ciphered and/or null integrity-protected
     * connections.
     *
     * @param result Callback message containing the success or failure status.
     * @param enabled true to allow null ciphered and/or null integrity-protected connections,
     * false to disallow.
     * @param result Callback message containing the success or failure status.
     */
    default void setNullCipherAndIntegrityEnabled(Message result, boolean enabled) {}
    default void setNullCipherAndIntegrityEnabled(boolean enabled, Message result) {}
}
+11 −0
Original line number Diff line number Diff line
@@ -2924,6 +2924,7 @@ public class GsmCdmaPhone extends Phone {
        mCi.getRadioCapability(obtainMessage(EVENT_GET_RADIO_CAPABILITY));
        mCi.areUiccApplicationsEnabled(obtainMessage(EVENT_GET_UICC_APPS_ENABLEMENT_DONE));

        handleNullCipherEnabledChange();
        startLceAfterRadioIsAvailable();
    }

@@ -3378,6 +3379,9 @@ public class GsmCdmaPhone extends Phone {
                logd("EVENT_SUBSCRIPTIONS_CHANGED");
                updateUsageSetting();
                break;
            case EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE:
                logd("EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE");
                break;

            case EVENT_IMS_DEREGISTRATION_TRIGGERED:
                logd("EVENT_IMS_DEREGISTRATION_TRIGGERED");
@@ -4914,4 +4918,11 @@ public class GsmCdmaPhone extends Phone {
        ArrayList<String> controlStrings = GsmMmiCode.getControlStrings(requestType, serviceType);
        return FdnUtils.isSuppServiceRequestBlockedByFdn(mPhoneId, controlStrings, getCountryIso());
    }

    @Override
    public void handleNullCipherEnabledChange() {
        mCi.setNullCipherAndIntegrityEnabled(
                getNullCipherAndIntegrityEnabledPreference(),
                obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE));
    }
}
+21 −13
Original line number Diff line number Diff line
@@ -239,8 +239,9 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    protected static final int EVENT_GET_USAGE_SETTING_DONE = 63;
    protected static final int EVENT_SET_USAGE_SETTING_DONE = 64;
    protected static final int EVENT_IMS_DEREGISTRATION_TRIGGERED = 65;
    protected static final int EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE = 66;

    protected static final int EVENT_LAST = EVENT_IMS_DEREGISTRATION_TRIGGERED;
    protected static final int EVENT_LAST = EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE;

    // For shared prefs.
    private static final String GSM_ROAMING_LIST_OVERRIDE_PREFIX = "gsm_roaming_list_";
@@ -267,6 +268,9 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    // Integer used to let the calling application know that the we are ignoring auto mode switch.
    private static final int ALREADY_IN_AUTO_SELECTION = 1;

    public static final String PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED =
            "pref_null_cipher_and_integrity_enabled";

    /**
     * This method is invoked when the Phone exits Emergency Callback Mode.
     */
@@ -4994,18 +4998,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.unregisterForEmergencyNetworkScan(h);
    }

    /**
     * Set the UE's ability to accept/reject null ciphered and/or null integrity-protected
     * connections.
     *
     * @param result Callback message.
     * @param enabled true to allow null ciphered and/or null integrity-protected connections,
     * false to disallow.
     */
    public void setNullCipherAndIntegrityEnabled(@Nullable Message result, boolean enabled) {
        mCi.setNullCipherAndIntegrityEnabled(result, enabled);
    }

    /**
     * Notifies that IMS deregistration is triggered.
     *
@@ -5044,6 +5036,22 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
                : null;
    }

    /**
     * @return global null cipher and integrity enabled preference
     */
    public boolean getNullCipherAndIntegrityEnabledPreference() {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        return sp.getBoolean(PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, true);
    }

    /**
     * Override to implement handling of an update to the enablement of the null cipher and
     * integrity preference.
     * {@see #PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED}
     */
    public void handleNullCipherEnabledChange() {
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Phone: subId=" + getSubId());
        pw.println(" mPhoneId=" + mPhoneId);
+1 −1
Original line number Diff line number Diff line
@@ -5555,7 +5555,7 @@ public class RIL extends BaseCommands implements CommandsInterface {
     * @param enabled true if null ciphering / null integrity modes are permitted, false otherwise
     */
    @Override
    public void setNullCipherAndIntegrityEnabled(Message result, boolean enabled) {
    public void setNullCipherAndIntegrityEnabled(boolean enabled, Message result) {
        RadioNetworkProxy networkProxy = getRadioServiceProxy(RadioNetworkProxy.class, result);
        if (networkProxy.isEmpty()) return;
        if (mHalVersion.get(HAL_SERVICE_NETWORK).greaterOrEqual(RADIO_HAL_VERSION_2_1)) {
+12 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.internal.telephony.CommandsInterface.CF_ACTION_ENABLE;
import static com.android.internal.telephony.CommandsInterface.CF_REASON_UNCONDITIONAL;
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_SRVCC_STATE_CHANGED;
import static com.android.internal.telephony.Phone.EVENT_UICC_APPS_ENABLEMENT_STATUS_CHANGED;
import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
@@ -2080,6 +2081,15 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        fdnCheckCleanup();
    }

    @Test
    public void testHandleNullCipherAndIntegrityEnabledOnRadioAvailable() {
        GsmCdmaPhone spiedPhone = spy(mPhoneUT);
        spiedPhone.sendMessage(spiedPhone.obtainMessage(EVENT_RADIO_AVAILABLE,
                new AsyncResult(null, new int[]{ServiceState.RIL_RADIO_TECHNOLOGY_GSM}, null)));
        processAllMessages();
        verify(spiedPhone, times(1)).handleNullCipherEnabledChange();
    }

    public void fdnCheckCleanup() {
        doReturn(false).when(mUiccCardApplication3gpp).getIccFdnAvailable();
        doReturn(false).when(mUiccCardApplication3gpp).getIccFdnEnabled();