RuntimeInfo.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #define LOG_TAG "libvintf"
  17. #include "RuntimeInfo.h"
  18. #include "CompatibilityMatrix.h"
  19. #include "parse_string.h"
  20. namespace android {
  21. namespace vintf {
  22. const std::string &RuntimeInfo::osName() const {
  23. return mOsName;
  24. }
  25. const std::string &RuntimeInfo::nodeName() const {
  26. return mNodeName;
  27. }
  28. const std::string &RuntimeInfo::osRelease() const {
  29. return mOsRelease;
  30. }
  31. const std::string &RuntimeInfo::osVersion() const {
  32. return mOsVersion;
  33. }
  34. const std::string &RuntimeInfo::hardwareId() const {
  35. return mHardwareId;
  36. }
  37. const KernelVersion &RuntimeInfo::kernelVersion() const {
  38. return mKernel.version();
  39. }
  40. const std::map<std::string, std::string> &RuntimeInfo::kernelConfigs() const {
  41. return mKernel.configs();
  42. }
  43. size_t RuntimeInfo::kernelSepolicyVersion() const {
  44. return mKernelSepolicyVersion;
  45. }
  46. const std::string &RuntimeInfo::cpuInfo() const {
  47. return mCpuInfo;
  48. }
  49. const Version &RuntimeInfo::bootVbmetaAvbVersion() const {
  50. return mBootVbmetaAvbVersion;
  51. }
  52. const Version &RuntimeInfo::bootAvbVersion() const {
  53. return mBootAvbVersion;
  54. }
  55. bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix& mat, std::string* error,
  56. CheckFlags::Type flags) const {
  57. if (mat.mType != SchemaType::FRAMEWORK) {
  58. if (error != nullptr) {
  59. *error = "Should not check runtime info against " + to_string(mat.mType)
  60. + " compatibility matrix.";
  61. }
  62. return false;
  63. }
  64. if (kernelSepolicyVersion() < mat.framework.mSepolicy.kernelSepolicyVersion()) {
  65. if (error != nullptr) {
  66. *error =
  67. "kernelSepolicyVersion = " + to_string(kernelSepolicyVersion()) +
  68. " but required >= " + to_string(mat.framework.mSepolicy.kernelSepolicyVersion());
  69. }
  70. return false;
  71. }
  72. // mat.mSepolicy.sepolicyVersion() is checked against static
  73. // HalManifest.device.mSepolicyVersion in HalManifest::checkCompatibility.
  74. if (flags.isKernelEnabled()) {
  75. if (!mKernel.matchKernelRequirements(mat.framework.mKernels, error)) {
  76. return false;
  77. }
  78. }
  79. if (flags.isAvbEnabled()) {
  80. const Version& matAvb = mat.framework.mAvbMetaVersion;
  81. if (mBootAvbVersion.majorVer != matAvb.majorVer ||
  82. mBootAvbVersion.minorVer < matAvb.minorVer) {
  83. if (error != nullptr) {
  84. std::stringstream ss;
  85. ss << "AVB version " << mBootAvbVersion << " does not match framework matrix "
  86. << matAvb;
  87. *error = ss.str();
  88. }
  89. return false;
  90. }
  91. if (mBootVbmetaAvbVersion.majorVer != matAvb.majorVer ||
  92. mBootVbmetaAvbVersion.minorVer < matAvb.minorVer) {
  93. if (error != nullptr) {
  94. std::stringstream ss;
  95. ss << "Vbmeta version " << mBootVbmetaAvbVersion
  96. << " does not match framework matrix " << matAvb;
  97. *error = ss.str();
  98. }
  99. return false;
  100. }
  101. }
  102. return true;
  103. }
  104. } // namespace vintf
  105. } // namespace android