From 8891c2002eefc1b9a5fcbe17c5bcff4143c6ec91 Mon Sep 17 00:00:00 2001 From: Will McVicker Date: Fri, 12 Mar 2021 17:32:14 -0800 Subject: [PATCH] init: fix debuggable paths for recovery mode Since recovery mode doesn't switch root to /first_stage_ramdisk, we need to update the debuggable file paths for recovery mode. Without this, adb needs to be authorized in recovery mode even with a debug vendor_ramdisk. Bug: 182612208 Test: verify adb is authorized on pixel 5 Signed-off-by: Will McVicker Change-Id: I557429e1834efcdd92ba0e135377055ffa677137 --- init/first_stage_init.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp index b2ab55082..5cde1671b 100644 --- a/init/first_stage_init.cpp +++ b/init/first_stage_init.cpp @@ -337,12 +337,21 @@ int FirstStageMain(int argc, char** argv) { SwitchRoot("/first_stage_ramdisk"); } + std::string force_debuggable("/force_debuggable"); + std::string adb_debug_prop("/adb_debug.prop"); + std::string userdebug_sepolicy("/userdebug_plat_sepolicy.cil"); + if (IsRecoveryMode()) { + // Update these file paths since we didn't switch root + force_debuggable.insert(0, "/first_stage_ramdisk"); + adb_debug_prop.insert(0, "/first_stage_ramdisk"); + userdebug_sepolicy.insert(0, "/first_stage_ramdisk"); + } // If this file is present, the second-stage init will use a userdebug sepolicy // and load adb_debug.prop to allow adb root, if the device is unlocked. - if (access("/force_debuggable", F_OK) == 0) { + if (access(force_debuggable.c_str(), F_OK) == 0) { std::error_code ec; // to invoke the overloaded copy_file() that won't throw. - if (!fs::copy_file("/adb_debug.prop", kDebugRamdiskProp, ec) || - !fs::copy_file("/userdebug_plat_sepolicy.cil", kDebugRamdiskSEPolicy, ec)) { + if (!fs::copy_file(adb_debug_prop, kDebugRamdiskProp, ec) || + !fs::copy_file(userdebug_sepolicy, kDebugRamdiskSEPolicy, ec)) { LOG(ERROR) << "Failed to setup debug ramdisk"; } else { // setenv for second-stage init to read above kDebugRamdisk* files.