1 // Copyright (C) 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <string>
18 
19 #ifdef LIBSNAPSHOT_USE_HAL
20 #include <BootControlClient.h>
21 #endif
22 #include <liblp/partition_opener.h>
23 #include <libsnapshot/snapshot.h>
24 
25 namespace android {
26 namespace snapshot {
27 
28 class DeviceInfo final : public SnapshotManager::IDeviceInfo {
29     using MergeStatus = ::aidl::android::hardware::boot::MergeStatus;
30 
31   public:
32     std::string GetMetadataDir() const override;
33     std::string GetSlotSuffix() const override;
34     std::string GetOtherSlotSuffix() const override;
35     const android::fs_mgr::IPartitionOpener& GetPartitionOpener() const override;
36     std::string GetSuperDevice(uint32_t slot) const override;
37     bool IsOverlayfsSetup() const override;
38     bool SetBootControlMergeStatus(MergeStatus status) override;
39     bool SetSlotAsUnbootable(unsigned int slot) override;
40     bool IsRecovery() const override;
41     std::unique_ptr<IImageManager> OpenImageManager() const override;
42     bool IsFirstStageInit() const override;
43     android::dm::IDeviceMapper& GetDeviceMapper() override;
44 
set_first_stage_init(bool value)45     void set_first_stage_init(bool value) { first_stage_init_ = value; }
46 
47   private:
48     bool EnsureBootHal();
49 
50     android::fs_mgr::PartitionOpener opener_;
51     bool first_stage_init_ = false;
52 #ifdef LIBSNAPSHOT_USE_HAL
53     std::unique_ptr<::android::hal::BootControlClient> boot_control_;
54 #endif
55 };
56 
57 }  // namespace snapshot
58 }  // namespace android
59