1 /* 2 * Copyright (C) 2019 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 <map> 20 #include <optional> 21 #include <string> 22 23 #include "linkerconfig/basecontext.h" 24 25 namespace android { 26 namespace linkerconfig { 27 namespace contents { 28 29 class Context; 30 using ApexNamespaceBuilder = 31 std::function<modules::Namespace(const Context&, const modules::ApexInfo&)>; 32 33 enum class SectionType { 34 System, 35 Vendor, 36 Product, 37 Unrestricted, 38 Other, 39 }; 40 41 enum class LinkerConfigType { 42 Default, 43 Legacy, 44 Vndklite, 45 Recovery, 46 ApexBinary, 47 }; 48 49 class Context : public modules::BaseContext { 50 public: Context()51 Context() 52 : current_section_(SectionType::System), 53 current_linkerconfig_type_(LinkerConfigType::Default) { 54 } 55 bool IsSystemSection() const; 56 bool IsVendorSection() const; 57 bool IsProductSection() const; 58 bool IsUnrestrictedSection() const; 59 60 bool IsDefaultConfig() const; 61 bool IsLegacyConfig() const; 62 bool IsVndkliteConfig() const; 63 bool IsRecoveryConfig() const; 64 bool IsApexBinaryConfig() const; 65 66 void SetCurrentSection(SectionType value); 67 void SetCurrentLinkerConfigType(LinkerConfigType value); 68 69 // Returns true if vndk apex is available 70 bool IsVndkAvailable() const; 71 72 // Returns the namespace that covers /system/${LIB}. 73 std::string GetSystemNamespaceName() const; 74 75 modules::Namespace BuildApexNamespace(const modules::ApexInfo& apex_info, 76 bool visible) const override; 77 void RegisterApexNamespaceBuilder(const std::string& name, 78 ApexNamespaceBuilder builder); 79 80 bool IsSectionVndkEnabled() const; 81 82 private: 83 std::map<std::string, ApexNamespaceBuilder> builders_; 84 85 SectionType current_section_; 86 LinkerConfigType current_linkerconfig_type_; 87 }; 88 89 std::string Var(const std::string& name); 90 91 std::string Var(const std::string& name, const std::string& default_value); 92 93 } // namespace contents 94 } // namespace linkerconfig 95 } // namespace android 96