-
Notifications
You must be signed in to change notification settings - Fork 43
android crash log 上报服务器
该系统可收集android设备错误日志信息和主动响应远程命令抓取log。没有root权限的设备只能收集apk自身的log,有root权限的设备可以收集系统范围的log。 工作方式分设备主动周期性上报和远程服务器触发上报。前者适合于Crash和ANR类信息,设备直接向服务器地址上传即可, 后者适合正常log,需要服务器通过NAT穿越技术(STUN)触发设备发送。
1.java层错误日志捕获:java本身提供了接口Thread.setDefaultUncaughtExceptionHandler,apk或android系统可利用该接口实现错误日志存储。 2.native层错误日志捕获:android在这种情况下会保存系统日志到/data/tombstones。 3.其他系统日志:/data/system/dropbox /data/anr
android自身提供了logcat工具,在java代码中也能调用来抓取log。有root权限能抓系统范围内的log。没root权限则只能抓取自身进程相关log。
stun协议,实现ANT穿透
demo中利用了ftp来实现上传
1 stb 向stun server发起bind请求; 2 stun server回复,stb得到映射的nat出口地址ip 3 stb 将sn + ip 发送到业务服务器,存储 4 控制服务器从业务服务器取的sn对应的映射ip 5 控制服务器send cmd到机顶盒 6 机顶盒响应 备注: 1 2 3需要循环进行,保持穿透畅通 3 存储时要考虑stb是否有心跳
需要在/system/build.prop要包含: ro.sn=sn123456
ro.remotelog.ipsaver.ip=110.1.56.50 ro.remotelog.ipsaver.port=56677
ro.remotelog.stunsrv.ip=218.205.58.251 ro.remotelog.stunsrv.port=37026
(ftp相关ip,port,username,pwd)
TODO (手机端实现目前没深入考虑,后期会综合统一)
1.网络环境有线,wifi均可。移动网络2g/3g/4g未验证。 2.日志来源中提到的一些系统目录默认是没有访问权限的。 3.java层错误日志捕获目前的默认实现是输出到log,有必要的话要重实现将其输出到文件。
ACRA wrapped the Thread.setDefaultUncaughtExceptionHandler
- app side
- java, status: ok
- native
- throw exception to java, status: ok
- panic directly in native, stauts: ok (这种情况的panic会在data/tombstones下有log(该目录要system权限drwx------ system system 2014-09-23 19:26 tombstones)。这些log是由android/system/core/debuggerd/tombstone.c写入的;但tombstone.c的调用者是/system/core/debuggerd/debuggerd.c)
- system wide, status: ok(java + native)
- 服务器端控制终端机顶盒抓log并上报
- Thread.setDefaultUncaughtExceptionHandler | RuntimeInit
- data/tombstones | debuggerd
- data/system/dropbox | DropBoxManagerService
- data/anr | dalvik.vm.stack-trace-file
- TODO any other ways?
- ACRA wrapped the Thread.setDefaultUncaughtExceptionHandler
- Android-Error-Reporter wrapped the Thread.setDefaultUncaughtExceptionHandler
- http://stackoverflow.com/questions/601503/how-do-i-obtain-crash-data-from-my-android-application
- http://stackoverflow.com/questions/4434192/dropboxmanager-use-cases
- How uncaught exceptions are handled http://www.javamex.com/tutorials/exceptions/exceptions_uncaught_handler.shtml
The specific procedure is as follows. When an uncaught exception occurs, the JVM does the following:
it calls a special private method, dispatchUncaughtException(), on the Thread class in which the exception occurs;
it then terminates the thread in which the exception occurred1.
The dispatchUncaughtException method, in turn, calls the thread's getUncaughtExceptionHandler() method to find out the appropriate uncaught exception handler to use. Normally, this will actually be the thread's parent ThreadGroup, whose handleException() method by default will print the stack trace.
/data/local/tmp/*
/data/tmp/*
/data/system/usagestats/*
/data/system/appusagestates/*
/data/system/dropbox/*
/data/tombstones/*
/data/anr/*
logcat的日志在
/dev/log/main
- ftp upload,stb主动上传
- 终端设备监控,实现stb被动响应上传(抓log等) STUN + snmp
1 stb 向stun server发起bind请求;
2 stun server回复,stb得到映射的nat出口地址ip
3 stb 将sn + ip 发送到业务服务器,存储
4 控制服务器从业务服务器取的sn对应的映射ip
5 控制服务器send cmd到机顶盒
6 机顶盒响应
1 2 3需要循环进行,保持穿透畅通
3 存储时要考虑stb是否有心跳
OR without stun??
1 stb 将sn + ip socket发送到业务服务器
2 业务服务器存储key value, sn ip:port并回复
3 控制服务器从业务服务器取的sn对应的映射ip
4 控制服务器send cmd到机顶盒
5 机顶盒响应
1 2 需要循环进行,保持穿透畅通
2 存储时要考虑stb是否有心跳
- /data/tombstones/ 和 /data/system/dropbox/ 及其子文件的默认权限是-rw-------,要修改。
- 修改方式
- java, File file = new File("xx");file.createNewFile();file.setReadable(true, false);file.setWritable(true, false);
- c, fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
- 修改方式
- snmp
- tr069
- 在内网环境中遇到过udp socket通信大概率不成功(50%, linux pc 和android机顶盒通讯时,而同样的代码linux pc和pc之间通讯确正常), 原因是stb的mac地址冲突导致的。
- https://github.com/bugsnag/bugsnag-android
Just build something.