Detect rollback and cleanup space allocated for apex
As part of this change, a new enum OTAResult is added to represent state
of OTA.
Test: th
Test: Apply OTA, force rollback, make sure space is cleaned up
Test: Apply OTA, kill update_engine and restart, make sure update_engine
is still in UPDATE_NEED_REBOOT state
Test: Apply OTA, reboot, make sure sure "OTA succeeded
is printed
Change-Id: I8e1bf20e658c22111c447bf70b2d25d6d10d6083
diff --git a/aosp/update_attempter_android.h b/aosp/update_attempter_android.h
index 7a5a635..3633178 100644
--- a/aosp/update_attempter_android.h
+++ b/aosp/update_attempter_android.h
@@ -45,6 +45,13 @@
namespace chromeos_update_engine {
+enum class OTAResult {
+ NOT_ATTEMPTED,
+ ROLLED_BACK,
+ UPDATED_NEED_REBOOT,
+ OTA_SUCCESSFUL,
+};
+
class UpdateAttempterAndroid
: public ServiceDelegateAndroidInterface,
public ActionProcessorDelegate,
@@ -114,9 +121,24 @@
// CleanupPreviousUpdateActionDelegateInterface
void OnCleanupProgressUpdate(double progress) override;
+ // Check the result of an OTA update. Intended to be called after reboot, this
+ // will use prefs on disk to determine if OTA was installed, or rolledback.
+ [[nodiscard]] OTAResult GetOTAUpdateResult() const;
+ // Intended to be called:
+ // 1. When system rebooted and slot switch is attempted
+ // 2. When a new update is started
+ // 3. When user called |ResetStatus()|
+ bool ClearUpdateCompletedMarker();
+
private:
friend class UpdateAttempterAndroidTest;
+ // Return |true| only if slot switched successfully after an OTA reboot.
+ // This will return |false| if an downgrade OTA is applied. Because after a
+ // downgrade OTA, we wipe /data, and there's no way for update_engine to
+ // "remember" that a downgrade OTA took place.
+ [[nodiscard]] bool OTARebootSucceeded() const;
+
// Schedules an event loop callback to start the action processor. This is
// scheduled asynchronously to unblock the event loop.
void ScheduleProcessingStart();
@@ -136,10 +158,10 @@
// Writes to the processing completed marker. Does nothing if
// |update_completed_marker_| is empty.
- bool WriteUpdateCompletedMarker();
+ [[nodiscard]] bool WriteUpdateCompletedMarker();
// Returns whether an update was completed in the current boot.
- bool UpdateCompletedOnThisBoot();
+ [[nodiscard]] bool UpdateCompletedOnThisBoot();
// Prefs to use for metrics report
// |kPrefsPayloadAttemptNumber|: number of update attempts for the current
@@ -171,7 +193,7 @@
// |ReportTimeToRebootMetrics|
// Prefs to update:
// |kPrefsBootId|, |kPrefsPreviousVersion|
- void UpdateStateAfterReboot();
+ void UpdateStateAfterReboot(OTAResult result);
// Prefs to update:
// |kPrefsPayloadAttemptNumber|, |kPrefsUpdateTimestampStart|,