漫漫擼2 v1.3.9版本的 MD5 值为:e07b15db49ff38b958ff7c8268ff1c9b
以下内容为反编译后的 WebViewApp.java 源代码,内容仅作参考
package com.unity3d.services.core.webview;
import android.os.Build;
import android.os.ConditionVariable;
import android.os.Looper;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebViewClient;
import com.openmediation.sdk.utils.constant.CommonConstants;
import com.openmediation.sdk.utils.constant.KeyConstants;
import com.unity3d.services.ads.api.AdUnit;
import com.unity3d.services.core.configuration.Configuration;
import com.unity3d.services.core.configuration.InitializeThread;
import com.unity3d.services.core.log.DeviceLog;
import com.unity3d.services.core.misc.Utilities;
import com.unity3d.services.core.misc.ViewUtilities;
import com.unity3d.services.core.properties.ClientProperties;
import com.unity3d.services.core.properties.SdkProperties;
import com.unity3d.services.core.request.SDKMetrics;
import com.unity3d.services.core.webview.bridge.CallbackStatus;
import com.unity3d.services.core.webview.bridge.IWebViewBridgeInvoker;
import com.unity3d.services.core.webview.bridge.Invocation;
import com.unity3d.services.core.webview.bridge.NativeCallback;
import com.unity3d.services.core.webview.bridge.WebViewBridge;
import g.b.a.a.a;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONArray;
import org.json.JSONException;
public class WebViewApp implements IWebViewBridgeInvoker {
private static final int INVOKE_JS_CHARS_LENGTH = 22;
private static ConditionVariable _conditionVariable;
private static WebViewApp _currentApp;
private Configuration _configuration;
private HashMap<String, NativeCallback> _nativeCallbacks;
private boolean _webAppLoaded;
private WebView _webView;
private static AtomicReference<Boolean> _initialized = new AtomicReference<>(Boolean.FALSE);
private static AtomicReference<String> _webAppFailureMessage = new AtomicReference<>();
private static AtomicReference<Integer> _webAppFailureCode = new AtomicReference<>();
public class WebAppChromeClient extends WebChromeClient {
private WebAppChromeClient() {
}
@Override
public void onConsoleMessage(String str, int i2, String str2) {
File file;
try {
file = new File(str2);
} catch (Exception e2) {
DeviceLog.exception("Could not handle sourceId", e2);
file = null;
}
if (file != null) {
file.getName();
}
}
}
public class WebAppClient extends WebViewClient {
private WebAppClient() {
}
@Override
public void onPageFinished(android.webkit.WebView webView, String str) {
super.onPageFinished(webView, str);
DeviceLog.debug("onPageFinished url: " + str);
}
@Override
public void onReceivedError(android.webkit.WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
super.onReceivedError(webView, webResourceRequest, webResourceError);
if (webView != null) {
StringBuilder D = a.D("WEBVIEW_ERROR: ");
D.append(webView.toString());
DeviceLog.error(D.toString());
}
if (webResourceRequest != null) {
StringBuilder D2 = a.D("WEBVIEW_ERROR: ");
D2.append(webResourceRequest.toString());
DeviceLog.error(D2.toString());
}
if (webResourceError != null) {
StringBuilder D3 = a.D("WEBVIEW_ERROR: ");
D3.append(webResourceError.toString());
DeviceLog.error(D3.toString());
}
}
@Override
public boolean onRenderProcessGone(android.webkit.WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
if (AdUnit.getAdUnitActivity() != null) {
AdUnit.getAdUnitActivity().finish();
}
if (WebViewApp.getCurrentApp() != null && WebViewApp.getCurrentApp().getWebView() != null) {
ViewUtilities.removeViewFromParent(WebViewApp.getCurrentApp().getWebView());
}
InitializeThread.reset();
}
});
DeviceLog.error("UnityAds Sdk WebView onRenderProcessGone : " + renderProcessGoneDetail.toString());
SDKMetrics.getInstance().sendEventWithTags("native_webview_render_process_gone", new HashMap<String, String>(renderProcessGoneDetail) {
public final RenderProcessGoneDetail val$detail;
{
this.val$detail = renderProcessGoneDetail;
if (Build.VERSION.SDK_INT >= 26) {
StringBuilder D = a.D("");
D.append(renderProcessGoneDetail.didCrash());
put("dc", D.toString());
put("pae", "" + renderProcessGoneDetail.rendererPriorityAtExit());
}
}
});
return true;
}
@Override
public boolean shouldOverrideUrlLoading(android.webkit.WebView webView, String str) {
DeviceLog.debug("Trying to load url: " + str);
return false;
}
}
public static boolean create(final Configuration configuration) throws IllegalThreadStateException {
DeviceLog.entered();
if (!Thread.currentThread().equals(Looper.getMainLooper().getThread())) {
Utilities.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
WebViewApp webViewApp = new WebViewApp(Configuration.this);
String str = "?platform=android";
try {
if (Configuration.this.getWebViewUrl() != null) {
str = "?platform=android&origin=" + URLEncoder.encode(Configuration.this.getWebViewUrl(), CommonConstants.CHARTSET_UTF8);
}
} catch (UnsupportedEncodingException e2) {
DeviceLog.exception("Unsupported charset when encoding origin url", e2);
}
try {
if (Configuration.this.getWebViewVersion() != null) {
str = str + "&version=" + URLEncoder.encode(Configuration.this.getWebViewVersion(), CommonConstants.CHARTSET_UTF8);
}
} catch (UnsupportedEncodingException e3) {
DeviceLog.exception("Unsupported charset when encoding webview version", e3);
}
WebView webView = webViewApp.getWebView();
StringBuilder D = a.D("file://");
D.append(SdkProperties.getLocalWebViewFile());
D.append(str);
webView.loadDataWithBaseURL(D.toString(), Configuration.this.getWebViewData(), "text/html", CommonConstants.CHARTSET_UTF8, null);
WebViewApp.setCurrentApp(webViewApp);
} catch (Exception unused) {
DeviceLog.error("Couldn't construct WebViewApp");
WebViewApp._conditionVariable.open();
}
}
});
ConditionVariable conditionVariable = new ConditionVariable();
_conditionVariable = conditionVariable;
boolean block = conditionVariable.block(configuration.getWebViewAppCreateTimeout());
boolean z = true;
boolean z2 = getCurrentApp() != null;
boolean z3 = z2 && getCurrentApp().isWebAppInitialized();
if (!block || !z2 || !z3) {
z = false;
}
if (!z) {
SDKMetrics.getInstance().sendEventWithTags("native_webview_creation_failed", new HashMap<String, String>(block, z2, z3) {
public final boolean val$webAppDefined;
public final boolean val$webAppInitialized;
public final boolean val$webViewCreateDidNotTimeout;
{
this.val$webViewCreateDidNotTimeout = block;
this.val$webAppDefined = z2;
this.val$webAppInitialized = z3;
StringBuilder D = a.D("");
D.append(!block);
put("wto", D.toString());
put("wad", "" + z2);
put("wai", "" + z3);
}
});
}
return z;
}
throw new IllegalThreadStateException("Cannot call create() from main thread!");
}
public static WebViewApp getCurrentApp() {
return _currentApp;
}
private void invokeJavascriptMethod(String str, String str2, JSONArray jSONArray) throws JSONException {
String jSONArray2 = jSONArray.toString();
StringBuilder sb = new StringBuilder(jSONArray2.length() + str2.length() + str.length() + 22);
sb.append("javascript:window.");
sb.append(str);
sb.append(".");
sb.append(str2);
String A = a.A(sb, "(", jSONArray2, ");");
DeviceLog.debug("Invoking javascript: " + A);
getWebView().invokeJavascript(A);
}
public static void setCurrentApp(WebViewApp webViewApp) {
_currentApp = webViewApp;
}
public void addCallback(NativeCallback nativeCallback) {
if (this._nativeCallbacks == null) {
this._nativeCallbacks = new HashMap<>();
}
synchronized (this._nativeCallbacks) {
this._nativeCallbacks.put(nativeCallback.getId(), nativeCallback);
}
}
public NativeCallback getCallback(String str) {
NativeCallback nativeCallback;
synchronized (this._nativeCallbacks) {
nativeCallback = this._nativeCallbacks.get(str);
}
return nativeCallback;
}
public Configuration getConfiguration() {
return this._configuration;
}
public int getWebAppFailureCode() {
return _webAppFailureCode.get().intValue();
}
public String getWebAppFailureMessage() {
return _webAppFailureMessage.get();
}
public WebView getWebView() {
return this._webView;
}
public boolean invokeCallback(Invocation invocation) {
if (!isWebAppLoaded()) {
DeviceLog.debug("invokeBatchCallback ignored because web app is not loaded");
return false;
}
JSONArray jSONArray = new JSONArray();
ArrayList<ArrayList<Object>> responses = invocation.getResponses();
if (responses != null && !responses.isEmpty()) {
Iterator<ArrayList<Object>> it = responses.iterator();
while (it.hasNext()) {
ArrayList<Object> next = it.next();
Enum r5 = (Enum) next.get(1);
Object[] objArr = (Object[]) next.get(2);
Object[] copyOfRange = Arrays.copyOfRange(objArr, 1, objArr.length);
ArrayList arrayList = new ArrayList();
arrayList.add((String) objArr[0]);
arrayList.add(((CallbackStatus) next.get(0)).toString());
JSONArray jSONArray2 = new JSONArray();
if (r5 != null) {
jSONArray2.put(r5.name());
}
for (Object obj : copyOfRange) {
jSONArray2.put(obj);
}
arrayList.add(jSONArray2);
JSONArray jSONArray3 = new JSONArray();
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
jSONArray3.put(it2.next());
}
jSONArray.put(jSONArray3);
}
}
try {
invokeJavascriptMethod(KeyConstants.Android.KEY_NATIVE_BRIDGE, "handleCallback", jSONArray);
} catch (Exception e2) {
DeviceLog.exception("Error while invoking batch response for WebView", e2);
}
return true;
}
@Override
public boolean invokeMethod(String str, String str2, Method method, Object... objArr) {
if (!isWebAppLoaded()) {
DeviceLog.debug("invokeMethod ignored because web app is not loaded");
return false;
}
JSONArray jSONArray = new JSONArray();
jSONArray.put(str);
jSONArray.put(str2);
if (method != null) {
NativeCallback nativeCallback = new NativeCallback(method);
addCallback(nativeCallback);
jSONArray.put(nativeCallback.getId());
} else {
jSONArray.put((Object) null);
}
if (objArr != null) {
for (Object obj : objArr) {
jSONArray.put(obj);
}
}
try {
invokeJavascriptMethod(KeyConstants.Android.KEY_NATIVE_BRIDGE, "handleInvocation", jSONArray);
return true;
} catch (Exception e2) {
DeviceLog.exception("Error invoking javascript method", e2);
return false;
}
}
public boolean isWebAppInitialized() {
return _initialized.get().booleanValue();
}
public boolean isWebAppLoaded() {
return this._webAppLoaded;
}
public void removeCallback(NativeCallback nativeCallback) {
HashMap<String, NativeCallback> hashMap = this._nativeCallbacks;
if (hashMap == null) {
return;
}
synchronized (hashMap) {
this._nativeCallbacks.remove(nativeCallback.getId());
}
}
public void resetWebViewAppInitialization() {
this._webAppLoaded = false;
_webAppFailureCode.set(-1);
_webAppFailureMessage.set("");
_initialized.set(Boolean.FALSE);
}
public boolean sendEvent(Enum r4, Enum r5, Object... objArr) {
if (!isWebAppLoaded()) {
DeviceLog.debug("sendEvent ignored because web app is not loaded");
return false;
}
JSONArray jSONArray = new JSONArray();
jSONArray.put(r4.name());
jSONArray.put(r5.name());
for (Object obj : objArr) {
jSONArray.put(obj);
}
try {
invokeJavascriptMethod(KeyConstants.Android.KEY_NATIVE_BRIDGE, "handleEvent", jSONArray);
return true;
} catch (Exception e2) {
DeviceLog.exception("Error while sending event to WebView", e2);
return false;
}
}
public void setConfiguration(Configuration configuration) {
this._configuration = configuration;
}
public void setWebAppFailureCode(int i2) {
_webAppFailureCode.set(Integer.valueOf(i2));
}
public void setWebAppFailureMessage(String str) {
_webAppFailureMessage.set(str);
}
public void setWebAppInitialized(boolean z) {
_initialized.set(Boolean.valueOf(z));
_conditionVariable.open();
}
public void setWebAppLoaded(boolean z) {
this._webAppLoaded = z;
}
public void setWebView(WebView webView) {
this._webView = webView;
}
private WebViewApp(Configuration configuration) {
this._webAppLoaded = false;
setConfiguration(configuration);
WebViewBridge.setClassTable(getConfiguration().getWebAppApiClassList());
WebView webView = new WebView(ClientProperties.getApplicationContext());
this._webView = webView;
webView.setWebViewClient(new WebAppClient());
this._webView.setWebChromeClient(new WebAppChromeClient());
}
public WebViewApp() {
this._webAppLoaded = false;
}
}