如何解决Google ANR报告

时间:2018-11-20 20:19:01

标签: android

因此,我有一个应用程序最近开始从goolge接收ANR,内容为:

executing service com.trueconf.videochat/com.vc.service.AppNotificationService

主线程的日志为:

"main" prio=5 tid=1 Native
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x72cfe5e0 self=0xb0f04000
  | sysTid=5344 nice=0 cgrp=default sched=0/0 handle=0xb4a004a8
  | state=S schedstat=( 662123421 313268952 1450 ) utm=45 stm=21 core=4 HZ=100
  | stack=0xbe303000-0xbe305000 stackSize=8MB
  | held mutexes=
  #00  pc 000000000004a75c  /system/lib/libc.so (read+8)
  #01  pc 000000000001f825  /system/lib/libjavacore.so (???)
  #02  pc 0000000000208781  /system/framework/arm/boot-core-libart.oat (Java_libcore_io_Linux_readBytes__Ljava_io_FileDescriptor_2Ljava_lang_Object_2II+128)
  at libcore.io.Linux.readBytes (Native method)
  at libcore.io.Linux.read (Linux.java:182)
  at libcore.io.BlockGuardOs.read (BlockGuardOs.java:251)
  at libcore.io.IoBridge.read (IoBridge.java:528)
  at java.io.FileInputStream.read (FileInputStream.java:254)
  at java.io.BufferedInputStream.read1 (BufferedInputStream.java:286)
  at java.io.BufferedInputStream.read (BufferedInputStream.java:347)
- locked <0x01d2acc7> (a java.lang.UNIXProcess$ProcessPipeInputStream)
  at java.io.FilterInputStream.read (FilterInputStream.java:107)
  at com.vc.utils.log.AdbHelper.saveCommandLog (AdbHelper.java:53)
  at com.vc.utils.log.AdbHelper.saveNetStatLog (AdbHelper.java:29)
  at com.vc.utils.file.AppFilesHelper.collectFilles (AppFilesHelper.java:269)
  at com.vc.gui.activities.CrashReport$3.onReceived (CrashReport.java:207)
  at com.vc.tasks.SaveLogTask.onPostExecute (SaveLogTask.java:123)
  at com.vc.tasks.SaveLogTask.onPostExecute (SaveLogTask.java:25)
  at android.os.AsyncTask.finish (AsyncTask.java:695)
  at android.os.AsyncTask.-wrap1 (AsyncTask.java)
  at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6565)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)

我怀疑ANR的原因是长时间的文件读取操作,因为堆栈中的最后一个方法是Linux.readBytes()(如果我输入错了,请改正我),而我并没有真正了解ANR和com.trueconf.videochat / com.vc.service.AppNotificationService服务。堆栈的这一部分说明该应用程序存在异常:

at com.vc.utils.log.AdbHelper.saveCommandLog (AdbHelper.java:53)
  at com.vc.utils.log.AdbHelper.saveNetStatLog (AdbHelper.java:29)
  at com.vc.utils.file.AppFilesHelper.collectFilles (AppFilesHelper.java:269)
  at com.vc.gui.activities.CrashReport$3.onReceived (CrashReport.java:207)
  at com.vc.tasks.SaveLogTask.onPostExecute (SaveLogTask.java:123)
  at com.vc.tasks.SaveLogTask.onPostExecute (SaveLogTask.java:25)

该堆栈中的最后一个方法-AdbHelper.saveCommandLog()如下所示:

private static void saveCommandLog(String targetFile, String[] command, String customInfo) {
        byte[] buf = new byte[LogSaveHelper.TEN_K];

        FileOutputStream logOutputStream = null;
        InputStream commandInputStream = null;

        File logFile = LogSaveHelper.getCustomLogFile(targetFile);
        if (logFile != null) {

            try {
                logOutputStream = new FileOutputStream(logFile);
                Process commandProc = Runtime.getRuntime().exec(command);

                writeStringToStream(logOutputStream, customInfo);

                commandInputStream = commandProc.getInputStream();
                int numRead;
                while ((numRead = commandInputStream.read(buf)) >= 0) {
                    logOutputStream.write(buf, 0, numRead);
                }

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (commandInputStream != null) {
                    try {
                        commandInputStream.close();
                        commandInputStream = null;
                    } catch (IOException e) {
                        commandInputStream = null;
                    }
                }
                if (logOutputStream != null) {
                    try {
                        logOutputStream.flush();
                        logOutputStream.close();
                        logOutputStream = null;
                    } catch (IOException e) {
                        logOutputStream = null;
                    }
                }
            }
        }
    }

所以我的问题是:我应该只将这个saveCommandLog()方法移至backgorund线程吗?如果报表与调用此方法绝对没有联系,为什么在报表中提到AppNotificationService-它是从活动CrashReportScreen调用的。

0 个答案:

没有答案