Merge "Tethering: switch to use tethering package resources"

This commit is contained in:
Mark Chien
2020-01-15 06:17:06 +00:00
committed by Gerrit Code Review
6 changed files with 73 additions and 82 deletions

View File

@@ -100,7 +100,7 @@
<!-- If the mobile hotspot feature requires provisioning, a package name and class name <!-- If the mobile hotspot feature requires provisioning, a package name and class name
can be provided to launch a supported application that provisions the devices. can be provided to launch a supported application that provisions the devices.
EntitlementManager will send an inent to Settings with the specified package name and EntitlementManager will send an intent to Settings with the specified package name and
class name in extras to launch provision app. class name in extras to launch provision app.
TODO: note what extras here. TODO: note what extras here.

View File

@@ -27,8 +27,6 @@ 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_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED; import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED;
import static com.android.internal.R.string.config_wifi_tether_enable;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -36,7 +34,6 @@ import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.util.SharedLog; import android.net.util.SharedLog;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -54,6 +51,7 @@ import android.util.SparseIntArray;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.StateMachine; import com.android.internal.util.StateMachine;
import com.android.networkstack.tethering.R;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -75,9 +73,7 @@ public class EntitlementManager {
"com.android.server.connectivity.tethering.PROVISIONING_RECHECK_ALARM"; "com.android.server.connectivity.tethering.PROVISIONING_RECHECK_ALARM";
private static final String EXTRA_SUBID = "subId"; private static final String EXTRA_SUBID = "subId";
// {@link ComponentName} of the Service used to run tether provisioning. private final ComponentName mSilentProvisioningService;
private static final ComponentName TETHER_SERVICE = ComponentName.unflattenFromString(
Resources.getSystem().getString(config_wifi_tether_enable));
private static final int MS_PER_HOUR = 60 * 60 * 1000; private static final int MS_PER_HOUR = 60 * 60 * 1000;
private static final int EVENT_START_PROVISIONING = 0; private static final int EVENT_START_PROVISIONING = 0;
private static final int EVENT_STOP_PROVISIONING = 1; private static final int EVENT_STOP_PROVISIONING = 1;
@@ -122,6 +118,8 @@ public class EntitlementManager {
mHandler = new EntitlementHandler(masterHandler.getLooper()); mHandler = new EntitlementHandler(masterHandler.getLooper());
mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_PROVISIONING_ALARM), mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_PROVISIONING_ALARM),
null, mHandler); null, mHandler);
mSilentProvisioningService = ComponentName.unflattenFromString(
mContext.getResources().getString(R.string.config_wifi_tether_enable));
} }
public void setOnUiEntitlementFailedListener(final OnUiEntitlementFailedListener listener) { public void setOnUiEntitlementFailedListener(final OnUiEntitlementFailedListener listener) {
@@ -377,7 +375,7 @@ public class EntitlementManager {
intent.putExtra(EXTRA_RUN_PROVISION, true); intent.putExtra(EXTRA_RUN_PROVISION, true);
intent.putExtra(EXTRA_PROVISION_CALLBACK, receiver); intent.putExtra(EXTRA_PROVISION_CALLBACK, receiver);
intent.putExtra(EXTRA_SUBID, subId); intent.putExtra(EXTRA_SUBID, subId);
intent.setComponent(TETHER_SERVICE); intent.setComponent(mSilentProvisioningService);
// Only admin user can change tethering and SilentTetherProvisioning don't need to // Only admin user can change tethering and SilentTetherProvisioning don't need to
// show UI, it is fine to always start setting's background service as system user. // show UI, it is fine to always start setting's background service as system user.
mContext.startService(intent); mContext.startService(intent);

View File

@@ -23,18 +23,6 @@ import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI; import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY; 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;
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_p2p_regexs;
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.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.TetheringConfigurationParcel; import android.net.TetheringConfigurationParcel;
@@ -45,6 +33,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.networkstack.tethering.R;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
@@ -113,27 +102,30 @@ public class TetheringConfiguration {
activeDataSubId = id; activeDataSubId = id;
Resources res = getResources(ctx, activeDataSubId); Resources res = getResources(ctx, activeDataSubId);
tetherableUsbRegexs = getResourceStringArray(res, config_tether_usb_regexs); tetherableUsbRegexs = getResourceStringArray(res, R.array.config_tether_usb_regexs);
// TODO: Evaluate deleting this altogether now that Wi-Fi always passes // TODO: Evaluate deleting this altogether now that Wi-Fi always passes
// us an interface name. Careful consideration needs to be given to // us an interface name. Careful consideration needs to be given to
// implications for Settings and for provisioning checks. // implications for Settings and for provisioning checks.
tetherableWifiRegexs = getResourceStringArray(res, config_tether_wifi_regexs); tetherableWifiRegexs = getResourceStringArray(res, R.array.config_tether_wifi_regexs);
tetherableWifiP2pRegexs = getResourceStringArray(res, config_tether_wifi_p2p_regexs); tetherableWifiP2pRegexs = getResourceStringArray(
tetherableBluetoothRegexs = getResourceStringArray(res, config_tether_bluetooth_regexs); res, R.array.config_tether_wifi_p2p_regexs);
tetherableBluetoothRegexs = getResourceStringArray(
res, R.array.config_tether_bluetooth_regexs);
isDunRequired = checkDunRequired(ctx); isDunRequired = checkDunRequired(ctx);
chooseUpstreamAutomatically = getResourceBoolean(res, config_tether_upstream_automatic); chooseUpstreamAutomatically = getResourceBoolean(
res, R.bool.config_tether_upstream_automatic);
preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired); preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired);
legacyDhcpRanges = getLegacyDhcpRanges(res); legacyDhcpRanges = getLegacyDhcpRanges(res);
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS); defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
enableLegacyDhcpServer = getEnableLegacyDhcpServer(res); enableLegacyDhcpServer = getEnableLegacyDhcpServer(res);
provisioningApp = getResourceStringArray(res, config_mobile_hotspot_provision_app); provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app);
provisioningAppNoUi = getProvisioningAppNoUi(res); provisioningAppNoUi = getProvisioningAppNoUi(res);
provisioningCheckPeriod = getResourceInteger(res, provisioningCheckPeriod = getResourceInteger(res,
config_mobile_hotspot_provision_check_period, R.integer.config_mobile_hotspot_provision_check_period,
0 /* No periodic re-check */); 0 /* No periodic re-check */);
configLog.log(toString()); configLog.log(toString());
@@ -248,7 +240,7 @@ public class TetheringConfiguration {
} }
private static Collection<Integer> getUpstreamIfaceTypes(Resources res, boolean dunRequired) { private static Collection<Integer> getUpstreamIfaceTypes(Resources res, boolean dunRequired) {
final int[] ifaceTypes = res.getIntArray(config_tether_upstream_types); final int[] ifaceTypes = res.getIntArray(R.array.config_tether_upstream_types);
final ArrayList<Integer> upstreamIfaceTypes = new ArrayList<>(ifaceTypes.length); final ArrayList<Integer> upstreamIfaceTypes = new ArrayList<>(ifaceTypes.length);
for (int i : ifaceTypes) { for (int i : ifaceTypes) {
switch (i) { switch (i) {
@@ -298,7 +290,7 @@ public class TetheringConfiguration {
} }
private static String[] getLegacyDhcpRanges(Resources res) { private static String[] getLegacyDhcpRanges(Resources res) {
final String[] fromResource = getResourceStringArray(res, config_tether_dhcp_range); final String[] fromResource = getResourceStringArray(res, R.array.config_tether_dhcp_range);
if ((fromResource.length > 0) && (fromResource.length % 2 == 0)) { if ((fromResource.length > 0) && (fromResource.length % 2 == 0)) {
return fromResource; return fromResource;
} }
@@ -307,7 +299,7 @@ public class TetheringConfiguration {
private static String getProvisioningAppNoUi(Resources res) { private static String getProvisioningAppNoUi(Resources res) {
try { try {
return res.getString(config_mobile_hotspot_provision_app_no_ui); return res.getString(R.string.config_mobile_hotspot_provision_app_no_ui);
} catch (Resources.NotFoundException e) { } catch (Resources.NotFoundException e) {
return ""; return "";
} }
@@ -339,7 +331,7 @@ public class TetheringConfiguration {
} }
private boolean getEnableLegacyDhcpServer(final Resources res) { private boolean getEnableLegacyDhcpServer(final Resources res) {
return getResourceBoolean(res, config_tether_enable_legacy_dhcp_server) return getResourceBoolean(res, R.bool.config_tether_enable_legacy_dhcp_server)
|| getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER); || getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER);
} }

View File

@@ -27,7 +27,6 @@ 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.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -56,10 +55,10 @@ import android.telephony.CarrierConfigManager;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.internal.R;
import com.android.internal.util.State; import com.android.internal.util.State;
import com.android.internal.util.StateMachine; import com.android.internal.util.StateMachine;
import com.android.internal.util.test.BroadcastInterceptingContext; import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.networkstack.tethering.R;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -157,16 +156,18 @@ public final class EntitlementManagerTest {
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean())); eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
when(mResources.getStringArray(R.array.config_tether_dhcp_range)) when(mResources.getStringArray(R.array.config_tether_dhcp_range))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getStringArray(R.array.config_tether_usb_regexs)) when(mResources.getStringArray(R.array.config_tether_usb_regexs))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getStringArray(R.array.config_tether_wifi_regexs)) when(mResources.getStringArray(R.array.config_tether_wifi_regexs))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getStringArray(R.array.config_tether_bluetooth_regexs)) when(mResources.getStringArray(R.array.config_tether_bluetooth_regexs))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getIntArray(R.array.config_tether_upstream_types)) when(mResources.getIntArray(R.array.config_tether_upstream_types))
.thenReturn(new int[0]); .thenReturn(new int[0]);
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
false);
when(mResources.getString(R.string.config_wifi_tether_enable)).thenReturn("");
when(mLog.forSubComponent(anyString())).thenReturn(mLog); when(mLog.forSubComponent(anyString())).thenReturn(mLog);
mMockContext = new MockContext(mContext); mMockContext = new MockContext(mContext);

View File

@@ -26,13 +26,6 @@ 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.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -51,6 +44,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.test.BroadcastInterceptingContext; import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.networkstack.tethering.R;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -120,15 +114,18 @@ public class TetheringConfigurationTest {
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY), () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean())); eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
when(mResources.getStringArray(config_tether_dhcp_range)).thenReturn(new String[0]); when(mResources.getStringArray(R.array.config_tether_dhcp_range)).thenReturn(
when(mResources.getStringArray(config_tether_usb_regexs)).thenReturn(new String[0]); new String[0]);
when(mResources.getStringArray(config_tether_wifi_regexs)) when(mResources.getStringArray(R.array.config_tether_usb_regexs)).thenReturn(new String[0]);
when(mResources.getStringArray(R.array.config_tether_wifi_regexs))
.thenReturn(new String[]{ "test_wlan\\d" }); .thenReturn(new String[]{ "test_wlan\\d" });
when(mResources.getStringArray(config_tether_bluetooth_regexs)).thenReturn(new String[0]); when(mResources.getStringArray(R.array.config_tether_bluetooth_regexs)).thenReturn(
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]); new String[0]);
when(mResources.getStringArray(config_mobile_hotspot_provision_app)) when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(new int[0]);
when(mResources.getStringArray(R.array.config_mobile_hotspot_provision_app))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
false);
mHasTelephonyManager = true; mHasTelephonyManager = true;
mMockContext = new MockContext(mContext); mMockContext = new MockContext(mContext);
mEnableLegacyDhcpServer = false; mEnableLegacyDhcpServer = false;
@@ -140,7 +137,7 @@ public class TetheringConfigurationTest {
} }
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) { private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn( when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(
legacyTetherUpstreamTypes); legacyTetherUpstreamTypes);
return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID); return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
} }
@@ -224,7 +221,7 @@ public class TetheringConfigurationTest {
@Test @Test
public void testNoDefinedUpstreamTypesAddsEthernet() { public void testNoDefinedUpstreamTypesAddsEthernet() {
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(new int[]{}); when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(new int[]{});
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false); when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
final TetheringConfiguration cfg = new TetheringConfiguration( final TetheringConfiguration cfg = new TetheringConfiguration(
@@ -246,7 +243,7 @@ public class TetheringConfigurationTest {
@Test @Test
public void testDefinedUpstreamTypesSansEthernetAddsEthernet() { public void testDefinedUpstreamTypesSansEthernetAddsEthernet() {
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn( when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(
new int[]{TYPE_WIFI, TYPE_MOBILE_HIPRI}); new int[]{TYPE_WIFI, TYPE_MOBILE_HIPRI});
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false); when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
@@ -264,7 +261,7 @@ public class TetheringConfigurationTest {
@Test @Test
public void testDefinedUpstreamTypesWithEthernetDoesNotAddEthernet() { public void testDefinedUpstreamTypesWithEthernetDoesNotAddEthernet() {
when(mResources.getIntArray(config_tether_upstream_types)) when(mResources.getIntArray(R.array.config_tether_upstream_types))
.thenReturn(new int[]{TYPE_WIFI, TYPE_ETHERNET, TYPE_MOBILE_HIPRI}); .thenReturn(new int[]{TYPE_WIFI, TYPE_ETHERNET, TYPE_MOBILE_HIPRI});
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false); when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
@@ -282,7 +279,8 @@ public class TetheringConfigurationTest {
@Test @Test
public void testNewDhcpServerDisabled() { public void testNewDhcpServerDisabled() {
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(true); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
true);
doReturn(false).when( doReturn(false).when(
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY), () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean())); eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
@@ -291,7 +289,8 @@ public class TetheringConfigurationTest {
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID); new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
assertTrue(enableByRes.enableLegacyDhcpServer); assertTrue(enableByRes.enableLegacyDhcpServer);
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
false);
doReturn(true).when( doReturn(true).when(
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY), () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean())); eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
@@ -303,7 +302,8 @@ public class TetheringConfigurationTest {
@Test @Test
public void testNewDhcpServerEnabled() { public void testNewDhcpServerEnabled() {
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
false);
doReturn(false).when( doReturn(false).when(
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY), () -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean())); eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
@@ -329,16 +329,17 @@ public class TetheringConfigurationTest {
private void setUpResourceForSubId() { private void setUpResourceForSubId() {
when(mResourcesForSubId.getStringArray( when(mResourcesForSubId.getStringArray(
config_tether_dhcp_range)).thenReturn(new String[0]); R.array.config_tether_dhcp_range)).thenReturn(new String[0]);
when(mResourcesForSubId.getStringArray( when(mResourcesForSubId.getStringArray(
config_tether_usb_regexs)).thenReturn(new String[0]); R.array.config_tether_usb_regexs)).thenReturn(new String[0]);
when(mResourcesForSubId.getStringArray( when(mResourcesForSubId.getStringArray(
config_tether_wifi_regexs)).thenReturn(new String[]{ "test_wlan\\d" }); R.array.config_tether_wifi_regexs)).thenReturn(new String[]{ "test_wlan\\d" });
when(mResourcesForSubId.getStringArray( when(mResourcesForSubId.getStringArray(
config_tether_bluetooth_regexs)).thenReturn(new String[0]); R.array.config_tether_bluetooth_regexs)).thenReturn(new String[0]);
when(mResourcesForSubId.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]); when(mResourcesForSubId.getIntArray(R.array.config_tether_upstream_types)).thenReturn(
new int[0]);
when(mResourcesForSubId.getStringArray( when(mResourcesForSubId.getStringArray(
config_mobile_hotspot_provision_app)).thenReturn(PROVISIONING_APP_NAME); R.array.config_mobile_hotspot_provision_app)).thenReturn(PROVISIONING_APP_NAME);
} }
} }

View File

@@ -37,8 +37,6 @@ import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED; import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; 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.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -120,6 +118,7 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.StateMachine; import com.android.internal.util.StateMachine;
import com.android.internal.util.test.BroadcastInterceptingContext; import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.internal.util.test.FakeSettingsProvider; import com.android.internal.util.test.FakeSettingsProvider;
import com.android.networkstack.tethering.R;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -416,24 +415,24 @@ public class TetheringTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mResources.getStringArray(com.android.internal.R.array.config_tether_dhcp_range)) when(mResources.getStringArray(R.array.config_tether_dhcp_range))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getStringArray(com.android.internal.R.array.config_tether_usb_regexs)) when(mResources.getStringArray(R.array.config_tether_usb_regexs))
.thenReturn(new String[] { "test_rndis\\d" }); .thenReturn(new String[] { "test_rndis\\d" });
when(mResources.getStringArray(com.android.internal.R.array.config_tether_wifi_regexs)) when(mResources.getStringArray(R.array.config_tether_wifi_regexs))
.thenReturn(new String[]{ "test_wlan\\d" }); .thenReturn(new String[]{ "test_wlan\\d" });
when(mResources.getStringArray(com.android.internal.R.array.config_tether_wifi_p2p_regexs)) when(mResources.getStringArray(R.array.config_tether_wifi_p2p_regexs))
.thenReturn(new String[]{ "test_p2p-p2p\\d-.*" }); .thenReturn(new String[]{ "test_p2p-p2p\\d-.*" });
when(mResources.getStringArray(com.android.internal.R.array.config_tether_bluetooth_regexs)) when(mResources.getStringArray(R.array.config_tether_bluetooth_regexs))
.thenReturn(new String[0]); .thenReturn(new String[0]);
when(mResources.getIntArray(com.android.internal.R.array.config_tether_upstream_types)) when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(new int[0]);
.thenReturn(new int[0]); when(mResources.getBoolean(R.bool.config_tether_upstream_automatic)).thenReturn(false);
when(mResources.getBoolean(com.android.internal.R.bool.config_tether_upstream_automatic)) when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
.thenReturn(false); false);
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
when(mNetd.interfaceGetList()) when(mNetd.interfaceGetList())
.thenReturn(new String[] { .thenReturn(new String[] {
TEST_MOBILE_IFNAME, TEST_WLAN_IFNAME, TEST_USB_IFNAME, TEST_P2P_IFNAME}); TEST_MOBILE_IFNAME, TEST_WLAN_IFNAME, TEST_USB_IFNAME, TEST_P2P_IFNAME});
when(mResources.getString(R.string.config_wifi_tether_enable)).thenReturn("");
mInterfaceConfiguration = new InterfaceConfigurationParcel(); mInterfaceConfiguration = new InterfaceConfigurationParcel();
mInterfaceConfiguration.flags = new String[0]; mInterfaceConfiguration.flags = new String[0];
when(mRouterAdvertisementDaemon.start()) when(mRouterAdvertisementDaemon.start())
@@ -694,7 +693,8 @@ public class TetheringTest {
@Test @Test
public void workingMobileUsbTethering_IPv4LegacyDhcp() { public void workingMobileUsbTethering_IPv4LegacyDhcp() {
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(true); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
true);
sendConfigurationChanged(); sendConfigurationChanged();
final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState(); final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState();
runUsbTethering(upstreamState); runUsbTethering(upstreamState);
@@ -782,8 +782,7 @@ public class TetheringTest {
@Test @Test
public void configTetherUpstreamAutomaticIgnoresConfigTetherUpstreamTypes() throws Exception { public void configTetherUpstreamAutomaticIgnoresConfigTetherUpstreamTypes() throws Exception {
when(mResources.getBoolean(com.android.internal.R.bool.config_tether_upstream_automatic)) when(mResources.getBoolean(R.bool.config_tether_upstream_automatic)).thenReturn(true);
.thenReturn(true);
sendConfigurationChanged(); sendConfigurationChanged();
// Setup IPv6 // Setup IPv6
@@ -1311,7 +1310,7 @@ public class TetheringTest {
private void workingWifiP2pGroupOwnerLegacyMode( private void workingWifiP2pGroupOwnerLegacyMode(
boolean emulateInterfaceStatusChanged) throws Exception { boolean emulateInterfaceStatusChanged) throws Exception {
// change to legacy mode and update tethering information by chaning SIM // change to legacy mode and update tethering information by chaning SIM
when(mResources.getStringArray(com.android.internal.R.array.config_tether_wifi_p2p_regexs)) when(mResources.getStringArray(R.array.config_tether_wifi_p2p_regexs))
.thenReturn(new String[]{}); .thenReturn(new String[]{});
final int fakeSubId = 1234; final int fakeSubId = 1234;
mPhoneStateListener.onActiveDataSubscriptionIdChanged(fakeSubId); mPhoneStateListener.onActiveDataSubscriptionIdChanged(fakeSubId);