blob: a878f2e9f7c3b92dbcebad859a0c57872c9ba3dd [file] [log] [blame]
Yifan Hong537802d2018-08-15 13:15:42 -07001//
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 Hong15726b92019-11-05 19:06:48 -080017#ifndef UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_
18#define UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_
Yifan Hong537802d2018-08-15 13:15:42 -070019
20#include <stdint.h>
21
22#include <memory>
23#include <string>
24
Yifan Hong90965502020-02-19 15:22:47 -080025#include "update_engine/common/action.h"
26#include "update_engine/common/cleanup_previous_update_action_delegate.h"
Yifan Hong2257ee12020-01-13 18:33:00 -080027#include "update_engine/common/error_code.h"
Yifan Hong13d41cb2019-09-16 13:18:22 -070028#include "update_engine/update_metadata.pb.h"
Yifan Hong012508e2019-07-22 18:30:40 -070029
Yifan Hong537802d2018-08-15 13:15:42 -070030namespace chromeos_update_engine {
31
Yifan Hong186bb682019-07-23 14:04:39 -070032struct 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 Hong6e0d0ef2019-10-17 14:34:22 -070037 constexpr bool IsLaunch() const { return value_ == Value::LAUNCH; }
Yifan Hong186bb682019-07-23 14:04:39 -070038
39 private:
40 Value value_;
41};
42
Yifan Hong90965502020-02-19 15:22:47 -080043class BootControlInterface;
44class PrefsInterface;
45
Yifan Hong537802d2018-08-15 13:15:42 -070046class DynamicPartitionControlInterface {
47 public:
48 virtual ~DynamicPartitionControlInterface() = default;
49
Yifan Hong186bb682019-07-23 14:04:39 -070050 // 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 Hong6e38b352018-11-19 14:12:37 -080055
Yifan Hong413d5722019-07-23 14:21:09 -070056 // Return the feature flags of Virtual A/B on this device.
57 virtual FeatureFlag GetVirtualAbFeatureFlag() = 0;
58
Yifan Hongf5261562020-03-10 10:28:10 -070059 // Attempt to optimize |operation|.
60 // If successful, |optimized| contains an operation with extents that
61 // needs to be written.
62 // If failed, no optimization is available, and caller should perform
63 // |operation| directly.
Yifan Hong6eec9952019-12-04 13:12:01 -080064 // |partition_name| should not have the slot suffix; implementation of
65 // DynamicPartitionControlInterface checks partition at the target slot
66 // previously set with PreparePartitionsForUpdate().
Yifan Hongf5261562020-03-10 10:28:10 -070067 virtual bool OptimizeOperation(const std::string& partition_name,
68 const InstallOperation& operation,
69 InstallOperation* optimized) = 0;
Alessio Balsini14980e22019-11-26 11:46:06 +000070
Yifan Hong537802d2018-08-15 13:15:42 -070071 // Do necessary cleanups before destroying the object.
72 virtual void Cleanup() = 0;
73
Yifan Hong13d41cb2019-09-16 13:18:22 -070074 // Prepare all partitions for an update specified in |manifest|.
Yifan Hong012508e2019-07-22 18:30:40 -070075 // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the
76 // device would be mapped in an inconsistent way.
Yifan Hongf0f4a912019-09-26 17:51:33 -070077 // If |update| is set, create snapshots and writes super partition metadata.
Yifan Hongf033ecb2020-01-07 18:13:56 -080078 // If |required_size| is not null and call fails due to insufficient space,
79 // |required_size| will be set to total free space required on userdata
80 // partition to apply the update. Otherwise (call succeeds, or fails
81 // due to other errors), |required_size| is set to zero.
Yifan Hongf0f4a912019-09-26 17:51:33 -070082 virtual bool PreparePartitionsForUpdate(uint32_t source_slot,
83 uint32_t target_slot,
84 const DeltaArchiveManifest& manifest,
Yifan Hongf033ecb2020-01-07 18:13:56 -080085 bool update,
86 uint64_t* required_size) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070087
Yifan Hong0b664d12020-01-13 18:06:54 -080088 // After writing to new partitions, before rebooting into the new slot, call
89 // this function to indicate writes to new partitions are done.
Yifan Honga33bca42019-09-03 20:29:45 -070090 virtual bool FinishUpdate() = 0;
Yifan Hong2257ee12020-01-13 18:33:00 -080091
Yifan Hong90965502020-02-19 15:22:47 -080092 // Get an action to clean up previous update.
93 // Return NoOpAction on non-Virtual A/B devices.
94 // Before applying the next update, run this action to clean up previous
95 // update files. This function blocks until delta files are merged into
96 // current OS partitions and finished cleaning up.
97 // - If successful, action completes with kSuccess.
98 // - If any error, but caller should retry after reboot, action completes with
99 // kError.
100 // - If any irrecoverable failures, action completes with kDeviceCorrupted.
101 virtual std::unique_ptr<AbstractAction> GetCleanupPreviousUpdateAction(
102 BootControlInterface* boot_control,
103 PrefsInterface* prefs,
104 CleanupPreviousUpdateActionDelegateInterface* delegate) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -0700105};
106
107} // namespace chromeos_update_engine
108
Yifan Hong15726b92019-11-05 19:06:48 -0800109#endif // UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_