本文主要是介绍Android系统 —— Recovery子系统下自动检测U盘内升级包并进行升级,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. bootable/recovery/recovery.cpp
(1) 下面宏变量 USB_BLK_PATH 是U盘节点路径,使用时按实际情况修改。
(2) 函数 usb_mount_thread 中的 max_mount_cnt 变量规定了尝试挂载U盘的次数,每次循环使用2秒延迟,按照实际情况修改。
(3) 当检测到U盘内有名为 force_ota.zip 升级包文件,则执行升级过程。升级成功后,重启到主系统;否则,重启Recovery系统。
diff --git a/recovery.cpp b/recovery.cpp
--- a/recovery.cpp
+++ b/recovery.cppstatic constexpr const char* LAST_LOG_FILE = "/cache/recovery/last_log";static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";#define UFS_DEV_SDCARD_BLK_PATH "/dev/block/mmcblk0p1"
+#define USB_BLK_PATH "dev/block/sda1"+std::string force_ota_path = "";static constexpr const char* CACHE_ROOT = "/cache";static Device::BuiltinAction prompt_and_wait(Device* device, int status) {status = ApplyFromAdb(device, false /* rescue_mode */, &reboot_action);} else {adb = false;
- status = ApplyFromSdcard(device, ui);
+ status = ApplyFromSdcard(device, ui, force_ota_path);}ui->Print("\nInstall from %s completed with status %d.\n", adb ? "ADB" : "SD card", status);static void log_failure_code(ErrorCode code, const std::string& update_package)LOG(INFO) << log_content;}+static InstallResult installOtaPackage(std::string force_ota_path, Device* device)
+{
+ LOG(INFO) << "force_ota.zip found, updating ...";
+ ui->InterruptKey();
+ ui->SetBackground(RecoveryUI::NONE);
+ ui->ShowText(false);
+ return static_cast<InstallResult>(ApplyFromSdcard(device, ui, force_ota_path));
+}+static void* usb_mount_thread(void* device) {
+ const int max_mount_cnt = 10;
+ int* install_result = static_cast<int*>(malloc(sizeof(int))
这篇关于Android系统 —— Recovery子系统下自动检测U盘内升级包并进行升级的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!