Add triggerPostinstall API to IUpdateEngine.aidl
Test: th
Bug: 377557752
Change-Id: I8cad42ec0eb1d6e359229555fd8cfd3517a69137
diff --git a/aosp/binder_service_android.cc b/aosp/binder_service_android.cc
index 37df9a5..ec9ea6e 100644
--- a/aosp/binder_service_android.cc
+++ b/aosp/binder_service_android.cc
@@ -24,6 +24,7 @@
#include <utils/String8.h>
#include "update_engine/aosp/binder_service_android_common.h"
+#include "update_engine/common/error_code.h"
using android::binder::Status;
using android::os::IUpdateEngineCallback;
@@ -254,4 +255,14 @@
return Status::ok();
}
+Status BinderUpdateEngineAndroidService::triggerPostinstall(
+ const ::android::String16& partition) {
+ Error error;
+ service_delegate_->TriggerPostinstall(android::String8(partition).c_str(),
+ &error);
+ if (error.error_code != ErrorCode::kSuccess)
+ return ErrorPtrToStatus(error);
+ return Status::ok();
+}
+
} // namespace chromeos_update_engine
diff --git a/aosp/binder_service_android.h b/aosp/binder_service_android.h
index f1ce6b5..25d3c4b 100644
--- a/aosp/binder_service_android.h
+++ b/aosp/binder_service_android.h
@@ -33,8 +33,9 @@
namespace chromeos_update_engine {
-class BinderUpdateEngineAndroidService : public android::os::BnUpdateEngine,
- public ServiceObserverInterface {
+class BinderUpdateEngineAndroidService final
+ : public android::os::BnUpdateEngine,
+ public ServiceObserverInterface {
public:
explicit BinderUpdateEngineAndroidService(
ServiceDelegateAndroidInterface* service_delegate);
@@ -79,6 +80,8 @@
int64_t* return_value) override;
android::binder::Status cleanupSuccessfulUpdate(
const android::sp<android::os::IUpdateEngineCallback>& callback) override;
+ ::android::binder::Status triggerPostinstall(
+ const ::android::String16& partition) override;
private:
// Remove the passed |callback| from the list of registered callbacks. Called
diff --git a/aosp/update_engine_client_android.cc b/aosp/update_engine_client_android.cc
index 4f42a59..4d01ea6 100644
--- a/aosp/update_engine_client_android.cc
+++ b/aosp/update_engine_client_android.cc
@@ -157,6 +157,11 @@
"Perform just the slow switching part of OTA. "
"Used to revert a slot switch or re-do slot switch. Valid "
"values are 'true' and 'false'");
+ DEFINE_string(
+ trigger_postinstall,
+ UNSPECIFIED_FLAG,
+ "Only run postinstall sciprts. And only run postinstall script for the "
+ "specified partition. Example: \"system\", \"product\"");
DEFINE_bool(suspend, false, "Suspend an ongoing update and exit.");
DEFINE_bool(resume, false, "Resume a suspended update.");
DEFINE_bool(cancel, false, "Cancel the ongoing update and exit.");
@@ -231,6 +236,11 @@
return ExitWhenIdle(service_->resetStatus());
}
+ if (FLAGS_trigger_postinstall != UNSPECIFIED_FLAG) {
+ return ExitWhenIdle(service_->triggerPostinstall(
+ android::String16(FLAGS_trigger_postinstall.c_str())));
+ }
+
if (FLAGS_switch_slot != UNSPECIFIED_FLAG) {
if (FLAGS_switch_slot != "true" && FLAGS_switch_slot != "false") {
LOG(ERROR) << "--switch_slot should be either true or false, got "
diff --git a/binder_bindings/android/os/IUpdateEngine.aidl b/binder_bindings/android/os/IUpdateEngine.aidl
index 4043b1a..7291391 100644
--- a/binder_bindings/android/os/IUpdateEngine.aidl
+++ b/binder_bindings/android/os/IUpdateEngine.aidl
@@ -76,4 +76,23 @@
* but needs reboot). DEVICE_CORRUPTED for permanent errors.
*/
void cleanupSuccessfulUpdate(IUpdateEngineCallback callback);
+ /**
+ * Run postinstall scripts for the given |partition|
+ * This allows developers to run postinstall for a partition at
+ * a time they see fit. For example, they may wish to run postinstall
+ * script when device is IDLE and charging. This method would return
+ * immediately if |partition| is empty or does not correspond to any
+ * partitions on device. |partition| is expected to be unsuffixed, for
+ * example system,product,system_ext, etc.
+ * It is allowed to call this function multiple times with the same
+ * partition. Postinstall script for that partition would get run more
+ * than once. Owners of postinstall scripts should be designed to work
+ * correctly in such cases(idempotent). Note this expectation holds even
+ * without this API, and it has been so for years.
+ * @param Name of thje partition to run postinstall scripts. Should not
+ * contain slot suffix.(e.g. system,product,system_ext)
+ *
+ * @hide
+ */
+ void triggerPostinstall(in String partition);
}