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

Commit 430e92f2 authored by Gil Cukierman's avatar Gil Cukierman
Browse files

Honor Feature Flag When Updating Null Cipher Settings

When a GsmCdmaPhone instance is asked to handle a null cipher
update, it will first check the cellular_security namespace for
the enable_null_cipher_toggle flag. If the flag is false (the default),
no command will be sent through the RIL to the modem.

When the feature flag is set to false after previously having been set
to true (feature disablement), the user's device will maintain the
behavior of the active setting until the modem reboots. Since one reason we may want to disable this feature is an issue in the HAL integration itself, it could be unsafe to try and call the modem to reset state, so we implement the simpler and safer option.

Bug: b/262063470
Test: atest GsmCdmaPhoneTest
Change-Id: I0ab9f118ef2df816c3b878c3a34d60f1c35518ab
parent 6901dfc3
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.WorkSource;
import android.preference.PreferenceManager;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.Telephony;
import android.sysprop.TelephonyProperties;
@@ -4995,6 +4996,11 @@ public class GsmCdmaPhone extends Phone {

    @Override
    public void handleNullCipherEnabledChange() {
        if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
                TelephonyManager.PROPERTY_ENABLE_NULL_CIPHER_TOGGLE, false)) {
            logi("Not handling null cipher update. Feature disabled by DeviceConfig.");
            return;
        }
        mCi.setNullCipherAndIntegrityEnabled(
                getNullCipherAndIntegrityEnabledPreference(),
                obtainMessage(EVENT_SET_NULL_CIPHER_AND_INTEGRITY_DONE));
+5 −0
Original line number Diff line number Diff line
@@ -176,6 +176,11 @@ public class ContextFixture implements TestFixture<Context> {
                    mKeyValuePairs.put(request, (String)args.get("value"));
                    mNumKeyValuePairs++;
                    break;
                case Settings.CALL_METHOD_PUT_CONFIG:
                    logd("PUT_config called");
                    logd("adding config flag: " + request + "-" + args.getString("value"));
                    mFlags.put(request, args.getString("value"));
                    break;
                case Settings.CALL_METHOD_LIST_CONFIG:
                    logd("LIST_config: " + mFlags);
                    Bundle result = new Bundle();
+43 −4
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import android.os.PersistableBundle;
import android.os.Process;
import android.os.WorkSource;
import android.preference.PreferenceManager;
import android.provider.DeviceConfig;
import android.telecom.VideoProfile;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
@@ -79,6 +80,7 @@ import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Log;

import androidx.test.filters.FlakyTest;

@@ -115,6 +117,7 @@ import java.util.List;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class GsmCdmaPhoneTest extends TelephonyTest {
    private static final String LOG_TAG = "GsmCdmaPhoneTest";
    private static final String TEST_EMERGENCY_NUMBER = "555";

    // Mocked classes
@@ -126,6 +129,11 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    //mPhoneUnderTest
    private GsmCdmaPhone mPhoneUT;

    // Ideally we would use TestableDeviceConfig, but that's not doable because the Settings
    // app is not currently debuggable. For now, we use the real device config and ensure that
    // we reset the cellular_security namespace property to its pre-test value after every test.
    private DeviceConfig.Properties mPreTestProperties;

    private static final int EVENT_EMERGENCY_CALLBACK_MODE_EXIT = 1;
    private static final int EVENT_EMERGENCY_CALL_TOGGLE = 2;
    private static final int EVENT_SET_ICC_LOCK_ENABLED = 3;
@@ -149,6 +157,8 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mPreTestProperties = DeviceConfig.getProperties(
                TelephonyManager.PROPERTY_ENABLE_NULL_CIPHER_TOGGLE);
        mTestHandler = Mockito.mock(Handler.class);
        mUiccSlot = Mockito.mock(UiccSlot.class);
        mUiccPort = Mockito.mock(UiccPort.class);
@@ -173,6 +183,13 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void tearDown() throws Exception {
        mPhoneUT.removeCallbacksAndMessages(null);
        mPhoneUT = null;
        try {
            DeviceConfig.setProperties(mPreTestProperties);
        } catch (DeviceConfig.BadConfigException e) {
            Log.e(LOG_TAG,
                    "Failed to reset DeviceConfig to pre-test state. Test results may be impacted. "
                            + e.getMessage());
        }
        super.tearDown();
    }

@@ -2090,12 +2107,34 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    }

    @Test
    public void testHandleNullCipherAndIntegrityEnabledOnRadioAvailable() {
        GsmCdmaPhone spiedPhone = spy(mPhoneUT);
        spiedPhone.sendMessage(spiedPhone.obtainMessage(EVENT_RADIO_AVAILABLE,
    public void testHandleNullCipherAndIntegrityEnabled_featureFlagOn() {
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
                TelephonyManager.PROPERTY_ENABLE_NULL_CIPHER_TOGGLE, Boolean.TRUE.toString(),
                false);
        mPhoneUT.mCi = mMockCi;

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

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

    @Test
    public void testHandleNullCipherAndIntegrityEnabled_featureFlagOff() {
        mPhoneUT.mCi = mMockCi;
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_CELLULAR_SECURITY,
                TelephonyManager.PROPERTY_ENABLE_NULL_CIPHER_TOGGLE, Boolean.FALSE.toString(),
                false);

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

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

    }

    public void fdnCheckCleanup() {