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 #pragma once
17 
18 #include <functional>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include <linker_config.pb.h>
24 
25 #include "linkerconfig/apex.h"
26 #include "linkerconfig/namespace.h"
27 
28 namespace android {
29 namespace linkerconfig {
30 namespace modules {
31 
32 class BaseContext {
33  public:
34   BaseContext();
35   virtual ~BaseContext() = default;
36 
37   void SetApexModules(std::vector<ApexInfo>&& apex_modules);
38   const std::vector<ApexInfo>& GetApexModules() const;
39   const std::unordered_map<std::string, std::reference_wrapper<const ApexInfo>>&
40   GetApexModuleMap() const;
41 
42   void SetStrictMode(bool strict);
43   bool IsStrictMode() const;
44 
45   void SetTargetApex(const std::string& target_apex);
46   const std::string& GetTargetApex() const;
47 
48   virtual Namespace BuildApexNamespace(const ApexInfo& apex_info,
49                                        bool visible) const;
50 
51   void SetSystemConfig(const android::linkerconfig::proto::LinkerConfig& config);
52   const std::vector<std::string>& GetSystemProvideLibs() const;
53   const std::vector<std::string>& GetSystemRequireLibs() const;
54 
55   void SetVendorConfig(const android::linkerconfig::proto::LinkerConfig& config);
56   const std::vector<std::string>& GetVendorProvideLibs() const;
57   const std::vector<std::string>& GetVendorRequireLibs() const;
58 
59   void SetProductConfig(const android::linkerconfig::proto::LinkerConfig& config);
60   const std::vector<std::string>& GetProductProvideLibs() const;
61   const std::vector<std::string>& GetProductRequireLibs() const;
62 
63  private:
64   bool strict_;
65   std::string target_apex_;
66 
67   // Available APEX Modules which contains binary and/or library
68   std::vector<ApexInfo> apex_modules_;
69 
70   // Map of library to the APEX module
71   std::unordered_map<std::string, std::reference_wrapper<const ApexInfo>>
72       apex_module_map_;
73 
74   std::vector<std::string> system_provide_libs_;
75   std::vector<std::string> system_require_libs_;
76   std::vector<std::string> vendor_provide_libs_;
77   std::vector<std::string> vendor_require_libs_;
78   std::vector<std::string> product_provide_libs_;
79   std::vector<std::string> product_require_libs_;
80 };
81 
82 }  // namespace modules
83 }  // namespace linkerconfig
84 }  // namespace android
85