CheckFlags.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_DISABLED_CHECKS_H_
  17. #define ANDROID_VINTF_DISABLED_CHECKS_H_
  18. namespace android {
  19. namespace vintf {
  20. namespace CheckFlags {
  21. // Flags for *::checkCompatibility functions.
  22. class Type {
  23. public:
  24. #define VINTF_CHECK_FLAGS_FIELD(name, bit) \
  25. [[nodiscard]] constexpr Type enable##name() const { return Type(mValue | (1 << bit)); } \
  26. [[nodiscard]] constexpr Type disable##name() const { return Type(mValue & ~(1 << bit)); } \
  27. constexpr bool is##name##Enabled() const { return mValue & (1 << bit); }
  28. VINTF_CHECK_FLAGS_FIELD(Avb, 0)
  29. VINTF_CHECK_FLAGS_FIELD(RuntimeInfo, 1)
  30. VINTF_CHECK_FLAGS_FIELD(Kernel, 2)
  31. #undef VINTF_CHECK_FLAGS_FIELD
  32. explicit constexpr Type(int32_t value) : mValue(value) {}
  33. private:
  34. int32_t mValue;
  35. };
  36. constexpr Type ENABLE_ALL_CHECKS{~0};
  37. constexpr Type DISABLE_ALL_CHECKS{0};
  38. // Disable AVB version check in RuntimeInfo::checkCompatibility
  39. constexpr Type DISABLE_AVB_CHECK = ENABLE_ALL_CHECKS.disableAvb();
  40. // Disable RuntimeInfo <-> Framework Matrix check. This implies DISABLE_AVB_CHECK.
  41. constexpr Type DISABLE_RUNTIME_INFO = ENABLE_ALL_CHECKS.disableRuntimeInfo();
  42. // Default flag if no flag is provided.
  43. constexpr Type DEFAULT = DISABLE_AVB_CHECK;
  44. // tests
  45. static_assert(ENABLE_ALL_CHECKS.isAvbEnabled(), "");
  46. static_assert(ENABLE_ALL_CHECKS.isRuntimeInfoEnabled(), "");
  47. static_assert(!DISABLE_AVB_CHECK.isAvbEnabled(), "");
  48. static_assert(DISABLE_AVB_CHECK.isRuntimeInfoEnabled(), "");
  49. static_assert(DISABLE_RUNTIME_INFO.isAvbEnabled(), "");
  50. static_assert(!DISABLE_RUNTIME_INFO.isRuntimeInfoEnabled(), "");
  51. } // namespace CheckFlags
  52. } // namespace vintf
  53. } // namespace android
  54. #endif // ANDROID_VINTF_DISABLED_CHECKS_H_