Merge "Move Setting constants for NetworkStack"
am: 587ee7240e
Change-Id: Ieedf7af48c408637c11c4ea7fe4cc93261ce613d
This commit is contained in:
@@ -34,6 +34,34 @@ public class NetworkStackUtils {
|
|||||||
// TODO: Refer to DeviceConfig definition.
|
// TODO: Refer to DeviceConfig definition.
|
||||||
public static final String NAMESPACE_CONNECTIVITY = "connectivity";
|
public static final String NAMESPACE_CONNECTIVITY = "connectivity";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of captive portal detection specifications used in addition to the fallback URLs.
|
||||||
|
* Each spec has the format url@@/@@statusCodeRegex@@/@@contentRegex. Specs are separated
|
||||||
|
* by "@@,@@".
|
||||||
|
*/
|
||||||
|
public static final String CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS =
|
||||||
|
"captive_portal_fallback_probe_specs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A comma separated list of URLs used for captive portal detection in addition to the
|
||||||
|
* fallback HTTP url associated with the CAPTIVE_PORTAL_FALLBACK_URL settings.
|
||||||
|
*/
|
||||||
|
public static final String CAPTIVE_PORTAL_OTHER_FALLBACK_URLS =
|
||||||
|
"captive_portal_other_fallback_urls";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which User-Agent string to use in the header of the captive portal detection probes.
|
||||||
|
* The User-Agent field is unset when this setting has no value (HttpUrlConnection default).
|
||||||
|
*/
|
||||||
|
public static final String CAPTIVE_PORTAL_USER_AGENT = "captive_portal_user_agent";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use HTTPS for network validation. This is enabled by default and the setting
|
||||||
|
* needs to be set to 0 to disable it. This setting is a misnomer because captive portals
|
||||||
|
* don't actually use HTTPS, but it's consistent with the other settings.
|
||||||
|
*/
|
||||||
|
public static final String CAPTIVE_PORTAL_USE_HTTPS = "captive_portal_use_https";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("networkstackutilsjni");
|
System.loadLibrary("networkstackutilsjni");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ import static android.net.util.DataStallUtils.DEFAULT_DATA_STALL_EVALUATION_TYPE
|
|||||||
import static android.net.util.DataStallUtils.DEFAULT_DATA_STALL_MIN_EVALUATE_TIME_MS;
|
import static android.net.util.DataStallUtils.DEFAULT_DATA_STALL_MIN_EVALUATE_TIME_MS;
|
||||||
import static android.net.util.DataStallUtils.DEFAULT_DATA_STALL_VALID_DNS_TIME_THRESHOLD_MS;
|
import static android.net.util.DataStallUtils.DEFAULT_DATA_STALL_VALID_DNS_TIME_THRESHOLD_MS;
|
||||||
import static android.net.util.DataStallUtils.DEFAULT_DNS_LOG_SIZE;
|
import static android.net.util.DataStallUtils.DEFAULT_DNS_LOG_SIZE;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_USER_AGENT;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_USE_HTTPS;
|
||||||
import static android.net.util.NetworkStackUtils.NAMESPACE_CONNECTIVITY;
|
import static android.net.util.NetworkStackUtils.NAMESPACE_CONNECTIVITY;
|
||||||
import static android.net.util.NetworkStackUtils.isEmpty;
|
import static android.net.util.NetworkStackUtils.isEmpty;
|
||||||
|
|
||||||
@@ -1171,7 +1175,8 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getUseHttpsValidation() {
|
private boolean getUseHttpsValidation() {
|
||||||
return mDependencies.getSetting(mContext, Settings.Global.CAPTIVE_PORTAL_USE_HTTPS, 1) == 1;
|
return mDependencies.getDeviceConfigPropertyInt(NAMESPACE_CONNECTIVITY,
|
||||||
|
CAPTIVE_PORTAL_USE_HTTPS, 1) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCaptivePortalServerHttpsUrl() {
|
private String getCaptivePortalServerHttpsUrl() {
|
||||||
@@ -1224,8 +1229,8 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
|
|
||||||
final URL[] settingProviderUrls;
|
final URL[] settingProviderUrls;
|
||||||
if (!TextUtils.isEmpty(firstUrl)) {
|
if (!TextUtils.isEmpty(firstUrl)) {
|
||||||
final String otherUrls = mDependencies.getSetting(mContext,
|
final String otherUrls = mDependencies.getDeviceConfigProperty(
|
||||||
Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS, "");
|
NAMESPACE_CONNECTIVITY, CAPTIVE_PORTAL_OTHER_FALLBACK_URLS, "");
|
||||||
// otherUrls may be empty, but .split() ignores trailing empty strings
|
// otherUrls may be empty, but .split() ignores trailing empty strings
|
||||||
final String separator = ",";
|
final String separator = ",";
|
||||||
final String[] urls = (firstUrl + separator + otherUrls).split(separator);
|
final String[] urls = (firstUrl + separator + otherUrls).split(separator);
|
||||||
@@ -1245,8 +1250,9 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
|
|
||||||
private CaptivePortalProbeSpec[] makeCaptivePortalFallbackProbeSpecs() {
|
private CaptivePortalProbeSpec[] makeCaptivePortalFallbackProbeSpecs() {
|
||||||
try {
|
try {
|
||||||
final String settingsValue = mDependencies.getSetting(
|
final String settingsValue = mDependencies.getDeviceConfigProperty(
|
||||||
mContext, Settings.Global.CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS, null);
|
NAMESPACE_CONNECTIVITY, CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS, null);
|
||||||
|
|
||||||
final CaptivePortalProbeSpec[] emptySpecs = new CaptivePortalProbeSpec[0];
|
final CaptivePortalProbeSpec[] emptySpecs = new CaptivePortalProbeSpec[0];
|
||||||
final CaptivePortalProbeSpec[] providerValue = TextUtils.isEmpty(settingsValue)
|
final CaptivePortalProbeSpec[] providerValue = TextUtils.isEmpty(settingsValue)
|
||||||
? emptySpecs
|
? emptySpecs
|
||||||
@@ -1340,8 +1346,8 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCaptivePortalUserAgent() {
|
private String getCaptivePortalUserAgent() {
|
||||||
return mDependencies.getSetting(mContext,
|
return mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
|
||||||
Settings.Global.CAPTIVE_PORTAL_USER_AGENT, DEFAULT_USER_AGENT);
|
CAPTIVE_PORTAL_USER_AGENT, DEFAULT_USER_AGENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL nextFallbackUrl() {
|
private URL nextFallbackUrl() {
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import static android.net.util.DataStallUtils.CONFIG_DATA_STALL_EVALUATION_TYPE;
|
|||||||
import static android.net.util.DataStallUtils.CONFIG_DATA_STALL_MIN_EVALUATE_INTERVAL;
|
import static android.net.util.DataStallUtils.CONFIG_DATA_STALL_MIN_EVALUATE_INTERVAL;
|
||||||
import static android.net.util.DataStallUtils.CONFIG_DATA_STALL_VALID_DNS_TIME_THRESHOLD;
|
import static android.net.util.DataStallUtils.CONFIG_DATA_STALL_VALID_DNS_TIME_THRESHOLD;
|
||||||
import static android.net.util.DataStallUtils.DATA_STALL_EVALUATION_TYPE_DNS;
|
import static android.net.util.DataStallUtils.DATA_STALL_EVALUATION_TYPE_DNS;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS;
|
||||||
|
import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_USE_HTTPS;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
@@ -159,7 +162,7 @@ public class NetworkMonitorTest {
|
|||||||
when(mDependencies.getRandom()).thenReturn(mRandom);
|
when(mDependencies.getRandom()).thenReturn(mRandom);
|
||||||
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_MODE), anyInt()))
|
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_MODE), anyInt()))
|
||||||
.thenReturn(Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
|
.thenReturn(Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
|
||||||
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_USE_HTTPS),
|
when(mDependencies.getDeviceConfigPropertyInt(any(), eq(CAPTIVE_PORTAL_USE_HTTPS),
|
||||||
anyInt())).thenReturn(1);
|
anyInt())).thenReturn(1);
|
||||||
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_HTTP_URL), any()))
|
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_HTTP_URL), any()))
|
||||||
.thenReturn(TEST_HTTP_URL);
|
.thenReturn(TEST_HTTP_URL);
|
||||||
@@ -682,13 +685,13 @@ public class NetworkMonitorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setOtherFallbackUrls(String urls) {
|
private void setOtherFallbackUrls(String urls) {
|
||||||
when(mDependencies.getSetting(any(),
|
when(mDependencies.getDeviceConfigProperty(any(),
|
||||||
eq(Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS), any())).thenReturn(urls);
|
eq(CAPTIVE_PORTAL_OTHER_FALLBACK_URLS), any())).thenReturn(urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFallbackSpecs(String specs) {
|
private void setFallbackSpecs(String specs) {
|
||||||
when(mDependencies.getSetting(any(),
|
when(mDependencies.getDeviceConfigProperty(any(),
|
||||||
eq(Settings.Global.CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS), any())).thenReturn(specs);
|
eq(CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS), any())).thenReturn(specs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCaptivePortalMode(int mode) {
|
private void setCaptivePortalMode(int mode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user