package androidx.webkit.internal; import android.os.Build; import android.webkit.WebView; import androidx.annotation.NonNull; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.chromium.support_lib_boundary.WebViewProviderFactoryBoundaryInterface; import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil; /* loaded from: classes.dex */ public class WebViewGlueCommunicator { private static final String GLUE_FACTORY_PROVIDER_FETCHER_CLASS = "org.chromium.support_lib_glue.SupportLibReflectionUtil"; private static final String GLUE_FACTORY_PROVIDER_FETCHER_METHOD = "createWebViewProviderFactory"; @NonNull public static WebViewProviderFactory getFactory() { return LAZY_FACTORY_HOLDER.INSTANCE; } @NonNull public static WebkitToCompatConverter getCompatConverter() { return LAZY_COMPAT_CONVERTER_HOLDER.INSTANCE; } public static class LAZY_FACTORY_HOLDER { static final WebViewProviderFactory INSTANCE = WebViewGlueCommunicator.createGlueProviderFactory(); private LAZY_FACTORY_HOLDER() { } } public static class LAZY_COMPAT_CONVERTER_HOLDER { static final WebkitToCompatConverter INSTANCE = new WebkitToCompatConverter(WebViewGlueCommunicator.getFactory().getWebkitToCompatConverter()); private LAZY_COMPAT_CONVERTER_HOLDER() { } } private static InvocationHandler fetchGlueProviderFactoryImpl() throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException { return (InvocationHandler) Class.forName(GLUE_FACTORY_PROVIDER_FETCHER_CLASS, false, getWebViewClassLoader()).getDeclaredMethod(GLUE_FACTORY_PROVIDER_FETCHER_METHOD, new Class[0]).invoke(null, new Object[0]); } @NonNull public static WebViewProviderFactory createGlueProviderFactory() { try { return new WebViewProviderFactoryAdapter((WebViewProviderFactoryBoundaryInterface) BoundaryInterfaceReflectionUtil.castToSuppLibClass(WebViewProviderFactoryBoundaryInterface.class, fetchGlueProviderFactoryImpl())); } catch (ClassNotFoundException unused) { return new IncompatibleApkWebViewProviderFactory(); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e2) { throw new RuntimeException(e2); } catch (InvocationTargetException e3) { throw new RuntimeException(e3); } } @NonNull public static ClassLoader getWebViewClassLoader() { if (Build.VERSION.SDK_INT >= 28) { return ApiHelperForP.getWebViewClassLoader(); } return getWebViewProviderFactory().getClass().getClassLoader(); } private static Object getWebViewProviderFactory() { try { Method declaredMethod = WebView.class.getDeclaredMethod("getFactory", new Class[0]); declaredMethod.setAccessible(true); return declaredMethod.invoke(null, new Object[0]); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e2) { throw new RuntimeException(e2); } catch (InvocationTargetException e3) { throw new RuntimeException(e3); } } private WebViewGlueCommunicator() { } }