c.java 源代码
package com.apm.insight.nativecrash;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.apm.insight.l.i;
import com.apm.insight.l.k;
import com.apm.insight.l.o;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
public class c {
public static class a extends C0103c {
a(File file) {
super(file);
this.f6666b = "Total FD Count:";
this.f6667c = ":";
this.f6668d = -2;
}
}
public static class b extends C0103c {
b(File file) {
super(file);
this.f6666b = "VmSize:";
this.f6667c = "\\s+";
this.f6668d = -1;
}
}
public static class C0103c {
protected File f6665a;
protected String f6666b;
protected String f6667c;
protected int f6668d;
public C0103c(File file) {
this.f6665a = file;
}
public int a() {
Throwable th;
int i6;
if (!this.f6665a.exists() || !this.f6665a.isFile()) {
return -1;
}
BufferedReader bufferedReader = null;
try {
BufferedReader bufferedReader2 = new BufferedReader(new FileReader(this.f6665a));
int i7 = -1;
do {
try {
String readLine = bufferedReader2.readLine();
if (readLine == null) {
break;
}
i7 = a(readLine);
} catch (Throwable th2) {
th = th2;
i6 = i7;
bufferedReader = bufferedReader2;
try {
com.apm.insight.b.a().a("NPTH_CATCH", th);
return i6;
} finally {
if (bufferedReader != null) {
k.a(bufferedReader);
}
}
}
} while (i7 == -1);
k.a(bufferedReader2);
return i7;
} catch (Throwable th3) {
th = th3;
i6 = -1;
}
}
public int a(String str) {
int i6 = this.f6668d;
if (!str.startsWith(this.f6666b)) {
return i6;
}
try {
i6 = Integer.parseInt(str.split(this.f6667c)[1].trim());
} catch (NumberFormatException e6) {
com.apm.insight.b.a().a("NPTH_CATCH", e6);
}
if (i6 < 0) {
return -2;
}
return i6;
}
}
public static class d extends C0103c {
d(File file) {
super(file);
}
@NonNull
public HashMap<String, List<String>> b() {
JSONArray b6;
String str;
HashMap<String, List<String>> hashMap = new HashMap<>();
try {
b6 = i.b(this.f6665a.getAbsolutePath());
} catch (IOException unused) {
} catch (Throwable th) {
com.apm.insight.b.a().a("NPTH_CATCH", th);
}
if (b6 == null) {
return hashMap;
}
for (int i6 = 0; i6 < b6.length(); i6++) {
String optString = b6.optString(i6);
if (!TextUtils.isEmpty(optString) && optString.startsWith("[tid:0") && optString.endsWith("sigstack:0x0]")) {
int indexOf = optString.indexOf("[routine:0x");
int i7 = indexOf + 11;
int indexOf2 = optString.indexOf(93, i7);
if (indexOf > 0) {
str = optString.substring(i7, indexOf2);
} else {
str = "unknown addr";
}
List<String> list = hashMap.get(str);
if (list == null) {
list = new ArrayList<>();
hashMap.put(str, list);
}
list.add(optString);
}
}
return hashMap;
}
}
public static class e extends C0103c {
e(File file) {
super(file);
}
@NonNull
public JSONArray a(HashMap<String, List<String>> hashMap) {
JSONArray b6;
List<String> list;
JSONArray jSONArray = new JSONArray();
if (hashMap.isEmpty()) {
return jSONArray;
}
try {
b6 = i.b(this.f6665a.getAbsolutePath());
} catch (IOException unused) {
} catch (Throwable th) {
com.apm.insight.b.a().a("NPTH_CATCH", th);
}
if (b6 == null) {
return jSONArray;
}
for (int i6 = 0; i6 < b6.length(); i6++) {
String optString = b6.optString(i6);
if (!TextUtils.isEmpty(optString)) {
String substring = optString.substring(2, optString.indexOf(":"));
if (hashMap.containsKey(substring) && (list = hashMap.get(substring)) != null) {
Iterator<String> it = list.iterator();
while (it.hasNext()) {
jSONArray.put(it.next() + " " + optString);
}
hashMap.remove(substring);
}
}
}
Iterator<List<String>> it2 = hashMap.values().iterator();
while (it2.hasNext()) {
Iterator<String> it3 = it2.next().iterator();
while (it3.hasNext()) {
jSONArray.put(it3.next() + " 0x000000:unknown");
}
}
return jSONArray;
}
}
public static class f extends C0103c {
f(File file) {
super(file);
this.f6666b = "Total Threads Count:";
this.f6667c = ":";
this.f6668d = -2;
}
}
public static int a(String str) {
return new a(o.b(str)).a();
}
public static int b(String str) {
return new f(o.c(str)).a();
}
public static int c(String str) {
return new b(o.d(str)).a();
}
@NonNull
public static JSONArray a(File file, File file2) {
return new e(file2).a(new d(file).b());
}
}