Merge "Move CaptivePortalProbeResult to its own file" into pi-dev

This commit is contained in:
Remi NGUYEN VAN
2018-05-22 08:00:56 +00:00
committed by Android (Google) Code Review
3 changed files with 59 additions and 41 deletions

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.captiveportal;
/**
* Result of calling isCaptivePortal().
* @hide
*/
public final class CaptivePortalProbeResult {
public static final int SUCCESS_CODE = 204;
public static final int FAILED_CODE = 599;
public static final CaptivePortalProbeResult FAILED = new CaptivePortalProbeResult(FAILED_CODE);
public static final CaptivePortalProbeResult SUCCESS =
new CaptivePortalProbeResult(SUCCESS_CODE);
private final int mHttpResponseCode; // HTTP response code returned from Internet probe.
public final String redirectUrl; // Redirect destination returned from Internet probe.
public final String detectUrl; // URL where a 204 response code indicates
// captive portal has been appeased.
public CaptivePortalProbeResult(int httpResponseCode) {
this(httpResponseCode, null, null);
}
public CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl) {
mHttpResponseCode = httpResponseCode;
this.redirectUrl = redirectUrl;
this.detectUrl = detectUrl;
}
public boolean isSuccessful() {
return mHttpResponseCode == SUCCESS_CODE;
}
public boolean isPortal() {
return !isSuccessful() && (mHttpResponseCode >= 200) && (mHttpResponseCode <= 399);
}
public boolean isFailed() {
return !isSuccessful() && !isPortal();
}
}

View File

@@ -34,6 +34,7 @@ import android.net.NetworkRequest;
import android.net.ProxyInfo;
import android.net.TrafficStats;
import android.net.Uri;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.dns.ResolvUtil;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.NetworkEvent;
@@ -561,47 +562,6 @@ public class NetworkMonitor extends StateMachine {
}
}
/**
* Result of calling isCaptivePortal().
* @hide
*/
@VisibleForTesting
public static final class CaptivePortalProbeResult {
static final int SUCCESS_CODE = 204;
static final int FAILED_CODE = 599;
static final CaptivePortalProbeResult FAILED = new CaptivePortalProbeResult(FAILED_CODE);
static final CaptivePortalProbeResult SUCCESS = new CaptivePortalProbeResult(SUCCESS_CODE);
private final int mHttpResponseCode; // HTTP response code returned from Internet probe.
final String redirectUrl; // Redirect destination returned from Internet probe.
final String detectUrl; // URL where a 204 response code indicates
// captive portal has been appeased.
public CaptivePortalProbeResult(
int httpResponseCode, String redirectUrl, String detectUrl) {
mHttpResponseCode = httpResponseCode;
this.redirectUrl = redirectUrl;
this.detectUrl = detectUrl;
}
public CaptivePortalProbeResult(int httpResponseCode) {
this(httpResponseCode, null, null);
}
boolean isSuccessful() {
return mHttpResponseCode == SUCCESS_CODE;
}
boolean isPortal() {
return !isSuccessful() && (mHttpResponseCode >= 200) && (mHttpResponseCode <= 399);
}
boolean isFailed() {
return !isSuccessful() && !isPortal();
}
}
// Being in the EvaluatingState State indicates the Network is being evaluated for internet
// connectivity, or that the user has indicated that this network is unwanted.
private class EvaluatingState extends State {

View File

@@ -112,6 +112,7 @@ import android.net.NetworkUtils;
import android.net.RouteInfo;
import android.net.StringNetworkSpecifier;
import android.net.UidRange;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.metrics.IpConnectivityLog;
import android.net.util.MultinetworkPolicyTracker;
import android.os.ConditionVariable;