1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.captiveportal; 18 19 import android.annotation.Nullable; 20 21 /** 22 * Result of calling isCaptivePortal(). 23 * @hide 24 */ 25 public final class CaptivePortalProbeResult { 26 public static final int SUCCESS_CODE = 204; 27 public static final int FAILED_CODE = 599; 28 public static final int PORTAL_CODE = 302; 29 30 public static final CaptivePortalProbeResult FAILED = new CaptivePortalProbeResult(FAILED_CODE); 31 public static final CaptivePortalProbeResult SUCCESS = 32 new CaptivePortalProbeResult(SUCCESS_CODE); 33 34 private final int mHttpResponseCode; // HTTP response code returned from Internet probe. 35 public final String redirectUrl; // Redirect destination returned from Internet probe. 36 public final String detectUrl; // URL where a 204 response code indicates 37 // captive portal has been appeased. 38 @Nullable 39 public final CaptivePortalProbeSpec probeSpec; 40 CaptivePortalProbeResult(int httpResponseCode)41 public CaptivePortalProbeResult(int httpResponseCode) { 42 this(httpResponseCode, null, null); 43 } 44 CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl)45 public CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl) { 46 this(httpResponseCode, redirectUrl, detectUrl, null); 47 } 48 CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl, CaptivePortalProbeSpec probeSpec)49 public CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl, 50 CaptivePortalProbeSpec probeSpec) { 51 mHttpResponseCode = httpResponseCode; 52 this.redirectUrl = redirectUrl; 53 this.detectUrl = detectUrl; 54 this.probeSpec = probeSpec; 55 } 56 isSuccessful()57 public boolean isSuccessful() { 58 return mHttpResponseCode == SUCCESS_CODE; 59 } 60 isPortal()61 public boolean isPortal() { 62 return !isSuccessful() && (mHttpResponseCode >= 200) && (mHttpResponseCode <= 399); 63 } 64 isFailed()65 public boolean isFailed() { 66 return !isSuccessful() && !isPortal(); 67 } 68 } 69