Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2018 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 | |
Yifan Hong | 15726b9 | 2019-11-05 19:06:48 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <memory> |
| 23 | #include <string> |
| 24 | |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame^] | 25 | #include "update_engine/common/action.h" |
| 26 | #include "update_engine/common/cleanup_previous_update_action_delegate.h" |
Yifan Hong | 2257ee1 | 2020-01-13 18:33:00 -0800 | [diff] [blame] | 27 | #include "update_engine/common/error_code.h" |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 28 | #include "update_engine/update_metadata.pb.h" |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 29 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 30 | namespace chromeos_update_engine { |
| 31 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 32 | struct FeatureFlag { |
| 33 | enum class Value { NONE = 0, RETROFIT, LAUNCH }; |
| 34 | constexpr explicit FeatureFlag(Value value) : value_(value) {} |
| 35 | constexpr bool IsEnabled() const { return value_ != Value::NONE; } |
| 36 | constexpr bool IsRetrofit() const { return value_ == Value::RETROFIT; } |
Yifan Hong | 6e0d0ef | 2019-10-17 14:34:22 -0700 | [diff] [blame] | 37 | constexpr bool IsLaunch() const { return value_ == Value::LAUNCH; } |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 38 | |
| 39 | private: |
| 40 | Value value_; |
| 41 | }; |
| 42 | |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame^] | 43 | class BootControlInterface; |
| 44 | class PrefsInterface; |
| 45 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 46 | class DynamicPartitionControlInterface { |
| 47 | public: |
| 48 | virtual ~DynamicPartitionControlInterface() = default; |
| 49 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 50 | // Return the feature flags of dynamic partitions on this device. |
| 51 | // Return RETROFIT iff dynamic partitions is retrofitted on this device, |
| 52 | // LAUNCH iff this device is launched with dynamic partitions, |
| 53 | // NONE iff dynamic partitions is disabled on this device. |
| 54 | virtual FeatureFlag GetDynamicPartitionsFeatureFlag() = 0; |
Yifan Hong | 6e38b35 | 2018-11-19 14:12:37 -0800 | [diff] [blame] | 55 | |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 56 | // Return the feature flags of Virtual A/B on this device. |
| 57 | virtual FeatureFlag GetVirtualAbFeatureFlag() = 0; |
| 58 | |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 59 | // Checks if |operation| can be skipped on the given partition. |
| 60 | // |partition_name| should not have the slot suffix; implementation of |
| 61 | // DynamicPartitionControlInterface checks partition at the target slot |
| 62 | // previously set with PreparePartitionsForUpdate(). |
| 63 | virtual bool ShouldSkipOperation(const std::string& partition_name, |
| 64 | const InstallOperation& operation) = 0; |
Alessio Balsini | 14980e2 | 2019-11-26 11:46:06 +0000 | [diff] [blame] | 65 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 66 | // Do necessary cleanups before destroying the object. |
| 67 | virtual void Cleanup() = 0; |
| 68 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 69 | // Prepare all partitions for an update specified in |manifest|. |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 70 | // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the |
| 71 | // device would be mapped in an inconsistent way. |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 72 | // If |update| is set, create snapshots and writes super partition metadata. |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 73 | // If |required_size| is not null and call fails due to insufficient space, |
| 74 | // |required_size| will be set to total free space required on userdata |
| 75 | // partition to apply the update. Otherwise (call succeeds, or fails |
| 76 | // due to other errors), |required_size| is set to zero. |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 77 | virtual bool PreparePartitionsForUpdate(uint32_t source_slot, |
| 78 | uint32_t target_slot, |
| 79 | const DeltaArchiveManifest& manifest, |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 80 | bool update, |
| 81 | uint64_t* required_size) = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 82 | |
Yifan Hong | 0b664d1 | 2020-01-13 18:06:54 -0800 | [diff] [blame] | 83 | // After writing to new partitions, before rebooting into the new slot, call |
| 84 | // this function to indicate writes to new partitions are done. |
Yifan Hong | a33bca4 | 2019-09-03 20:29:45 -0700 | [diff] [blame] | 85 | virtual bool FinishUpdate() = 0; |
Yifan Hong | 2257ee1 | 2020-01-13 18:33:00 -0800 | [diff] [blame] | 86 | |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame^] | 87 | // Deprecated. Use GetCleanupPreviousUpdateAction instead. |
Yifan Hong | 2257ee1 | 2020-01-13 18:33:00 -0800 | [diff] [blame] | 88 | // Before applying the next update, call this function to clean up previous |
| 89 | // update files. This function blocks until delta files are merged into |
| 90 | // current OS partitions and finished cleaning up. |
| 91 | // - If successful, return kSuccess. |
| 92 | // - If any error, but caller should retry after reboot, return kError. |
| 93 | // - If any irrecoverable failures, return kDeviceCorrupted. |
| 94 | virtual ErrorCode CleanupSuccessfulUpdate() = 0; |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame^] | 95 | |
| 96 | // Get an action to clean up previous update. |
| 97 | // Return NoOpAction on non-Virtual A/B devices. |
| 98 | // Before applying the next update, run this action to clean up previous |
| 99 | // update files. This function blocks until delta files are merged into |
| 100 | // current OS partitions and finished cleaning up. |
| 101 | // - If successful, action completes with kSuccess. |
| 102 | // - If any error, but caller should retry after reboot, action completes with |
| 103 | // kError. |
| 104 | // - If any irrecoverable failures, action completes with kDeviceCorrupted. |
| 105 | virtual std::unique_ptr<AbstractAction> GetCleanupPreviousUpdateAction( |
| 106 | BootControlInterface* boot_control, |
| 107 | PrefsInterface* prefs, |
| 108 | CleanupPreviousUpdateActionDelegateInterface* delegate) = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } // namespace chromeos_update_engine |
| 112 | |
Yifan Hong | 15726b9 | 2019-11-05 19:06:48 -0800 | [diff] [blame] | 113 | #endif // UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |