1 /* 2 * Copyright (C) 2017 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 ANDROID_VINTF_COMPATIBILITY_MATRIX_H 18 #define ANDROID_VINTF_COMPATIBILITY_MATRIX_H 19 20 #include <map> 21 #include <string> 22 23 #include <utils/Errors.h> 24 25 #include "HalGroup.h" 26 #include "Level.h" 27 #include "MapValueIterator.h" 28 #include "MatrixHal.h" 29 #include "MatrixInstance.h" 30 #include "MatrixKernel.h" 31 #include "Named.h" 32 #include "SchemaType.h" 33 #include "Sepolicy.h" 34 #include "SystemSdk.h" 35 #include "VendorNdk.h" 36 #include "Vndk.h" 37 #include "XmlFileGroup.h" 38 39 namespace android { 40 namespace vintf { 41 42 // Compatibility matrix defines what hardware does the framework requires. 43 struct CompatibilityMatrix : public HalGroup<MatrixHal>, public XmlFileGroup<MatrixXmlFile> { 44 // Create a framework compatibility matrix. CompatibilityMatrixCompatibilityMatrix45 CompatibilityMatrix() : mType(SchemaType::FRAMEWORK) {}; 46 47 SchemaType type() const; 48 Level level() const; 49 Version getMinimumMetaVersion() const; 50 51 // If the corresponding <xmlfile> with the given version exists, for the first match, 52 // - Return the overridden <path> if it is present, 53 // - otherwise the default value: /{system,vendor}/etc/<name>_V<major>_<minor-max>.<format> 54 // Otherwise if the <xmlfile> entry does not exist, "" is returned. 55 // For example, if the matrix says ["audio@1.0-5" -> "foo.xml", "audio@1.3-7" -> bar.xml] 56 // getXmlSchemaPath("audio", 1.0) -> foo.xml 57 // getXmlSchemaPath("audio", 1.5) -> foo.xml 58 // getXmlSchemaPath("audio", 1.7) -> bar.xml 59 // (Normally, version ranges do not overlap, and the only match is returned.) 60 std::string getXmlSchemaPath(const std::string& xmlFileName, const Version& version) const; 61 62 bool forEachInstanceOfVersion( 63 const std::string& package, const Version& expectVersion, 64 const std::function<bool(const MatrixInstance&)>& func) const override; 65 66 private: 67 bool add(MatrixHal &&hal); 68 bool add(MatrixKernel &&kernel); 69 70 // Add all HALs as optional HALs from "other". This function moves MatrixHal objects 71 // from "other". 72 // Require other->level() > this->level(), otherwise do nothing. 73 bool addAllHalsAsOptional(CompatibilityMatrix* other, std::string* error); 74 75 // Similar to addAllHalsAsOptional but on <xmlfile> entries. 76 bool addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error); 77 78 // Similar to addAllHalsAsOptional but on <kernel> entries. 79 bool addAllKernelsAsOptional(CompatibilityMatrix* other, std::string* error); 80 81 status_t fetchAllInformation(const std::string& path, std::string* error = nullptr); 82 83 // Combine a subset of "matrices". For each CompatibilityMatrix in matrices, 84 // - If level() == UNSPECIFIED, use it as the base matrix (for non-HAL, non-XML-file 85 // requirements). 86 // - If level() < deviceLevel, ignore 87 // - If level() == deviceLevel, all HAL versions and XML files are added as is 88 // (optionality is kept) 89 // - If level() > deviceLevel, all HAL versions and XML files are added as optional. 90 // Return a pointer into one of the elements in "matrices". 91 static CompatibilityMatrix* combine(Level deviceLevel, 92 std::vector<Named<CompatibilityMatrix>>* matrices, 93 std::string* error); 94 static CompatibilityMatrix* findOrInsertBaseMatrix( 95 std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error); 96 97 MatrixHal* splitInstance(MatrixHal* existingHal, const std::string& interface, 98 const std::string& instance, bool isRegex); 99 100 // Return whether instance is in "this"; that is, instance is in any <instance> tag or 101 // matches any <regex-instance> tag. 102 bool matchInstance(const std::string& halName, const Version& version, 103 const std::string& interfaceName, const std::string& instance) const; 104 105 friend struct HalManifest; 106 friend struct RuntimeInfo; 107 friend struct CompatibilityMatrixConverter; 108 friend struct LibVintfTest; 109 friend class VintfObject; 110 friend class AssembleVintfImpl; 111 friend bool operator==(const CompatibilityMatrix &, const CompatibilityMatrix &); 112 113 SchemaType mType; 114 Level mLevel = Level::UNSPECIFIED; 115 116 // entries only for framework compatibility matrix. 117 struct { 118 std::vector<MatrixKernel> mKernels; 119 Sepolicy mSepolicy; 120 Version mAvbMetaVersion; 121 } framework; 122 123 // entries only for device compatibility matrix. 124 struct { 125 #pragma clang diagnostic push 126 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 127 Vndk mVndk; 128 #pragma clang diagnostic pop 129 130 VendorNdk mVendorNdk; 131 SystemSdk mSystemSdk; 132 } device; 133 }; 134 135 } // namespace vintf 136 } // namespace android 137 138 #endif // ANDROID_VINTF_COMPATIBILITY_MATRIX_H 139