在 debug 版本上,可以在關機狀態下,同時按 電源鍵 和 音量加鍵 進 recovery 。
user 版本上不行。
參考 使用 build 變體
debug 版本和 user 版本的差別之一就是 ro.debuggable
屬性不同。
順著這個思路追蹤,找到 bootable/recovery/recovery.cpp
,
添加如下修改即可,
--- a/bootable/recovery/recovery.cpp
+++ b/bootable/recovery/recovery.cpp
@@ -130,6 +130,10 @@ static bool IsRoDebuggable() {return android::base::GetBoolProperty("ro.debuggable", false);}+// refer to device.mk , we have set user.enable.recovery=true
+static bool IsUserEnableRecovery() {
+ return android::base::GetBoolProperty("user.enable.recovery", false);
+}// Clear the recovery command and prepare to boot a (hopefully working) system,// copy our log file to cache as well (for the system to read). This function is
@@ -1272,7 +1276,7 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri// If this is an eng or userdebug build, then automatically// turn the text display on if the script fails so the error// message is visible.
- if (IsRoDebuggable()) {
+ if (IsRoDebuggable() || IsUserEnableRecovery()) {ui->ShowText(true);}}else{
@@ -1389,7 +1393,7 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri// If this is an eng or userdebug build, automatically turn on the text display if no command// is specified. Note that this should be called before setting the background to avoid// flickering the background image.
- if (IsRoDebuggable()) {
+ if (IsRoDebuggable() || IsUserEnableRecovery()) {ui->ShowText(true);}status = INSTALL_NONE; // No command specified
為了不同 device 可復用,根據屬性判斷,如果其他客戶也需要,在對應的 device.mk 里加上該屬性就行。