Android2.2 Vold 分析-1---20110104
文件:system/vold/main.cpp-----mian函数分析
声明 VolumeManager *vm; CommandListener *cl; NetlinkManager *nm;对象指针;
创建目录/dev/block/vold mkdir("/dev/block/vold", 0755);
分别构建VolumeManager 、 CommandListener 、NetlinkManager 对象*vm,*cl,*nm;
if (!(vm = VolumeManager::Instance()))
if (!(nm = NetlinkManager::Instance()))
cl = new CommandListener();
广播相关参数 mBroadcaster = sl 设置;
vm->setBroadcaster((SocketListener *) cl);
nm->setBroadcaster((SocketListener *) cl);
解析 /system/etc/vold.fstab文件,做三件事:
if (process_config(vm))
(1). 构建DirectVolume对象 :中定义的挂载项构建对应的DirectVolume对象 dv = new DirectVolume(vm, label, mount_point, -1);
(2). 添加vold.fstab中定义的某一挂载项对应的sysfs_path到 DirectVolume对象的mPaths容器 dv->addPath(sysfs_path);
(3). 将这个DirectVolume 对象添加到 VolumeManager对象的容器mVolumes中 vm->addVolume(dv);
启动NetlinkManager,创建相应的socket,通过NetlinkHandler的start函数启动 SocketListener::startListen,关于SocketListener到后面再进行分析;
nm->start()
int NetlinkManager::start()------->mHandler->start()-------->this->startListener()调用 SocketListener::startListen();
递归打开sys/block目录下的所有子目录 coldboot("/sys/block");
/*
* Switch uevents are broken.
* For now we manually bootstrap
* the ums switch
*/
查询/sys/devices/virtual/switch/usb_mass_storage/state状态信息,并发送广播
if ((fp = fopen("/sys/devices/virtual/switch/usb_mass_storage/state","r"))) {
if (fgets(state, sizeof(state), fp)) {
if (!strncmp(state, "online", 6)) {
vm->notifyUmsConnected(true);
监听命令,并进行相应的处理,Eventually we'll become the monitoring thread .
cl->startListener() 调用SocketListener::startListener(),在startListener函数中启动线程pthread_create(&mThread, NULL, SocketListener::threadStart, this) ;
void *SocketListener::threadStart(void *obj) {
SocketListener *me = reinterpret_cast(obj);
me->runListener(); ------------>void SocketListener::runListener()无限循环,监听消息及消息出理
pthread_exit(NULL);
return NULL;
}
阅读(1517) | 评论(0) | 转发(1) |