• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #pragma once
18 
19 #include <android-base/result.h>
20 #include <libfiemap/image_manager.h>
21 
22 #include <memory>
23 #include <span>
24 #include <string>
25 #include <vector>
26 
27 #include "apex_file.h"
28 
29 namespace android::apex {
30 
31 class ApexImageManager {
32  public:
33   ~ApexImageManager() = default;
34 
35   // Pin APEX files in /data/apex/images and save their metadata(e.g. FIEMAP
36   // extents) in /metadata/apex/images so that they are available before /data
37   // partition is mounted.
38   // Returns names which correspond to pinned APEX files.
39   base::Result<std::vector<std::string>> PinApexFiles(
40       std::span<const ApexFile> apex_files);
41   base::Result<void> DeleteImage(const std::string& image);
42   std::vector<std::string> GetAllImages();
43 
44   static std::unique_ptr<ApexImageManager> Create(
45       const std::string& metadata_images_dir,
46       const std::string& data_images_dir);
47 
48  private:
49   ApexImageManager(const std::string& metadata_dir,
50                    const std::string& data_dir);
51 
52   std::string metadata_dir_;
53   std::string data_dir_;
54   std::unique_ptr<fiemap::IImageManager> fsmgr_;
55 };
56 
57 void InitializeImageManager(ApexImageManager* image_manager);
58 ApexImageManager* GetImageManager();
59 
60 }  // namespace android::apex