feat ; 去掉 carshCat

This commit is contained in:
eggmanQQQ
2024-09-26 16:11:20 +08:00
parent 7223db9e9c
commit ce50e32a73
2 changed files with 0 additions and 122 deletions

View File

@@ -21,7 +21,6 @@ import androidx.multidex.MultiDex;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.request.target.ViewTarget;
import com.chwl.app.support.IMUserInfoProvider;
import com.chwl.library.error.CrashCat;
import com.chwl.library.language.LanguageHelper;
import com.coorchice.library.utils.LogUtils;
import com.example.lib_utils.ServiceTime;
@@ -537,7 +536,6 @@ public class App extends BaseApp {
HashMap<String, Object> map = new HashMap<>(2);
map.put(IReportConstants.MODULE, IReportConstants.MOLISTAR_ACTIVATE);
ReportManager.get().reportEvent(IReportConstants.ACTIVATE_FIRST, map);
CrashCat.getInstance(getApplicationContext(), Environment.getExternalStorageDirectory().getPath()+ "/Log","log.txt").start();
}
/**

View File

@@ -1,120 +0,0 @@
package com.chwl.library.error;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CrashCat implements Thread.UncaughtExceptionHandler {
private static CrashCat crashCat;
private Context mContext;
private Thread.UncaughtExceptionHandler mDefaultHandler;
private static String DEVICE_INFO="";
private File outPutDir;
private FileOutputStream fileOutputStream;
private BufferedOutputStream bufferedOutputStream;
private static String FILE_NAME = "";
private Intent intent;
private PackageManager packageManager;
private PackageInfo packageInfo;
private CrashCat(Context context, String filePath, String fileName){
init(context,filePath,fileName);
}
public static CrashCat getInstance(Context context, String filePath, String fileName){
crashCat = new CrashCat(context,filePath,fileName);
return crashCat;
}
private void init(Context context, String filePath, String fileName){
this.mContext = context;
this.FILE_NAME = fileName;
try {
packageManager = mContext.getPackageManager();
packageInfo = packageManager.getPackageInfo(mContext.getPackageName(),0);
intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} catch (Exception e) {
writeLog(e.toString());
intent = null;
}
outPutDir = context.getExternalFilesDir(null);
if (outPutDir != null){
if (!outPutDir.exists()) {
outPutDir.mkdirs();
}
}
StringBuffer sb = new StringBuffer();
sb.append("DeviceID="+ Build.ID+"\n");
sb.append("AndroidApi="+ Build.VERSION.SDK_INT+"\n");
sb.append("AndroidVersion="+ Build.VERSION.RELEASE+"\n");
sb.append("Brand="+ Build.BRAND+"\n");
sb.append("ManuFacture="+ Build.MANUFACTURER+"\n");
sb.append("Model="+ Build.MODEL+"\n");
sb.append("PackageName="+mContext.getPackageName()+"\n");
sb.append("CurrentVersionName="+packageInfo.versionName+"\n");
DEVICE_INFO = sb.toString();
// writeLog("Application Start");
}
public void start(){
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
}
private void writeLog(String log){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat fileTime = new SimpleDateFormat("yyyy-MM-dd--HH-mm-ss");
log = "----------"+simpleDateFormat.format(new Date(System.currentTimeMillis())).toString()+"----------"+"\n"+log+"\n";
try {
File outPutFile = new File(outPutDir, "error-"+fileTime.format(new Date(System.currentTimeMillis()))+".txt");
fileOutputStream = new FileOutputStream(outPutFile,true);
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
bufferedOutputStream.write(log.getBytes());
bufferedOutputStream.flush();
fileOutputStream.close();
bufferedOutputStream.close();
} catch (Exception e) {
Log.e("IO Exception",e.toString());
}
}
private void handlerException(String exception) {
if (exception !=null){
try{
writeLog(DEVICE_INFO+exception.toString());
}finally {
try{
mContext.startActivity(intent);
System.exit(1);
}catch (Exception e){
Log.e("App can not restart",e.toString());
}
}
}
}
@Override
public void uncaughtException(Thread t, Throwable e) {
StackTraceElement[] stackTraceElements = e.getStackTrace();
StringBuffer sb = new StringBuffer(e.toString()+"\n");
for (int i=0,size = stackTraceElements.length;i<size;i++){
sb.append(stackTraceElements[i].toString()+"\n");
}
Log.e("errororor",sb.toString());
handlerException(sb.toString());
}
}