调用DropBox的情景

来源:互联网 发布:mac缺少flash插件 编辑:程序博客网 时间:2024/04/29 15:26

1.写到那个位置?

new DropBoxManagerService(context, new File("/data/system/dropbox"))

写到路径 /data/system/dropbox目录下


2. BootReceiver.java会写入 :

db.addText("SYSTEM_BOOT", headers);

db.addText("SYSTEM_RESTART", headers);

last_kmsg/ last_logcat/ anr/等多个文件

这里学习到了:当收到boot_complete message时是kernel重启还是 android framework的方法:

if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
if (db != null) db.addText("SYSTEM_BOOT", headers);
}
else {
if (db != null) db.addText("SYSTEM_RESTART", headers);
}

使framework 重启的方法是:kill zygote64

1|root@gemini:/data/system/mcd/klo # ps | grep zygote                          676

root      518   1     8756   1860  __skb_recv 7f8edb2f8c S zygote
root      676   1     2112820 78056 poll_sched 7fb3811554 S zygote64
root      677   1     1549244 66004 poll_sched 00f72190ac S zygote

kill 676


3. FC/ANR/WTF/Native_crash发生时写入dropbox

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    /**
     * Write a description of an error (crash, WTF, ANR) to the drop box.
     * @param eventType to include in the drop box tag ("crash", "wtf", etc.)
     * @param process which caused the error, null means the system server
     * @param activity which triggered the error, null if unknown
     * @param parent activity related to the error, null if unknown
     * @param subject line related to the error, null if absent
     * @param report in long form describing the error, null if absent
     * @param logFile to include in the report, null if none
     * @param crashInfo giving an application stack trace, null if absent
     */
    public void addErrorToDropBox(String eventType,
            ProcessRecord process, String processName, ActivityRecord activity,
            ActivityRecord parent, String subject,
            final String report, final File logFile,
            final ApplicationErrorReport.CrashInfo crashInfo) {
    }


4. 出现错误时的提示窗口

    /**
     * Bring up the "unexpected error" dialog box for a crashing app.
     * Deal with edge cases (intercepts from instrumented applications,
     * ActivityController, error intent receivers, that sort of thing).
     * @param r the application crashing
     * @param crashInfo describing the failure
     */
    private void crashApplication(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo) {


    }


5. 监听native的crash的程序:NativeCrashListener

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    public void startObservingNativeCrashes() {
        final NativeCrashListener ncl = new NativeCrashListener(this);
        ncl.start();
    }


构造函数:NativeCrashListener
    /*
     * Daemon thread that accept()s incoming domain socket connections from debuggerd
     * and processes the crash dump that is passed through.
     */
    NativeCrashListener(ActivityManagerService am) {
        mAm = am;
    }


这里没有找到start 函数:看下基类:thread
想起来了: thread总有调用 start, 且run()总有被重写:
final class NativeCrashListener extends Thread {
}
    /**
     * Starts the new Thread of execution. The <code>run()</code> method of
     * the receiver will be called by the receiver Thread itself (and not the
     * Thread calling <code>start()</code>).
     *
     * @throws IllegalThreadStateException - if this thread has already started.
     * @see Thread#run
     */
    public synchronized void start() {
        checkNotStarted();


        hasBeenStarted = true;


        nativeCreate(this, stackSize, daemon);
    }


    @Override
    public void run() {
            while (true) {
                InetSocketAddress peer = new InetSocketAddress();
                FileDescriptor peerFd = null;
                try {
                        consumeNativeCrashData(peerFd);
                    }
                }
    }


    // Read the crash report from the debuggerd connection
    void consumeNativeCrashData(FileDescriptor fd) {
        final byte[] buf = new byte[4096];
        final ByteArrayOutputStream os = new ByteArrayOutputStream(4096);


            // first, the pid and signal number
            int headerBytes = readExactly(fd, buf, 0, 8);


            int pid = unpackInt(buf, 0);
            int signal = unpackInt(buf, 4);
            if (DEBUG) {
                Slog.v(TAG, "Read pid=" + pid + " signal=" + signal);
            }


                    do {
                        // get some data
                        bytes = Os.read(fd, buf, 0, buf.length);
                        if (bytes > 0) {
                            // did we just get the EOD null byte?
                            if (buf[bytes-1] == 0) {
                                os.write(buf, 0, bytes-1);  // exclude the EOD token
                                break;
                            }
                            // no EOD, so collect it and read more
                            os.write(buf, 0, bytes);
                        }
                    } while (bytes > 0);


                    final String reportString = new String(os.toByteArray(), "UTF-8");
                    (new NativeCrashReporter(pr, signal, reportString)).start();
}


(new NativeCrashReporter(pr, signal, reportString)).start();
调用构造函数NativeCrashReporter,并调用start:
        @Override
        public void run() {
            try {
                CrashInfo ci = new CrashInfo();
                ci.exceptionClassName = "Native crash";
                ci.exceptionMessage = Os.strsignal(mSignal);
                ci.throwFileName = "unknown";
                ci.throwClassName = "unknown";
                ci.throwMethodName = "unknown";
                ci.stackTrace = mCrashReport;


                if (DEBUG) Slog.v(TAG, "Calling handleApplicationCrash()");
                mAm.handleApplicationCrashInner("native_crash", mApp, mApp.processName, ci);
                if (DEBUG) Slog.v(TAG, "<-- handleApplicationCrash() returned");
            } catch (Exception e) {
                Slog.e(TAG, "Unable to report native crash", e);
            }
        }
    }


    /* Native crash reporting uses this inner version because it needs to be somewhat
     * decoupled from the AM-managed cleanup lifecycle
     */
    void handleApplicationCrashInner(String eventType, ProcessRecord r, String processName,
            ApplicationErrorReport.CrashInfo crashInfo) {
        EventLog.writeEvent(EventLogTags.AM_CRASH, Binder.getCallingPid(),
                UserHandle.getUserId(Binder.getCallingUid()), processName,
                r == null ? -1 : r.info.flags,
                crashInfo.exceptionClassName,
                crashInfo.exceptionMessage,
                crashInfo.throwFileName,
                crashInfo.throwLineNumber);


        addErrorToDropBox(eventType, r, processName, null, null, null, null, null, crashInfo);


        crashApplication(r, crashInfo);
    }


0 0
原创粉丝点击