Remove hidden connectivity method usage

Becuase of modulization work for connectivity module, the
connectivity hidden methods are not accessible outside the
module. This commit replace the hidden methods usage under
ConnectivityManagerTest.

Bug: 182859030
Test: Remove framework-connectivity from the private API ; atest
Change-Id: I5e23bd0ab2e82fc3583c56162d5ac3fec6cfc359
This commit is contained in:
Chiachang Wang
2021-04-08 16:34:48 +08:00
parent bcc5b4c1ff
commit 27691f8468
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);
} }