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