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

Commit 03d50f9b authored by Mark Chien's avatar Mark Chien Committed by Automerger Merge Worker
Browse files

Merge "Fix READ_DEVICE_CONFIG permission denied problem in TetheringTests"...

Merge "Fix READ_DEVICE_CONFIG permission denied problem in TetheringTests" into rvc-dev am: 1c65357c

Change-Id: I7e85c0d8cdcca92943e81f6d08520c8b9e6d6bb3
parents 7e2072d4 1c65357c
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class TetheringConfiguration {
        isDunRequired = checkDunRequired(ctx);

        chooseUpstreamAutomatically = getResourceBoolean(
                res, R.bool.config_tether_upstream_automatic, false /** default value */);
                res, R.bool.config_tether_upstream_automatic, false /** defaultValue */);
        preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired);

        legacyDhcpRanges = getLegacyDhcpRanges(res);
@@ -375,30 +375,31 @@ public class TetheringConfiguration {
        // Priority 1: Device config
        // Priority 2: Resource config
        // Priority 3: Default value
        final boolean resourceValue = getResourceBoolean(
        final boolean defaultValue = getResourceBoolean(
                res, R.bool.config_tether_enable_bpf_offload, true /** default value */);

        // Due to the limitation of static mock for testing, using #getProperty directly instead
        // of getDeviceConfigBoolean. getDeviceConfigBoolean is not invoked because it uses
        // #getBoolean to get the boolean device config. The test can't know that the returned
        // boolean value comes from device config or default value (because of null property
        // string). Because the test would like to verify null property boolean string case,
        // use DeviceConfig.getProperty here. See also the test case testBpfOffload{*} in
        // TetheringConfigurationTest.java.
        final String value = DeviceConfig.getProperty(
                NAMESPACE_CONNECTIVITY, OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD);
        return (value != null) ? Boolean.parseBoolean(value) : resourceValue;
        return getDeviceConfigBoolean(OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD, defaultValue);
    }

    private boolean getEnableLegacyDhcpServer(final Resources res) {
        return getResourceBoolean(
                res, R.bool.config_tether_enable_legacy_dhcp_server, false /** default value */)
                || getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER);
                res, R.bool.config_tether_enable_legacy_dhcp_server, false /** defaultValue */)
                || getDeviceConfigBoolean(
                TETHER_ENABLE_LEGACY_DHCP_SERVER, false /** defaultValue */);
    }

    private boolean getDeviceConfigBoolean(final String name, final boolean defaultValue) {
        // Due to the limitation of static mock for testing, using #getDeviceConfigProperty instead
        // of DeviceConfig#getBoolean. If using #getBoolean here, the test can't know that the
        // returned boolean value comes from device config or default value (because of null
        // property string). See the test case testBpfOffload{*} in TetheringConfigurationTest.java.
        final String value = getDeviceConfigProperty(name);
        return value != null ? Boolean.parseBoolean(value) : defaultValue;
    }

    @VisibleForTesting
    protected boolean getDeviceConfigBoolean(final String name) {
        return DeviceConfig.getBoolean(NAMESPACE_CONNECTIVITY, name, false /** defaultValue */);
    protected String getDeviceConfigProperty(String name) {
        return DeviceConfig.getProperty(NAMESPACE_CONNECTIVITY, name);
    }

    private Resources getResources(Context ctx, int subId) {
+2 −3
Original line number Diff line number Diff line
@@ -147,9 +147,8 @@ public final class EntitlementManagerTest {
        doReturn(false).when(
                () -> SystemProperties.getBoolean(
                eq(EntitlementManager.DISABLE_PROVISIONING_SYSPROP_KEY), anyBoolean()));
        doReturn(false).when(
                () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
        doReturn(null).when(
                () -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY), anyString()));

        when(mResources.getStringArray(R.array.config_tether_dhcp_range))
                .thenReturn(new String[0]);
+12 −13
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;

@@ -109,9 +108,9 @@ public class TetheringConfigurationTest {
                .mockStatic(DeviceConfig.class)
                .strictness(Strictness.WARN)
                .startMocking();
        doReturn(false).when(
                () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
        doReturn(null).when(
                () -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));

        when(mResources.getStringArray(R.array.config_tether_dhcp_range)).thenReturn(
                new String[0]);
@@ -328,9 +327,9 @@ public class TetheringConfigurationTest {
    public void testNewDhcpServerDisabled() {
        when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
                true);
        doReturn(false).when(
                () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
        doReturn("false").when(
                () -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));

        final TetheringConfiguration enableByRes =
                new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
@@ -338,9 +337,9 @@ public class TetheringConfigurationTest {

        when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
                false);
        doReturn(true).when(
                () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
        doReturn("true").when(
                () -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));

        final TetheringConfiguration enableByDevConfig =
                new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
@@ -351,9 +350,9 @@ public class TetheringConfigurationTest {
    public void testNewDhcpServerEnabled() {
        when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
                false);
        doReturn(false).when(
                () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
        doReturn("false").when(
                () -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
                eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));

        final TetheringConfiguration cfg =
                new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
+2 −2
Original line number Diff line number Diff line
@@ -312,8 +312,8 @@ public class TetheringTest {
        }

        @Override
        protected boolean getDeviceConfigBoolean(final String name) {
            return false;
        protected String getDeviceConfigProperty(final String name) {
            return null;
        }

        @Override