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

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

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

View File

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