| /* |
| * Copyright 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 androidx.webkit; |
| |
| import androidx.annotation.NonNull; |
| import androidx.annotation.RestrictTo; |
| import androidx.annotation.StringDef; |
| import androidx.webkit.internal.WebViewFeatureInternal; |
| |
| import org.chromium.support_lib_boundary.util.Features; |
| |
| import java.lang.annotation.ElementType; |
| import java.lang.annotation.Retention; |
| import java.lang.annotation.RetentionPolicy; |
| import java.lang.annotation.Target; |
| |
| /** |
| * Utility class for checking which WebView Support Library features are supported on the device. |
| */ |
| public class WebViewFeature { |
| |
| private WebViewFeature() {} |
| |
| /** |
| * @hide |
| */ |
| @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) |
| @StringDef(value = { |
| VISUAL_STATE_CALLBACK, |
| }) |
| @Retention(RetentionPolicy.SOURCE) |
| @Target({ElementType.PARAMETER, ElementType.METHOD}) |
| public @interface WebViewSupportFeature {} |
| |
| /** |
| * Feature for {@link #isFeatureSupported(String)}. |
| * This feature covers |
| * {@link androidx.webkit.WebViewCompat#postVisualStateCallback(android.webkit.WebView, long, |
| * WebViewCompat.VisualStateCallback)}. |
| */ |
| public static final String VISUAL_STATE_CALLBACK = Features.VISUAL_STATE_CALLBACK; |
| |
| /** |
| * Return whether a feature is supported at run-time. This depends on the Android version of the |
| * device and the WebView APK on the device. |
| */ |
| public static boolean isFeatureSupported(@NonNull @WebViewSupportFeature String feature) { |
| WebViewFeatureInternal webviewFeature = WebViewFeatureInternal.getFeature(feature); |
| return webviewFeature.isSupportedByFramework() || webviewFeature.isSupportedByWebView(); |
| } |
| } |