Merge "Migrate legacy dhcp server config to DeviceConfig"
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_USB" />
|
||||
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
||||
<uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" />
|
||||
<uses-permission android:name="android.permission.TETHER_PRIVILEGED" />
|
||||
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
<item>"bt-pan"</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Use the old dnsmasq DHCP server for tethering instead of the framework implementation. -->
|
||||
<bool translatable="false" name="config_tether_enable_legacy_dhcp_server">false</bool>
|
||||
|
||||
<!-- Dhcp range (min, max) to use for tethering purposes -->
|
||||
<string-array translatable="false" name="config_tether_dhcp_range">
|
||||
</string-array>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<item type="array" name="config_tether_wifi_p2p_regexs"/>
|
||||
<item type="array" name="config_tether_bluetooth_regexs"/>
|
||||
<item type="array" name="config_tether_dhcp_range"/>
|
||||
<item type="bool" name="config_tether_enable_legacy_dhcp_server"/>
|
||||
<item type="array" name="config_tether_upstream_types"/>
|
||||
<item type="bool" name="config_tether_upstream_automatic"/>
|
||||
<!-- Configuration values for tethering entitlement check -->
|
||||
|
||||
@@ -21,7 +21,7 @@ import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
|
||||
import static android.provider.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||
|
||||
import static com.android.internal.R.array.config_mobile_hotspot_provision_app;
|
||||
import static com.android.internal.R.array.config_tether_bluetooth_regexs;
|
||||
@@ -33,13 +33,13 @@ import static com.android.internal.R.array.config_tether_wifi_regexs;
|
||||
import static com.android.internal.R.bool.config_tether_upstream_automatic;
|
||||
import static com.android.internal.R.integer.config_mobile_hotspot_provision_check_period;
|
||||
import static com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui;
|
||||
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.TetheringConfigurationParcel;
|
||||
import android.net.util.SharedLog;
|
||||
import android.provider.Settings;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -84,6 +84,12 @@ public class TetheringConfiguration {
|
||||
|
||||
private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"};
|
||||
|
||||
/**
|
||||
* Use the old dnsmasq DHCP server for tethering instead of the framework implementation.
|
||||
*/
|
||||
public static final String TETHER_ENABLE_LEGACY_DHCP_SERVER =
|
||||
"tether_enable_legacy_dhcp_server";
|
||||
|
||||
public final String[] tetherableUsbRegexs;
|
||||
public final String[] tetherableWifiRegexs;
|
||||
public final String[] tetherableWifiP2pRegexs;
|
||||
@@ -122,7 +128,7 @@ public class TetheringConfiguration {
|
||||
|
||||
legacyDhcpRanges = getLegacyDhcpRanges(res);
|
||||
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
|
||||
enableLegacyDhcpServer = getEnableLegacyDhcpServer(ctx);
|
||||
enableLegacyDhcpServer = getEnableLegacyDhcpServer(res);
|
||||
|
||||
provisioningApp = getResourceStringArray(res, config_mobile_hotspot_provision_app);
|
||||
provisioningAppNoUi = getProvisioningAppNoUi(res);
|
||||
@@ -332,10 +338,14 @@ public class TetheringConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getEnableLegacyDhcpServer(Context ctx) {
|
||||
final ContentResolver cr = ctx.getContentResolver();
|
||||
final int intVal = Settings.Global.getInt(cr, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
||||
return intVal != 0;
|
||||
private boolean getEnableLegacyDhcpServer(final Resources res) {
|
||||
return getResourceBoolean(res, config_tether_enable_legacy_dhcp_server)
|
||||
|| getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected boolean getDeviceConfigBoolean(final String name) {
|
||||
return DeviceConfig.getBoolean(NAMESPACE_CONNECTIVITY, name, false /** defaultValue */);
|
||||
}
|
||||
|
||||
private Resources getResources(Context ctx, int subId) {
|
||||
|
||||
@@ -22,10 +22,12 @@ import static android.net.TetheringManager.TETHERING_WIFI;
|
||||
import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKONWN;
|
||||
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
||||
import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
|
||||
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -39,7 +41,6 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.util.SharedLog;
|
||||
@@ -49,9 +50,8 @@ import android.os.PersistableBundle;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.test.TestLooper;
|
||||
import android.provider.Settings;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.test.mock.MockContentResolver;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
@@ -60,7 +60,6 @@ import com.android.internal.R;
|
||||
import com.android.internal.util.State;
|
||||
import com.android.internal.util.StateMachine;
|
||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||
import com.android.internal.util.test.FakeSettingsProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -94,7 +93,6 @@ public final class EntitlementManagerTest {
|
||||
private final PersistableBundle mCarrierConfig = new PersistableBundle();
|
||||
private final TestLooper mLooper = new TestLooper();
|
||||
private Context mMockContext;
|
||||
private MockContentResolver mContentResolver;
|
||||
|
||||
private TestStateMachine mSM;
|
||||
private WrappedEntitlementManager mEnMgr;
|
||||
@@ -110,11 +108,6 @@ public final class EntitlementManagerTest {
|
||||
public Resources getResources() {
|
||||
return mResources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentResolver getContentResolver() {
|
||||
return mContentResolver;
|
||||
}
|
||||
}
|
||||
|
||||
public class WrappedEntitlementManager extends EntitlementManager {
|
||||
@@ -151,13 +144,17 @@ public final class EntitlementManagerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mMockingSession = mockitoSession()
|
||||
.initMocks(this)
|
||||
.spyStatic(SystemProperties.class)
|
||||
.mockStatic(SystemProperties.class)
|
||||
.mockStatic(DeviceConfig.class)
|
||||
.strictness(Strictness.WARN)
|
||||
.startMocking();
|
||||
// Don't disable tethering provisioning unless requested.
|
||||
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()));
|
||||
|
||||
when(mResources.getStringArray(R.array.config_tether_dhcp_range))
|
||||
.thenReturn(new String[0]);
|
||||
@@ -169,10 +166,9 @@ public final class EntitlementManagerTest {
|
||||
.thenReturn(new String[0]);
|
||||
when(mResources.getIntArray(R.array.config_tether_upstream_types))
|
||||
.thenReturn(new int[0]);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
when(mLog.forSubComponent(anyString())).thenReturn(mLog);
|
||||
|
||||
mContentResolver = new MockContentResolver();
|
||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||
mMockContext = new MockContext(mContext);
|
||||
mSM = new TestStateMachine();
|
||||
mEnMgr = new WrappedEntitlementManager(mMockContext, mSM, mLog, EVENT_EM_UPDATE);
|
||||
|
||||
@@ -21,40 +21,44 @@ import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.provider.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
|
||||
import static com.android.internal.R.array.config_mobile_hotspot_provision_app;
|
||||
import static com.android.internal.R.array.config_tether_bluetooth_regexs;
|
||||
import static com.android.internal.R.array.config_tether_dhcp_range;
|
||||
import static com.android.internal.R.array.config_tether_upstream_types;
|
||||
import static com.android.internal.R.array.config_tether_usb_regexs;
|
||||
import static com.android.internal.R.array.config_tether_wifi_regexs;
|
||||
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||
|
||||
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;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.util.SharedLog;
|
||||
import android.provider.Settings;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.test.mock.MockContentResolver;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||
import com.android.internal.util.test.FakeSettingsProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.MockitoSession;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@@ -69,9 +73,10 @@ public class TetheringConfigurationTest {
|
||||
@Mock private TelephonyManager mTelephonyManager;
|
||||
@Mock private Resources mResources;
|
||||
@Mock private Resources mResourcesForSubId;
|
||||
private MockContentResolver mContentResolver;
|
||||
private Context mMockContext;
|
||||
private boolean mHasTelephonyManager;
|
||||
private boolean mEnableLegacyDhcpServer;
|
||||
private MockitoSession mMockingSession;
|
||||
|
||||
private class MockTetheringConfiguration extends TetheringConfiguration {
|
||||
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||
@@ -101,16 +106,20 @@ public class TetheringConfigurationTest {
|
||||
}
|
||||
return super.getSystemService(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentResolver getContentResolver() {
|
||||
return mContentResolver;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
// TODO: use a dependencies class instead of mock statics.
|
||||
mMockingSession = mockitoSession()
|
||||
.initMocks(this)
|
||||
.mockStatic(DeviceConfig.class)
|
||||
.strictness(Strictness.WARN)
|
||||
.startMocking();
|
||||
doReturn(false).when(
|
||||
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||
|
||||
when(mResources.getStringArray(config_tether_dhcp_range)).thenReturn(new String[0]);
|
||||
when(mResources.getStringArray(config_tether_usb_regexs)).thenReturn(new String[0]);
|
||||
when(mResources.getStringArray(config_tether_wifi_regexs))
|
||||
@@ -119,10 +128,15 @@ public class TetheringConfigurationTest {
|
||||
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]);
|
||||
when(mResources.getStringArray(config_mobile_hotspot_provision_app))
|
||||
.thenReturn(new String[0]);
|
||||
mContentResolver = new MockContentResolver();
|
||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
mHasTelephonyManager = true;
|
||||
mMockContext = new MockContext(mContext);
|
||||
mEnableLegacyDhcpServer = false;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mMockingSession.finishMocking();
|
||||
}
|
||||
|
||||
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
|
||||
@@ -268,19 +282,35 @@ public class TetheringConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void testNewDhcpServerDisabled() {
|
||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 1);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(true);
|
||||
doReturn(false).when(
|
||||
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||
|
||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
assertTrue(cfg.enableLegacyDhcpServer);
|
||||
final TetheringConfiguration enableByRes =
|
||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
assertTrue(enableByRes.enableLegacyDhcpServer);
|
||||
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
doReturn(true).when(
|
||||
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||
|
||||
final TetheringConfiguration enableByDevConfig =
|
||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
assertTrue(enableByDevConfig.enableLegacyDhcpServer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewDhcpServerEnabled() {
|
||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
doReturn(false).when(
|
||||
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||
|
||||
final TetheringConfiguration cfg =
|
||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
assertFalse(cfg.enableLegacyDhcpServer);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,10 @@ import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
|
||||
import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY;
|
||||
import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
|
||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
|
||||
import static android.provider.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -269,6 +270,11 @@ public class TetheringTest {
|
||||
super(ctx, log, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getDeviceConfigBoolean(final String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Resources getResourcesForSubIdWrapper(Context ctx, int subId) {
|
||||
return mResources;
|
||||
@@ -428,6 +434,7 @@ public class TetheringTest {
|
||||
.thenReturn(new int[0]);
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_tether_upstream_automatic))
|
||||
.thenReturn(false);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
when(mNetd.interfaceGetList())
|
||||
.thenReturn(new String[] {
|
||||
TEST_MOBILE_IFNAME, TEST_WLAN_IFNAME, TEST_USB_IFNAME, TEST_P2P_IFNAME});
|
||||
@@ -440,7 +447,6 @@ public class TetheringTest {
|
||||
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(null);
|
||||
mContentResolver = new MockContentResolver(mServiceContext);
|
||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
||||
mIntents = new Vector<>();
|
||||
mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -692,7 +698,7 @@ public class TetheringTest {
|
||||
|
||||
@Test
|
||||
public void workingMobileUsbTethering_IPv4LegacyDhcp() {
|
||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 1);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(true);
|
||||
sendConfigurationChanged();
|
||||
final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState();
|
||||
runUsbTethering(upstreamState);
|
||||
|
||||
Reference in New Issue
Block a user