Runt
2025-08-29 f2a3965a672fca33831d361872874fec104846d5
libmvi/src/main/java/com/runt/open/mvi/CrashHandler.java
@@ -87,7 +87,7 @@
     */
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        Log.i(TAG, "uncaughtException Throwable:"+ex);
        //Log.i(TAG, "uncaughtException Throwable:"+ex);
        if (!handleException(ex) && mDefaultHandler != null) {
            //如果用户没有处理则让系统默认的异常处理器来处理
            mDefaultHandler.uncaughtException(thread, ex);
@@ -104,7 +104,7 @@
     * @return true:如果处理了该异常信息;否则返回false.
     */
    private boolean handleException(Throwable ex) {
        Log.i(TAG, "handleException Throwable:"+ex);
        //Log.i(TAG, "handleException Throwable:"+ex);
        if (ex == null) {
            return false;
        }
@@ -121,7 +121,7 @@
     * @param ctx
     */
    public void collectDeviceInfo(Context ctx) {
        Log.i(TAG, "collectDeviceInfo Context:"+ctx);
        Log.e(TAG, "collectDeviceInfo Context:"+ctx);
        try {
            PackageManager pm = ctx.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);
@@ -139,7 +139,7 @@
            try {
                field.setAccessible(true);
                infos.put(field.getName(), field.get(null).toString());
                Log.d(TAG, field.getName() + " : " + field.get(null));
                //Log.d(TAG, field.getName() + " : " + field.get(null));
            } catch (Exception e) {
                Log.e(TAG, "an error occured when collect crash info", e);
            }
@@ -153,8 +153,8 @@
     * @return  返回文件名称,便于将文件传送到服务器
     */
    private String saveCatchInfoFile(Throwable ex) {
        ex.printStackTrace();
        Log.i(TAG, "saveCatchInfo2File Throwable:"+ex);
        //ex.printStackTrace();
        //Log.i(TAG, "saveCatchInfo2File Throwable:"+ex);
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, String> entry : infos.entrySet()) {
@@ -168,11 +168,12 @@
        ex.printStackTrace(printWriter);
        Throwable cause = ex.getCause();
        while (cause != null) {
            cause.printStackTrace(printWriter);
            //cause.printStackTrace(printWriter);
            cause = cause.getCause();
        }
        printWriter.close();
        String result = writer.toString();
        Log.e("TAG", result);
        sb.append(result);
        try {
            long timestamp = System.currentTimeMillis();
@@ -226,18 +227,18 @@
                s = reader.readLine();
                if(s == null) break;
                //由于目前尚未确定以何种方式发送,所以先打出log日志。
                Log.i("info", s.toString());
                //Log.i("info", s.toString());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            //e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
            //e.printStackTrace();
        }finally{   // 关闭流
            try {
                reader.close();
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
                //e.printStackTrace();
            }
        }
    }