diff options
| author | Anay Wadhera <awadhera@berkeley.edu> | 2021-01-29 12:03:39 -0800 |
|---|---|---|
| committer | Semavi Ulusoy <doc.divxm@gmail.com> | 2023-01-17 21:09:53 +0300 |
| commit | 741b6db55562e8b5313f9bfa1776cebbffb94a02 (patch) | |
| tree | f897d325e349dedc0ab56140dbedae3f5f4aca50 | |
| parent | 197546536a310884f66b66bd51562eb38edfb2cf (diff) | |
recovery: rewrite slot switch logic using bootcontrol APIs
Change-Id: I1eb136c81cc9246b0c9f5e52bcf6e7ba40fbc12d
Signed-off-by: jhonboy121 <alfredmathew05@gmail.com>
| -rw-r--r-- | Android.bp | 1 | ||||
| -rw-r--r-- | recovery.cpp | 34 |
2 files changed, 16 insertions, 19 deletions
@@ -100,7 +100,6 @@ cc_defaults { "libcrypto", "libcutils", "libfs_mgr", - "libhardware", "liblp", "liblog", "libprotobuf-cpp-lite", diff --git a/recovery.cpp b/recovery.cpp index 4c1d8275..bcc6fb39 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -42,11 +42,10 @@ #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> +#include <android/hardware/boot/1.0/IBootControl.h> #include <cutils/properties.h> /* for property_list */ #include <fs_mgr/roots.h> #include <volume_manager/VolumeManager.h> -#include <hardware/boot_control.h> -#include <hardware/hardware.h> #include <ziparchive/zip_archive.h> #include "bootloader_message/bootloader_message.h" @@ -71,6 +70,11 @@ using android::volmgr::VolumeManager; using android::volmgr::VolumeInfo; +using android::sp; +using android::hardware::boot::V1_0::IBootControl; +using android::hardware::boot::V1_0::CommandResult; +using android::hardware::boot::V1_0::Slot; + static constexpr const char* COMMAND_FILE = "/cache/recovery/command"; static constexpr const char* LAST_KMSG_FILE = "/cache/recovery/last_kmsg"; static constexpr const char* LAST_LOG_FILE = "/cache/recovery/last_log"; @@ -208,28 +212,22 @@ std::string get_chosen_slot(Device* device) { int set_slot(Device* device) { std::string slot = get_chosen_slot(device); - if (slot == "") - return 0; - const hw_module_t *hw_module; - boot_control_module_t *module; - int ret; - ret = hw_get_module("bootctrl", &hw_module); - if (ret != 0) { + CommandResult ret; + auto cb = [&ret](CommandResult result) { ret = result; }; + Slot sslot = (slot == "A") ? 0 : 1; + sp<IBootControl> module = IBootControl::getService(); + if (!module) { device->GetUI()->Print("Error getting bootctrl module.\n"); } else { - module = (boot_control_module_t*) hw_module; - module->init(module); - int slot_number = 0; - if (slot == "B") - slot_number = 1; - if (module->setActiveBootSlot(module, slot_number)) - device->GetUI()->Print("Error changing bootloader boot slot to %s", slot.c_str()); - else { + auto result = module->setActiveBootSlot(sslot, cb); + if (result.isOk() && ret.success) { device->GetUI()->Print("Switched slot to %s.\n", slot.c_str()); device->GoHome(); + } else { + device->GetUI()->Print("Error changing bootloader boot slot to %s", slot.c_str()); } } - return ret; + return ret.success ? 0 : 1; } static bool ask_to_wipe_data(Device* device) { |
