新增bugly
This commit is contained in:
5
test/crashreport-bugly/src/main/AndroidManifest.xml
Normal file
5
test/crashreport-bugly/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.test.crashreport.bugly">
|
||||
|
||||
/
|
||||
</manifest>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user