blob: c171fb5dcbf10efb2dc1d348f9e8b9d814780e63 [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 Hong13d41cb2019-09-16 13:18:22 -070025#include "update_engine/update_metadata.pb.h"
Yifan Hong012508e2019-07-22 18:30:40 -070026
Yifan Hong537802d2018-08-15 13:15:42 -070027namespace chromeos_update_engine {
28
Yifan Hong186bb682019-07-23 14:04:39 -070029struct FeatureFlag {
30 enum class Value { NONE = 0, RETROFIT, LAUNCH };
31 constexpr explicit FeatureFlag(Value value) : value_(value) {}
32 constexpr bool IsEnabled() const { return value_ != Value::NONE; }
33 constexpr bool IsRetrofit() const { return value_ == Value::RETROFIT; }
Yifan Hong6e0d0ef2019-10-17 14:34:22 -070034 constexpr bool IsLaunch() const { return value_ == Value::LAUNCH; }
Yifan Hong186bb682019-07-23 14:04:39 -070035
36 private:
37 Value value_;
38};
39
Yifan Hong537802d2018-08-15 13:15:42 -070040class DynamicPartitionControlInterface {
41 public:
42 virtual ~DynamicPartitionControlInterface() = default;
43
Yifan Hong186bb682019-07-23 14:04:39 -070044 // Return the feature flags of dynamic partitions on this device.
45 // Return RETROFIT iff dynamic partitions is retrofitted on this device,
46 // LAUNCH iff this device is launched with dynamic partitions,
47 // NONE iff dynamic partitions is disabled on this device.
48 virtual FeatureFlag GetDynamicPartitionsFeatureFlag() = 0;
Yifan Hong6e38b352018-11-19 14:12:37 -080049
Yifan Hong413d5722019-07-23 14:21:09 -070050 // Return the feature flags of Virtual A/B on this device.
51 virtual FeatureFlag GetVirtualAbFeatureFlag() = 0;
52
Yifan Hong6eec9952019-12-04 13:12:01 -080053 // Checks if |operation| can be skipped on the given partition.
54 // |partition_name| should not have the slot suffix; implementation of
55 // DynamicPartitionControlInterface checks partition at the target slot
56 // previously set with PreparePartitionsForUpdate().
57 virtual bool ShouldSkipOperation(const std::string& partition_name,
58 const InstallOperation& operation) = 0;
Alessio Balsini14980e22019-11-26 11:46:06 +000059
Yifan Hong537802d2018-08-15 13:15:42 -070060 // Do necessary cleanups before destroying the object.
61 virtual void Cleanup() = 0;
62
Yifan Hong13d41cb2019-09-16 13:18:22 -070063 // Prepare all partitions for an update specified in |manifest|.
Yifan Hong012508e2019-07-22 18:30:40 -070064 // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the
65 // device would be mapped in an inconsistent way.
Yifan Hongf0f4a912019-09-26 17:51:33 -070066 // If |update| is set, create snapshots and writes super partition metadata.
67 virtual bool PreparePartitionsForUpdate(uint32_t source_slot,
68 uint32_t target_slot,
69 const DeltaArchiveManifest& manifest,
70 bool update) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070071
Yifan Hong0b664d12020-01-13 18:06:54 -080072 // After writing to new partitions, before rebooting into the new slot, call
73 // this function to indicate writes to new partitions are done.
Yifan Honga33bca42019-09-03 20:29:45 -070074 virtual bool FinishUpdate() = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070075};
76
77} // namespace chromeos_update_engine
78
Yifan Hong15726b92019-11-05 19:06:48 -080079#endif // UPDATE_ENGINE_COMMON_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_