adb: handle adbd auth in recovery mode

If /data/misc/adb/adb_keys exists, copy it to /adb_keys, set property
for secure adb, and restart the adbd daemon.

Change-Id: I2f826d4c1f6a49cb0959c9cd1a803cb10ec4e408
This commit is contained in:
jt1134 2013-02-25 21:22:05 -06:00 committed by Pawit Pornkitprasan
parent 74341a38a3
commit 1ec4e7bdde
2 changed files with 36 additions and 5 deletions

View File

@ -52,11 +52,7 @@ service recovery /sbin/recovery
service adbd /sbin/adbd recovery
disabled
# Always start adbd on userdebug and eng builds
on property:ro.debuggable=1
write /sys/class/android_usb/android0/enable 1
start adbd
setprop service.adb.root 1
# Recovery will start adb once it has checked the keys
# Restart adbd so it can run as root
on property:service.adb.root=1

View File

@ -751,6 +751,39 @@ print_property(const char *key, const char *name, void *cookie) {
printf("%s=%s\n", key, name);
}
static void
setup_adbd() {
struct stat f;
static char *key_src = "/data/misc/adb/adb_keys";
static char *key_dest = "/adb_keys";
// Mount /data and copy adb_keys to root if it exists
ensure_path_mounted("/data");
if (stat(key_src, &f) == 0) {
FILE *file_src = fopen(key_src, "r");
if (file_src == NULL) {
LOGE("Can't open %s\n", key_src);
} else {
FILE *file_dest = fopen(key_dest, "w");
if (file_dest == NULL) {
LOGE("Can't open %s\n", key_dest);
} else {
char buf[4096];
while (fgets(buf, sizeof(buf), file_src)) fputs(buf, file_dest);
check_and_fclose(file_dest, key_dest);
// Enable secure adbd
property_set("ro.adb.secure", "1");
}
check_and_fclose(file_src, key_src);
}
}
ensure_path_unmounted("/data");
// Trigger (re)start of adb daemon
property_set("service.adb.root", "1");
}
int
main(int argc, char **argv) {
@ -912,6 +945,8 @@ main(int argc, char **argv) {
}
}
setup_adbd();
if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) {
ui_set_show_text(1);
ui_set_background(BACKGROUND_ICON_ERROR);