上次添加adb reboot factory 的代码看懂还不是很难,结果今天师傅让我把这个命令加到另一款手机里面,加是加进去了,功能也有了,但几乎没怎么看懂....从来没了解过MK文件的原理和语法,不过还是记录下来,赶快奋斗吧~~骚年~
PS:这个功能的修改方法应该还有很大的发展空间,因为修改过后进入shell,虽然可以获取root权限,但adb root disable命令也就变得没有用了,权限回不去,不过貌似基本没人会把权限改回去。。。就看什么时候我能看懂再优化成可进可退的了~~
(1)build/corn/main.mk文件修改:
ifeq(true,$(strip$(enable_target_debugging)))
................................
else # !enable_target_debugging
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable = 0改为
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable = 1
再添加:
# Include the debugging/testing OTA keys in this build.
INCLUDE_TEST_OTA_KEYS :=true
(2) dediatek/config/x160v/ProjectConfig.mk文件修改:
MTK_USER_ROOT_SWITCH = no改为
MTK_USER_ROOT_SWITCH = yes
(3)system/core/adb/Android.mk文件修改:
ifneq(,$filter userdebug eng user , $(TARGET_BUILD_VARIANT)))
................
LOCAL_CFLAGS += -DSECRETCODE = \"67754400\"
(4)system/core/adb/services.c文件修改:
void restart_root_service(int fd ,void *cookie)函数内添加:
char *p_magic = (char *)cookie;
char magic[100];
if(getuid() == 0){
if((strncmp(p_magic,"disable",7) == 0)||(strncmp(p_magic,"d",1) == 0)){
property_set("service.adb.root","0");
snprintf(buf,sizeof(buf),"adbd is already running as shell\n");
writex(fd,buf,strlen(buf));
adb_close(fd);
return;
}
else{
snprintf(buf,sizeof(buf),"adbd is already running as root \n");
writex(fd,buf,strlen(buf));
adb_close(fd);
}
return;
}else...........
..............................
property_set("service.adb.root","1");
snprintf(buf,sizeof(buf),"restarting adbd as root\n");
writex(fd,buf,strlen(buf));
adb_close(fd);
sprintf(magic,"%s",SECRETCODE);
if((strlen(p_magic) == 8)&&(strncmp(magic,p_magic,8) == 0)){
property_set("service.adb.root","1");
snprintf(buf,sizeof(buf),"restarting adbd as root ~~\n");
writex(fd,buf,strlen(buf));
adb_close(fd);
return;
}else{
snprintf(buf,sizeof(buf),"adbd can not run as root because of error password\n");
writex(fd,buf,strlen(buf));
adb_close(fd);
return;
}
int service_to_fd(const char *name)函数修改
ret = create_service_thread(restart_root_service,NULL);改为
ret = create_service_thread(restart_root_service,(void*)(name + 5));