diff --git a/Android.bp b/Android.bp index fcb0bb4..69907b6 100644 --- a/Android.bp +++ b/Android.bp @@ -43,6 +43,8 @@ cc_defaults { ], shared_libs: [ "android.hardware.boot@1.0", + "android.hardware.boot-V1-ndk", + "libboot_control_client", "libbase", "libbinder", "libcrypto", diff --git a/Checkpoint.cpp b/Checkpoint.cpp index 755f0e3..948231d 100644 --- a/Checkpoint.cpp +++ b/Checkpoint.cpp @@ -26,12 +26,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -48,11 +48,7 @@ using android::base::SetProperty; using android::binder::Status; using android::fs_mgr::Fstab; using android::fs_mgr::ReadFstabFromFile; -using android::hardware::hidl_string; -using android::hardware::boot::V1_0::BoolResult; -using android::hardware::boot::V1_0::CommandResult; -using android::hardware::boot::V1_0::IBootControl; -using android::hardware::boot::V1_0::Slot; +using android::hal::BootControlClient; namespace android { namespace vold { @@ -128,11 +124,10 @@ Status cp_startCheckpoint(int retry) { if (retry < -1) return error(EINVAL, "Retry count must be more than -1"); std::string content = std::to_string(retry + 1); if (retry == -1) { - sp module = IBootControl::getService(); + auto module = BootControlClient::WaitForService(); if (module) { - std::string suffix; - auto cb = [&suffix](hidl_string s) { suffix = s; }; - if (module->getSuffix(module->getCurrentSlot(), cb).isOk()) content += " " + suffix; + std::string suffix = module->GetSuffix(module->GetCurrentSlot()); + if (!suffix.empty()) content += " " + suffix; } } if (!android::base::WriteStringToFile(content, kMetadataCPFile)) @@ -162,10 +157,9 @@ Status cp_commitChanges() { << "NOT COMMITTING CHECKPOINT BECAUSE persist.vold.dont_commit_checkpoint IS 1"; return Status::ok(); } - sp module = IBootControl::getService(); + auto module = BootControlClient::WaitForService(); if (module) { - CommandResult cr; - module->markBootSuccessful([&cr](CommandResult result) { cr = result; }); + auto cr = module->MarkBootSuccessful(); if (!cr.success) return error(EINVAL, "Error marking booted successfully: " + std::string(cr.errMsg)); LOG(INFO) << "Marked slot as booted successfully."; @@ -173,6 +167,8 @@ Status cp_commitChanges() { if (!SetProperty("ota.warm_reset", "0")) { LOG(WARNING) << "Failed to reset the warm reset flag"; } + } else { + LOG(ERROR) << "Failed to get BootControl HAL, not marking slot as successful."; } // Must take action for list of mounted checkpointed things here // To do this, we walk the list of mounted file systems. @@ -254,12 +250,11 @@ bool cp_needsRollback() { if (content == "0") return true; if (content.substr(0, 3) == "-1 ") { std::string oldSuffix = content.substr(3); - sp module = IBootControl::getService(); + auto module = BootControlClient::WaitForService(); std::string newSuffix; if (module) { - auto cb = [&newSuffix](hidl_string s) { newSuffix = s; }; - module->getSuffix(module->getCurrentSlot(), cb); + newSuffix = module->GetSuffix(module->GetCurrentSlot()); if (oldSuffix == newSuffix) return true; } } @@ -276,11 +271,11 @@ bool cp_needsCheckpoint() { bool ret; std::string content; - sp module = IBootControl::getService(); + auto module = BootControlClient::WaitForService(); if (isCheckpointing) return isCheckpointing; - - if (module && module->isSlotMarkedSuccessful(module->getCurrentSlot()) == BoolResult::FALSE) { + // In case of INVALID slot or other failures, we do not perform checkpoint. + if (module && !module->IsSlotMarkedSuccessful(module->GetCurrentSlot()).value_or(true)) { isCheckpointing = true; return true; }