Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2020 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #ifndef UPDATE_ENGINE_CLEANUP_PREVIOUS_UPDATE_ACTION_H_ |
| 18 | #define UPDATE_ENGINE_CLEANUP_PREVIOUS_UPDATE_ACTION_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include <brillo/message_loops/message_loop.h> |
| 23 | #include <libsnapshot/snapshot.h> |
| 24 | |
| 25 | #include "update_engine/common/action.h" |
| 26 | #include "update_engine/common/boot_control_interface.h" |
| 27 | #include "update_engine/common/cleanup_previous_update_action_delegate.h" |
| 28 | #include "update_engine/common/error_code.h" |
| 29 | #include "update_engine/common/prefs_interface.h" |
| 30 | |
| 31 | namespace chromeos_update_engine { |
| 32 | |
| 33 | class CleanupPreviousUpdateAction; |
| 34 | |
| 35 | template <> |
| 36 | class ActionTraits<CleanupPreviousUpdateAction> { |
| 37 | public: |
| 38 | typedef NoneType InputObjectType; |
| 39 | typedef NoneType OutputObjectType; |
| 40 | }; |
| 41 | |
| 42 | // On Android Virtual A/B devices, clean up snapshots from previous update |
| 43 | // attempt. See DynamicPartitionControlAndroid::CleanupSuccessfulUpdate. |
| 44 | class CleanupPreviousUpdateAction : public Action<CleanupPreviousUpdateAction> { |
| 45 | public: |
| 46 | CleanupPreviousUpdateAction( |
| 47 | PrefsInterface* prefs, |
| 48 | BootControlInterface* boot_control, |
| 49 | android::snapshot::SnapshotManager* snapshot, |
| 50 | CleanupPreviousUpdateActionDelegateInterface* delegate); |
| 51 | |
| 52 | void PerformAction() override; |
| 53 | void SuspendAction() override; |
| 54 | void ResumeAction() override; |
| 55 | void TerminateProcessing() override; |
| 56 | void ActionCompleted(ErrorCode error_code) override; |
| 57 | std::string Type() const override; |
| 58 | static std::string StaticType(); |
| 59 | typedef ActionTraits<CleanupPreviousUpdateAction>::InputObjectType |
| 60 | InputObjectType; |
| 61 | typedef ActionTraits<CleanupPreviousUpdateAction>::OutputObjectType |
| 62 | OutputObjectType; |
| 63 | |
| 64 | private: |
| 65 | PrefsInterface* prefs_; |
| 66 | BootControlInterface* boot_control_; |
| 67 | android::snapshot::SnapshotManager* snapshot_; |
| 68 | CleanupPreviousUpdateActionDelegateInterface* delegate_; |
| 69 | bool running_{false}; |
| 70 | bool cancel_failed_{false}; |
| 71 | unsigned int last_percentage_{0}; |
| 72 | |
| 73 | void StartActionInternal(); |
| 74 | void ScheduleWaitBootCompleted(); |
| 75 | void WaitBootCompletedOrSchedule(); |
| 76 | void ScheduleWaitMarkBootSuccessful(); |
| 77 | void CheckSlotMarkedSuccessfulOrSchedule(); |
| 78 | void ScheduleWaitForMerge(); |
| 79 | void WaitForMergeOrSchedule(); |
| 80 | void InitiateMergeAndWait(); |
| 81 | |
| 82 | // Callbacks to ProcessUpdateState. |
| 83 | bool OnMergePercentageUpdate(); |
| 84 | bool BeforeCancel(); |
| 85 | }; |
| 86 | |
| 87 | } // namespace chromeos_update_engine |
| 88 | |
| 89 | #endif // UPDATE_ENGINE_CLEANUP_PREVIOUS_UPDATE_ACTION_H_ |