Merge "Fix READ_DEVICE_CONFIG permission denied problem in TetheringTests" am: fb2caff580
Change-Id: Id517f4122c4b078d16035274e8979247bc0b40f8
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user