CompatibilityMatrix.h 6.9 KB

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