下面的方法就是判断要不要打开root,先上代码
static int should_drop_privileges() {
#ifndef ALLOW_ADBD_ROOT
return 1; //如果没定义AllOW_ADVD_ROOT,则return1,不能root
#else /* ALLOW_ADBD_ROOT */
int secure = 0;
char value[PROPERTY_VALUE_MAX];
/* run adbd in secure mode if ro.secure is set and
** we are not in the emulator
*/
property_get("ro.kernel.qemu", value, ""); //这个属性不知道是什么,一般不存在
if (strcmp(value, "1") != 0) {
property_get("ro.secure", value, "1"); //如果ro.secure是1,不打开root,但如果ro.debuggable是1,且service.adb.root是1,则可以打开root
if (strcmp(value, "1") == 0) {
// don't run as root if ro.secure is set...
secure = 1;
// ... except we allow running as root in userdebug builds if the
// service.adb.root property has been set by the "adb root" command
property_get("ro.debuggable", value, "");
if (strcmp(value, "1") == 0) {
property_get("service.adb.root", value, "");
if (strcmp(value, "1") == 0) {
secure = 0;
}
}
}
}
return secure;
#endif /* ALLOW_ADBD_ROOT */
}
所以根据上面的代码,可以设置属性ro.secure为0,则打开了root!!!!