Merge "Fix restorePrivateDnsSetting with null hostnames"
This commit is contained in:
@@ -87,6 +87,7 @@ public final class CtsNetUtils {
|
|||||||
private static final int PRIVATE_DNS_SETTING_TIMEOUT_MS = 10_000;
|
private static final int PRIVATE_DNS_SETTING_TIMEOUT_MS = 10_000;
|
||||||
private static final int CONNECTIVITY_CHANGE_TIMEOUT_SECS = 30;
|
private static final int CONNECTIVITY_CHANGE_TIMEOUT_SECS = 30;
|
||||||
private static final String PRIVATE_DNS_MODE_OPPORTUNISTIC = "opportunistic";
|
private static final String PRIVATE_DNS_MODE_OPPORTUNISTIC = "opportunistic";
|
||||||
|
private static final String PRIVATE_DNS_MODE_STRICT = "hostname";
|
||||||
public static final int HTTP_PORT = 80;
|
public static final int HTTP_PORT = 80;
|
||||||
public static final String TEST_HOST = "connectivitycheck.gstatic.com";
|
public static final String TEST_HOST = "connectivitycheck.gstatic.com";
|
||||||
public static final String HTTP_REQUEST =
|
public static final String HTTP_REQUEST =
|
||||||
@@ -523,12 +524,17 @@ public final class CtsNetUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void restorePrivateDnsSetting() throws InterruptedException {
|
public void restorePrivateDnsSetting() throws InterruptedException {
|
||||||
if (mOldPrivateDnsMode == null || mOldPrivateDnsSpecifier == null) {
|
if (mOldPrivateDnsMode == null) {
|
||||||
return;
|
fail("restorePrivateDnsSetting without storing settings first");
|
||||||
}
|
}
|
||||||
// restore private DNS setting
|
// restore private DNS setting
|
||||||
if ("hostname".equals(mOldPrivateDnsMode)) {
|
if (PRIVATE_DNS_MODE_STRICT.equals(mOldPrivateDnsMode)) {
|
||||||
setPrivateDnsStrictMode(mOldPrivateDnsSpecifier);
|
setPrivateDnsStrictMode(mOldPrivateDnsSpecifier);
|
||||||
|
|
||||||
|
// In case of invalid setting, still restore it but fail the test
|
||||||
|
if (mOldPrivateDnsSpecifier == null) {
|
||||||
|
fail("Invalid private DNS setting: no hostname specified in strict mode");
|
||||||
|
}
|
||||||
awaitPrivateDnsSetting("restorePrivateDnsSetting timeout",
|
awaitPrivateDnsSetting("restorePrivateDnsSetting timeout",
|
||||||
mCm.getActiveNetwork(),
|
mCm.getActiveNetwork(),
|
||||||
mOldPrivateDnsSpecifier, true);
|
mOldPrivateDnsSpecifier, true);
|
||||||
@@ -539,13 +545,14 @@ public final class CtsNetUtils {
|
|||||||
|
|
||||||
public void setPrivateDnsStrictMode(String server) {
|
public void setPrivateDnsStrictMode(String server) {
|
||||||
// To reduce flake rate, set PRIVATE_DNS_SPECIFIER before PRIVATE_DNS_MODE. This ensures
|
// To reduce flake rate, set PRIVATE_DNS_SPECIFIER before PRIVATE_DNS_MODE. This ensures
|
||||||
// that if the previous private DNS mode was not "hostname", the system only sees one
|
// that if the previous private DNS mode was not strict, the system only sees one
|
||||||
// EVENT_PRIVATE_DNS_SETTINGS_CHANGED event instead of two.
|
// EVENT_PRIVATE_DNS_SETTINGS_CHANGED event instead of two.
|
||||||
Settings.Global.putString(mCR, Settings.Global.PRIVATE_DNS_SPECIFIER, server);
|
Settings.Global.putString(mCR, Settings.Global.PRIVATE_DNS_SPECIFIER, server);
|
||||||
final String mode = Settings.Global.getString(mCR, Settings.Global.PRIVATE_DNS_MODE);
|
final String mode = Settings.Global.getString(mCR, Settings.Global.PRIVATE_DNS_MODE);
|
||||||
// If current private DNS mode is "hostname", we only need to set PRIVATE_DNS_SPECIFIER.
|
// If current private DNS mode is strict, we only need to set PRIVATE_DNS_SPECIFIER.
|
||||||
if (!"hostname".equals(mode)) {
|
if (!PRIVATE_DNS_MODE_STRICT.equals(mode)) {
|
||||||
Settings.Global.putString(mCR, Settings.Global.PRIVATE_DNS_MODE, "hostname");
|
Settings.Global.putString(mCR, Settings.Global.PRIVATE_DNS_MODE,
|
||||||
|
PRIVATE_DNS_MODE_STRICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user