Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
package com.ubtrobot.log;
import android.content.Context;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.CsvFormatStrategy;
import com.orhanobut.logger.DiskLogAdapter;
import com.orhanobut.logger.LogAdapter;
import com.orhanobut.logger.LogcatLogStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.orhanobut.logger.Printer;
import java.io.File;
import java.lang.Thread;
import java.text.SimpleDateFormat;
import java.util.Locale;
/* loaded from: classes2.dex */
public class ALog {
private static AndroidLogAdapter a;
private static Thread.UncaughtExceptionHandler b;
public static void a(Context context, String str) {
PrettyFormatStrategy.Builder a2 = PrettyFormatStrategy.a();
a2.a(false);
a2.a(0);
a2.b(1);
a2.a(new LogcatLogStrategy());
a2.a(str);
a = new AndroidLogAdapter(a2.a());
Logger.a((LogAdapter) a);
File a3 = ExternalOverFroyoUtils.a(context, "log");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.UK);
CsvFormatStrategy.Builder a4 = CsvFormatStrategy.a();
a4.a(simpleDateFormat);
a4.a(a3.getAbsolutePath());
a4.b(str);
Logger.a((LogAdapter) new DiskLogAdapter(a4.a()));
Thread.setDefaultUncaughtExceptionHandler(a(context));
}
public static void b(String str, Object... objArr) {
Logger.b(str, objArr);
}
public static void c(String str, Object... objArr) {
Logger.c(str, objArr);
}
public static Printer a(String str) {
return Logger.a(str);
}
public static void a(Object obj) {
Logger.a(obj);
}
public static void a(String str, Object... objArr) {
Logger.a(str, objArr);
}
public static void a(Throwable th, String str, Object... objArr) {
Logger.a(th, str, objArr);
}
private static Thread.UncaughtExceptionHandler a(Context context) {
if (b == null) {
b = CrashExceptionHandler.b(context);
}
return b;
}
}

View File

@@ -0,0 +1,14 @@
package com.ubtrobot.log;
import android.os.Build;
/* loaded from: classes2.dex */
class AndroidVersionCheckUtils {
public static boolean a() {
return Build.VERSION.SDK_INT >= 8;
}
public static boolean b() {
return Build.VERSION.SDK_INT >= 9;
}
}

View File

