### Start privacy helper with NormalMethodList Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorPrivacy/README.md Starts the privacy helper with the default NormalMethodList. Add this dependency only in the debug package; no initialization is required. ```java PrivacyHelper.start(new NormalMethodList()); ``` -------------------------------- ### Start privacy helper with custom MyMethodList Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorPrivacy/README.md Starts the privacy helper with a custom MyMethodList that implements HookMethodList. Use this when the default NormalMethodList does not meet your privacy API requirements. ```java PrivacyHelper.start(new MyMethodList()); ``` -------------------------------- ### Configure OkHttpClient with NetworkListener and NetworkInterceptor Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Configure an OkHttpClient with NetworkListener and NetworkInterceptor to enable network interception for the library. This setup calculates network time consumption and handles request/response interception. ```java new OkHttpClient.Builder() //配置工厂监听器。主要是计算网络过程消耗时间 .eventListenerFactory(NetworkListener.get()) //主要是处理拦截请求,响应等信息 .addNetworkInterceptor(new NetworkInterceptor()) .build() ``` -------------------------------- ### Restart app with reStartApp1 Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Restart the app by starting a KillSelfService with a handler delay. ```java CrashToolUtils.reStartApp1(App.this,1000); ``` -------------------------------- ### Create and execute NetDiagnoService for ping Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Create and execute a NetDiagnoService for ping diagnostics. Pass the context, package name, version name, user ID, device ID, host, and a listener; then call execute() to start. ```java _netDiagnoService = new NetDiagnoService(getContext(), getContext().getPackageName() , versionName, userId, deviceId, host, this); _netDiagnoService.execute(); ``` -------------------------------- ### Start crash log list activity Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Navigate to the crash log list activity. Clicking an item in the list opens the details. ```java CrashToolUtils.startCrashListActivity(this); ``` -------------------------------- ### Restart app with CrashToolUtils Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Three ways to restart the app after a crash. reStartApp1 uses a service with handler delay, reStartApp2 uses an alarm and clears temporary data (recommended), reStartApp3 finds the LauncherActivity and starts it with flags. ```java //开启一个新的服务KillSelfService,用来重启本APP【使用handler延迟】 CrashToolUtils.reStartApp1(App.this,1000); //用来重启本APP[使用闹钟,整体重启,临时数据清空(推荐)] CrashToolUtils.reStartApp2(App.this,1000, MainActivity.class); //检索获取项目中LauncherActivity,然后设置该activity的flag和component启动app【推荐】 CrashToolUtils.reStartApp3(AppManager.getAppManager().currentActivity()); ``` -------------------------------- ### Get crash log and screenshot paths Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Get the paths for crash logs and crash screenshots. The paths are under the app's cache directory. ```java //崩溃文件存储路径:/storage/emulated/0/Android/data/你的包名/cache/crashLogs //崩溃页面截图存储路径:/storage/emulated/0/Android/data/你的包名/cache/crashPics String crashLogPath = ToolFileUtils.getCrashLogPath(this); String crashPicPath = ToolFileUtils.getCrashPicPath(this); ``` -------------------------------- ### Get and sort crash log files Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Get the list of crash log files and sort them by modification time (newest first). Recommended to run in a background thread. ```java List fileList = ToolFileUtils.getCrashFileList(this); //如果是要自己拿到这些文件,建议根据时间来排个序 //排序 Collections.sort(fileList, new Comparator() { @Override public int compare(File file01, File file02) { try { //根据修改时间排序 long lastModified01 = file01.lastModified(); long lastModified02 = file02.lastModified(); if (lastModified01 > lastModified02) { return -1; } else { return 1; } } catch (Exception e) { return 1; } } }); ``` -------------------------------- ### CrashHandler.getInstance().init(Context, CrashListener) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 初始化崩溃处理库,设置崩溃监听器。 ```APIDOC ## CrashHandler.getInstance().init(Context, CrashListener) ### Description 初始化崩溃处理库,建议在Application中调用。设置崩溃监听器,用于处理重启App和自定义上传崩溃信息。 ### Method init ### Parameters - **context** (Context) - Required - 应用上下文 - **listener** (CrashListener) - Required - 崩溃监听器,包含回调方法 ### Callback Methods - **againStartApp()** - 重启App - **recordException(Throwable ex)** - 自定义上传崩溃信息 ### Request Example ```java CrashHandler.getInstance().init(this, new CrashListener() { @Override public void againStartApp() { CrashToolUtils.reStartApp1(App.this,1000); } @Override public void recordException(Throwable ex) { //自定义上传crash } }); ``` ``` -------------------------------- ### 使用start和end打点统计耗时 Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorTimeLib/README.md 高效打点示例。start和end的actionName必须一致才会计算耗时。 ```java TimeMonitorHelper.start("startActivity统计耗时"); TimeMonitorHelper.end("startActivity统计耗时"); ``` -------------------------------- ### CrashToolUtils.startCrashListActivity(Context) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 跳转到崩溃日志列表页面。 ```APIDOC ## CrashToolUtils.startCrashListActivity(Context) ### Description 跳转到错误日志列表页面,点击列表条目可进入详情。 ### Method startCrashListActivity ### Parameters - **context** (Context) - Required - 应用上下文 ### Request Example ```java CrashToolUtils.startCrashListActivity(this); ``` ``` -------------------------------- ### 设置WeakNetworkManager网络异常类型 Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorInterceptor/README.md 通过WeakNetworkManager设置网络异常模拟的开关和类型,包括断网400、服务端异常500、重定向300、网络超时和弱网限速。 ```java //设置网络拦截模拟异常工具生效 WeakNetworkManager.get().setActive(true); //模拟断网400 WeakNetworkManager.get().setType(WeakNetworkManager.TYPE_OFF_NETWORK); //模拟服务端异常500 WeakNetworkManager.get().setType(WeakNetworkManager.TYPE_SERVER_ERROR); //模拟重定向300 WeakNetworkManager.get().setType(WeakNetworkManager.TYPE_REDIRECTED); //模拟网路超时 WeakNetworkManager.get().setType(WeakNetworkManager.TYPE_TIMEOUT); //模拟弱网限速 WeakNetworkManager.get().setType(WeakNetworkManager.TYPE_SPEED_LIMIT); ``` -------------------------------- ### Monitor dex file loading with DexposedBridge Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorPrivacy/README.md Hooks DexFile.loadDex to log dex file loading. Requires DexposedBridge and XC_MethodHook; the epic library must be available. ```java DexposedBridge.findAndHookMethod(DexFile.class, "loadDex", String.class, String.class, int.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { super.beforeHookedMethod(param); String dex = (String) param.args[0]; String odex = (String) param.args[1]; Log.i(TAG, "load dex, input:" + dex + ", output:" + odex); } }); ``` -------------------------------- ### ScreenShotsUtils.measureSize(Context, View) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 截图崩溃页面。 ```APIDOC ## ScreenShotsUtils.measureSize(Context, View) ### Description 截图崩溃页面,返回Bitmap。 ### Method measureSize ### Parameters - **context** (Context) - Required - 应用上下文 - **view** (View) - Required - 要截图的视图 ### Response - **Bitmap** - 截图结果 ### Request Example ```java final Bitmap bitmap = ScreenShotsUtils.measureSize(this,view); ``` ``` -------------------------------- ### CrashToolUtils.reStartApp1(Context, long) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 通过服务重启App。 ```APIDOC ## CrashToolUtils.reStartApp1(Context, long) ### Description 开启一个新的服务KillSelfService,用来重启本APP,使用handler延迟。 ### Method reStartApp1 ### Parameters - **context** (Context) - Required - 应用上下文 - **delayMillis** (long) - Required - 延迟时间(毫秒) ### Request Example ```java CrashToolUtils.reStartApp1(App.this,1000); ``` ``` -------------------------------- ### CrashToolUtils.reStartApp2(Context, long, Class) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 通过闹钟延时重启App。 ```APIDOC ## CrashToolUtils.reStartApp2(Context, long, Class) ### Description 使用闹钟延时重启App,整体重启,临时数据清空(推荐)。 ### Method reStartApp2 ### Parameters - **context** (Context) - Required - 应用上下文 - **delayMillis** (long) - Required - 延迟时间(毫秒) - **activityClass** (Class) - Required - 启动的Activity类 ### Request Example ```java CrashToolUtils.reStartApp2(App.this,1000, MainActivity.class); ``` ``` -------------------------------- ### ToolFileUtils.copyFile(File, File) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 拷贝文件。 ```APIDOC ## ToolFileUtils.copyFile(File, File) ### Description 拷贝文件,两个参数分别是源文件和目标文件。 ### Method copyFile ### Parameters - **srcFile** (File) - Required - 源文件 - **destFile** (File) - Required - 目标文件 ### Response - **boolean** - 拷贝是否成功 ### Request Example ```java boolean copy = ToolFileUtils.copyFile(srcFile, destFile); ``` ``` -------------------------------- ### CrashToolUtils.reStartApp3(Activity) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 通过LauncherActivity重启App。 ```APIDOC ## CrashToolUtils.reStartApp3(Activity) ### Description 检索获取项目中LauncherActivity,然后设置该activity的flag和component启动app(推荐)。 ### Method reStartApp3 ### Parameters - **activity** (Activity) - Required - 当前Activity ### Request Example ```java CrashToolUtils.reStartApp3(AppManager.getAppManager().currentActivity()); ``` ``` -------------------------------- ### 添加WeakNetworkInterceptor拦截器 Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorInterceptor/README.md 在OkHttpClient构建时添加WeakNetworkInterceptor拦截器,用于模拟各种网络异常case操作,建议在debug下使用。 ```java OkHttpClient okHttpClient = new OkHttpClient.Builder() //添加拦截器,用于模拟各种网络异常case操作,建议在debug下使用 .addInterceptor(new WeakNetworkInterceptor()) .build(); ``` -------------------------------- ### CrashLibUtils.shareFile(Context, File) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 分享崩溃文件。 ```APIDOC ## CrashLibUtils.shareFile(Context, File) ### Description 分享文件,调用原生的分享。 ### Method shareFile ### Parameters - **context** (Context) - Required - 应用上下文 - **file** (File) - Required - 要分享的文件 ### Request Example ```java CrashLibUtils.shareFile(CrashDetailsActivity.this, destFile); ``` ``` -------------------------------- ### Restart app with reStartApp3 Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Restart the app by finding the LauncherActivity and setting its flags and component. ```java CrashToolUtils.reStartApp3(AppManager.getAppManager().currentActivity()); ``` -------------------------------- ### ToolFileUtils.getCrashFileList(Context) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 获取所有崩溃日志文件列表。 ```APIDOC ## ToolFileUtils.getCrashFileList(Context) ### Description 获取所有崩溃日志文件列表,建议放到子线程中处理。 ### Method getCrashFileList ### Parameters - **context** (Context) - Required - 应用上下文 ### Response - **List** - 崩溃日志文件列表 ### Request Example ```java List fileList = ToolFileUtils.getCrashFileList(this); ``` ``` -------------------------------- ### Initialize CrashHandler in Application Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Initialize the crash handler in your Application class. Override againStartApp to restart the app and recordException to upload crash data. ```java CrashHandler.getInstance().init(this, new CrashListener() { /** * 重启app */ @Override public void againStartApp() { CrashToolUtils.reStartApp1(App.this,1000); //CrashToolUtils.reStartApp2(App.this,1000, MainActivity.class); //CrashToolUtils.reStartApp3(AppManager.getAppManager().currentActivity()); } /** * 自定义上传crash,支持开发者上传自己捕获的crash数据 * @param ex ex */ @Override public void recordException(Throwable ex) { //自定义上传crash,支持开发者上传自己捕获的crash数据 //StatService.recordException(getApplication(), ex); } }); ``` -------------------------------- ### ToolFileUtils.getCrashPicPath(Context) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 获取崩溃页面截图存储路径。 ```APIDOC ## ToolFileUtils.getCrashPicPath(Context) ### Description 获取崩溃页面截图存储路径。 ### Method getCrashPicPath ### Parameters - **context** (Context) - Required - 应用上下文 ### Response - **String** - 截图路径,例如:/storage/emulated/0/Android/data/你的包名/cache/crashPics ### Request Example ```java String crashPicPath = ToolFileUtils.getCrashPicPath(this); ``` ``` -------------------------------- ### Copy, share, and screenshot crash files Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Additional utilities: copy a file, share a file via the system share sheet, and capture a screenshot of a view and save it to the crash picture directory. ```java //拷贝文件,两个参数分别是源文件,还有目标文件 boolean copy = ToolFileUtils.copyFile(srcFile, destFile); //分享文件。这个是调用原生的分享 CrashLibUtils.shareFile(CrashDetailsActivity.this, destFile); //截图崩溃然后保存到相册。截图---> 创建截图存储文件路径---> 保存图片【图片质量,缩放比还有采样率压缩】 final Bitmap bitmap = ScreenShotsUtils.measureSize(this,view); String crashPicPath = ToolFileUtils.getCrashPicPath(CrashDetailsActivity.this) + "/crash_pic_" + System.currentTimeMillis() + ".jpg"; boolean saveBitmap = CrashLibUtils.saveBitmap(CrashDetailsActivity.this, bitmap, crashPicPath); ``` -------------------------------- ### 初始化TimeMonitorHelper并设置监听 Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorTimeLib/README.md 初始化时间打点库并设置监听器。第一个参数控制是否开启打点,第二个参数为自定义打印适配器,可传null。设置监听后,所有打点结果都会通过onMonitorResult回调。 ```java // 初始化打点计时器 // 第一个参数是是否开启打点,如果是true则打点,如果是false则表示不会记录打点 // 第二个参数是自定义打印接口适配器,主要是自定义打印日志 TimeMonitorHelper.init(true,null); // 设置自定义监听日志listener,所有的打点都会回调该方法 TimeMonitorHelper.setOnMonitorListener(new OnMonitorListener() { @Override public void onMonitorResult(String processName, String result) { AppLogUtils.d("TimeMonitor result: " + result); } }); ``` -------------------------------- ### ToolFileUtils.getCrashLogPath(Context) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 获取崩溃日志存储路径。 ```APIDOC ## ToolFileUtils.getCrashLogPath(Context) ### Description 获取崩溃日志存储路径。 ### Method getCrashLogPath ### Parameters - **context** (Context) - Required - 应用上下文 ### Response - **String** - 崩溃日志路径,例如:/storage/emulated/0/Android/data/你的包名/cache/crashLogs ### Request Example ```java String crashLogPath = ToolFileUtils.getCrashLogPath(this); ``` ``` -------------------------------- ### CrashLibUtils.saveBitmap(Context, Bitmap, String) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 保存截图到相册。 ```APIDOC ## CrashLibUtils.saveBitmap(Context, Bitmap, String) ### Description 保存截图到相册,包含图片质量、缩放比和采样率压缩。 ### Method saveBitmap ### Parameters - **context** (Context) - Required - 应用上下文 - **bitmap** (Bitmap) - Required - 要保存的Bitmap - **path** (String) - Required - 保存路径 ### Response - **boolean** - 保存是否成功 ### Request Example ```java String crashPicPath = ToolFileUtils.getCrashPicPath(CrashDetailsActivity.this) + "/crash_pic_" + System.currentTimeMillis() + ".jpg"; boolean saveBitmap = CrashLibUtils.saveBitmap(CrashDetailsActivity.this, bitmap, crashPicPath); ``` ``` -------------------------------- ### Monitor Java thread creation and destruction with DexposedBridge Source: https://github.com/yangchong211/ycandroidtool/blob/master/MonitorPrivacy/README.md Hooks Thread constructors and the run method to log Java thread creation and destruction. Uses DexposedBridge and XC_MethodHook; requires the epic library and its native libepic.so. ```java class ThreadMethodHook extends XC_MethodHook{ @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { super.beforeHookedMethod(param); Thread t = (Thread) param.thisObject; PrivacyHelper.getLogger().log("thread:" + t + ", started.."); } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); Thread t = (Thread) param.thisObject; PrivacyHelper.getLogger().log("thread:" + t + ", exit.."); } } DexposedBridge.hookAllConstructors(Thread.class, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); Thread thread = (Thread) param.thisObject; Class clazz = thread.getClass(); if (clazz != Thread.class) { PrivacyHelper.getLogger().log( "found class extend Thread:" + clazz); DexposedBridge.findAndHookMethod(clazz, "run", new ThreadMethodHook()); } PrivacyHelper.getLogger().log("Thread: " + thread.getName() + " class:" + thread.getClass() + " is created."); } }); DexposedBridge.findAndHookMethod(Thread.class, "run", new ThreadMethodHook()); ``` -------------------------------- ### ToolFileUtils.readFile2String(String) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 读取崩溃文件内容。 ```APIDOC ## ToolFileUtils.readFile2String(String) ### Description 获取崩溃文件中的内容。 ### Method readFile2String ### Parameters - **filePath** (String) - Required - 文件路径 ### Response - **String** - 文件内容 ### Request Example ```java String crashContent = ToolFileUtils.readFile2String(filePath); ``` ``` -------------------------------- ### Implement NetDiagnoService listener callbacks Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Implement the NetDiagnoService listener callbacks: OnNetDiagnoFinished outputs the complete log when diagnosis ends, and OnNetDiagnoUpdated appends and displays incremental logs during the process. ```java /** * 诊断结束,输出全部日志记录 * @param log log日志输出 */ @Override public void OnNetDiagnoFinished(String log) { setText(log); } /** * 监控网络诊断过程中的日志输出 * @param log log日志输出 */ @Override public void OnNetDiagnoUpdated(String log) { showInfo += log; setText(showInfo); } ``` -------------------------------- ### Restart app with reStartApp2 Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Restart the app using an alarm with a delay, clearing temporary data. ```java CrashToolUtils.reStartApp2(App.this,1000, MainActivity.class); ``` -------------------------------- ### Add MonitorCrashLib dependencies Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Add the MonitorCrashLib and related monitoring libraries to your Gradle dependencies. All libraries are version 1.2.8. ```java //磁盘文件查看工具 implementation 'com.github.yangchong211.YCAndroidTool:MonitorFileLib:1.2.8' //卡顿工具 implementation 'com.github.yangchong211.YCAndroidTool:MonitorCatonLib:1.2.8' //网络工具 implementation 'com.github.yangchong211.YCAndroidTool:MonitorNetLib:1.2.8' //崩溃工具 implementation 'com.github.yangchong211.YCAndroidTool:MonitorCrashLib:1.2.8' //anr工具 implementation 'com.github.yangchong211.YCAndroidTool:MonitorAnrLib:1.2.8' ``` -------------------------------- ### ToolFileUtils.deleteAllFiles(File) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 删除所有崩溃日志文件。 ```APIDOC ## ToolFileUtils.deleteAllFiles(File) ### Description 删除所有崩溃日志文件,建议放到子线程中处理。 ### Method deleteAllFiles ### Parameters - **dir** (File) - Required - 目录文件 ### Request Example ```java File fileCrash = new File(ToolFileUtils.getCrashLogPath(CrashListActivity.this)); ToolFileUtils.deleteAllFiles(fileCrash); ``` ``` -------------------------------- ### Enable floating button with NetworkTool.setFloat Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Enable the floating button for network interception. It is recommended to show it only in debug environments; clicking it navigates to the network interception list page to view request data. ```java //建议只在debug环境下显示,点击去网络拦截列表页面查看网络请求数据 NetworkTool.getInstance().setFloat(getApplication()); ``` -------------------------------- ### ToolFileUtils.deleteFile(String) Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md 删除单个崩溃日志文件。 ```APIDOC ## ToolFileUtils.deleteFile(String) ### Description 删除单个崩溃日志文件。 ### Method deleteFile ### Parameters - **path** (String) - Required - 文件路径 ### Response - **boolean** - 删除成功返回true ### Request Example ```java boolean isDelete = ToolFileUtils.deleteFile(file.getPath()); ``` ``` -------------------------------- ### Read crash file content Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Read the content of a crash log file as a string. ```java //获取内容 String crashContent = ToolFileUtils.readFile2String(filePath); ``` -------------------------------- ### Delete all crash files Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Delete all crash log files in the crash log directory. Recommended to run in a background thread. ```java File fileCrash = new File(ToolFileUtils.getCrashLogPath(CrashListActivity.this)); ToolFileUtils.deleteAllFiles(fileCrash); ``` -------------------------------- ### Stop ping with NetDiagnoService.stopNetDialogsis Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Stop the ping thread directly and set the object to null. This is an alternative to cancel(true) for stopping the diagnostic service. ```java _netDiagnoService.stopNetDialogsis(); ``` -------------------------------- ### Cancel ping with NetDiagnoService.cancel Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Cancel an ongoing ping by calling cancel(true) on the NetDiagnoService and setting the reference to null. This stops the diagnostic process. ```java if (_netDiagnoService!=null){ _netDiagnoService.cancel(true); _netDiagnoService = null; } ``` -------------------------------- ### Delete a single crash file Source: https://github.com/yangchong211/ycandroidtool/blob/master/README.md Delete a single crash log file. Returns true if deletion succeeds. ```java //返回true表示删除成功 boolean isDelete = ToolFileUtils.deleteFile(file.getPath()); ```