1 /* 2 * Copyright 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 androidx.webkit; 18 19 import android.webkit.WebResourceError; 20 import android.webkit.WebViewClient; 21 22 import androidx.annotation.IntDef; 23 import androidx.annotation.RequiresFeature; 24 import androidx.annotation.RestrictTo; 25 26 import org.jspecify.annotations.NonNull; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 31 /** 32 * Compatibility version of {@link WebResourceError}. 33 */ 34 public abstract class WebResourceErrorCompat { 35 @RestrictTo(RestrictTo.Scope.LIBRARY) 36 @IntDef(value = { 37 WebViewClient.ERROR_UNKNOWN, 38 WebViewClient.ERROR_HOST_LOOKUP, 39 WebViewClient.ERROR_UNSUPPORTED_AUTH_SCHEME, 40 WebViewClient.ERROR_AUTHENTICATION, 41 WebViewClient.ERROR_PROXY_AUTHENTICATION, 42 WebViewClient.ERROR_CONNECT, 43 WebViewClient.ERROR_IO, 44 WebViewClient.ERROR_TIMEOUT, 45 WebViewClient.ERROR_REDIRECT_LOOP, 46 WebViewClient.ERROR_UNSUPPORTED_SCHEME, 47 WebViewClient.ERROR_FAILED_SSL_HANDSHAKE, 48 WebViewClient.ERROR_BAD_URL, 49 WebViewClient.ERROR_FILE, 50 WebViewClient.ERROR_FILE_NOT_FOUND, 51 WebViewClient.ERROR_TOO_MANY_REQUESTS, 52 WebViewClient.ERROR_UNSAFE_RESOURCE, 53 }) 54 @Retention(RetentionPolicy.SOURCE) 55 public @interface NetErrorCode {} 56 57 /** 58 * Gets the error code of the error. The code corresponds to one 59 * of the {@code ERROR_*} constants in {@link WebViewClient}. 60 * 61 * <p> 62 * This method should only be called if 63 * {@link WebViewFeature#isFeatureSupported(String)} 64 * returns true for {@link WebViewFeature#WEB_RESOURCE_ERROR_GET_CODE}. 65 * 66 * @return The error code of the error 67 */ 68 @RequiresFeature(name = WebViewFeature.WEB_RESOURCE_ERROR_GET_CODE, 69 enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") getErrorCode()70 public abstract @NetErrorCode int getErrorCode(); 71 72 /** 73 * Gets the string describing the error. Descriptions are localized, 74 * and thus can be used for communicating the problem to the user. 75 * 76 * <p> 77 * This method should only be called if 78 * {@link WebViewFeature#isFeatureSupported(String)} 79 * returns true for {@link WebViewFeature#WEB_RESOURCE_ERROR_GET_DESCRIPTION}. 80 * 81 * @return The description of the error 82 */ 83 @RequiresFeature(name = WebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION, 84 enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") getDescription()85 public abstract @NonNull CharSequence getDescription(); 86 87 /** 88 * This class cannot be created by applications. 89 */ 90 @RestrictTo(RestrictTo.Scope.LIBRARY) WebResourceErrorCompat()91 public WebResourceErrorCompat() { 92 } 93 } 94