Initial commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum CallbackStatus {
|
||||
OK,
|
||||
ERROR
|
||||
}
|
83
sources/com/unity3d/ads/webview/bridge/Invocation.java
Normal file
83
sources/com/unity3d/ads/webview/bridge/Invocation.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.webview.WebViewApp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class Invocation {
|
||||
private static AtomicInteger _idCount = new AtomicInteger(0);
|
||||
private static Map<Integer, Invocation> _invocationSets;
|
||||
private int _invocationId = _idCount.getAndIncrement();
|
||||
private ArrayList<ArrayList<Object>> _invocations;
|
||||
private ArrayList<ArrayList<Object>> _responses;
|
||||
|
||||
public Invocation() {
|
||||
if (_invocationSets == null) {
|
||||
_invocationSets = new HashMap();
|
||||
}
|
||||
_invocationSets.put(Integer.valueOf(this._invocationId), this);
|
||||
}
|
||||
|
||||
public static synchronized Invocation getInvocationById(int i) {
|
||||
synchronized (Invocation.class) {
|
||||
if (_invocationSets == null || !_invocationSets.containsKey(Integer.valueOf(i))) {
|
||||
return null;
|
||||
}
|
||||
return _invocationSets.get(Integer.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void addInvocation(String str, String str2, Object[] objArr, WebViewCallback webViewCallback) {
|
||||
if (this._invocations == null) {
|
||||
this._invocations = new ArrayList<>();
|
||||
}
|
||||
ArrayList<Object> arrayList = new ArrayList<>();
|
||||
arrayList.add(str);
|
||||
arrayList.add(str2);
|
||||
arrayList.add(objArr);
|
||||
arrayList.add(webViewCallback);
|
||||
this._invocations.add(arrayList);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this._invocationId;
|
||||
}
|
||||
|
||||
public ArrayList<ArrayList<Object>> getResponses() {
|
||||
return this._responses;
|
||||
}
|
||||
|
||||
public boolean nextInvocation() {
|
||||
ArrayList<ArrayList<Object>> arrayList = this._invocations;
|
||||
if (arrayList == null || arrayList.size() <= 0) {
|
||||
return false;
|
||||
}
|
||||
ArrayList<Object> remove = this._invocations.remove(0);
|
||||
try {
|
||||
WebViewBridge.handleInvocation((String) remove.get(0), (String) remove.get(1), (Object[]) remove.get(2), (WebViewCallback) remove.get(3));
|
||||
} catch (Exception e) {
|
||||
DeviceLog.exception("Error handling invocation", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendInvocationCallback() {
|
||||
_invocationSets.remove(Integer.valueOf(getId()));
|
||||
WebViewApp.getCurrentApp().invokeCallback(this);
|
||||
}
|
||||
|
||||
public void setInvocationResponse(CallbackStatus callbackStatus, Enum r3, Object... objArr) {
|
||||
if (this._responses == null) {
|
||||
this._responses = new ArrayList<>();
|
||||
}
|
||||
ArrayList<Object> arrayList = new ArrayList<>();
|
||||
arrayList.add(callbackStatus);
|
||||
arrayList.add(r3);
|
||||
arrayList.add(objArr);
|
||||
this._responses.add(arrayList);
|
||||
}
|
||||
}
|
46
sources/com/unity3d/ads/webview/bridge/NativeCallback.java
Normal file
46
sources/com/unity3d/ads/webview/bridge/NativeCallback.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.webview.WebViewApp;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class NativeCallback {
|
||||
private static AtomicInteger _callbackCount = new AtomicInteger(0);
|
||||
private Method _callback;
|
||||
private String _id;
|
||||
|
||||
public NativeCallback(Method method) {
|
||||
this._callback = method;
|
||||
this._id = this._callback.getName().toUpperCase(Locale.US) + "_" + _callbackCount.getAndIncrement();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public void invoke(String str, Object... objArr) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
|
||||
Object[] array;
|
||||
try {
|
||||
CallbackStatus valueOf = CallbackStatus.valueOf(str);
|
||||
if (objArr == null) {
|
||||
array = new Object[]{valueOf};
|
||||
} else {
|
||||
ArrayList arrayList = new ArrayList(Arrays.asList(objArr));
|
||||
arrayList.add(0, valueOf);
|
||||
array = arrayList.toArray();
|
||||
}
|
||||
this._callback.invoke(null, array);
|
||||
WebViewApp.getCurrentApp().removeCallback(this);
|
||||
} catch (Exception e) {
|
||||
DeviceLog.error("Illegal status");
|
||||
WebViewApp.getCurrentApp().removeCallback(this);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
100
sources/com/unity3d/ads/webview/bridge/WebViewBridge.java
Normal file
100
sources/com/unity3d/ads/webview/bridge/WebViewBridge.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
import com.unity3d.ads.BuildConfig;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import com.unity3d.ads.webview.WebViewApp;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import org.json.JSONException;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WebViewBridge {
|
||||
private static HashMap<String, HashMap<String, HashMap<Integer, Method>>> _classTable;
|
||||
|
||||
private static Method findMethod(String str, String str2, Object[] objArr) throws JSONException, NoSuchMethodException {
|
||||
if (!_classTable.containsKey(str)) {
|
||||
throw new NoSuchMethodException();
|
||||
}
|
||||
HashMap<String, HashMap<Integer, Method>> hashMap = _classTable.get(str);
|
||||
if (hashMap.containsKey(str2)) {
|
||||
return hashMap.get(str2).get(Integer.valueOf(Arrays.deepHashCode(getTypes(objArr))));
|
||||
}
|
||||
throw new NoSuchMethodException();
|
||||
}
|
||||
|
||||
private static Class<?>[] getTypes(Object[] objArr) throws JSONException {
|
||||
Class<?>[] clsArr = objArr == null ? new Class[1] : new Class[objArr.length + 1];
|
||||
if (objArr != null) {
|
||||
for (int i = 0; i < objArr.length; i++) {
|
||||
clsArr[i] = objArr[i].getClass();
|
||||
}
|
||||
}
|
||||
clsArr[clsArr.length - 1] = WebViewCallback.class;
|
||||
return clsArr;
|
||||
}
|
||||
|
||||
private static Object[] getValues(Object[] objArr, WebViewCallback webViewCallback) throws JSONException {
|
||||
Object[] objArr2;
|
||||
if (objArr != null) {
|
||||
objArr2 = new Object[objArr.length + (webViewCallback != null ? 1 : 0)];
|
||||
} else {
|
||||
if (webViewCallback == null) {
|
||||
return null;
|
||||
}
|
||||
objArr2 = new Object[1];
|
||||
}
|
||||
if (objArr != null) {
|
||||
System.arraycopy(objArr, 0, objArr2, 0, objArr.length);
|
||||
}
|
||||
if (webViewCallback != null) {
|
||||
objArr2[objArr2.length - 1] = webViewCallback;
|
||||
}
|
||||
return objArr2;
|
||||
}
|
||||
|
||||
public static void handleCallback(String str, String str2, Object[] objArr) throws Exception {
|
||||
try {
|
||||
WebViewApp.getCurrentApp().getCallback(str).invoke(str2, getValues(objArr, null));
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JSONException e) {
|
||||
DeviceLog.error("Error while invoking method");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleInvocation(String str, String str2, Object[] objArr, WebViewCallback webViewCallback) throws Exception {
|
||||
try {
|
||||
try {
|
||||
findMethod(str, str2, objArr).invoke(null, getValues(objArr, webViewCallback));
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JSONException e) {
|
||||
webViewCallback.error(WebViewBridgeError.INVOCATION_FAILED, str, str2, objArr, e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
} catch (NoSuchMethodException | JSONException e2) {
|
||||
webViewCallback.error(WebViewBridgeError.METHOD_NOT_FOUND, str, str2, objArr);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setClassTable(Class[] clsArr) {
|
||||
if (clsArr == null) {
|
||||
return;
|
||||
}
|
||||
_classTable = new HashMap<>();
|
||||
for (Class cls : clsArr) {
|
||||
if (cls != null && cls.getPackage().getName().startsWith(BuildConfig.APPLICATION_ID)) {
|
||||
HashMap<String, HashMap<Integer, Method>> hashMap = new HashMap<>();
|
||||
for (Method method : cls.getMethods()) {
|
||||
if (method.getAnnotation(WebViewExposed.class) != null) {
|
||||
String name = method.getName();
|
||||
HashMap<Integer, Method> hashMap2 = hashMap.containsKey(name) ? hashMap.get(name) : new HashMap<>();
|
||||
hashMap2.put(Integer.valueOf(Arrays.deepHashCode(method.getParameterTypes())), method);
|
||||
hashMap.put(name, hashMap2);
|
||||
}
|
||||
}
|
||||
_classTable.put(cls.getName(), hashMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum WebViewBridgeError {
|
||||
CLASS_NOT_FOUND,
|
||||
CLASS_NOT_EXPOSED,
|
||||
GETALLOWEDMETHODS_NOT_FOUND,
|
||||
GETALLOWEDMETHODS_INVOCATION_FAILED,
|
||||
METHOD_NOT_FOUND,
|
||||
METHOD_UNALLOWED,
|
||||
DATA_JSON_PARSE_FAILED,
|
||||
DATA_GET_PARAMETER_VALUE_FAILED,
|
||||
DATA_PARAMETER_NULL,
|
||||
INVOCATION_FAILED
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
import android.webkit.JavascriptInterface;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WebViewBridgeInterface {
|
||||
private Object[] getParameters(JSONArray jSONArray) throws JSONException {
|
||||
Object[] objArr = new Object[jSONArray.length()];
|
||||
for (int i = 0; i < jSONArray.length(); i++) {
|
||||
objArr[i] = jSONArray.get(i);
|
||||
}
|
||||
return objArr;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void handleCallback(String str, String str2, String str3) throws Exception {
|
||||
Object[] objArr;
|
||||
DeviceLog.debug("handleCallback " + str + " " + str2 + " " + str3);
|
||||
JSONArray jSONArray = new JSONArray(str3);
|
||||
if (jSONArray.length() > 0) {
|
||||
objArr = new Object[jSONArray.length()];
|
||||
for (int i = 0; i < jSONArray.length(); i++) {
|
||||
objArr[i] = jSONArray.get(i);
|
||||
}
|
||||
} else {
|
||||
objArr = null;
|
||||
}
|
||||
WebViewBridge.handleCallback(str, str2, objArr);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void handleInvocation(String str) throws JSONException {
|
||||
DeviceLog.debug("handleInvocation " + str);
|
||||
JSONArray jSONArray = new JSONArray(str);
|
||||
Invocation invocation = new Invocation();
|
||||
for (int i = 0; i < jSONArray.length(); i++) {
|
||||
JSONArray jSONArray2 = (JSONArray) jSONArray.get(i);
|
||||
invocation.addInvocation((String) jSONArray2.get(0), (String) jSONArray2.get(1), getParameters((JSONArray) jSONArray2.get(2)), new WebViewCallback((String) jSONArray2.get(3), invocation.getId()));
|
||||
}
|
||||
for (int i2 = 0; i2 < jSONArray.length(); i2++) {
|
||||
invocation.nextInvocation();
|
||||
}
|
||||
invocation.sendInvocationCallback();
|
||||
}
|
||||
}
|
83
sources/com/unity3d/ads/webview/bridge/WebViewCallback.java
Normal file
83
sources/com/unity3d/ads/webview/bridge/WebViewCallback.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.unity3d.ads.log.DeviceLog;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WebViewCallback implements Parcelable {
|
||||
public static final Parcelable.Creator<WebViewCallback> CREATOR = new Parcelable.Creator<WebViewCallback>() { // from class: com.unity3d.ads.webview.bridge.WebViewCallback.1
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public WebViewCallback createFromParcel(Parcel parcel) {
|
||||
return new WebViewCallback(parcel);
|
||||
}
|
||||
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public WebViewCallback[] newArray(int i) {
|
||||
return new WebViewCallback[i];
|
||||
}
|
||||
};
|
||||
private String _callbackId;
|
||||
private int _invocationId;
|
||||
private boolean _invoked;
|
||||
|
||||
public WebViewCallback(String str, int i) {
|
||||
this._callbackId = str;
|
||||
this._invocationId = i;
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable
|
||||
public int describeContents() {
|
||||
return 45678;
|
||||
}
|
||||
|
||||
public void error(Enum r2, Object... objArr) {
|
||||
invoke(CallbackStatus.ERROR, r2, objArr);
|
||||
}
|
||||
|
||||
public String getCallbackId() {
|
||||
return this._callbackId;
|
||||
}
|
||||
|
||||
public int getInvocationId() {
|
||||
return this._invocationId;
|
||||
}
|
||||
|
||||
public void invoke(Object... objArr) {
|
||||
invoke(CallbackStatus.OK, null, objArr);
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeString(this._callbackId);
|
||||
parcel.writeByte(this._invoked ? (byte) 1 : (byte) 0);
|
||||
parcel.writeInt(this._invocationId);
|
||||
}
|
||||
|
||||
private void invoke(CallbackStatus callbackStatus, Enum r4, Object... objArr) {
|
||||
String str;
|
||||
if (this._invoked || (str = this._callbackId) == null || str.length() == 0) {
|
||||
return;
|
||||
}
|
||||
this._invoked = true;
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.addAll(Arrays.asList(objArr));
|
||||
arrayList.add(0, this._callbackId);
|
||||
Invocation invocationById = Invocation.getInvocationById(this._invocationId);
|
||||
if (invocationById != null) {
|
||||
invocationById.setInvocationResponse(callbackStatus, r4, arrayList.toArray());
|
||||
return;
|
||||
}
|
||||
DeviceLog.error("Couldn't get batch with id: " + getInvocationId());
|
||||
}
|
||||
|
||||
public WebViewCallback(Parcel parcel) {
|
||||
this._callbackId = parcel.readString();
|
||||
this._invoked = parcel.readByte() != 0;
|
||||
this._invocationId = parcel.readInt();
|
||||
}
|
||||
}
|
12
sources/com/unity3d/ads/webview/bridge/WebViewExposed.java
Normal file
12
sources/com/unity3d/ads/webview/bridge/WebViewExposed.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.unity3d.ads.webview.bridge;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
/* loaded from: classes2.dex */
|
||||
public @interface WebViewExposed {
|
||||
}
|
Reference in New Issue
Block a user