Merge "Wait for network to be validated when setting a valid private DNS"

This commit is contained in:
Lucas Lin
2021-10-21 11:34:35 +00:00
committed by Gerrit Code Review

View File

@@ -714,6 +714,12 @@ public class ConnectivityManagerTest {
.build(); .build();
} }
private boolean hasPrivateDnsValidated(CallbackEntry entry, Network networkForPrivateDns) {
if (!networkForPrivateDns.equals(entry.getNetwork())) return false;
final NetworkCapabilities nc = ((CallbackEntry.CapabilitiesChanged) entry).getCaps();
return !nc.isPrivateDnsBroken() && nc.hasCapability(NET_CAPABILITY_VALIDATED);
}
@AppModeFull(reason = "WRITE_SECURE_SETTINGS permission can't be granted to instant apps") @AppModeFull(reason = "WRITE_SECURE_SETTINGS permission can't be granted to instant apps")
@Test @IgnoreUpTo(Build.VERSION_CODES.Q) @Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testIsPrivateDnsBroken() throws InterruptedException { public void testIsPrivateDnsBroken() throws InterruptedException {
@@ -727,8 +733,7 @@ public class ConnectivityManagerTest {
mCtsNetUtils.setPrivateDnsStrictMode(goodPrivateDnsServer); mCtsNetUtils.setPrivateDnsStrictMode(goodPrivateDnsServer);
final Network networkForPrivateDns = mCtsNetUtils.ensureWifiConnected(); final Network networkForPrivateDns = mCtsNetUtils.ensureWifiConnected();
cb.eventuallyExpect(CallbackEntry.NETWORK_CAPS_UPDATED, NETWORK_CALLBACK_TIMEOUT_MS, cb.eventuallyExpect(CallbackEntry.NETWORK_CAPS_UPDATED, NETWORK_CALLBACK_TIMEOUT_MS,
entry -> (!((CallbackEntry.CapabilitiesChanged) entry).getCaps() entry -> hasPrivateDnsValidated(entry, networkForPrivateDns));
.isPrivateDnsBroken()) && networkForPrivateDns.equals(entry.getNetwork()));
// Verifying the broken private DNS sever // Verifying the broken private DNS sever
mCtsNetUtils.setPrivateDnsStrictMode(invalidPrivateDnsServer); mCtsNetUtils.setPrivateDnsStrictMode(invalidPrivateDnsServer);