Initial commit
This commit is contained in:
@@ -0,0 +1,308 @@
|
||||
package com.tencent.bugly.crashreport.crash.anr;
|
||||
|
||||
import com.tencent.bugly.proguard.x;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
/* loaded from: classes.dex */
|
||||
public class TraceFileHelper {
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
public static class a {
|
||||
public long a;
|
||||
public String b;
|
||||
public long c;
|
||||
public Map<String, String[]> d;
|
||||
}
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
public interface b {
|
||||
boolean a(long j);
|
||||
|
||||
boolean a(long j, long j2, String str);
|
||||
|
||||
boolean a(String str, int i, String str2, String str3);
|
||||
}
|
||||
|
||||
private static Object[] a(BufferedReader bufferedReader, Pattern... patternArr) throws IOException {
|
||||
if (bufferedReader != null && patternArr != null) {
|
||||
while (true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine == null) {
|
||||
break;
|
||||
}
|
||||
for (Pattern pattern : patternArr) {
|
||||
if (pattern.matcher(readLine).matches()) {
|
||||
return new Object[]{pattern, readLine};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String b(BufferedReader bufferedReader) throws IOException {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while (true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine == null || readLine.trim().length() <= 0) {
|
||||
break;
|
||||
}
|
||||
stringBuffer.append(readLine + "\n");
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public static a readFirstDumpInfo(String str, final boolean z) {
|
||||
if (str == null) {
|
||||
x.e("path:%s", str);
|
||||
return null;
|
||||
}
|
||||
final a aVar = new a();
|
||||
readTraceFile(str, new b() { // from class: com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.2
|
||||
@Override // com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.b
|
||||
public final boolean a(String str2, int i, String str3, String str4) {
|
||||
x.c("new thread %s", str2);
|
||||
a aVar2 = a.this;
|
||||
if (aVar2.d == null) {
|
||||
aVar2.d = new HashMap();
|
||||
}
|
||||
Map<String, String[]> map = a.this.d;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(i);
|
||||
map.put(str2, new String[]{str3, str4, sb.toString()});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.b
|
||||
public final boolean a(long j, long j2, String str2) {
|
||||
x.c("new process %s", str2);
|
||||
a aVar2 = a.this;
|
||||
aVar2.a = j;
|
||||
aVar2.b = str2;
|
||||
aVar2.c = j2;
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override // com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.b
|
||||
public final boolean a(long j) {
|
||||
x.c("process end %d", Long.valueOf(j));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (aVar.a > 0 && aVar.c > 0 && aVar.b != null) {
|
||||
return aVar;
|
||||
}
|
||||
x.e("first dump error %s", aVar.a + " " + aVar.c + " " + aVar.b);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static a readTargetDumpInfo(final String str, String str2, final boolean z) {
|
||||
if (str != null && str2 != null) {
|
||||
final a aVar = new a();
|
||||
readTraceFile(str2, new b() { // from class: com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.1
|
||||
@Override // com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.b
|
||||
public final boolean a(String str3, int i, String str4, String str5) {
|
||||
x.c("new thread %s", str3);
|
||||
a aVar2 = a.this;
|
||||
if (aVar2.a > 0 && aVar2.c > 0 && aVar2.b != null) {
|
||||
if (aVar2.d == null) {
|
||||
aVar2.d = new HashMap();
|
||||
}
|
||||
Map<String, String[]> map = a.this.d;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(i);
|
||||
map.put(str3, new String[]{str4, str5, sb.toString()});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.b
|
||||
public final boolean a(long j, long j2, String str3) {
|
||||
x.c("new process %s", str3);
|
||||
if (!str3.equals(str)) {
|
||||
return true;
|
||||
}
|
||||
a aVar2 = a.this;
|
||||
aVar2.a = j;
|
||||
aVar2.b = str3;
|
||||
aVar2.c = j2;
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override // com.tencent.bugly.crashreport.crash.anr.TraceFileHelper.b
|
||||
public final boolean a(long j) {
|
||||
x.c("process end %d", Long.valueOf(j));
|
||||
a aVar2 = a.this;
|
||||
return aVar2.a <= 0 || aVar2.c <= 0 || aVar2.b == null;
|
||||
}
|
||||
});
|
||||
if (aVar.a > 0 && aVar.c > 0 && aVar.b != null) {
|
||||
return aVar;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void readTraceFile(String str, b bVar) {
|
||||
Throwable th;
|
||||
BufferedReader bufferedReader;
|
||||
if (str == null || bVar == null) {
|
||||
return;
|
||||
}
|
||||
File file = new File(str);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
file.lastModified();
|
||||
file.length();
|
||||
BufferedReader bufferedReader2 = null;
|
||||
try {
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new FileReader(file));
|
||||
try {
|
||||
Pattern compile = Pattern.compile("-{5}\\spid\\s\\d+\\sat\\s\\d+-\\d+-\\d+\\s\\d{2}:\\d{2}:\\d{2}\\s-{5}");
|
||||
Pattern compile2 = Pattern.compile("-{5}\\send\\s\\d+\\s-{5}");
|
||||
Pattern compile3 = Pattern.compile("Cmd\\sline:\\s(\\S+)");
|
||||
Pattern compile4 = Pattern.compile("\".+\"\\s(daemon\\s){0,1}prio=\\d+\\stid=\\d+\\s.*");
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
||||
while (true) {
|
||||
Object[] a2 = a(bufferedReader, compile);
|
||||
if (a2 == null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
if (x.a(e)) {
|
||||
return;
|
||||
}
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
String[] split = a2[1].toString().split("\\s");
|
||||
long parseLong = Long.parseLong(split[2]);
|
||||
long time = simpleDateFormat.parse(split[4] + " " + split[5]).getTime();
|
||||
Object[] a3 = a(bufferedReader, compile3);
|
||||
if (a3 == null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
return;
|
||||
} catch (IOException e2) {
|
||||
if (x.a(e2)) {
|
||||
return;
|
||||
}
|
||||
e2.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Matcher matcher = compile3.matcher(a3[1].toString());
|
||||
matcher.find();
|
||||
matcher.group(1);
|
||||
SimpleDateFormat simpleDateFormat2 = simpleDateFormat;
|
||||
if (!bVar.a(parseLong, time, matcher.group(1))) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
return;
|
||||
} catch (IOException e3) {
|
||||
if (x.a(e3)) {
|
||||
return;
|
||||
}
|
||||
e3.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
Object[] a4 = a(bufferedReader, compile4, compile2);
|
||||
if (a4 == null) {
|
||||
break;
|
||||
}
|
||||
if (a4[0] == compile4) {
|
||||
String obj = a4[1].toString();
|
||||
Matcher matcher2 = Pattern.compile("\".+\"").matcher(obj);
|
||||
matcher2.find();
|
||||
String group = matcher2.group();
|
||||
String substring = group.substring(1, group.length() - 1);
|
||||
obj.contains("NATIVE");
|
||||
Matcher matcher3 = Pattern.compile("tid=\\d+").matcher(obj);
|
||||
matcher3.find();
|
||||
String group2 = matcher3.group();
|
||||
bVar.a(substring, Integer.parseInt(group2.substring(group2.indexOf("=") + 1)), a(bufferedReader), b(bufferedReader));
|
||||
} else if (!bVar.a(Long.parseLong(a4[1].toString().split("\\s")[2]))) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
return;
|
||||
} catch (IOException e4) {
|
||||
if (x.a(e4)) {
|
||||
return;
|
||||
}
|
||||
e4.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
simpleDateFormat = simpleDateFormat2;
|
||||
}
|
||||
} catch (Exception e5) {
|
||||
e = e5;
|
||||
bufferedReader2 = bufferedReader;
|
||||
if (!x.a(e)) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
x.d("trace open fail:%s : %s", e.getClass().getName(), e.getMessage());
|
||||
if (bufferedReader2 != null) {
|
||||
try {
|
||||
bufferedReader2.close();
|
||||
} catch (IOException e6) {
|
||||
if (x.a(e6)) {
|
||||
return;
|
||||
}
|
||||
e6.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
if (bufferedReader == null) {
|
||||
throw th;
|
||||
}
|
||||
try {
|
||||
bufferedReader.close();
|
||||
throw th;
|
||||
} catch (IOException e7) {
|
||||
if (x.a(e7)) {
|
||||
throw th;
|
||||
}
|
||||
e7.printStackTrace();
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
} catch (Exception e8) {
|
||||
e = e8;
|
||||
}
|
||||
} catch (Throwable th3) {
|
||||
th = th3;
|
||||
bufferedReader = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String a(BufferedReader bufferedReader) throws IOException {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine == null) {
|
||||
return null;
|
||||
}
|
||||
stringBuffer.append(readLine + "\n");
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
15
sources/com/tencent/bugly/crashreport/crash/anr/a.java
Normal file
15
sources/com/tencent/bugly/crashreport/crash/anr/a.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.tencent.bugly.crashreport.crash.anr;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
/* loaded from: classes.dex */
|
||||
public final class a {
|
||||
public String a = null;
|
||||
public Map<String, String> b = null;
|
||||
public long c = -1;
|
||||
public String d = null;
|
||||
public String e = null;
|
||||
public String f = null;
|
||||
public String g = null;
|
||||
}
|
548
sources/com/tencent/bugly/crashreport/crash/anr/b.java
Normal file
548
sources/com/tencent/bugly/crashreport/crash/anr/b.java
Normal file
@@ -0,0 +1,548 @@
|
||||
package com.tencent.bugly.crashreport.crash.anr;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.FileObserver;
|
||||
import android.os.Process;
|
||||
import com.tencent.bugly.crashreport.common.strategy.StrategyBean;
|
||||
import com.tencent.bugly.crashreport.crash.CrashDetailBean;
|
||||
import com.tencent.bugly.crashreport.crash.anr.TraceFileHelper;
|
||||
import com.tencent.bugly.crashreport.crash.c;
|
||||
import com.tencent.bugly.proguard.ab;
|
||||
import com.tencent.bugly.proguard.ac;
|
||||
import com.tencent.bugly.proguard.w;
|
||||
import com.tencent.bugly.proguard.x;
|
||||
import com.tencent.bugly.proguard.y;
|
||||
import com.tencent.bugly.proguard.z;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* compiled from: BUGLY */
|
||||
/* loaded from: classes.dex */
|
||||
public final class b implements ac {
|
||||
private final Context c;
|
||||
private final com.tencent.bugly.crashreport.common.info.a d;
|
||||
private final w e;
|
||||
private final com.tencent.bugly.crashreport.common.strategy.a f;
|
||||
private final String g;
|
||||
private final com.tencent.bugly.crashreport.crash.b h;
|
||||
private FileObserver i;
|
||||
private ab k;
|
||||
private int l;
|
||||
private AtomicInteger a = new AtomicInteger(0);
|
||||
private long b = -1;
|
||||
private boolean j = true;
|
||||
|
||||
public b(Context context, com.tencent.bugly.crashreport.common.strategy.a aVar, com.tencent.bugly.crashreport.common.info.a aVar2, w wVar, com.tencent.bugly.crashreport.crash.b bVar) {
|
||||
this.c = z.a(context);
|
||||
this.g = context.getDir("bugly", 0).getAbsolutePath();
|
||||
this.d = aVar2;
|
||||
this.e = wVar;
|
||||
this.f = aVar;
|
||||
this.h = bVar;
|
||||
}
|
||||
|
||||
private static ActivityManager.ProcessErrorStateInfo a(Context context, long j) {
|
||||
try {
|
||||
x.c("to find!", new Object[0]);
|
||||
ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
|
||||
int i = 0;
|
||||
while (true) {
|
||||
x.c("waiting!", new Object[0]);
|
||||
List<ActivityManager.ProcessErrorStateInfo> processesInErrorState = activityManager.getProcessesInErrorState();
|
||||
if (processesInErrorState != null) {
|
||||
for (ActivityManager.ProcessErrorStateInfo processErrorStateInfo : processesInErrorState) {
|
||||
if (processErrorStateInfo.condition == 2) {
|
||||
x.c("found!", new Object[0]);
|
||||
return processErrorStateInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
z.b(500L);
|
||||
int i2 = i + 1;
|
||||
if (i >= 20) {
|
||||
x.c("end!", new Object[0]);
|
||||
return null;
|
||||
}
|
||||
i = i2;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
x.b(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void b(boolean z) {
|
||||
if (z) {
|
||||
e();
|
||||
} else {
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void c(boolean z) {
|
||||
if (this.j != z) {
|
||||
x.a("user change anr %b", Boolean.valueOf(z));
|
||||
this.j = z;
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void e() {
|
||||
if (g()) {
|
||||
x.d("start when started!", new Object[0]);
|
||||
return;
|
||||
}
|
||||
this.i = new FileObserver("/data/anr/", 8) { // from class: com.tencent.bugly.crashreport.crash.anr.b.1
|
||||
@Override // android.os.FileObserver
|
||||
public final void onEvent(int i, String str) {
|
||||
if (str == null) {
|
||||
return;
|
||||
}
|
||||
String str2 = "/data/anr/" + str;
|
||||
if (str2.contains("trace")) {
|
||||
b.this.a(str2);
|
||||
} else {
|
||||
x.d("not anr file %s", str2);
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
this.i.startWatching();
|
||||
x.a("start anr monitor!", new Object[0]);
|
||||
this.e.a(new Runnable() { // from class: com.tencent.bugly.crashreport.crash.anr.b.2
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
b.this.b();
|
||||
}
|
||||
});
|
||||
} catch (Throwable th) {
|
||||
this.i = null;
|
||||
x.d("start anr monitor failed!", new Object[0]);
|
||||
if (x.a(th)) {
|
||||
return;
|
||||
}
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void f() {
|
||||
if (!g()) {
|
||||
x.d("close when closed!", new Object[0]);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.i.stopWatching();
|
||||
this.i = null;
|
||||
x.d("close anr monitor!", new Object[0]);
|
||||
} catch (Throwable th) {
|
||||
x.d("stop anr monitor failed!", new Object[0]);
|
||||
if (x.a(th)) {
|
||||
return;
|
||||
}
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized boolean g() {
|
||||
return this.i != null;
|
||||
}
|
||||
|
||||
private synchronized boolean h() {
|
||||
return this.j;
|
||||
}
|
||||
|
||||
public final boolean d() {
|
||||
ab abVar = this.k;
|
||||
if (abVar == null) {
|
||||
return false;
|
||||
}
|
||||
abVar.b();
|
||||
this.k.b(this);
|
||||
boolean c = this.k.c();
|
||||
this.k = null;
|
||||
return c;
|
||||
}
|
||||
|
||||
protected final void b() {
|
||||
long b = z.b() - c.g;
|
||||
File file = new File(this.g);
|
||||
if (file.exists() && file.isDirectory()) {
|
||||
try {
|
||||
File[] listFiles = file.listFiles();
|
||||
if (listFiles != null && listFiles.length != 0) {
|
||||
int i = 0;
|
||||
for (File file2 : listFiles) {
|
||||
String name = file2.getName();
|
||||
if (name.startsWith("bugly_trace_")) {
|
||||
try {
|
||||
int indexOf = name.indexOf(".txt");
|
||||
if (indexOf > 0 && Long.parseLong(name.substring(12, indexOf)) >= b) {
|
||||
}
|
||||
} catch (Throwable unused) {
|
||||
x.c("Trace file that has invalid format: " + name, new Object[0]);
|
||||
}
|
||||
if (file2.delete()) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
x.c("Number of overdue trace files that has deleted: " + i, new Object[0]);
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
x.a(th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean c() {
|
||||
ab abVar = this.k;
|
||||
if (abVar != null && abVar.isAlive()) {
|
||||
return false;
|
||||
}
|
||||
this.k = new ab();
|
||||
ab abVar2 = this.k;
|
||||
StringBuilder sb = new StringBuilder("Bugly-ThreadMonitor");
|
||||
int i = this.l;
|
||||
this.l = i + 1;
|
||||
sb.append(i);
|
||||
abVar2.setName(sb.toString());
|
||||
this.k.a();
|
||||
this.k.a(this);
|
||||
return this.k.d();
|
||||
}
|
||||
|
||||
private CrashDetailBean a(a aVar) {
|
||||
CrashDetailBean crashDetailBean = new CrashDetailBean();
|
||||
try {
|
||||
crashDetailBean.C = com.tencent.bugly.crashreport.common.info.b.k();
|
||||
crashDetailBean.D = com.tencent.bugly.crashreport.common.info.b.i();
|
||||
crashDetailBean.E = com.tencent.bugly.crashreport.common.info.b.m();
|
||||
crashDetailBean.F = this.d.p();
|
||||
crashDetailBean.G = this.d.o();
|
||||
crashDetailBean.H = this.d.q();
|
||||
crashDetailBean.w = z.a(this.c, c.e, (String) null);
|
||||
crashDetailBean.b = 3;
|
||||
crashDetailBean.e = this.d.h();
|
||||
crashDetailBean.f = this.d.j;
|
||||
crashDetailBean.g = this.d.w();
|
||||
crashDetailBean.m = this.d.g();
|
||||
crashDetailBean.n = "ANR_EXCEPTION";
|
||||
crashDetailBean.o = aVar.f;
|
||||
crashDetailBean.q = aVar.g;
|
||||
crashDetailBean.O = new HashMap();
|
||||
crashDetailBean.O.put("BUGLY_CR_01", aVar.e);
|
||||
int indexOf = crashDetailBean.q != null ? crashDetailBean.q.indexOf("\n") : -1;
|
||||
crashDetailBean.p = indexOf > 0 ? crashDetailBean.q.substring(0, indexOf) : "GET_FAIL";
|
||||
crashDetailBean.r = aVar.c;
|
||||
if (crashDetailBean.q != null) {
|
||||
crashDetailBean.u = z.b(crashDetailBean.q.getBytes());
|
||||
}
|
||||
crashDetailBean.z = aVar.b;
|
||||
crashDetailBean.A = aVar.a;
|
||||
crashDetailBean.B = "main(1)";
|
||||
crashDetailBean.I = this.d.y();
|
||||
crashDetailBean.h = this.d.v();
|
||||
crashDetailBean.i = this.d.J();
|
||||
crashDetailBean.v = aVar.d;
|
||||
crashDetailBean.L = this.d.n;
|
||||
crashDetailBean.M = this.d.a;
|
||||
crashDetailBean.N = this.d.a();
|
||||
crashDetailBean.P = this.d.H();
|
||||
crashDetailBean.Q = this.d.I();
|
||||
crashDetailBean.R = this.d.B();
|
||||
crashDetailBean.S = this.d.G();
|
||||
this.h.c(crashDetailBean);
|
||||
crashDetailBean.y = y.a();
|
||||
} catch (Throwable th) {
|
||||
if (!x.a(th)) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
return crashDetailBean;
|
||||
}
|
||||
|
||||
private static boolean a(String str, String str2, String str3) {
|
||||
Map<String, String[]> map;
|
||||
BufferedWriter bufferedWriter;
|
||||
TraceFileHelper.a readTargetDumpInfo = TraceFileHelper.readTargetDumpInfo(str3, str, true);
|
||||
if (readTargetDumpInfo != null && (map = readTargetDumpInfo.d) != null && map.size() > 0) {
|
||||
File file = new File(str2);
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
file.createNewFile();
|
||||
}
|
||||
if (file.exists() && file.canWrite()) {
|
||||
BufferedWriter bufferedWriter2 = null;
|
||||
try {
|
||||
try {
|
||||
bufferedWriter = new BufferedWriter(new FileWriter(file, false));
|
||||
try {
|
||||
String[] strArr = readTargetDumpInfo.d.get("main");
|
||||
int i = 3;
|
||||
if (strArr != null && strArr.length >= 3) {
|
||||
String str4 = strArr[0];
|
||||
String str5 = strArr[1];
|
||||
bufferedWriter.write("\"main\" tid=" + strArr[2] + " :\n" + str4 + "\n" + str5 + "\n\n");
|
||||
bufferedWriter.flush();
|
||||
}
|
||||
for (Map.Entry<String, String[]> entry : readTargetDumpInfo.d.entrySet()) {
|
||||
if (!entry.getKey().equals("main")) {
|
||||
if (entry.getValue() != null && entry.getValue().length >= i) {
|
||||
String str6 = entry.getValue()[0];
|
||||
String str7 = entry.getValue()[1];
|
||||
bufferedWriter.write("\"" + entry.getKey() + "\" tid=" + entry.getValue()[2] + " :\n" + str6 + "\n" + str7 + "\n\n");
|
||||
bufferedWriter.flush();
|
||||
}
|
||||
i = 3;
|
||||
}
|
||||
}
|
||||
try {
|
||||
bufferedWriter.close();
|
||||
} catch (IOException e) {
|
||||
if (!x.a(e)) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e2) {
|
||||
e = e2;
|
||||
bufferedWriter2 = bufferedWriter;
|
||||
if (!x.a(e)) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
x.e("dump trace fail %s", e.getClass().getName() + ":" + e.getMessage());
|
||||
if (bufferedWriter2 != null) {
|
||||
try {
|
||||
bufferedWriter2.close();
|
||||
} catch (IOException e3) {
|
||||
if (!x.a(e3)) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (Throwable th) {
|
||||
th = th;
|
||||
Throwable th2 = th;
|
||||
if (bufferedWriter != null) {
|
||||
try {
|
||||
bufferedWriter.close();
|
||||
throw th2;
|
||||
} catch (IOException e4) {
|
||||
if (!x.a(e4)) {
|
||||
e4.printStackTrace();
|
||||
throw th2;
|
||||
}
|
||||
throw th2;
|
||||
}
|
||||
}
|
||||
throw th2;
|
||||
}
|
||||
} catch (Throwable th3) {
|
||||
th = th3;
|
||||
bufferedWriter = bufferedWriter2;
|
||||
}
|
||||
} catch (IOException e5) {
|
||||
e = e5;
|
||||
}
|
||||
} else {
|
||||
x.e("backup file create fail %s", str2);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e6) {
|
||||
if (!x.a(e6)) {
|
||||
e6.printStackTrace();
|
||||
}
|
||||
x.e("backup file create error! %s %s", e6.getClass().getName() + ":" + e6.getMessage(), str2);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
x.e("not found trace dump for %s", str3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean a() {
|
||||
return this.a.get() != 0;
|
||||
}
|
||||
|
||||
private boolean a(Context context, String str, ActivityManager.ProcessErrorStateInfo processErrorStateInfo, long j, Map<String, String> map) {
|
||||
File file = new File(context.getFilesDir(), "bugly/bugly_trace_" + j + ".txt");
|
||||
a aVar = new a();
|
||||
aVar.c = j;
|
||||
aVar.d = file.getAbsolutePath();
|
||||
aVar.a = processErrorStateInfo != null ? processErrorStateInfo.processName : "";
|
||||
aVar.f = processErrorStateInfo != null ? processErrorStateInfo.shortMsg : "";
|
||||
aVar.e = processErrorStateInfo != null ? processErrorStateInfo.longMsg : "";
|
||||
aVar.b = map;
|
||||
if (map != null) {
|
||||
for (String str2 : map.keySet()) {
|
||||
if (str2.startsWith("main(")) {
|
||||
aVar.g = map.get(str2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] objArr = new Object[6];
|
||||
objArr[0] = Long.valueOf(aVar.c);
|
||||
objArr[1] = aVar.d;
|
||||
objArr[2] = aVar.a;
|
||||
objArr[3] = aVar.f;
|
||||
objArr[4] = aVar.e;
|
||||
Map<String, String> map2 = aVar.b;
|
||||
objArr[5] = Integer.valueOf(map2 == null ? 0 : map2.size());
|
||||
x.c("anr tm:%d\ntr:%s\nproc:%s\nsMsg:%s\n lMsg:%s\n threads:%d", objArr);
|
||||
if (!this.f.b()) {
|
||||
x.e("crash report sync remote fail, will not upload to Bugly , print local for helpful!", new Object[0]);
|
||||
com.tencent.bugly.crashreport.crash.b.a("ANR", z.a(), aVar.a, "main", aVar.e, null);
|
||||
return false;
|
||||
}
|
||||
if (!this.f.c().j) {
|
||||
x.d("ANR Report is closed!", new Object[0]);
|
||||
return false;
|
||||
}
|
||||
x.a("found visiable anr , start to upload!", new Object[0]);
|
||||
CrashDetailBean a = a(aVar);
|
||||
if (a == null) {
|
||||
x.e("pack anr fail!", new Object[0]);
|
||||
return false;
|
||||
}
|
||||
c.a().a(a);
|
||||
if (a.a >= 0) {
|
||||
x.a("backup anr record success!", new Object[0]);
|
||||
} else {
|
||||
x.d("backup anr record fail!", new Object[0]);
|
||||
}
|
||||
if (str != null && new File(str).exists()) {
|
||||
this.a.set(3);
|
||||
if (a(str, aVar.d, aVar.a)) {
|
||||
x.a("backup trace success", new Object[0]);
|
||||
}
|
||||
}
|
||||
com.tencent.bugly.crashreport.crash.b.a("ANR", z.a(), aVar.a, "main", aVar.e, a);
|
||||
if (!this.h.a(a)) {
|
||||
this.h.a(a, 3000L, true);
|
||||
}
|
||||
this.h.b(a);
|
||||
return true;
|
||||
}
|
||||
|
||||
public final void a(String str) {
|
||||
synchronized (this) {
|
||||
if (this.a.get() != 0) {
|
||||
x.c("trace started return ", new Object[0]);
|
||||
return;
|
||||
}
|
||||
this.a.set(1);
|
||||
try {
|
||||
x.c("read trace first dump for create time!", new Object[0]);
|
||||
TraceFileHelper.a readFirstDumpInfo = TraceFileHelper.readFirstDumpInfo(str, false);
|
||||
long j = readFirstDumpInfo != null ? readFirstDumpInfo.c : -1L;
|
||||
if (j == -1) {
|
||||
x.d("trace dump fail could not get time!", new Object[0]);
|
||||
j = System.currentTimeMillis();
|
||||
}
|
||||
long j2 = j;
|
||||
if (Math.abs(j2 - this.b) < 10000) {
|
||||
x.d("should not process ANR too Fre in %d", Integer.valueOf(XStream.PRIORITY_VERY_HIGH));
|
||||
} else {
|
||||
this.b = j2;
|
||||
this.a.set(1);
|
||||
try {
|
||||
Map<String, String> a = z.a(c.f, false);
|
||||
if (a != null && a.size() > 0) {
|
||||
ActivityManager.ProcessErrorStateInfo a2 = a(this.c, 10000L);
|
||||
if (a2 == null) {
|
||||
x.c("proc state is unvisiable!", new Object[0]);
|
||||
} else if (a2.pid != Process.myPid()) {
|
||||
x.c("not mind proc!", a2.processName);
|
||||
} else {
|
||||
x.a("found visiable anr , start to process!", new Object[0]);
|
||||
a(this.c, str, a2, j2, a);
|
||||
}
|
||||
}
|
||||
x.d("can't get all thread skip this anr", new Object[0]);
|
||||
} catch (Throwable th) {
|
||||
x.a(th);
|
||||
x.e("get all thread stack fail!", new Object[0]);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void a(boolean z) {
|
||||
c(z);
|
||||
boolean h = h();
|
||||
com.tencent.bugly.crashreport.common.strategy.a a = com.tencent.bugly.crashreport.common.strategy.a.a();
|
||||
if (a != null) {
|
||||
h = h && a.c().g;
|
||||
}
|
||||
if (h != g()) {
|
||||
x.a("anr changed to %b", Boolean.valueOf(h));
|
||||
b(h);
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized void a(StrategyBean strategyBean) {
|
||||
if (strategyBean == null) {
|
||||
return;
|
||||
}
|
||||
if (strategyBean.j != g()) {
|
||||
x.d("server anr changed to %b", Boolean.valueOf(strategyBean.j));
|
||||
}
|
||||
if (Build.VERSION.SDK_INT <= 19) {
|
||||
boolean z = strategyBean.j && h();
|
||||
if (z != g()) {
|
||||
x.a("anr changed to %b", Boolean.valueOf(z));
|
||||
b(z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (strategyBean.j) {
|
||||
c();
|
||||
} else {
|
||||
d();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.tencent.bugly.proguard.ac
|
||||
public final boolean a(Thread thread) {
|
||||
new HashMap();
|
||||
if (thread.getName().contains("main")) {
|
||||
ActivityManager.ProcessErrorStateInfo a = a(this.c, 10000L);
|
||||
if (a == null) {
|
||||
x.c("anr handler onThreadBlock proc state is unvisiable!", new Object[0]);
|
||||
return false;
|
||||
}
|
||||
if (a.pid != Process.myPid()) {
|
||||
x.c("onThreadBlock not mind proc!", a.processName);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Map<String, String> a2 = z.a(200000, false);
|
||||
x.a("onThreadBlock found visiable anr , start to process!", new Object[0]);
|
||||
a(this.c, "", a, System.currentTimeMillis(), a2);
|
||||
} catch (Throwable unused) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
x.c("anr handler onThreadBlock only care main thread", new Object[0]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user