android usb挂载分析---FrameWork层处理收到的vold消息

来源:互联网 发布:python pandas 十分钟 编辑:程序博客网 时间:2024/05/16 19:04

vold模块收到内核消息后,通过前面建立的socket通信各上去发送相应的消息,我们可以看到主要发了两类消息:

1、DirectVolume::handleDiskAdded以及handlePartitionAdded都调用setState发送了一条VolumeStateChange消息。

2、handleDiskAdded中还发送了 VolumeDiskInserted消息。

我们先看下FrameWork层的消息处理流程:


这里的消息处理还算比较简单,主要只要处理VolumeDiskInserted消息,另外两条消息收到后都被忽略了,

我们看下VolumeDiskInserted的处理,首先阻塞在listenToSocket等待vold消息的到来:

 while (true) {                int count = inputStream.read(buffer, start, BUFFER_SIZE - start);                if (count < 0) break;         。         。         。try {                                    if (!mCallbacks.onEvent(code, event, tokens)) {                                        Slog.w(TAG, String.format(                                                "Unhandled event (%s)", event));                                    }                                } 。。。
收到消息后,调用onEvent函数

onEvent的函数实现在MountService中

 public boolean onEvent(int code, String raw, String[] cooked) {        Intent in = null;        .        .        .        if (code == VoldResponseCode.VolumeDiskInserted) {                new Thread() {                    public void run() {                        try {                            int rc;                            if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {                                Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));                            }                        } catch (Exception ex) {                            Slog.w(TAG, "Failed to mount media on insertion", ex);                        }                    }                }.start();这里的消息为VolumeDiskInserted,new 一个Thread并start,在run函数中调用doMountVolume函数向vold层发送挂载命令:

private int doMountVolume(String path) {        int rc = StorageResultCode.OperationSucceeded;        if (DEBUG_EVENTS) Slog.i(TAG, "doMountVolume: Mouting " + path);        try {            mConnector.doCommand(String.format("volume mount %s", path));        }       .      .      .}

这里调用doCommand并以volume mount path为参数,我们看下doCommand:
public synchronized ArrayList<String> doCommand(String cmd)            throws NativeDaemonConnectorException  {        sendCommand(cmd);      .      .      .    }
继续看sendCommand:

 private void sendCommand(String command, String argument)            throws NativeDaemonConnectorException  {        .        。         .                try {                    mOutputStream.write(builder.toString().getBytes());                } catch (IOException ex) {                    Slog.e(TAG, "IOException in sendCommand", ex);                } }
调用write函数把消息发送到vold层,这样FrameWork层就把挂载命令下发到了vold层。



	
				
		
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 耳钉容易掉怎么办 皮球鱼产卵了怎么办 孩子在家太孤独怎么办 宝宝老是挠头是怎么办 猫脸花浇水多了怎么办 夏天钓鲫鱼小杂鱼闹窝怎么办 家里养花生虫子怎么办 生鸡蛋拌饭怎么办 出柜家里人会怎么办 百灵鸟怕人撞笼怎么办 乌鸫雏鸟撞笼返生怎么办 泥石流来了怎么办教案 墙壁插座不通电怎么办 当前目录不能用怎么办 海鲜过敏怎么办没有药 哺乳后胸变小怎么办 有脑出血前兆该怎么办 体检发现甲状腺结节怎么办 月子里宝宝感冒怎么办 10天新生儿感冒怎么办 20天新生儿感冒怎么办 新生儿20天鼻塞怎么办 25天新生儿感冒怎么办 42天新生儿感冒怎么办 上呼吸道感染怎么办比较好 小猫咪太调皮怎么办 水晶彩泥弄到衣服上怎么办 进境动植物检疫许可怎么办 跳舞不会听拍子怎么办 税盘丢了注销公司怎么办 认缴资金不到位怎么办 同一单元有凶宅怎么办 有地皮没房产证怎么办 社保资金被侵吞怎么办? 集体计件手脚慢怎么办 发票当月没用完怎么办 非工业用地怎么办环评 商标注册途中英文错误怎么办 孩子的英文不好怎么办 高盛英文不好怎么办 去美国英文不好怎么办