Add stub implementation for APIs to switch slot
Test: build
Bug: 187321613
Change-Id: Icdd402df711c8d35962bad2ef70f3c43e069c83b
diff --git a/aosp/binder_service_android.cc b/aosp/binder_service_android.cc
index 8e87588..84b5b7a 100644
--- a/aosp/binder_service_android.cc
+++ b/aosp/binder_service_android.cc
@@ -159,12 +159,19 @@
Status BinderUpdateEngineAndroidService::setShouldSwitchSlotOnReboot(
const android::String16& metadata_filename) {
- // TODO(187321613) Call the service_delegate_ for the actual implementation
+ brillo::ErrorPtr error;
+ if (!service_delegate_->setShouldSwitchSlotOnReboot(
+ android::String8(metadata_filename).string(), &error)) {
+ return ErrorPtrToStatus(error);
+ }
return Status::ok();
}
Status BinderUpdateEngineAndroidService::resetShouldSwitchSlotOnReboot() {
- // TODO(187321613) Call the service_delegate_ for the actual implementation
+ brillo::ErrorPtr error;
+ if (!service_delegate_->resetShouldSwitchSlotOnReboot(&error)) {
+ return ErrorPtrToStatus(error);
+ }
return Status::ok();
}
diff --git a/aosp/service_delegate_android_interface.h b/aosp/service_delegate_android_interface.h
index 3c28794..b3660ab 100644
--- a/aosp/service_delegate_android_interface.h
+++ b/aosp/service_delegate_android_interface.h
@@ -95,6 +95,17 @@
// In case of error, returns false and sets |error| accordingly.
virtual bool VerifyPayloadApplicable(const std::string& metadata_filename,
brillo::ErrorPtr* error) = 0;
+ // Sets the A/B slot switch for the next boot after applying an ota update.
+ // If applyPayload hasn't switched the slot by itself, the client can call
+ // this API to switch the slot and apply the update on next boot. Returns
+ // true on success.
+ virtual bool setShouldSwitchSlotOnReboot(const std::string& metadata_filename,
+ brillo::ErrorPtr* error) = 0;
+
+ // Resets the boot slot to the source/current slot, without cancelling the
+ // update progress. This can be called after the update is installed, and to
+ // prevent the device from accidentally taking the update when it reboots.
+ virtual bool resetShouldSwitchSlotOnReboot(brillo::ErrorPtr* error) = 0;
// Allocates space for a payload.
// Returns 0 if space is successfully preallocated.
diff --git a/aosp/update_attempter_android.cc b/aosp/update_attempter_android.cc
index 28c193e..cceecd9 100644
--- a/aosp/update_attempter_android.cc
+++ b/aosp/update_attempter_android.cc
@@ -1167,6 +1167,30 @@
ScheduleCleanupPreviousUpdate();
}
+bool UpdateAttempterAndroid::setShouldSwitchSlotOnReboot(
+ const std::string& metadata_filename, brillo::ErrorPtr* error) {
+ if (processor_->IsRunning()) {
+ return LogAndSetError(
+ error, FROM_HERE, "Already processing an update, cancel it first.");
+ }
+ // TODO(187321613) Implement this
+ return LogAndSetError(
+ error, FROM_HERE, "setShouldSwitchSlotOnReboot is not implemented yet.");
+}
+
+bool UpdateAttempterAndroid::resetShouldSwitchSlotOnReboot(
+ brillo::ErrorPtr* error) {
+ if (processor_->IsRunning()) {
+ return LogAndSetError(
+ error, FROM_HERE, "Already processing an update, cancel it first.");
+ }
+ // TODO(187321613) Implement this
+ return LogAndSetError(
+ error,
+ FROM_HERE,
+ "resetShouldSwitchSlotOnReboot is not implemented yet.");
+}
+
void UpdateAttempterAndroid::ScheduleCleanupPreviousUpdate() {
// If a previous CleanupSuccessfulUpdate call has not finished, or an update
// is in progress, skip enqueueing the action.
diff --git a/aosp/update_attempter_android.h b/aosp/update_attempter_android.h
index 3633178..7fa01e8 100644
--- a/aosp/update_attempter_android.h
+++ b/aosp/update_attempter_android.h
@@ -96,6 +96,9 @@
void CleanupSuccessfulUpdate(
std::unique_ptr<CleanupSuccessfulUpdateCallbackInterface> callback,
brillo::ErrorPtr* error) override;
+ bool setShouldSwitchSlotOnReboot(const std::string& metadata_filename,
+ brillo::ErrorPtr* error) override;
+ bool resetShouldSwitchSlotOnReboot(brillo::ErrorPtr* error) override;
// ActionProcessorDelegate methods:
void ProcessingDone(const ActionProcessor* processor,