Initial commit
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
package com.tencent.bugly.crashreport.crash.h5;
|
||||
|
||||
import android.webkit.JavascriptInterface;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.tencent.bugly.crashreport.inner.InnerApi;
|
||||
import com.tencent.bugly.proguard.x;
|
||||
import com.tencent.bugly.proguard.z;
|
||||
import com.unity3d.ads.metadata.MediationMetaData;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
/* loaded from: classes.dex */
|
||||
public class H5JavaScriptInterface {
|
||||
private static HashSet<Integer> a = new HashSet<>();
|
||||
private String b = null;
|
||||
private Thread c = null;
|
||||
private String d = null;
|
||||
private Map<String, String> e = null;
|
||||
|
||||
private H5JavaScriptInterface() {
|
||||
}
|
||||
|
||||
private static a a(String str) {
|
||||
String string;
|
||||
if (str != null && str.length() > 0) {
|
||||
try {
|
||||
JSONObject jSONObject = new JSONObject(str);
|
||||
a aVar = new a();
|
||||
aVar.a = jSONObject.getString("projectRoot");
|
||||
if (aVar.a == null) {
|
||||
return null;
|
||||
}
|
||||
aVar.b = jSONObject.getString("context");
|
||||
if (aVar.b == null) {
|
||||
return null;
|
||||
}
|
||||
aVar.c = jSONObject.getString("url");
|
||||
if (aVar.c == null) {
|
||||
return null;
|
||||
}
|
||||
aVar.d = jSONObject.getString("userAgent");
|
||||
if (aVar.d == null) {
|
||||
return null;
|
||||
}
|
||||
aVar.e = jSONObject.getString("language");
|
||||
if (aVar.e == null) {
|
||||
return null;
|
||||
}
|
||||
aVar.f = jSONObject.getString(MediationMetaData.KEY_NAME);
|
||||
if (aVar.f == null || aVar.f.equals("null") || (string = jSONObject.getString("stacktrace")) == null) {
|
||||
return null;
|
||||
}
|
||||
int indexOf = string.indexOf("\n");
|
||||
if (indexOf < 0) {
|
||||
x.d("H5 crash stack's format is wrong!", new Object[0]);
|
||||
return null;
|
||||
}
|
||||
aVar.h = string.substring(indexOf + 1);
|
||||
aVar.g = string.substring(0, indexOf);
|
||||
int indexOf2 = aVar.g.indexOf(":");
|
||||
if (indexOf2 > 0) {
|
||||
aVar.g = aVar.g.substring(indexOf2 + 1);
|
||||
}
|
||||
aVar.i = jSONObject.getString("file");
|
||||
if (aVar.f == null) {
|
||||
return null;
|
||||
}
|
||||
aVar.j = jSONObject.getLong("lineNumber");
|
||||
if (aVar.j < 0) {
|
||||
return null;
|
||||
}
|
||||
aVar.k = jSONObject.getLong("columnNumber");
|
||||
if (aVar.k < 0) {
|
||||
return null;
|
||||
}
|
||||
x.a("H5 crash information is following: ", new Object[0]);
|
||||
x.a("[projectRoot]: " + aVar.a, new Object[0]);
|
||||
x.a("[context]: " + aVar.b, new Object[0]);
|
||||
x.a("[url]: " + aVar.c, new Object[0]);
|
||||
x.a("[userAgent]: " + aVar.d, new Object[0]);
|
||||
x.a("[language]: " + aVar.e, new Object[0]);
|
||||
x.a("[name]: " + aVar.f, new Object[0]);
|
||||
x.a("[message]: " + aVar.g, new Object[0]);
|
||||
x.a("[stacktrace]: \n" + aVar.h, new Object[0]);
|
||||
x.a("[file]: " + aVar.i, new Object[0]);
|
||||
x.a("[lineNumber]: " + aVar.j, new Object[0]);
|
||||
x.a("[columnNumber]: " + aVar.k, new Object[0]);
|
||||
return aVar;
|
||||
} catch (Throwable th) {
|
||||
if (!x.a(th)) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static H5JavaScriptInterface getInstance(CrashReport.WebViewInterface webViewInterface) {
|
||||
String str = null;
|
||||
if (webViewInterface == null || a.contains(Integer.valueOf(webViewInterface.hashCode()))) {
|
||||
return null;
|
||||
}
|
||||
H5JavaScriptInterface h5JavaScriptInterface = new H5JavaScriptInterface();
|
||||
a.add(Integer.valueOf(webViewInterface.hashCode()));
|
||||
h5JavaScriptInterface.c = Thread.currentThread();
|
||||
Thread thread = h5JavaScriptInterface.c;
|
||||
if (thread != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\n");
|
||||
for (int i = 2; i < thread.getStackTrace().length; i++) {
|
||||
StackTraceElement stackTraceElement = thread.getStackTrace()[i];
|
||||
if (!stackTraceElement.toString().contains("crashreport")) {
|
||||
sb.append(stackTraceElement.toString());
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
str = sb.toString();
|
||||
}
|
||||
h5JavaScriptInterface.d = str;
|
||||
HashMap hashMap = new HashMap();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
sb2.append((Object) webViewInterface.getContentDescription());
|
||||
hashMap.put("[WebView] ContentDescription", sb2.toString());
|
||||
h5JavaScriptInterface.e = hashMap;
|
||||
return h5JavaScriptInterface;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void printLog(String str) {
|
||||
x.d("Log from js: %s", str);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void reportJSException(String str) {
|
||||
if (str == null) {
|
||||
x.d("Payload from JS is null.", new Object[0]);
|
||||
return;
|
||||
}
|
||||
String b = z.b(str.getBytes());
|
||||
String str2 = this.b;
|
||||
if (str2 != null && str2.equals(b)) {
|
||||
x.d("Same payload from js. Please check whether you've injected bugly.js more than one times.", new Object[0]);
|
||||
return;
|
||||
}
|
||||
this.b = b;
|
||||
x.d("Handling JS exception ...", new Object[0]);
|
||||
a a2 = a(str);
|
||||
if (a2 == null) {
|
||||
x.d("Failed to parse payload.", new Object[0]);
|
||||
return;
|
||||
}
|
||||
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||||
LinkedHashMap linkedHashMap2 = new LinkedHashMap();
|
||||
String str3 = a2.a;
|
||||
if (str3 != null) {
|
||||
linkedHashMap2.put("[JS] projectRoot", str3);
|
||||
}
|
||||
String str4 = a2.b;
|
||||
if (str4 != null) {
|
||||
linkedHashMap2.put("[JS] context", str4);
|
||||
}
|
||||
String str5 = a2.c;
|
||||
if (str5 != null) {
|
||||
linkedHashMap2.put("[JS] url", str5);
|
||||
}
|
||||
String str6 = a2.d;
|
||||
if (str6 != null) {
|
||||
linkedHashMap2.put("[JS] userAgent", str6);
|
||||
}
|
||||
String str7 = a2.i;
|
||||
if (str7 != null) {
|
||||
linkedHashMap2.put("[JS] file", str7);
|
||||
}
|
||||
long j = a2.j;
|
||||
if (j != 0) {
|
||||
linkedHashMap2.put("[JS] lineNumber", Long.toString(j));
|
||||
}
|
||||
linkedHashMap.putAll(linkedHashMap2);
|
||||
linkedHashMap.putAll(this.e);
|
||||
linkedHashMap.put("Java Stack", this.d);
|
||||
Thread thread = this.c;
|
||||
if (a2 != null) {
|
||||
InnerApi.postH5CrashAsync(thread, a2.f, a2.g, a2.h, linkedHashMap);
|
||||
}
|
||||
}
|
||||
}
|
17
sources/com/tencent/bugly/crashreport/crash/h5/a.java
Normal file
17
sources/com/tencent/bugly/crashreport/crash/h5/a.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.tencent.bugly.crashreport.crash.h5;
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
/* loaded from: classes.dex */
|
||||
public final class a {
|
||||
public String a = null;
|
||||
public String b = null;
|
||||
public String c = null;
|
||||
public String d = null;
|
||||
public String e = null;
|
||||
public String f = null;
|
||||
public String g = null;
|
||||
public String h = null;
|
||||
public String i = null;
|
||||
public long j = 0;
|
||||
public long k = 0;
|
||||
}
|
27
sources/com/tencent/bugly/crashreport/crash/h5/b.java
Normal file
27
sources/com/tencent/bugly/crashreport/crash/h5/b.java
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user