@Test public void testGetCurrentWebViewPackage() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { assertNull(WebViewCompat.getCurrentWebViewPackage( InstrumentationRegistry.getTargetContext())); } else { assertNotNull( WebViewCompat.getCurrentWebViewPackage( InstrumentationRegistry.getTargetContext())); } }
@Nullable public static PackageInfo getCurrentWebViewPackage(@NonNull Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return WebView.getCurrentWebViewPackage(); } else { try { PackageInfo loadedWebViewPackageInfo = getLoadedWebViewPackageInfo(); if (loadedWebViewPackageInfo != null) return loadedWebViewPackageInfo; } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return null; } return getNotYetLoadedWebViewPackageInfo(context); } }
WebViewCompat { @Nullable public static PackageInfo getCurrentWebViewPackage(@NonNull Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return WebView.getCurrentWebViewPackage(); } else { try { PackageInfo loadedWebViewPackageInfo = getLoadedWebViewPackageInfo(); if (loadedWebViewPackageInfo != null) return loadedWebViewPackageInfo; } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return null; } return getNotYetLoadedWebViewPackageInfo(context); } } }
WebViewCompat { @Nullable public static PackageInfo getCurrentWebViewPackage(@NonNull Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return WebView.getCurrentWebViewPackage(); } else { try { PackageInfo loadedWebViewPackageInfo = getLoadedWebViewPackageInfo(); if (loadedWebViewPackageInfo != null) return loadedWebViewPackageInfo; } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return null; } return getNotYetLoadedWebViewPackageInfo(context); } } private  WebViewCompat(); }
WebViewCompat { @Nullable public static PackageInfo getCurrentWebViewPackage(@NonNull Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return WebView.getCurrentWebViewPackage(); } else { try { PackageInfo loadedWebViewPackageInfo = getLoadedWebViewPackageInfo(); if (loadedWebViewPackageInfo != null) return loadedWebViewPackageInfo; } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return null; } return getNotYetLoadedWebViewPackageInfo(context); } } private  WebViewCompat(); @SuppressWarnings("NewApi") @RequiresFeature(name = WebViewFeature.VISUAL_STATE_CALLBACK, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static void postVisualStateCallback(@NonNull WebView webview, long requestId,
            @NonNull final VisualStateCallback callback); @SuppressLint("NewApi") @RequiresFeature(name = WebViewFeature.START_SAFE_BROWSING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static void startSafeBrowsing(@NonNull Context context,
            @Nullable ValueCallback<Boolean> callback); @SuppressLint("NewApi") @RequiresFeature(name = WebViewFeature.SAFE_BROWSING_WHITELIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static void setSafeBrowsingWhitelist(@NonNull List<String> hosts,
            @Nullable ValueCallback<Boolean> callback); @SuppressLint("NewApi") @NonNull @RequiresFeature(name = WebViewFeature.SAFE_BROWSING_PRIVACY_POLICY_URL, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static Uri getSafeBrowsingPrivacyPolicyUrl(); @Nullable static PackageInfo getCurrentWebViewPackage(@NonNull Context context); static @NonNull WebMessagePortCompat[] createWebMessageChannel(
            @NonNull WebView webview); static void postWebMessage(@NonNull WebView webview, @NonNull WebMessageCompat message,
            @NonNull Uri targetOrigin); }
WebViewCompat { @Nullable public static PackageInfo getCurrentWebViewPackage(@NonNull Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return WebView.getCurrentWebViewPackage(); } else { try { PackageInfo loadedWebViewPackageInfo = getLoadedWebViewPackageInfo(); if (loadedWebViewPackageInfo != null) return loadedWebViewPackageInfo; } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { return null; } return getNotYetLoadedWebViewPackageInfo(context); } } private  WebViewCompat(); @SuppressWarnings("NewApi") @RequiresFeature(name = WebViewFeature.VISUAL_STATE_CALLBACK, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static void postVisualStateCallback(@NonNull WebView webview, long requestId,
            @NonNull final VisualStateCallback callback); @SuppressLint("NewApi") @RequiresFeature(name = WebViewFeature.START_SAFE_BROWSING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static void startSafeBrowsing(@NonNull Context context,
            @Nullable ValueCallback<Boolean> callback); @SuppressLint("NewApi") @RequiresFeature(name = WebViewFeature.SAFE_BROWSING_WHITELIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static void setSafeBrowsingWhitelist(@NonNull List<String> hosts,
            @Nullable ValueCallback<Boolean> callback); @SuppressLint("NewApi") @NonNull @RequiresFeature(name = WebViewFeature.SAFE_BROWSING_PRIVACY_POLICY_URL, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") static Uri getSafeBrowsingPrivacyPolicyUrl(); @Nullable static PackageInfo getCurrentWebViewPackage(@NonNull Context context); static @NonNull WebMessagePortCompat[] createWebMessageChannel(
            @NonNull WebView webview); static void postWebMessage(@NonNull WebView webview, @NonNull WebMessageCompat message,
            @NonNull Uri targetOrigin);  }