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_PAYLOAD_CONSUMER_PARTITION_UPDATE_GENERATOR_ANDROID_H_
18 #define UPDATE_ENGINE_PAYLOAD_CONSUMER_PARTITION_UPDATE_GENERATOR_ANDROID_H_
19 
20 #include <optional>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
25 #include <brillo/secure_blob.h>
26 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
27 
28 #include "update_engine/common/boot_control_interface.h"
29 #include "update_engine/payload_consumer/partition_update_generator_interface.h"
30 
31 namespace chromeos_update_engine {
32 class PartitionUpdateGeneratorAndroid
33     : public PartitionUpdateGeneratorInterface {
34  public:
35   PartitionUpdateGeneratorAndroid(BootControlInterface* boot_control,
36                                   std::string device_dir,
37                                   size_t block_size);
38 
39   bool GenerateOperationsForPartitionsNotInPayload(
40       BootControlInterface::Slot source_slot,
41       BootControlInterface::Slot target_slot,
42       const std::set<std::string>& partitions_in_payload,
43       std::vector<PartitionUpdate>* update_list) override;
44 
45  private:
46   friend class PartitionUpdateGeneratorAndroidTest;
47   FRIEND_TEST(PartitionUpdateGeneratorAndroidTest, GetStaticPartitions);
48   FRIEND_TEST(PartitionUpdateGeneratorAndroidTest, CreatePartitionUpdate);
49 
50   // Gets the name of the static a/b partitions on the device.
51   std::optional<std::set<std::string>> GetStaticAbPartitionsOnDevice();
52 
53   // Creates a PartitionUpdate object for a given partition to update from
54   // source to target. Returns std::nullopt on failure.
55   std::optional<PartitionUpdate> CreatePartitionUpdate(
56       const std::string& partition_name,
57       const std::string& source_device,
58       const std::string& target_device,
59       int64_t partition_size);
60 
61   std::optional<PartitionUpdate> CreatePartitionUpdate(
62       const std::string& partition_name,
63       BootControlInterface::Slot source_slot,
64       BootControlInterface::Slot target_slot);
65 
66   std::optional<brillo::Blob> CalculateHashForPartition(
67       const std::string& block_device, int64_t partition_size);
68 
69   BootControlInterface* boot_control_;
70   // Path to look for a/b partitions
71   std::string block_device_dir_;
72   size_t block_size_;
73 };
74 
75 }  // namespace chromeos_update_engine
76 
77 #endif
78