新增bugly

This commit is contained in:
wangcongtao
2020-09-09 14:43:03 +08:00
parent ef677ae4b8
commit e3eed35123
32 changed files with 451 additions and 39 deletions

View File

@@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.test.crashreport.bugly">
/
</manifest>

View File

@@ -0,0 +1,67 @@
package com.mogo.test.crashreport.bugly;
import android.content.Context;
import android.text.TextUtils;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.test.crashreport.CrashReportConstants;
import com.mogo.test.crashreport.ITestCrashReportProvider;
import com.mogo.utils.logger.Logger;
import com.tencent.bugly.crashreport.CrashReport;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public
/**
* @author congtaowang
* @since 2020/9/9
*
* 描述
*/
@Route( path = CrashReportConstants.PATH )
class BuglyCrashReportProvider implements ITestCrashReportProvider {
private static final String TAG = "BuglyCrashReportProvider";
@Override
public void init( Context context ) {
Logger.d(TAG, "init");
String packageName = context.getPackageName();
String processName = getProcessName( android.os.Process.myPid() );
CrashReport.UserStrategy strategy = new CrashReport.UserStrategy( context );
strategy.setUploadProcess( processName == null || processName.equals( packageName ) );
CrashReport.initCrashReport( context, "f3f8b0b2f1", true, strategy );
}
/**
* 获取进程号对应的进程名
*
* @param pid 进程号
* @return 进程名
*/
private static String getProcessName( int pid ) {
BufferedReader reader = null;
try {
reader = new BufferedReader( new FileReader( "/proc/" + pid + "/cmdline" ) );
String processName = reader.readLine();
if ( !TextUtils.isEmpty( processName ) ) {
processName = processName.trim();
}
return processName;
} catch ( Throwable throwable ) {
throwable.printStackTrace();
} finally {
try {
if ( reader != null ) {
reader.close();
}
} catch ( IOException exception ) {
exception.printStackTrace();
}
}
return null;
}
}