DropBoxManagerService源码

DropBoxManagerService

Q:\1103\frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java的addErrorToDropBox方法
public void addErrorToDropBox(String eventType,\\error的类型(crash anr wtf等等)
            ProcessRecord process, 
            String processName,
            String activityShortComponentName,
            String parentShortComponentName,  \\跟此error相关的activity
            ProcessRecord parentProcess,
            String subject, \\与error有关的相关行
            final String report,
            final File dataFile,
            final ApplicationErrorReport.CrashInfo crashInfo)\\error方法调用堆栈

        if (ServiceManager.getService(Context.DROPBOX_SERVICE) == null) return;
        final DropBoxManager dbox = mContext.getSystemService(DropBoxManager.class);
        //获取DropBoxManagerService的管理对象DropBoxManager
        ......
         final StringBuilder sb = new StringBuilder(1024);
         //创建一个大小为1024的StringBuilder对象拼接信息
        ......
        //创建一个线程进行数据的读写(防止在AMS中发生IO阻塞)
        Thread worker = new Thread("Error dump: " + dropboxTag) {
            @Override
            public void run() {
                if (report != null) {
                    sb.append(report);
                }
                ......
                 dbox.addText(dropboxTag, sb.toString());//把信息传递给DropBoxManager
                .....
                
              }};
         //进程不为空时,线程运行保存信息
         if (process == null) {
            final int oldMask = StrictMode.allowThreadDiskWritesMask();
            try {
                worker.run();
            } finally {
                StrictMode.setThreadPolicyMask(oldMask);
            }
        } else {
            worker.start();
        }
              

调用DropBoxManager的addText,进而调用到DropBoxManagerService服务

Q:\1103\frameworks\base\core\java\android\os\DropBoxManager.java
    public void addText(String tag, String data) {
        try {
            mService.add(new Entry(tag, 0, data)); //将信息包装成一个Entry对象
        } catch (RemoteException e) {
            if (e instanceof TransactionTooLargeException
                    && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
                Log.e(TAG, "App sent too much data, so it was ignored", e);
                return;
            }
            throw e.rethrowFromSystemServer();
        }
    }

DropBoxManagerService创建

Q:\1103\frameworks\base\services\java\com\android\server\SystemServer.java
在startOtherServices方法中
            t.traceBegin("StartDropBoxManager");
            mSystemServiceManager.startService(DropBoxManagerService.class);
            t.traceEnd();
    Q:\1103\frameworks\base\services\core\java\com\android\server\DropBoxManagerService.java
    public DropBoxManagerService(final Context context) {
        this(context, new File("/data/system/dropbox"), FgThread.get().getLooper());
    }
    //文件保存路径

    public DropBoxManagerService(final Context context, File path, Looper looper) {
        super(context);
        mDropBoxDir = path;
        mContentResolver = getContext().getContentResolver();
        mHandler = new DropBoxManagerBroadcastHandler(looper);
    }
    
    
    public void add(DropBoxManager.Entry entry) {
        File temp = null;
        InputStream input = null;
        OutputStream output = null;
        //创建InputStream OutputStream File
        ......
        input = entry.getInputStream();
        //从传入的Entry对象获取信息
       temp = new File(mDropBoxDir, "drop" + Thread.currentThread().getId() + ".tmp");
       //创建文件
       .....
       while循环output.write(buffer, 0, read); 写入数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值