|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
除了在程序加载的时候把我的view加载到他上目前我还没用到过其他的苹果一直很推崇MVC的程序结构视图模型控制器简单说就是视图负责显示内容模型负责所有数据的保存结构或者一些其他数据操作控制器是用来协调视图和模型举车的发动机系统的例子倘使使用程序必要对/dev/xxx举行读写操纵,就必要提拔其权限。提权办法不惟一,必要依据详细需讨情况而选择。归根结柢,毕竟都落到chmod777/dev/xxx上,分歧的是,chmod操纵被实行在什么时候何地,在此做个剖析总结。
内核启动后会实行/system/init,传说中的体系1号历程,init程序后来的义务是初始化,包含各类mkdir来构建文件体系,失掉硬件信息创建设备节点,安装SIGCHLD旌旗灯号往返收僵尸历程的资本,剖析init.rc启动剧本等等,然后init程序变身为property_service来办理体系的权限。我们能够动手的中央有两处:device_init和init.rc。
init.rc
这个计划是人人用的对照多的,在个中增加chmod操纵很复杂未几说。
device.c
这个计划用的对照少,先懂得下device.c。
device_init在/system/core/init/device.c中,具体剖析以下:
- //分离遍历/sys/class/sys/block/sys/devices
- device_init()
- {
- coldboot(fd,"/sys/class");
- coldboot(fd,"/sys/block");
- coldboot(fd,"/sys/devices");
- }
- //前面有个递回/sys下是内核天生的设备,这就相称于udev的感化
- do_coldboot()
- {
- if(fd>=0){
- write(fd,"addn",4);
- close(fd);
- handle_device_fd(event_fd);
- }
- }
- //从socket里读出add处置
- handle_device_fd()
- {
- if(!strcmp(uevent->action,"add")){
- make_device(devpath,block,uevent->major,uevent->minor);
- return;
- }
- }
- //失掉设备的相干信息创立设备节点
- make_device()
- {
- mode=get_device_perm(path,&uid,&gid)|(block?S_IFBLK:S_IFCHR);
- dev=(major<<8)|minor;
- mknod(path,mode,dev);
- chown(path,uid,gid);
- }
- get_device_perm()
- {
- if(get_device_perm_inner(qemu_perms,path,uid,gid,&perm)==0){
- returnperm;
- }elseif(get_device_perm_inner(devperms,path,uid,gid,&perm)==0){
- returnperm;
- }else{
- …….
- }
- //失掉devperms布局体的信息
- get_device_perm_inner
- {
- for(i=0;perms.name;i++){
- if(perms.prefix){
- if(strncmp(path,perms.name,strlen(perms.name)))
- continue;
- }else{
- if(strcmp(path,perms.name))
- continue;
- }
- *uid=perms.uid;
- *gid=perms.gid;
- *perm=perms.perm;//权限位
- return0;
- }
- }
- 这是devperms的详细内容
- structperms_{
- char*name;
- mode_tperm;
- unsignedintuid;
- unsignedintgid;
- unsignedshortprefix;
- };
- staticstructperms_devperms[]={
- {"/dev/null",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/zero",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/full",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/ptmx",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/tty",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/random",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/urandom",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/ashmem",0666,AID_ROOT,AID_ROOT,0},
- {"/dev/binder",0666,AID_ROOT,AID_ROOT,0},
- /*loggershouldbeworldwritable(forlogging)butnotreadable*/
- {"/dev/log/",0662,AID_ROOT,AID_LOG,1},
- /*theseshouldnotbeworldwritable*/
- {"/dev/android_adb",0660,AID_ADB,AID_ADB,0},
- {"/dev/android_adb_enable",0660,AID_ADB,AID_ADB,0},
- {"/dev/ttyMSM0",0660,AID_BLUETOOTH,AID_BLUETOOTH,0},
- {"/dev/alarm",0664,AID_SYSTEM,AID_RADIO,0},
- {"/dev/tty0",0666,AID_ROOT,AID_SYSTEM,0},
- {"/dev/graphics/",0660,AID_ROOT,AID_GRAPHICS,1},
- {"/dev/hw3d",0660,AID_SYSTEM,AID_GRAPHICS,0},
- {"/dev/input/",0660,AID_ROOT,AID_INPUT,1},
- {"/dev/eac",0660,AID_ROOT,AID_AUDIO,0},
- {"/dev/cam",0660,AID_ROOT,AID_CAMERA,0},
- {"/dev/pmem",0660,AID_SYSTEM,AID_GRAPHICS,0},
- {"/dev/pmem_gpu",0660,AID_SYSTEM,AID_GRAPHICS,1},
- {"/dev/pmem_adsp",0660,AID_SYSTEM,AID_AUDIO,1},
- {"/dev/pmem_camera",0660,AID_SYSTEM,AID_CAMERA,1},
- {"/dev/oncrpc/",0660,AID_ROOT,AID_SYSTEM,1},
- {"/dev/adsp/",0660,AID_SYSTEM,AID_AUDIO,1},
- {"/dev/mt9t013",0660,AID_SYSTEM,AID_SYSTEM,0},
- {"/dev/akm8976_daemon",0640,AID_COMPASS,AID_SYSTEM,0},
- {"/dev/akm8976_aot",0640,AID_COMPASS,AID_SYSTEM,0},
- {"/dev/akm8976_pffd",0640,AID_COMPASS,AID_SYSTEM,0},
- {"/dev/msm_pcm_out",0660,AID_SYSTEM,AID_AUDIO,1},
- {"/dev/msm_pcm_in",0660,AID_SYSTEM,AID_AUDIO,1},
- {"/dev/msm_pcm_ctl",0660,AID_SYSTEM,AID_AUDIO,1},
- {"/dev/msm_mp3",0660,AID_SYSTEM,AID_AUDIO,1},
- {"/dev/smd0",0640,AID_RADIO,AID_RADIO,0},
- {"/dev/qmi",0640,AID_RADIO,AID_RADIO,0},
- {"/dev/qmi0",0640,AID_RADIO,AID_RADIO,0},
- {"/dev/qmi1",0640,AID_RADIO,AID_RADIO,0},
- {"/dev/qmi2",0640,AID_RADIO,AID_RADIO,0},
- {"/dev/htc-acoustic",0640,AID_RADIO,AID_RADIO,0},
- {NULL,0,0,0,0},
- };
//分离遍历/sys/class/sys/block/sys/devicesdevice_init(){coldboot(fd,"/sys/class");coldboot(fd,"/sys/block");coldboot(fd,"/sys/devices");}//前面有个递回/sys下是内核天生的设备,这就相称于udev的感化do_coldboot(){if(fd>=0){write(fd,"addn",4);close(fd);handle_device_fd(event_fd);}}//从socket里读出add处置handle_device_fd(){if(!strcmp(uevent->action,"add")){make_device(devpath,block,uevent->major,uevent->minor);return;}}//失掉设备的相干信息创立设备节点make_device(){mode=get_device_perm(path,&uid,&gid)|(block?S_IFBLK:S_IFCHR);dev=(major<<8)|minor;mknod(path,mode,dev);chown(path,uid,gid);}get_device_perm(){if(get_device_perm_inner(qemu_perms,path,uid,gid,&perm)==0){returnperm;}elseif(get_device_perm_inner(devperms,path,uid,gid,&perm)==0){returnperm;}else{…….}//失掉devperms布局体的信息get_device_perm_inner{for(i=0;perms.name;i++){if(perms.prefix){if(strncmp(path,perms.name,strlen(perms.name)))continue;}else{if(strcmp(path,perms.name))continue;}*uid=perms.uid;*gid=perms.gid;*perm=perms.perm;//权限位return0;}}这是devperms的详细内容structperms_{char*name;mode_tperm;unsignedintuid;unsignedintgid;unsignedshortprefix;};staticstructperms_devperms[]={{"/dev/null",0666,AID_ROOT,AID_ROOT,0},{"/dev/zero",0666,AID_ROOT,AID_ROOT,0},{"/dev/full",0666,AID_ROOT,AID_ROOT,0},{"/dev/ptmx",0666,AID_ROOT,AID_ROOT,0},{"/dev/tty",0666,AID_ROOT,AID_ROOT,0},{"/dev/random",0666,AID_ROOT,AID_ROOT,0},{"/dev/urandom",0666,AID_ROOT,AID_ROOT,0},{"/dev/ashmem",0666,AID_ROOT,AID_ROOT,0},{"/dev/binder",0666,AID_ROOT,AID_ROOT,0},/*loggershouldbeworldwritable(forlogging)butnotreadable*/{"/dev/log/",0662,AID_ROOT,AID_LOG,1},/*theseshouldnotbeworldwritable*/{"/dev/android_adb",0660,AID_ADB,AID_ADB,0},{"/dev/android_adb_enable",0660,AID_ADB,AID_ADB,0},{"/dev/ttyMSM0",0660,AID_BLUETOOTH,AID_BLUETOOTH,0},{"/dev/alarm",0664,AID_SYSTEM,AID_RADIO,0},{"/dev/tty0",0666,AID_ROOT,AID_SYSTEM,0},{"/dev/graphics/",0660,AID_ROOT,AID_GRAPHICS,1},{"/dev/hw3d",0660,AID_SYSTEM,AID_GRAPHICS,0},{"/dev/input/",0660,AID_ROOT,AID_INPUT,1},{"/dev/eac",0660,AID_ROOT,AID_AUDIO,0},{"/dev/cam",0660,AID_ROOT,AID_CAMERA,0},{"/dev/pmem",0660,AID_SYSTEM,AID_GRAPHICS,0},{"/dev/pmem_gpu",0660,AID_SYSTEM,AID_GRAPHICS,1},{"/dev/pmem_adsp",0660,AID_SYSTEM,AID_AUDIO,1},{"/dev/pmem_camera",0660,AID_SYSTEM,AID_CAMERA,1},{"/dev/oncrpc/",0660,AID_ROOT,AID_SYSTEM,1},{"/dev/adsp/",0660,AID_SYSTEM,AID_AUDIO,1},{"/dev/mt9t013",0660,AID_SYSTEM,AID_SYSTEM,0},{"/dev/akm8976_daemon",0640,AID_COMPASS,AID_SYSTEM,0},{"/dev/akm8976_aot",0640,AID_COMPASS,AID_SYSTEM,0},{"/dev/akm8976_pffd",0640,AID_COMPASS,AID_SYSTEM,0},{"/dev/msm_pcm_out",0660,AID_SYSTEM,AID_AUDIO,1},{"/dev/msm_pcm_in",0660,AID_SYSTEM,AID_AUDIO,1},{"/dev/msm_pcm_ctl",0660,AID_SYSTEM,AID_AUDIO,1},{"/dev/msm_mp3",0660,AID_SYSTEM,AID_AUDIO,1},{"/dev/smd0",0640,AID_RADIO,AID_RADIO,0},{"/dev/qmi",0640,AID_RADIO,AID_RADIO,0},{"/dev/qmi0",0640,AID_RADIO,AID_RADIO,0},{"/dev/qmi1",0640,AID_RADIO,AID_RADIO,0},{"/dev/qmi2",0640,AID_RADIO,AID_RADIO,0},{"/dev/htc-acoustic",0640,AID_RADIO,AID_RADIO,0},{NULL,0,0,0,0},};
init.c
init.rc剧本和老版本android中的init.goldfish.rc剧本很早就被parse_config_file()函数剖析将剧本内容分为几个段,early-init,init,early-boot,boot,和各个服务。然后在分歧的工夫点上实行各个段得命令大概开启各类服务。
init.c的一段节选:
- intmain(intargc,char**argv)
- {
- ……
- mkdir("/dev",0755);
- mkdir("/proc",0755);
- mkdir("/sys",0755);
- mount("tmpfs","/dev","tmpfs",0,"mode=0755");
- mkdir("/dev/pts",0755);
- mkdir("/dev/socket",0755);
- mount("devpts","/dev/pts","devpts",0,NULL);
- mount("proc","/proc","proc",0,NULL);
- mount("sysfs","/sys","sysfs",0,NULL);
- ……
- INFO("readingconfigfilen");
- parse_config_file("/init.rc");
- //挪用parse_config剖析init.rc剧本
- //经由剖析,init.rc的内容就被分为几个段,被串在action_list链表中。
- //on开首的都是action范例的段,好比init段,init段用一个布局体structaction暗示,个中name是init,
- //一切这个段内的命令,都被串在commands链表中。
- action_for_each_trigger("early-init",action_add_queue_tail);
- //遍历action_list链表,查找name是early-init的谁人action,将这个节点放在action_queue的尾部。
- drain_action_queue();
- //将action_queue尾部的节点遍历,然后删除。
- //就相称于遍历name是early-init的action节点内的commands链表。
- //就是在实行init.rc剧本中onearly-init段内的一切命令。
- ……
- INFO("deviceinitn");
- device_fd=device_init();//罕见需要的设备节点
- property_init();//init今后的义务就是proper_service
- action_for_each_trigger("init",action_add_queue_tail);//将init段,到场action_queue
- drain_action_queue();//实行init段得命令
- ……
- }
intmain(intargc,char**argv){……mkdir("/dev",0755);mkdir("/proc",0755);mkdir("/sys",0755);mount("tmpfs","/dev","tmpfs",0,"mode=0755");mkdir("/dev/pts",0755);mkdir("/dev/socket",0755);mount("devpts","/dev/pts","devpts",0,NULL);mount("proc","/proc","proc",0,NULL);mount("sysfs","/sys","sysfs",0,NULL);……INFO("readingconfigfilen");parse_config_file("/init.rc");//挪用parse_config剖析init.rc剧本//经由剖析,init.rc的内容就被分为几个段,被串在action_list链表中。//on开首的都是action范例的段,好比init段,init段用一个布局体structaction暗示,个中name是init,//一切这个段内的命令,都被串在commands链表中。action_for_each_trigger("early-init",action_add_queue_tail);//遍历action_list链表,查找name是early-init的谁人action,将这个节点放在action_queue的尾部。drain_action_queue();//将action_queue尾部的节点遍历,然后删除。//就相称于遍历name是early-init的action节点内的commands链表。//就是在实行init.rc剧本中onearly-init段内的一切命令。……INFO("deviceinitn");device_fd=device_init();//罕见需要的设备节点property_init();//init今后的义务就是proper_serviceaction_for_each_trigger("init",action_add_queue_tail);//将init段,到场action_queuedrain_action_queue();//实行init段得命令……}
本节小结
device_init实在就是linux中的udev的一个复杂的替换。把/sys/下的一切内核供应的设备都布置在/dev下创立设备节点。假如要修改/dev/一些设备的权限,能够把chmod777写在init.rc中,可是要注重写的地位,不克不及太早实行,不克不及写在early-init段内,由于当时/dev/下的设备节点还没有被创立。
在devices.c中修正的办法埋没的较深不简单被发明,可是假如init.rc内再次修正便可能把之前的修正掩盖失落。
iOS5开始支持CoreImage了还没去看Mac上的CI是很强大的CFNetwork---从来没用过我一般都会用ASIHttpRequset封装好的高层网络库OBJC实现的CFNetwork好像是C实现CoreLocation---获取位置的库工具很少 |
|