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

Commit e03454ad authored by Michael Groover's avatar Michael Groover Committed by Android (Google) Code Review
Browse files

Merge "Update modems on null cipher notification preference changes" into main

parents 10051dc7 9b6396e3
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -257,6 +257,7 @@ public class GsmCdmaPhone extends Phone {

    private boolean mIsNullCipherAndIntegritySupported = false;
    private boolean mIsIdentifierDisclosureTransparencySupported = false;
    private boolean mIsNullCipherNotificationSupported = false;

    // Create Cfu (Call forward unconditional) so that dialing number &
    // mOnComplete (Message object passed by client) can be packed &
@@ -3160,6 +3161,7 @@ public class GsmCdmaPhone extends Phone {

        handleNullCipherEnabledChange();
        handleIdentifierDisclosureNotificationPreferenceChange();
        handleNullCipherNotificationPreferenceChanged();
    }

    private void handleRadioOn() {
@@ -3725,6 +3727,12 @@ public class GsmCdmaPhone extends Phone {
                }
                break;

            case EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE:
                logd("EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE");
                ar = (AsyncResult) msg.obj;
                mIsNullCipherNotificationSupported = doesResultIndicateModemSupport(ar);
                break;

            default:
                super.handleMessage(msg);
        }
@@ -5356,6 +5364,21 @@ public class GsmCdmaPhone extends Phone {
                obtainMessage(EVENT_SET_IDENTIFIER_DISCLOSURE_ENABLED_DONE));
    }

    @Override
    public void handleNullCipherNotificationPreferenceChanged() {
        if (!mFeatureFlags.enableModemCipherTransparency()) {
            logi("Not handling null cipher notification preference change. Feature flag "
                    + "enable_modem_cipher_transparency disabled");
            return;
        }
        boolean prefEnabled = getNullCipherNotificationsPreferenceEnabled();

        // TODO(b/316592273): Enable / disable in NullCipherNotifier once the class is available.

        mCi.setSecurityAlgorithmsUpdatedEnabled(prefEnabled,
                obtainMessage(EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE));
    }

    @Override
    public boolean isNullCipherAndIntegritySupported() {
        return mIsNullCipherAndIntegritySupported;
@@ -5365,4 +5388,9 @@ public class GsmCdmaPhone extends Phone {
    public boolean isIdentifierDisclosureTransparencySupported() {
        return mIsIdentifierDisclosureTransparencySupported;
    }

    @Override
    public boolean isNullCipherNotificationSupported() {
        return mIsNullCipherNotificationSupported;
    }
}
+27 −1
Original line number Diff line number Diff line
@@ -258,7 +258,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    protected static final int EVENT_CELL_IDENTIFIER_DISCLOSURE = 72;
    protected static final int EVENT_SET_IDENTIFIER_DISCLOSURE_ENABLED_DONE = 73;
    protected static final int EVENT_SECURITY_ALGORITHM_UPDATE = 74;
    protected static final int EVENT_LAST = EVENT_SECURITY_ALGORITHM_UPDATE;
    protected static final int EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE = 75;
    protected static final int EVENT_LAST = EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE;

    // For shared prefs.
    private static final String GSM_ROAMING_LIST_OVERRIDE_PREFIX = "gsm_roaming_list_";
@@ -292,6 +293,9 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    public static final String PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED =
            "pref_identifier_disclosure_notifications_enabled";

    public static final String PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED =
            "pref_null_cipher_notifications_enabled";

    protected final FeatureFlags mFeatureFlags;

    /**
@@ -5187,6 +5191,28 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    public void handleIdentifierDisclosureNotificationPreferenceChange() {
    }

    /**
     * @return whether this Phone interacts with a modem that supports the null cipher
     * notification feature.
     */
    public boolean isNullCipherNotificationSupported() {
        return false;
    }

    /**
     * @return whether the global null cipher notifications preference is enabled.
     */
    public boolean getNullCipherNotificationsPreferenceEnabled() {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        return sp.getBoolean(PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, false);
    }

    /**
     * Override to handle an update to the null cipher notification preference.
     */
    public void handleNullCipherNotificationPreferenceChanged() {
    }

    /**
     * Notifies the IMS call status to the modem.
     *
+46 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.internal.telephony.Phone.EVENT_IMS_DEREGISTRATION_TRIG
import static com.android.internal.telephony.Phone.EVENT_RADIO_AVAILABLE;
import static com.android.internal.telephony.Phone.EVENT_SET_IDENTIFIER_DISCLOSURE_ENABLED_DONE;
import static com.android.internal.telephony.Phone.EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE;
import static com.android.internal.telephony.Phone.EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_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;
@@ -2930,7 +2931,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        sendRadioAvailableToPhone(phoneUT);
        verify(mMockCi, times(1)).setCellularIdentifierTransparencyEnabled(anyBoolean(),
                any(Message.class));
        sendIdentifierDisclosureEnabledSuccessToPhone(phoneUT);
        sendRequestSuccessToPhone(phoneUT, EVENT_SET_IDENTIFIER_DISCLOSURE_ENABLED_DONE);

        assertTrue(phoneUT.isIdentifierDisclosureTransparencySupported());
    }
@@ -2977,6 +2978,48 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        verify(mNullCipherNotifier, times(1)).onSecurityAlgorithmUpdate(eq(0), eq(update));
    }

    @Test
    public void testNullCipherNotification_noModemCallOnRadioAvailable_FlagOff() {
        when(mFeatureFlags.enableModemCipherTransparency()).thenReturn(false);
        GsmCdmaPhone phoneUT = makeNewPhoneUT();
        assertFalse(phoneUT.isNullCipherNotificationSupported());

        sendRadioAvailableToPhone(phoneUT);

        verify(mMockCi, never()).setSecurityAlgorithmsUpdatedEnabled(anyBoolean(),
                any(Message.class));
        assertFalse(phoneUT.isNullCipherNotificationSupported());
    }

    @Test
    public void testNullCipherNotification_unsupportedByModemOnRadioAvailable() {
        when(mFeatureFlags.enableModemCipherTransparency()).thenReturn(true);
        GsmCdmaPhone phoneUT = makeNewPhoneUT();
        assertFalse(phoneUT.isNullCipherNotificationSupported());

        sendRadioAvailableToPhone(phoneUT);
        verify(mMockCi, times(1)).setSecurityAlgorithmsUpdatedEnabled(anyBoolean(),
                any(Message.class));
        sendRequestNotSupportedToPhone(phoneUT, EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE);

        assertFalse(phoneUT.isNullCipherNotificationSupported());
    }

    @Test
    public void testNullCipherNotification_supportedByModem() {
        when(mFeatureFlags.enableModemCipherTransparency()).thenReturn(true);
        GsmCdmaPhone phoneUT = makeNewPhoneUT();
        assertFalse(phoneUT.isNullCipherNotificationSupported());

        sendRadioAvailableToPhone(phoneUT);
        verify(mMockCi, times(1)).setSecurityAlgorithmsUpdatedEnabled(anyBoolean(),
                any(Message.class));
        sendRequestSuccessToPhone(phoneUT, EVENT_SET_SECURITY_ALGORITHMS_UPDATED_ENABLED_DONE);

        assertTrue(phoneUT.isNullCipherNotificationSupported());
    }


    private void sendRadioAvailableToPhone(GsmCdmaPhone phone) {
        phone.sendMessage(phone.obtainMessage(EVENT_RADIO_AVAILABLE,
                new AsyncResult(null, new int[]{ServiceState.RIL_RADIO_TECHNOLOGY_GSM}, null)));
@@ -2989,9 +3032,8 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        processAllMessages();
    }

    private void sendIdentifierDisclosureEnabledSuccessToPhone(GsmCdmaPhone phone) {
        phone.sendMessage(phone.obtainMessage(EVENT_SET_IDENTIFIER_DISCLOSURE_ENABLED_DONE,
                new AsyncResult(null, null, null)));
    private void sendRequestSuccessToPhone(GsmCdmaPhone phone, int eventId) {
        phone.sendMessage(phone.obtainMessage(eventId, new AsyncResult(null, null, null)));
        processAllMessages();
    }