Merge "Fix linter errors in NetworkMonitor"
This commit is contained in:
@@ -126,21 +126,21 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
private static final int DEFAULT_DATA_STALL_EVALUATION_TYPES =
|
private static final int DEFAULT_DATA_STALL_EVALUATION_TYPES =
|
||||||
(1 << DATA_STALL_EVALUATION_TYPE_DNS);
|
(1 << DATA_STALL_EVALUATION_TYPE_DNS);
|
||||||
|
|
||||||
static enum EvaluationResult {
|
enum EvaluationResult {
|
||||||
VALIDATED(true),
|
VALIDATED(true),
|
||||||
CAPTIVE_PORTAL(false);
|
CAPTIVE_PORTAL(false);
|
||||||
final boolean isValidated;
|
final boolean mIsValidated;
|
||||||
EvaluationResult(boolean isValidated) {
|
EvaluationResult(boolean isValidated) {
|
||||||
this.isValidated = isValidated;
|
this.mIsValidated = isValidated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ValidationStage {
|
enum ValidationStage {
|
||||||
FIRST_VALIDATION(true),
|
FIRST_VALIDATION(true),
|
||||||
REVALIDATION(false);
|
REVALIDATION(false);
|
||||||
final boolean isFirstValidation;
|
final boolean mIsFirstValidation;
|
||||||
ValidationStage(boolean isFirstValidation) {
|
ValidationStage(boolean isFirstValidation) {
|
||||||
this.isFirstValidation = isFirstValidation;
|
this.mIsFirstValidation = isFirstValidation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
|
|
||||||
// Start mReevaluateDelayMs at this value and double.
|
// Start mReevaluateDelayMs at this value and double.
|
||||||
private static final int INITIAL_REEVALUATE_DELAY_MS = 1000;
|
private static final int INITIAL_REEVALUATE_DELAY_MS = 1000;
|
||||||
private static final int MAX_REEVALUATE_DELAY_MS = 10*60*1000;
|
private static final int MAX_REEVALUATE_DELAY_MS = 10 * 60 * 1000;
|
||||||
// Before network has been evaluated this many times, ignore repeated reevaluate requests.
|
// Before network has been evaluated this many times, ignore repeated reevaluate requests.
|
||||||
private static final int IGNORE_REEVALUATE_ATTEMPTS = 5;
|
private static final int IGNORE_REEVALUATE_ATTEMPTS = 5;
|
||||||
private int mReevaluateToken = 0;
|
private int mReevaluateToken = 0;
|
||||||
@@ -261,7 +261,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
// Stop blaming UID that requested re-evaluation after this many attempts.
|
// Stop blaming UID that requested re-evaluation after this many attempts.
|
||||||
private static final int BLAME_FOR_EVALUATION_ATTEMPTS = 5;
|
private static final int BLAME_FOR_EVALUATION_ATTEMPTS = 5;
|
||||||
// Delay between reevaluations once a captive portal has been found.
|
// Delay between reevaluations once a captive portal has been found.
|
||||||
private static final int CAPTIVE_PORTAL_REEVALUATE_DELAY_MS = 10*60*1000;
|
private static final int CAPTIVE_PORTAL_REEVALUATE_DELAY_MS = 10 * 60 * 1000;
|
||||||
|
|
||||||
private static final int NUM_VALIDATION_LOG_LINES = 20;
|
private static final int NUM_VALIDATION_LOG_LINES = 20;
|
||||||
|
|
||||||
@@ -393,10 +393,17 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request the NetworkMonitor to reevaluate the network.
|
||||||
|
*/
|
||||||
public void forceReevaluation(int responsibleUid) {
|
public void forceReevaluation(int responsibleUid) {
|
||||||
sendMessage(CMD_FORCE_REEVALUATION, responsibleUid, 0);
|
sendMessage(CMD_FORCE_REEVALUATION, responsibleUid, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a notification to NetworkMonitor indicating that private DNS settings have changed.
|
||||||
|
* @param newCfg The new private DNS configuration.
|
||||||
|
*/
|
||||||
public void notifyPrivateDnsSettingsChanged(PrivateDnsConfig newCfg) {
|
public void notifyPrivateDnsSettingsChanged(PrivateDnsConfig newCfg) {
|
||||||
// Cancel any outstanding resolutions.
|
// Cancel any outstanding resolutions.
|
||||||
removeMessages(CMD_PRIVATE_DNS_SETTINGS_CHANGED);
|
removeMessages(CMD_PRIVATE_DNS_SETTINGS_CHANGED);
|
||||||
@@ -655,8 +662,9 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
public boolean processMessage(Message message) {
|
public boolean processMessage(Message message) {
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case CMD_REEVALUATE:
|
case CMD_REEVALUATE:
|
||||||
if (message.arg1 != mReevaluateToken || mUserDoesNotWant)
|
if (message.arg1 != mReevaluateToken || mUserDoesNotWant) {
|
||||||
return HANDLED;
|
return HANDLED;
|
||||||
|
}
|
||||||
// Don't bother validating networks that don't satisfy the default request.
|
// Don't bother validating networks that don't satisfy the default request.
|
||||||
// This includes:
|
// This includes:
|
||||||
// - VPNs which can be considered explicitly desired by the user and the
|
// - VPNs which can be considered explicitly desired by the user and the
|
||||||
@@ -813,9 +821,9 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isStrictModeHostnameResolved() {
|
private boolean isStrictModeHostnameResolved() {
|
||||||
return (mPrivateDnsConfig != null) &&
|
return (mPrivateDnsConfig != null)
|
||||||
mPrivateDnsConfig.hostname.equals(mPrivateDnsProviderHostname) &&
|
&& mPrivateDnsConfig.hostname.equals(mPrivateDnsProviderHostname)
|
||||||
(mPrivateDnsConfig.ips.length > 0);
|
&& (mPrivateDnsConfig.ips.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveStrictModeHostname() {
|
private void resolveStrictModeHostname() {
|
||||||
@@ -852,9 +860,9 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
|
|
||||||
private boolean sendPrivateDnsProbe() {
|
private boolean sendPrivateDnsProbe() {
|
||||||
// q.v. system/netd/server/dns/DnsTlsTransport.cpp
|
// q.v. system/netd/server/dns/DnsTlsTransport.cpp
|
||||||
final String ONE_TIME_HOSTNAME_SUFFIX = "-dnsotls-ds.metric.gstatic.com";
|
final String oneTimeHostnameSuffix = "-dnsotls-ds.metric.gstatic.com";
|
||||||
final String host = UUID.randomUUID().toString().substring(0, 8) +
|
final String host = UUID.randomUUID().toString().substring(0, 8)
|
||||||
ONE_TIME_HOSTNAME_SUFFIX;
|
+ oneTimeHostnameSuffix;
|
||||||
final Stopwatch watch = new Stopwatch().start();
|
final Stopwatch watch = new Stopwatch().start();
|
||||||
try {
|
try {
|
||||||
final InetAddress[] ips = mNetworkAgentInfo.network().getAllByName(host);
|
final InetAddress[] ips = mNetworkAgentInfo.network().getAllByName(host);
|
||||||
@@ -966,7 +974,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
// most one per address family. This ensures we only wait up to 20 seconds for TCP connections
|
// most one per address family. This ensures we only wait up to 20 seconds for TCP connections
|
||||||
// to complete, regardless of how many IP addresses a host has.
|
// to complete, regardless of how many IP addresses a host has.
|
||||||
private static class OneAddressPerFamilyNetwork extends Network {
|
private static class OneAddressPerFamilyNetwork extends Network {
|
||||||
public OneAddressPerFamilyNetwork(Network network) {
|
OneAddressPerFamilyNetwork(Network network) {
|
||||||
// Always bypass Private DNS.
|
// Always bypass Private DNS.
|
||||||
super(network.getPrivateDnsBypassingCopy());
|
super(network.getPrivateDnsBypassingCopy());
|
||||||
}
|
}
|
||||||
@@ -1000,7 +1008,8 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getWifiScansAlwaysAvailableDisabled() {
|
public boolean getWifiScansAlwaysAvailableDisabled() {
|
||||||
return mDependencies.getSetting(mContext, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0;
|
return mDependencies.getSetting(
|
||||||
|
mContext, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCaptivePortalServerHttpsUrl() {
|
private String getCaptivePortalServerHttpsUrl() {
|
||||||
@@ -1246,10 +1255,10 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
// Time how long it takes to get a response to our request
|
// Time how long it takes to get a response to our request
|
||||||
long responseTimestamp = SystemClock.elapsedRealtime();
|
long responseTimestamp = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
validationLog(probeType, url, "time=" + (responseTimestamp - requestTimestamp) + "ms" +
|
validationLog(probeType, url, "time=" + (responseTimestamp - requestTimestamp) + "ms"
|
||||||
" ret=" + httpResponseCode +
|
+ " ret=" + httpResponseCode
|
||||||
" request=" + requestHeader +
|
+ " request=" + requestHeader
|
||||||
" headers=" + urlConnection.getHeaderFields());
|
+ " headers=" + urlConnection.getHeaderFields());
|
||||||
// NOTE: We may want to consider an "HTTP/1.0 204" response to be a captive
|
// NOTE: We may want to consider an "HTTP/1.0 204" response to be a captive
|
||||||
// portal. The only example of this seen so far was a captive portal. For
|
// portal. The only example of this seen so far was a captive portal. For
|
||||||
// the time being go with prior behavior of assuming it's not a captive
|
// the time being go with prior behavior of assuming it's not a captive
|
||||||
@@ -1267,7 +1276,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
// sign-in to an empty page. Probably the result of a broken transparent proxy.
|
// sign-in to an empty page. Probably the result of a broken transparent proxy.
|
||||||
// See http://b/9972012.
|
// See http://b/9972012.
|
||||||
validationLog(probeType, url,
|
validationLog(probeType, url,
|
||||||
"200 response with Content-length=0 interpreted as 204 response.");
|
"200 response with Content-length=0 interpreted as 204 response.");
|
||||||
httpResponseCode = CaptivePortalProbeResult.SUCCESS_CODE;
|
httpResponseCode = CaptivePortalProbeResult.SUCCESS_CODE;
|
||||||
} else if (urlConnection.getContentLengthLong() == -1) {
|
} else if (urlConnection.getContentLengthLong() == -1) {
|
||||||
// When no Content-length (default value == -1), attempt to read a byte from the
|
// When no Content-length (default value == -1), attempt to read a byte from the
|
||||||
@@ -1309,7 +1318,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
private final boolean mIsHttps;
|
private final boolean mIsHttps;
|
||||||
private volatile CaptivePortalProbeResult mResult = CaptivePortalProbeResult.FAILED;
|
private volatile CaptivePortalProbeResult mResult = CaptivePortalProbeResult.FAILED;
|
||||||
|
|
||||||
public ProbeThread(boolean isHttps) {
|
ProbeThread(boolean isHttps) {
|
||||||
mIsHttps = isHttps;
|
mIsHttps = isHttps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1443,8 +1452,10 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
if (cellInfo.isRegistered()) {
|
if (cellInfo.isRegistered()) {
|
||||||
numRegisteredCellInfo++;
|
numRegisteredCellInfo++;
|
||||||
if (numRegisteredCellInfo > 1) {
|
if (numRegisteredCellInfo > 1) {
|
||||||
if (VDBG) logw("more than one registered CellInfo." +
|
if (VDBG) {
|
||||||
" Can't tell which is active. Bailing.");
|
logw("more than one registered CellInfo."
|
||||||
|
+ " Can't tell which is active. Bailing.");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cellInfo instanceof CellInfoCdma) {
|
if (cellInfo instanceof CellInfoCdma) {
|
||||||
@@ -1492,14 +1503,14 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int networkEventType(ValidationStage s, EvaluationResult r) {
|
private int networkEventType(ValidationStage s, EvaluationResult r) {
|
||||||
if (s.isFirstValidation) {
|
if (s.mIsFirstValidation) {
|
||||||
if (r.isValidated) {
|
if (r.mIsValidated) {
|
||||||
return NetworkEvent.NETWORK_FIRST_VALIDATION_SUCCESS;
|
return NetworkEvent.NETWORK_FIRST_VALIDATION_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return NetworkEvent.NETWORK_FIRST_VALIDATION_PORTAL_FOUND;
|
return NetworkEvent.NETWORK_FIRST_VALIDATION_PORTAL_FOUND;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (r.isValidated) {
|
if (r.mIsValidated) {
|
||||||
return NetworkEvent.NETWORK_REVALIDATION_SUCCESS;
|
return NetworkEvent.NETWORK_REVALIDATION_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return NetworkEvent.NETWORK_REVALIDATION_PORTAL_FOUND;
|
return NetworkEvent.NETWORK_REVALIDATION_PORTAL_FOUND;
|
||||||
@@ -1517,7 +1528,7 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
|
|
||||||
private void logValidationProbe(long durationMs, int probeType, int probeResult) {
|
private void logValidationProbe(long durationMs, int probeType, int probeResult) {
|
||||||
int[] transports = mNetworkAgentInfo.networkCapabilities.getTransportTypes();
|
int[] transports = mNetworkAgentInfo.networkCapabilities.getTransportTypes();
|
||||||
boolean isFirstValidation = validationStage().isFirstValidation;
|
boolean isFirstValidation = validationStage().mIsFirstValidation;
|
||||||
ValidationProbeEvent ev = new ValidationProbeEvent();
|
ValidationProbeEvent ev = new ValidationProbeEvent();
|
||||||
ev.probeType = ValidationProbeEvent.makeProbeType(probeType, isFirstValidation);
|
ev.probeType = ValidationProbeEvent.makeProbeType(probeType, isFirstValidation);
|
||||||
ev.returnCode = probeResult;
|
ev.returnCode = probeResult;
|
||||||
@@ -1535,10 +1546,20 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
return new Random();
|
return new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a global integer setting.
|
||||||
|
* @param symbol Name of the setting
|
||||||
|
* @param defaultValue Value to return if the setting is not defined.
|
||||||
|
*/
|
||||||
public int getSetting(Context context, String symbol, int defaultValue) {
|
public int getSetting(Context context, String symbol, int defaultValue) {
|
||||||
return Settings.Global.getInt(context.getContentResolver(), symbol, defaultValue);
|
return Settings.Global.getInt(context.getContentResolver(), symbol, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a global String setting.
|
||||||
|
* @param symbol Name of the setting
|
||||||
|
* @param defaultValue Value to return if the setting is not defined.
|
||||||
|
*/
|
||||||
public String getSetting(Context context, String symbol, String defaultValue) {
|
public String getSetting(Context context, String symbol, String defaultValue) {
|
||||||
final String value = Settings.Global.getString(context.getContentResolver(), symbol);
|
final String value = Settings.Global.getString(context.getContentResolver(), symbol);
|
||||||
return value != null ? value : defaultValue;
|
return value != null ? value : defaultValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user