@@ -0,0 +1,184 @@
package com.ubtrobot.log;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Process;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.Thread;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes2.dex */
public class CrashExceptionHandler implements Thread.UncaughtExceptionHandler {
private static CrashExceptionHandler d;
private Context a;
private Thread.UncaughtExceptionHandler b;
private Map<String, String> c = new HashMap();
private CrashExceptionHandler(Context context) {
c(context);
}
private boolean a(Throwable th, Thread thread) {
if (th == null) {
return true;
}
a(this.a);
a(th);
return true;
}
public static CrashExceptionHandler b(Context context) {
if (d == null) {
d = new CrashExceptionHandler(context);
}
return d;
}
private void c(Context context) {
this.a = context;
this.b = Thread.getDefaultUncaughtExceptionHandler();
}
@Override // java.lang.Thread.UncaughtExceptionHandler
public void uncaughtException(Thread thread, Throwable th) {
Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
if (!a(th, thread) || (uncaughtExceptionHandler = this.b) == null) {
this.b.uncaughtException(thread, th);
return;
}
uncaughtExceptionHandler.uncaughtException(thread, th);
Process.killProcess(Process.myPid());
System.exit(10);
}
@SuppressLint({"SimpleDateFormat"})
private void a(Throwable th) {
StringBuilder sb;
if (th == null) {
return;
}
StringBuilder sb2 = new StringBuilder();
for (String str : this.c.keySet()) {
String str2 = this.c.get(str);
sb2.append(str);
sb2.append("=");
sb2.append(str2);
sb2.append("\n");
}
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
th.printStackTrace(printWriter);
for (Throwable cause = th.getCause(); cause != null; cause = cause.getCause()) {
cause.printStackTrace(printWriter);
}
printWriter.close();
sb2.append(stringWriter.toString());
FileOutputStream fileOutputStream = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
long currentTimeMillis = System.currentTimeMillis();
String str3 = simpleDateFormat.format(new Date()) + "_" + currentTimeMillis + ".txt";
try {
try {
File a = ExternalOverFroyoUtils.a(this.a, "crash");
if (!a.exists()) {
a.mkdirs();
}
FileOutputStream fileOutputStream2 = new FileOutputStream(new File(a.getAbsolutePath() + File.separator + str3));
try {
fileOutputStream2.write(sb2.toString().getBytes());
try {
fileOutputStream2.close();
} catch (IOException e) {
e = e;
sb = new StringBuilder();
sb.append("关闭Crash文件流时出错:");
sb.append(e.getMessage());
Log.e("CrashExceptionHandler", sb.toString());
}
} catch (FileNotFoundException e2) {
e = e2;
fileOutputStream = fileOutputStream2;
Log.e("CrashExceptionHandler", "保存crash文件时出错" + e.getMessage());
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e3) {
e = e3;
sb = new StringBuilder();
sb.append("关闭Crash文件流时出错:");
sb.append(e.getMessage());
Log.e("CrashExceptionHandler", sb.toString());
}
}
} catch (Exception e4) {
e = e4;
fileOutputStream = fileOutputStream2;
Log.e("CrashExceptionHandler", "保存crash文件时出错" + e.getMessage());
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e5) {
e = e5;
sb = new StringBuilder();
sb.append("关闭Crash文件流时出错:");
sb.append(e.getMessage());
Log.e("CrashExceptionHandler", sb.toString());
}
}
} catch (Throwable th2) {
th = th2;
fileOutputStream = fileOutputStream2;
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e6) {
Log.e("CrashExceptionHandler", "关闭Crash文件流时出错:" + e6.getMessage());
}
}
throw th;
}
} catch (FileNotFoundException e7) {
e = e7;
} catch (Exception e8) {
e = e8;
}
} catch (Throwable th3) {
th = th3;
}
}
private void a(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 1);
if (packageInfo != null) {
String str = packageInfo.versionName == null ? "null" : packageInfo.versionName;
String str2 = packageInfo.versionCode + "";
this.c.put("versionName", str);
this.c.put("versionCode", str2);
}
} catch (PackageManager.NameNotFoundException unused) {
Log.e("CrashExceptionHandler", "收集包信息时出错。");
}
try {
for (Field field : Build.class.getDeclaredFields()) {
field.setAccessible(true);
this.c.put(field.getName(), field.get(null).toString());
}
} catch (Exception unused2) {
Log.e("CrashExceptionHandler", "收集crash信息时出错。");
}
}
}

View File

@@ -0,0 +1,55 @@
package com.ubtrobot.log;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import java.io.File;
@TargetApi(9)
/* loaded from: classes2.dex */
public class ExternalOverFroyoUtils {
public enum Dir {
Model("model"),
Cache("cache"),
User("user"),
Image("image");
private String name;
Dir(String str) {
this.name = str;
}
public String getName() {
return this.name;
}
}
public static boolean a() {
if (AndroidVersionCheckUtils.b()) {
return Environment.isExternalStorageRemovable();
}
return true;
}
public static File a(Context context, String str) {
String path = context.getCacheDir().getPath();
try {
if ("mounted".equals(Environment.getExternalStorageState()) || !a()) {
path = a(context).getPath();
}
} catch (Exception e) {
Log.e("DiskCacheDir", e.getMessage() + "");
}
return new File(path + File.separator + str);
}
public static File a(Context context) {
if (AndroidVersionCheckUtils.a()) {
return context.getExternalCacheDir();
}
return new File(Environment.getExternalStorageDirectory().getPath() + ("/Android/data/" + context.getPackageName() + "/cache/"));
}
}