Merge "Remove hidden connectivity method usage" am: 82628265f6 am: cec2c552d1

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1674570

Change-Id: Ief89028aaabb21be85063cb9ba1e59f84c59419c
This commit is contained in:
Chiachang Wang
2021-04-16 03:03:19 +00:00
committed by Automerger Merge Worker
2 changed files with 14 additions and 10 deletions

View File

@@ -76,6 +76,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
private Context mContext;
protected List<ScanResult> mLastScanResult;
protected Object mWifiScanResultLock = new Object();
public TetheringManager mTetheringManager;
/* Control Wifi States */
public WifiManager mWifiManager;
@@ -129,6 +130,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
// Get an instance of WifiManager
mWifiManager =(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
mTetheringManager = mContext.getSystemService(TetheringManager.class);
// register a connectivity receiver for CONNECTIVITY_ACTION;
mConnectivityReceiver = new ConnectivityReceiver();
@@ -216,13 +218,13 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
*/
protected boolean waitForTetherStateChange(long timeout) {
long startTime = SystemClock.uptimeMillis();
String[] wifiRegexes = mCm.getTetherableWifiRegexs();
String[] wifiRegexes = mTetheringManager.getTetherableWifiRegexs();
while (true) {
if ((SystemClock.uptimeMillis() - startTime) > timeout) {
return false;
}
String[] active = mCm.getTetheredIfaces();
String[] error = mCm.getTetheringErroredIfaces();
String[] active = mTetheringManager.getTetheredIfaces();
String[] error = mTetheringManager.getTetheringErroredIfaces();
for (String iface: active) {
for (String regex: wifiRegexes) {
if (iface.matches(regex)) {

View File

@@ -244,17 +244,19 @@ public class WifiConfigurationHelper {
IpConfiguration ipConfiguration = config.getIpConfiguration();
if (jsonConfig.has("ip")) {
StaticIpConfiguration staticIpConfig = new StaticIpConfiguration();
InetAddress ipAddress = getInetAddress(jsonConfig.getString("ip"));
int prefixLength = getPrefixLength(jsonConfig.getInt("prefix_length"));
staticIpConfig.ipAddress = new LinkAddress(ipAddress, prefixLength);
staticIpConfig.gateway = getInetAddress(jsonConfig.getString("gateway"));
staticIpConfig.dnsServers.add(getInetAddress(jsonConfig.getString("dns1")));
staticIpConfig.dnsServers.add(getInetAddress(jsonConfig.getString("dns2")));
final StaticIpConfiguration.Builder builder = new StaticIpConfiguration.Builder();
builder.setIpAddress(new LinkAddress(ipAddress, prefixLength));
builder.setGateway(getInetAddress(jsonConfig.getString("gateway")));
final ArrayList<InetAddress> dnsServers = new ArrayList<>();
dnsServers.add(getInetAddress(jsonConfig.getString("dns1")));
dnsServers.add(getInetAddress(jsonConfig.getString("dns2")));
builder.setDnsServers(dnsServers);
ipConfiguration.setStaticIpConfiguration(builder.build());
ipConfiguration.setIpAssignment(IpAssignment.STATIC);
ipConfiguration.setStaticIpConfiguration(staticIpConfig);
} else {
ipConfiguration.setIpAssignment(IpAssignment.DHCP);
}