| 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 |  | 
| Yifan Hong | d976cc5 | 2020-02-25 14:51:42 -0800 | [diff] [blame] | 20 | #include <chrono>  // NOLINT(build/c++11) -- for merge times | 
|  | 21 | #include <memory> | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 22 | #include <string> | 
|  | 23 |  | 
|  | 24 | #include <brillo/message_loops/message_loop.h> | 
|  | 25 | #include <libsnapshot/snapshot.h> | 
| Yifan Hong | d976cc5 | 2020-02-25 14:51:42 -0800 | [diff] [blame] | 26 | #include <libsnapshot/snapshot_stats.h> | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 27 |  | 
|  | 28 | #include "update_engine/common/action.h" | 
|  | 29 | #include "update_engine/common/boot_control_interface.h" | 
|  | 30 | #include "update_engine/common/cleanup_previous_update_action_delegate.h" | 
|  | 31 | #include "update_engine/common/error_code.h" | 
|  | 32 | #include "update_engine/common/prefs_interface.h" | 
|  | 33 |  | 
|  | 34 | namespace chromeos_update_engine { | 
|  | 35 |  | 
|  | 36 | class CleanupPreviousUpdateAction; | 
|  | 37 |  | 
|  | 38 | template <> | 
|  | 39 | class ActionTraits<CleanupPreviousUpdateAction> { | 
|  | 40 | public: | 
|  | 41 | typedef NoneType InputObjectType; | 
|  | 42 | typedef NoneType OutputObjectType; | 
|  | 43 | }; | 
|  | 44 |  | 
|  | 45 | // On Android Virtual A/B devices, clean up snapshots from previous update | 
|  | 46 | // attempt. See DynamicPartitionControlAndroid::CleanupSuccessfulUpdate. | 
|  | 47 | class CleanupPreviousUpdateAction : public Action<CleanupPreviousUpdateAction> { | 
|  | 48 | public: | 
|  | 49 | CleanupPreviousUpdateAction( | 
|  | 50 | PrefsInterface* prefs, | 
|  | 51 | BootControlInterface* boot_control, | 
| Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 52 | android::snapshot::ISnapshotManager* snapshot, | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 53 | CleanupPreviousUpdateActionDelegateInterface* delegate); | 
|  | 54 |  | 
|  | 55 | void PerformAction() override; | 
|  | 56 | void SuspendAction() override; | 
|  | 57 | void ResumeAction() override; | 
|  | 58 | void TerminateProcessing() override; | 
|  | 59 | void ActionCompleted(ErrorCode error_code) override; | 
|  | 60 | std::string Type() const override; | 
|  | 61 | static std::string StaticType(); | 
|  | 62 | typedef ActionTraits<CleanupPreviousUpdateAction>::InputObjectType | 
|  | 63 | InputObjectType; | 
|  | 64 | typedef ActionTraits<CleanupPreviousUpdateAction>::OutputObjectType | 
|  | 65 | OutputObjectType; | 
|  | 66 |  | 
|  | 67 | private: | 
|  | 68 | PrefsInterface* prefs_; | 
|  | 69 | BootControlInterface* boot_control_; | 
| Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 70 | android::snapshot::ISnapshotManager* snapshot_; | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 71 | CleanupPreviousUpdateActionDelegateInterface* delegate_; | 
| Yifan Hong | 5cd63fa | 2020-03-16 12:31:16 -0700 | [diff] [blame] | 72 | std::unique_ptr<android::snapshot::AutoDevice> metadata_device_; | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 73 | bool running_{false}; | 
|  | 74 | bool cancel_failed_{false}; | 
|  | 75 | unsigned int last_percentage_{0}; | 
| Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 76 | android::snapshot::ISnapshotMergeStats* merge_stats_; | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 77 |  | 
|  | 78 | void StartActionInternal(); | 
|  | 79 | void ScheduleWaitBootCompleted(); | 
|  | 80 | void WaitBootCompletedOrSchedule(); | 
|  | 81 | void ScheduleWaitMarkBootSuccessful(); | 
|  | 82 | void CheckSlotMarkedSuccessfulOrSchedule(); | 
|  | 83 | void ScheduleWaitForMerge(); | 
|  | 84 | void WaitForMergeOrSchedule(); | 
|  | 85 | void InitiateMergeAndWait(); | 
| Yifan Hong | d976cc5 | 2020-02-25 14:51:42 -0800 | [diff] [blame] | 86 | void ReportMergeStats(); | 
| Yifan Hong | dad0af8 | 2020-02-19 17:19:49 -0800 | [diff] [blame] | 87 |  | 
|  | 88 | // Callbacks to ProcessUpdateState. | 
|  | 89 | bool OnMergePercentageUpdate(); | 
|  | 90 | bool BeforeCancel(); | 
|  | 91 | }; | 
|  | 92 |  | 
|  | 93 | }  // namespace chromeos_update_engine | 
|  | 94 |  | 
|  | 95 | #endif  // UPDATE_ENGINE_CLEANUP_PREVIOUS_UPDATE_ACTION_H_ |