summaryrefslogtreecommitdiffstats
path: root/update_verifier
diff options
context:
space:
mode:
Diffstat (limited to 'update_verifier')
-rw-r--r--update_verifier/Android.bp6
-rw-r--r--update_verifier/include/update_verifier/update_verifier.h5
-rw-r--r--update_verifier/update_verifier.cpp51
3 files changed, 46 insertions, 16 deletions
diff --git a/update_verifier/Android.bp b/update_verifier/Android.bp
index 220b007f5..3c4ec4a99 100644
--- a/update_verifier/Android.bp
+++ b/update_verifier/Android.bp
@@ -73,8 +73,13 @@ cc_library_static {
"libvold_binder",
],
+ whole_static_libs: [
+ "libsnapshot_snapuserd",
+ ],
+
shared_libs: [
"android.hardware.boot@1.0",
+ "libboot_control_client",
"libbase",
"libcutils",
"libbinder",
@@ -114,6 +119,7 @@ cc_binary {
"libprotobuf-cpp-lite",
"libbinder",
"libutils",
+ "libboot_control_client",
],
init_rc: [
diff --git a/update_verifier/include/update_verifier/update_verifier.h b/update_verifier/include/update_verifier/update_verifier.h
index 4c64b1ea1..0cccc9075 100644
--- a/update_verifier/include/update_verifier/update_verifier.h
+++ b/update_verifier/include/update_verifier/update_verifier.h
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
+#include <snapuserd/snapuserd_client.h>
#include "otautil/rangeset.h"
// The update verifier performs verification upon the first boot to a new slot on A/B devices.
@@ -68,4 +69,8 @@ class UpdateVerifier {
// The function to read the device property; default value: android::base::GetProperty()
std::function<std::string(const std::string&)> property_reader_;
+
+ // Check if snapuserd daemon has already completed the update verification
+ // Applicable only for VABC with userspace snapshots
+ bool CheckVerificationStatus();
};
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
index a042f9008..ea47a65ca 100644
--- a/update_verifier/update_verifier.cpp
+++ b/update_verifier/update_verifier.cpp
@@ -52,13 +52,14 @@
#include <future>
#include <thread>
+#include <BootControlClient.h>
+#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
-#include <android/hardware/boot/1.0/IBootControl.h>
#include <android/os/IVold.h>
#include <binder/BinderService.h>
#include <binder/Status.h>
@@ -66,11 +67,6 @@
#include "care_map.pb.h"
-using android::sp;
-using android::hardware::boot::V1_0::IBootControl;
-using android::hardware::boot::V1_0::BoolResult;
-using android::hardware::boot::V1_0::CommandResult;
-
// TODO(xunchang) remove the prefix and use a default path instead.
constexpr const char* kDefaultCareMapPrefix = "/data/ota_package/care_map";
@@ -91,7 +87,7 @@ UpdateVerifier::UpdateVerifier()
// partition's integrity.
std::map<std::string, std::string> UpdateVerifier::FindDmPartitions() {
static constexpr auto DM_PATH_PREFIX = "/sys/block/";
- dirent** namelist;
+ dirent** namelist = nullptr;
int n = scandir(DM_PATH_PREFIX, &namelist, dm_name_filter, alphasort);
if (n == -1) {
PLOG(ERROR) << "Failed to scan dir " << DM_PATH_PREFIX;
@@ -188,7 +184,28 @@ bool UpdateVerifier::ReadBlocks(const std::string partition_name,
return ret;
}
+bool UpdateVerifier::CheckVerificationStatus() {
+ auto client =
+ android::snapshot::SnapuserdClient::Connect(android::snapshot::kSnapuserdSocket, 5s);
+ if (!client) {
+ LOG(ERROR) << "Unable to connect to snapuserd";
+ return false;
+ }
+
+ return client->QueryUpdateVerification();
+}
+
bool UpdateVerifier::VerifyPartitions() {
+ const bool userspace_snapshots =
+ android::base::GetBoolProperty("ro.virtual_ab.userspace.snapshots.enabled", false);
+
+ if (userspace_snapshots && CheckVerificationStatus()) {
+ LOG(INFO) << "Partitions verified by snapuserd daemon";
+ return true;
+ }
+
+ LOG(INFO) << "Partitions not verified by snapuserd daemon";
+
auto dm_block_devices = FindDmPartitions();
if (dm_block_devices.empty()) {
LOG(ERROR) << "No dm-enabled block device is found.";
@@ -307,18 +324,21 @@ int update_verifier(int argc, char** argv) {
LOG(INFO) << "Started with arg " << i << ": " << argv[i];
}
- sp<IBootControl> module = IBootControl::getService();
+ const auto module = android::hal::BootControlClient::WaitForService();
if (module == nullptr) {
LOG(ERROR) << "Error getting bootctrl module.";
return reboot_device();
}
- uint32_t current_slot = module->getCurrentSlot();
- BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot);
- LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful="
- << static_cast<int32_t>(is_successful);
-
- if (is_successful == BoolResult::FALSE) {
+ uint32_t current_slot = module->GetCurrentSlot();
+ const auto is_successful = module->IsSlotMarkedSuccessful(current_slot);
+ if (!is_successful.has_value()) {
+ LOG(INFO) << "Booting slot " << current_slot << " failed";
+ } else {
+ LOG(INFO) << "Booting slot " << current_slot
+ << ": isSlotMarkedSuccessful=" << is_successful.value();
+ }
+ if (is_successful.has_value() && !is_successful.value()) {
// The current slot has not booted successfully.
bool skip_verification = false;
@@ -364,8 +384,7 @@ int update_verifier(int argc, char** argv) {
}
if (!supports_checkpoint) {
- CommandResult cr;
- module->markBootSuccessful([&cr](CommandResult result) { cr = result; });
+ const auto cr = module->MarkBootSuccessful();
if (!cr.success) {
LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg;
return reboot_device();