Merge "Convert vold to new BootControl client"

This commit is contained in:
Treehugger Robot 2022-06-29 18:03:39 +00:00 committed by Gerrit Code Review
commit 6083e0196b
2 changed files with 16 additions and 19 deletions

View file

@ -43,6 +43,8 @@ cc_defaults {
],
shared_libs: [
"android.hardware.boot@1.0",
"android.hardware.boot-V1-ndk",
"libboot_control_client",
"libbase",
"libbinder",
"libcrypto",

View file

@ -26,12 +26,12 @@
#include <thread>
#include <vector>
#include <BootControlClient.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/unique_fd.h>
#include <android/hardware/boot/1.0/IBootControl.h>
#include <cutils/android_reboot.h>
#include <fcntl.h>
#include <fs_mgr.h>
@ -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<IBootControl> 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<IBootControl> 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<IBootControl> 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<IBootControl> 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;
}