1*70a7ec85SAndroid Build Coastguard Worker /* 2*70a7ec85SAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*70a7ec85SAndroid Build Coastguard Worker * 4*70a7ec85SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*70a7ec85SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*70a7ec85SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*70a7ec85SAndroid Build Coastguard Worker * 8*70a7ec85SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*70a7ec85SAndroid Build Coastguard Worker * 10*70a7ec85SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*70a7ec85SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*70a7ec85SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*70a7ec85SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*70a7ec85SAndroid Build Coastguard Worker * limitations under the License. 15*70a7ec85SAndroid Build Coastguard Worker */ 16*70a7ec85SAndroid Build Coastguard Worker 17*70a7ec85SAndroid Build Coastguard Worker #ifndef ANDROID_VINTF_COMPATIBILITY_MATRIX_H 18*70a7ec85SAndroid Build Coastguard Worker #define ANDROID_VINTF_COMPATIBILITY_MATRIX_H 19*70a7ec85SAndroid Build Coastguard Worker 20*70a7ec85SAndroid Build Coastguard Worker #include <map> 21*70a7ec85SAndroid Build Coastguard Worker #include <memory> 22*70a7ec85SAndroid Build Coastguard Worker #include <string> 23*70a7ec85SAndroid Build Coastguard Worker 24*70a7ec85SAndroid Build Coastguard Worker #include <utils/Errors.h> 25*70a7ec85SAndroid Build Coastguard Worker 26*70a7ec85SAndroid Build Coastguard Worker #include "FileSystem.h" 27*70a7ec85SAndroid Build Coastguard Worker #include "HalGroup.h" 28*70a7ec85SAndroid Build Coastguard Worker #include "Level.h" 29*70a7ec85SAndroid Build Coastguard Worker #include "MapValueIterator.h" 30*70a7ec85SAndroid Build Coastguard Worker #include "MatrixHal.h" 31*70a7ec85SAndroid Build Coastguard Worker #include "MatrixInstance.h" 32*70a7ec85SAndroid Build Coastguard Worker #include "MatrixKernel.h" 33*70a7ec85SAndroid Build Coastguard Worker #include "SchemaType.h" 34*70a7ec85SAndroid Build Coastguard Worker #include "Sepolicy.h" 35*70a7ec85SAndroid Build Coastguard Worker #include "SystemSdk.h" 36*70a7ec85SAndroid Build Coastguard Worker #include "VendorNdk.h" 37*70a7ec85SAndroid Build Coastguard Worker #include "Vndk.h" 38*70a7ec85SAndroid Build Coastguard Worker #include "WithFileName.h" 39*70a7ec85SAndroid Build Coastguard Worker #include "XmlFileGroup.h" 40*70a7ec85SAndroid Build Coastguard Worker 41*70a7ec85SAndroid Build Coastguard Worker namespace android { 42*70a7ec85SAndroid Build Coastguard Worker namespace vintf { 43*70a7ec85SAndroid Build Coastguard Worker 44*70a7ec85SAndroid Build Coastguard Worker namespace details { 45*70a7ec85SAndroid Build Coastguard Worker class CheckVintfUtils; 46*70a7ec85SAndroid Build Coastguard Worker } // namespace details 47*70a7ec85SAndroid Build Coastguard Worker 48*70a7ec85SAndroid Build Coastguard Worker // Compatibility matrix defines what hardware does the framework requires. 49*70a7ec85SAndroid Build Coastguard Worker struct CompatibilityMatrix : public HalGroup<MatrixHal>, 50*70a7ec85SAndroid Build Coastguard Worker public XmlFileGroup<MatrixXmlFile>, 51*70a7ec85SAndroid Build Coastguard Worker public WithFileName { 52*70a7ec85SAndroid Build Coastguard Worker // Create a framework compatibility matrix. CompatibilityMatrixCompatibilityMatrix53*70a7ec85SAndroid Build Coastguard Worker CompatibilityMatrix() : mType(SchemaType::FRAMEWORK) {} 54*70a7ec85SAndroid Build Coastguard Worker 55*70a7ec85SAndroid Build Coastguard Worker SchemaType type() const; 56*70a7ec85SAndroid Build Coastguard Worker Level level() const; 57*70a7ec85SAndroid Build Coastguard Worker 58*70a7ec85SAndroid Build Coastguard Worker // If the corresponding <xmlfile> with the given version exists, for the first match, 59*70a7ec85SAndroid Build Coastguard Worker // - Return the overridden <path> if it is present, 60*70a7ec85SAndroid Build Coastguard Worker // - otherwise the default value: /{system,vendor}/etc/<name>_V<major>_<minor-max>.<format> 61*70a7ec85SAndroid Build Coastguard Worker // Otherwise if the <xmlfile> entry does not exist, "" is returned. 62*70a7ec85SAndroid Build Coastguard Worker // For example, if the matrix says ["[email protected]" -> "foo.xml", "[email protected]" -> bar.xml] 63*70a7ec85SAndroid Build Coastguard Worker // getXmlSchemaPath("audio", 1.0) -> foo.xml 64*70a7ec85SAndroid Build Coastguard Worker // getXmlSchemaPath("audio", 1.5) -> foo.xml 65*70a7ec85SAndroid Build Coastguard Worker // getXmlSchemaPath("audio", 1.7) -> bar.xml 66*70a7ec85SAndroid Build Coastguard Worker // (Normally, version ranges do not overlap, and the only match is returned.) 67*70a7ec85SAndroid Build Coastguard Worker std::string getXmlSchemaPath(const std::string& xmlFileName, const Version& version) const; 68*70a7ec85SAndroid Build Coastguard Worker 69*70a7ec85SAndroid Build Coastguard Worker std::string getVendorNdkVersion() const; 70*70a7ec85SAndroid Build Coastguard Worker 71*70a7ec85SAndroid Build Coastguard Worker std::vector<SepolicyVersionRange> getSepolicyVersions() const; 72*70a7ec85SAndroid Build Coastguard Worker 73*70a7ec85SAndroid Build Coastguard Worker bool add(MatrixHal&&, std::string* error = nullptr); 74*70a7ec85SAndroid Build Coastguard Worker // Move all hals from another CompatibilityMatrix to this. 75*70a7ec85SAndroid Build Coastguard Worker bool addAllHals(CompatibilityMatrix* other, std::string* error = nullptr); 76*70a7ec85SAndroid Build Coastguard Worker 77*70a7ec85SAndroid Build Coastguard Worker protected: 78*70a7ec85SAndroid Build Coastguard Worker bool forEachInstanceOfVersion( 79*70a7ec85SAndroid Build Coastguard Worker HalFormat format, ExclusiveTo exclusiveTo, const std::string& package, 80*70a7ec85SAndroid Build Coastguard Worker const Version& expectVersion, 81*70a7ec85SAndroid Build Coastguard Worker const std::function<bool(const MatrixInstance&)>& func) const override; 82*70a7ec85SAndroid Build Coastguard Worker 83*70a7ec85SAndroid Build Coastguard Worker private: 84*70a7ec85SAndroid Build Coastguard Worker // Add everything in inputMatrix to "this" as requirements. 85*70a7ec85SAndroid Build Coastguard Worker bool addAll(CompatibilityMatrix* inputMatrix, std::string* error); 86*70a7ec85SAndroid Build Coastguard Worker 87*70a7ec85SAndroid Build Coastguard Worker // Add all <kernel> from other to "this". Error if there is a conflict. 88*70a7ec85SAndroid Build Coastguard Worker bool addAllKernels(CompatibilityMatrix* other, std::string* error); 89*70a7ec85SAndroid Build Coastguard Worker 90*70a7ec85SAndroid Build Coastguard Worker // Add a <kernel> tag to "this". Error if there is a conflict. 91*70a7ec85SAndroid Build Coastguard Worker bool addKernel(MatrixKernel&& kernel, std::string* error); 92*70a7ec85SAndroid Build Coastguard Worker 93*70a7ec85SAndroid Build Coastguard Worker // Merge <sepolicy> with other's <sepolicy>. Error if there is a conflict. 94*70a7ec85SAndroid Build Coastguard Worker bool addSepolicy(CompatibilityMatrix* other, std::string* error); 95*70a7ec85SAndroid Build Coastguard Worker 96*70a7ec85SAndroid Build Coastguard Worker // Merge <avb><vbmeta-version> with other's <avb><vbmeta-version>. Error if there is a conflict. 97*70a7ec85SAndroid Build Coastguard Worker bool addAvbMetaVersion(CompatibilityMatrix* other, std::string* error); 98*70a7ec85SAndroid Build Coastguard Worker 99*70a7ec85SAndroid Build Coastguard Worker // Merge <vndk> with other's <vndk>. Error if there is a conflict. 100*70a7ec85SAndroid Build Coastguard Worker bool addVndk(CompatibilityMatrix* other, std::string* error); 101*70a7ec85SAndroid Build Coastguard Worker 102*70a7ec85SAndroid Build Coastguard Worker // Merge <vendor-ndk> with other's <vendor-ndk>. Error if there is a conflict. 103*70a7ec85SAndroid Build Coastguard Worker bool addVendorNdk(CompatibilityMatrix* other, std::string* error); 104*70a7ec85SAndroid Build Coastguard Worker 105*70a7ec85SAndroid Build Coastguard Worker // Merge <system-sdk> with other's <system-sdk>. 106*70a7ec85SAndroid Build Coastguard Worker bool addSystemSdk(CompatibilityMatrix* other, std::string* error); 107*70a7ec85SAndroid Build Coastguard Worker 108*70a7ec85SAndroid Build Coastguard Worker // Add everything in inputMatrix to "this" as optional. 109*70a7ec85SAndroid Build Coastguard Worker bool addAllAsOptional(CompatibilityMatrix* inputMatrix, std::string* error); 110*70a7ec85SAndroid Build Coastguard Worker 111*70a7ec85SAndroid Build Coastguard Worker // Add all HALs as optional HALs from "other". This function moves MatrixHal objects 112*70a7ec85SAndroid Build Coastguard Worker // from "other". 113*70a7ec85SAndroid Build Coastguard Worker // Require other->level() > this->level(), otherwise do nothing. 114*70a7ec85SAndroid Build Coastguard Worker bool addAllHalsAsOptional(CompatibilityMatrix* other, std::string* error); 115*70a7ec85SAndroid Build Coastguard Worker 116*70a7ec85SAndroid Build Coastguard Worker // Similar to addAllHalsAsOptional but on <xmlfile> entries. 117*70a7ec85SAndroid Build Coastguard Worker bool addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error); 118*70a7ec85SAndroid Build Coastguard Worker 119*70a7ec85SAndroid Build Coastguard Worker // Combine a set of framework compatibility matrices. For each CompatibilityMatrix in matrices 120*70a7ec85SAndroid Build Coastguard Worker // (in the order of level(), where UNSPECIFIED (empty) is treated as deviceLevel) 121*70a7ec85SAndroid Build Coastguard Worker // - If level() < deviceLevel: 122*70a7ec85SAndroid Build Coastguard Worker // - If kernelLevel is UNSPECIFIED, ignore 123*70a7ec85SAndroid Build Coastguard Worker // - If kernelLevel is not UNSPECIFIED and level() < kernelLevel, ignore 124*70a7ec85SAndroid Build Coastguard Worker // - If kernelLevel is not UNSPECIFIED and level() >= kernelLevel, add kernel() 125*70a7ec85SAndroid Build Coastguard Worker // - If level() == UNSPECIFIED or level() == deviceLevel, 126*70a7ec85SAndroid Build Coastguard Worker // - Add as hard requirements. See combineSameFcmVersion 127*70a7ec85SAndroid Build Coastguard Worker // - If level() > deviceLevel, 128*70a7ec85SAndroid Build Coastguard Worker // - all <hal> versions and <xmlfile>s are added as optional. 129*70a7ec85SAndroid Build Coastguard Worker // - <kernel minlts="x.y.z"> is added only if x.y does not exist in a file 130*70a7ec85SAndroid Build Coastguard Worker // with lower level() 131*70a7ec85SAndroid Build Coastguard Worker // - <sepolicy>, <avb><vbmeta-version> is ignored 132*70a7ec85SAndroid Build Coastguard Worker // Return the combined matrix, nullptr if any error (e.g. conflict of information). 133*70a7ec85SAndroid Build Coastguard Worker static std::unique_ptr<CompatibilityMatrix> combine(Level deviceLevel, Level kernelLevel, 134*70a7ec85SAndroid Build Coastguard Worker std::vector<CompatibilityMatrix>* matrices, 135*70a7ec85SAndroid Build Coastguard Worker std::string* error); 136*70a7ec85SAndroid Build Coastguard Worker 137*70a7ec85SAndroid Build Coastguard Worker // Combine a set of device compatibility matrices. 138*70a7ec85SAndroid Build Coastguard Worker static std::unique_ptr<CompatibilityMatrix> combineDeviceMatrices( 139*70a7ec85SAndroid Build Coastguard Worker std::vector<CompatibilityMatrix>* matrices, std::string* error); 140*70a7ec85SAndroid Build Coastguard Worker 141*70a7ec85SAndroid Build Coastguard Worker status_t fetchAllInformation(const FileSystem* fileSystem, const std::string& path, 142*70a7ec85SAndroid Build Coastguard Worker std::string* error = nullptr); 143*70a7ec85SAndroid Build Coastguard Worker 144*70a7ec85SAndroid Build Coastguard Worker MatrixHal* splitInstance(MatrixHal* existingHal, const std::string& interface, 145*70a7ec85SAndroid Build Coastguard Worker const std::string& instance, bool isRegex); 146*70a7ec85SAndroid Build Coastguard Worker 147*70a7ec85SAndroid Build Coastguard Worker // Return whether instance is in "this"; that is, instance is in any <instance> tag or 148*70a7ec85SAndroid Build Coastguard Worker // matches any <regex-instance> tag. 149*70a7ec85SAndroid Build Coastguard Worker bool matchInstance(HalFormat format, ExclusiveTo exclusiveTo, const std::string& halName, 150*70a7ec85SAndroid Build Coastguard Worker const Version& version, const std::string& interfaceName, 151*70a7ec85SAndroid Build Coastguard Worker const std::string& instance) const; 152*70a7ec85SAndroid Build Coastguard Worker 153*70a7ec85SAndroid Build Coastguard Worker // Return the minlts of the latest <kernel>, or empty value if any error (e.g. this is not an 154*70a7ec85SAndroid Build Coastguard Worker // FCM, or there are no <kernel> tags). 155*70a7ec85SAndroid Build Coastguard Worker [[nodiscard]] KernelVersion getLatestKernelMinLts() const; 156*70a7ec85SAndroid Build Coastguard Worker 157*70a7ec85SAndroid Build Coastguard Worker friend struct HalManifest; 158*70a7ec85SAndroid Build Coastguard Worker friend struct RuntimeInfo; 159*70a7ec85SAndroid Build Coastguard Worker friend struct CompatibilityMatrixConverter; 160*70a7ec85SAndroid Build Coastguard Worker friend struct LibVintfTest; 161*70a7ec85SAndroid Build Coastguard Worker friend struct FrameworkCompatibilityMatrixCombineTest; 162*70a7ec85SAndroid Build Coastguard Worker friend struct DeviceCompatibilityMatrixCombineTest; 163*70a7ec85SAndroid Build Coastguard Worker friend class VintfObject; 164*70a7ec85SAndroid Build Coastguard Worker friend class AssembleVintfImpl; 165*70a7ec85SAndroid Build Coastguard Worker friend class KernelInfo; 166*70a7ec85SAndroid Build Coastguard Worker friend class details::CheckVintfUtils; 167*70a7ec85SAndroid Build Coastguard Worker friend bool operator==(const CompatibilityMatrix &, const CompatibilityMatrix &); 168*70a7ec85SAndroid Build Coastguard Worker 169*70a7ec85SAndroid Build Coastguard Worker SchemaType mType; 170*70a7ec85SAndroid Build Coastguard Worker Level mLevel = Level::UNSPECIFIED; 171*70a7ec85SAndroid Build Coastguard Worker 172*70a7ec85SAndroid Build Coastguard Worker // entries only for framework compatibility matrix. 173*70a7ec85SAndroid Build Coastguard Worker struct { 174*70a7ec85SAndroid Build Coastguard Worker std::vector<MatrixKernel> mKernels; 175*70a7ec85SAndroid Build Coastguard Worker Sepolicy mSepolicy; 176*70a7ec85SAndroid Build Coastguard Worker Version mAvbMetaVersion; 177*70a7ec85SAndroid Build Coastguard Worker } framework; 178*70a7ec85SAndroid Build Coastguard Worker 179*70a7ec85SAndroid Build Coastguard Worker // entries only for device compatibility matrix. 180*70a7ec85SAndroid Build Coastguard Worker struct { 181*70a7ec85SAndroid Build Coastguard Worker #pragma clang diagnostic push 182*70a7ec85SAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wdeprecated-declarations" 183*70a7ec85SAndroid Build Coastguard Worker Vndk mVndk; 184*70a7ec85SAndroid Build Coastguard Worker #pragma clang diagnostic pop 185*70a7ec85SAndroid Build Coastguard Worker 186*70a7ec85SAndroid Build Coastguard Worker VendorNdk mVendorNdk; 187*70a7ec85SAndroid Build Coastguard Worker SystemSdk mSystemSdk; 188*70a7ec85SAndroid Build Coastguard Worker } device; 189*70a7ec85SAndroid Build Coastguard Worker }; 190*70a7ec85SAndroid Build Coastguard Worker 191*70a7ec85SAndroid Build Coastguard Worker } // namespace vintf 192*70a7ec85SAndroid Build Coastguard Worker } // namespace android 193*70a7ec85SAndroid Build Coastguard Worker 194*70a7ec85SAndroid Build Coastguard Worker #endif // ANDROID_VINTF_COMPATIBILITY_MATRIX_H 195