blob: 22f6db8748134eab874aa73b59404da02d551a8b [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>
Tianjie99d570d2020-06-04 14:57:19 -070024#include <vector>
Yifan Hong537802d2018-08-15 13:15:42 -070025
Yifan Hong90965502020-02-19 15:22:47 -080026#include "update_engine/common/action.h"
27#include "update_engine/common/cleanup_previous_update_action_delegate.h"
Yifan Hong2257ee12020-01-13 18:33:00 -080028#include "update_engine/common/error_code.h"
Yifan Hong13d41cb2019-09-16 13:18:22 -070029#include "update_engine/update_metadata.pb.h"
Yifan Hong012508e2019-07-22 18:30:40 -070030
Yifan Hong537802d2018-08-15 13:15:42 -070031namespace chromeos_update_engine {
32
Yifan Hong186bb682019-07-23 14:04:39 -070033struct FeatureFlag {
34 enum class Value { NONE = 0, RETROFIT, LAUNCH };
35 constexpr explicit FeatureFlag(Value value) : value_(value) {}
36 constexpr bool IsEnabled() const { return value_ != Value::NONE; }
37 constexpr bool IsRetrofit() const { return value_ == Value::RETROFIT; }
Yifan Hong6e0d0ef2019-10-17 14:34:22 -070038 constexpr bool IsLaunch() const { return value_ == Value::LAUNCH; }
Yifan Hong186bb682019-07-23 14:04:39 -070039
40 private:
41 Value value_;
42};
43
Yifan Hong90965502020-02-19 15:22:47 -080044class BootControlInterface;
45class PrefsInterface;
46
Yifan Hong537802d2018-08-15 13:15:42 -070047class DynamicPartitionControlInterface {
48 public:
49 virtual ~DynamicPartitionControlInterface() = default;
50
Yifan Hong186bb682019-07-23 14:04:39 -070051 // Return the feature flags of dynamic partitions on this device.
52 // Return RETROFIT iff dynamic partitions is retrofitted on this device,
53 // LAUNCH iff this device is launched with dynamic partitions,
54 // NONE iff dynamic partitions is disabled on this device.
55 virtual FeatureFlag GetDynamicPartitionsFeatureFlag() = 0;
Yifan Hong6e38b352018-11-19 14:12:37 -080056
Yifan Hong413d5722019-07-23 14:21:09 -070057 // Return the feature flags of Virtual A/B on this device.
58 virtual FeatureFlag GetVirtualAbFeatureFlag() = 0;
Kelvin Zhangda1b3142020-09-24 17:09:02 -040059 // Return the feature flags of Virtual A/B Compression on this device.
60 virtual FeatureFlag GetVirtualAbCompressionFeatureFlag() = 0;
Yifan Hong413d5722019-07-23 14:21:09 -070061
Yifan Hongf5261562020-03-10 10:28:10 -070062 // Attempt to optimize |operation|.
63 // If successful, |optimized| contains an operation with extents that
64 // needs to be written.
65 // If failed, no optimization is available, and caller should perform
66 // |operation| directly.
Yifan Hong6eec9952019-12-04 13:12:01 -080067 // |partition_name| should not have the slot suffix; implementation of
68 // DynamicPartitionControlInterface checks partition at the target slot
69 // previously set with PreparePartitionsForUpdate().
Yifan Hongf5261562020-03-10 10:28:10 -070070 virtual bool OptimizeOperation(const std::string& partition_name,
71 const InstallOperation& operation,
72 InstallOperation* optimized) = 0;
Alessio Balsini14980e22019-11-26 11:46:06 +000073
Yifan Hong537802d2018-08-15 13:15:42 -070074 // Do necessary cleanups before destroying the object.
75 virtual void Cleanup() = 0;
76
Yifan Hong13d41cb2019-09-16 13:18:22 -070077 // Prepare all partitions for an update specified in |manifest|.
Yifan Hong012508e2019-07-22 18:30:40 -070078 // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the
79 // device would be mapped in an inconsistent way.
Yifan Hongf0f4a912019-09-26 17:51:33 -070080 // If |update| is set, create snapshots and writes super partition metadata.
Yifan Hongf033ecb2020-01-07 18:13:56 -080081 // If |required_size| is not null and call fails due to insufficient space,
82 // |required_size| will be set to total free space required on userdata
83 // partition to apply the update. Otherwise (call succeeds, or fails
84 // due to other errors), |required_size| is set to zero.
Yifan Hongf0f4a912019-09-26 17:51:33 -070085 virtual bool PreparePartitionsForUpdate(uint32_t source_slot,
86 uint32_t target_slot,
87 const DeltaArchiveManifest& manifest,
Yifan Hongf033ecb2020-01-07 18:13:56 -080088 bool update,
89 uint64_t* required_size) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070090
Yifan Hong0b664d12020-01-13 18:06:54 -080091 // After writing to new partitions, before rebooting into the new slot, call
92 // this function to indicate writes to new partitions are done.
Yifan Hong7b3910a2020-03-24 17:47:32 -070093 virtual bool FinishUpdate(bool powerwash_required) = 0;
Yifan Hong2257ee12020-01-13 18:33:00 -080094
Yifan Hong90965502020-02-19 15:22:47 -080095 // Get an action to clean up previous update.
96 // Return NoOpAction on non-Virtual A/B devices.
97 // Before applying the next update, run this action to clean up previous
98 // update files. This function blocks until delta files are merged into
99 // current OS partitions and finished cleaning up.
100 // - If successful, action completes with kSuccess.
101 // - If any error, but caller should retry after reboot, action completes with
102 // kError.
103 // - If any irrecoverable failures, action completes with kDeviceCorrupted.
Yifan Hong6a6d0f12020-03-11 13:20:52 -0700104 //
105 // See ResetUpdate for differences between CleanuPreviousUpdateAction and
106 // ResetUpdate.
Yifan Hong90965502020-02-19 15:22:47 -0800107 virtual std::unique_ptr<AbstractAction> GetCleanupPreviousUpdateAction(
108 BootControlInterface* boot_control,
109 PrefsInterface* prefs,
110 CleanupPreviousUpdateActionDelegateInterface* delegate) = 0;
Yifan Hong6a6d0f12020-03-11 13:20:52 -0700111
112 // Called after an unwanted payload has been successfully applied and the
113 // device has not yet been rebooted.
114 //
115 // For snapshot updates (Virtual A/B), it calls
116 // DeltaPerformer::ResetUpdateProgress(false /* quick */) and
117 // frees previously allocated space; the next update will need to be
118 // started over.
119 //
120 // Note: CleanupPreviousUpdateAction does not do anything if an update is in
121 // progress, while ResetUpdate() forcefully free previously
122 // allocated space for snapshot updates.
123 virtual bool ResetUpdate(PrefsInterface* prefs) = 0;
Tianjie99d570d2020-06-04 14:57:19 -0700124
125 // Reads the dynamic partitions metadata from the current slot, and puts the
126 // name of the dynamic partitions with the current suffix to |partitions|.
127 // Returns true on success.
128 virtual bool ListDynamicPartitionsForSlot(
129 uint32_t current_slot, std::vector<std::string>* partitions) = 0;
130
131 // Finds a possible location that list all block devices by name; and puts
132 // the result in |path|. Returns true on success.
133 // Sample result: /dev/block/by-name/
134 virtual bool GetDeviceDir(std::string* path) = 0;
Tianjie24f96092020-06-30 12:26:25 -0700135
136 // Verifies that the untouched dynamic partitions in the target metadata have
137 // the same extents as the source metadata.
138 virtual bool VerifyExtentsForUntouchedPartitions(
139 uint32_t source_slot,
140 uint32_t target_slot,
141 const std::vector<std::string>& partitions) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -0700142};
143
144} // namespace chromeos_update_engine
145
Yifan Hong15726b92019-11-05 19:06:48 -0800146#endif // UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_