David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 ART_LIBARTBASE_BASE_HIDDENAPI_FLAGS_H_ |
| 18 | #define ART_LIBARTBASE_BASE_HIDDENAPI_FLAGS_H_ |
| 19 | |
| 20 | #include "sdk_version.h" |
| 21 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 24 | #include "android-base/logging.h" |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 25 | #include "base/bit_utils.h" |
| 26 | #include "base/dumpable.h" |
| 27 | #include "base/macros.h" |
Andrei Onea | 370a064 | 2019-03-01 17:48:27 +0000 | [diff] [blame] | 28 | #include "base/hiddenapi_stubs.h" |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | namespace hiddenapi { |
| 32 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 33 | // Helper methods used inside ApiList. These were moved outside of the ApiList |
| 34 | // class so that they can be used in static_asserts. If they were inside, they |
| 35 | // would be part of an unfinished type. |
| 36 | namespace helper { |
| 37 | // Casts enum value to uint32_t. |
| 38 | template<typename T> |
| 39 | constexpr uint32_t ToUint(T val) { return static_cast<uint32_t>(val); } |
| 40 | |
| 41 | // Returns uint32_t with one bit set at an index given by an enum value. |
| 42 | template<typename T> |
| 43 | constexpr uint32_t ToBit(T val) { return 1u << ToUint(val); } |
| 44 | |
| 45 | // Returns a bit mask with `size` least significant bits set. |
| 46 | constexpr uint32_t BitMask(uint32_t size) { return (1u << size) - 1; } |
| 47 | |
| 48 | // Returns a bit mask formed from an enum defining kMin and kMax. The values |
| 49 | // are assumed to be indices of min/max bits and the resulting bitmask has |
| 50 | // bits [kMin, kMax] set. |
| 51 | template<typename T> |
| 52 | constexpr uint32_t BitMask() { |
| 53 | return BitMask(ToUint(T::kMax) + 1) & (~BitMask(ToUint(T::kMin))); |
| 54 | } |
| 55 | |
| 56 | // Returns true if `val` is a bitwise subset of `mask`. |
| 57 | constexpr bool MatchesBitMask(uint32_t val, uint32_t mask) { return (val & mask) == val; } |
| 58 | |
| 59 | // Returns true if the uint32_t value of `val` is a bitwise subset of `mask`. |
| 60 | template<typename T> |
| 61 | constexpr bool MatchesBitMask(T val, uint32_t mask) { return MatchesBitMask(ToUint(val), mask); } |
| 62 | |
| 63 | // Returns the number of values defined in an enum, assuming the enum defines |
| 64 | // kMin and kMax and no integer values are skipped between them. |
| 65 | template<typename T> |
| 66 | constexpr uint32_t NumValues() { return ToUint(T::kMax) - ToUint(T::kMin) + 1; } |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 67 | |
| 68 | // Returns enum value at position i from enum list. |
| 69 | template <typename T> |
| 70 | constexpr T GetEnumAt(uint32_t i) { |
| 71 | return static_cast<T>(ToUint(T::kMin) + i); |
| 72 | } |
| 73 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 74 | } // namespace helper |
| 75 | |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 76 | /* |
| 77 | * This class represents the information whether a field/method is in |
| 78 | * public API (whitelist) or if it isn't, apps targeting which SDK |
| 79 | * versions are allowed to access it. |
| 80 | */ |
| 81 | class ApiList { |
| 82 | private: |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 83 | // Number of bits reserved for Value in dex flags, and the corresponding bit mask. |
| 84 | static constexpr uint32_t kValueBitSize = 3; |
| 85 | static constexpr uint32_t kValueBitMask = helper::BitMask(kValueBitSize); |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 86 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 87 | enum class Value : uint32_t { |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 88 | // Values independent of target SDK version of app |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 89 | kWhitelist = 0, |
| 90 | kGreylist = 1, |
| 91 | kBlacklist = 2, |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 92 | |
| 93 | // Values dependent on target SDK version of app. Put these last as |
| 94 | // their list will be extended in future releases. |
| 95 | // The max release code implicitly includes all maintenance releases, |
| 96 | // e.g. GreylistMaxO is accessible to targetSdkVersion <= 27 (O_MR1). |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 97 | kGreylistMaxO = 3, |
| 98 | kGreylistMaxP = 4, |
David Brazdil | 6ae463f | 2019-05-01 11:55:01 +0100 | [diff] [blame] | 99 | kGreylistMaxQ = 5, |
Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 100 | kGreylistMaxR = 6, |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 101 | |
| 102 | // Special values |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 103 | kInvalid = (static_cast<uint32_t>(-1) & kValueBitMask), |
| 104 | kMin = kWhitelist, |
Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 105 | kMax = kGreylistMaxR, |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 108 | // Additional bit flags after the first kValueBitSize bits in dex flags. |
| 109 | // These are used for domain-specific API. |
| 110 | enum class DomainApi : uint32_t { |
| 111 | kCorePlatformApi = kValueBitSize, |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 112 | kTestApi = kValueBitSize + 1, |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 113 | |
| 114 | // Special values |
| 115 | kMin = kCorePlatformApi, |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 116 | kMax = kTestApi, |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | // Bit mask of all domain API flags. |
| 120 | static constexpr uint32_t kDomainApiBitMask = helper::BitMask<DomainApi>(); |
| 121 | |
| 122 | // Check that Values fit in the designated number of bits. |
| 123 | static_assert(kValueBitSize >= MinimumBitsToStore(helper::ToUint(Value::kMax)), |
| 124 | "Not enough bits to store all ApiList values"); |
| 125 | |
Ian Pedowitz | 2d53643 | 2020-07-22 14:33:00 -0700 | [diff] [blame] | 126 | // Checks that all Values are covered by kValueBitMask. |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 127 | static_assert(helper::MatchesBitMask(Value::kMin, kValueBitMask)); |
| 128 | static_assert(helper::MatchesBitMask(Value::kMax, kValueBitMask)); |
| 129 | |
| 130 | // Assert that Value::kInvalid is larger than the maximum Value. |
| 131 | static_assert(helper::ToUint(Value::kMax) < helper::ToUint(Value::kInvalid)); |
| 132 | |
| 133 | // Names corresponding to Values. |
| 134 | static constexpr const char* kValueNames[] = { |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 135 | "whitelist", |
| 136 | "greylist", |
| 137 | "blacklist", |
| 138 | "greylist-max-o", |
David Brazdil | 80d1628 | 2018-11-01 09:55:09 +0000 | [diff] [blame] | 139 | "greylist-max-p", |
David Brazdil | 6ae463f | 2019-05-01 11:55:01 +0100 | [diff] [blame] | 140 | "greylist-max-q", |
Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 141 | "greylist-max-r", |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 144 | // Names corresponding to DomainApis. |
| 145 | static constexpr const char* kDomainApiNames[] { |
| 146 | "core-platform-api", |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 147 | "test-api", |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 148 | }; |
David Brazdil | 91690d3 | 2018-11-04 18:07:23 +0000 | [diff] [blame] | 149 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 150 | // Maximum SDK versions allowed to access ApiList of given Value. |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 151 | static constexpr SdkVersion kMaxSdkVersions[] { |
| 152 | /* whitelist */ SdkVersion::kMax, |
| 153 | /* greylist */ SdkVersion::kMax, |
| 154 | /* blacklist */ SdkVersion::kMin, |
| 155 | /* greylist-max-o */ SdkVersion::kO_MR1, |
David Brazdil | 80d1628 | 2018-11-01 09:55:09 +0000 | [diff] [blame] | 156 | /* greylist-max-p */ SdkVersion::kP, |
David Brazdil | 6ae463f | 2019-05-01 11:55:01 +0100 | [diff] [blame] | 157 | /* greylist-max-q */ SdkVersion::kQ, |
Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 158 | /* greylist-max-r */ SdkVersion::kR, |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 161 | explicit ApiList(Value val, uint32_t domain_apis = 0u) |
| 162 | : dex_flags_(helper::ToUint(val) | domain_apis) { |
| 163 | DCHECK(GetValue() == val); |
| 164 | DCHECK_EQ(GetDomainApis(), domain_apis); |
| 165 | } |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 166 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 167 | explicit ApiList(DomainApi val) : ApiList(Value::kInvalid, helper::ToBit(val)) {} |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 168 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 169 | Value GetValue() const { |
| 170 | uint32_t value = (dex_flags_ & kValueBitMask); |
| 171 | |
| 172 | // Treat all ones as invalid value |
| 173 | if (value == helper::ToUint(Value::kInvalid)) { |
| 174 | return Value::kInvalid; |
| 175 | } else { |
| 176 | DCHECK_GE(value, helper::ToUint(Value::kMin)); |
| 177 | DCHECK_LE(value, helper::ToUint(Value::kMax)); |
| 178 | return static_cast<Value>(value); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | uint32_t GetDomainApis() const { return (dex_flags_ & kDomainApiBitMask); } |
| 183 | |
| 184 | uint32_t dex_flags_; |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 185 | |
| 186 | public: |
David Brazdil | 62a4bcf | 2018-12-13 17:00:06 +0000 | [diff] [blame] | 187 | ApiList() : ApiList(Value::kInvalid) {} |
| 188 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 189 | explicit ApiList(uint32_t dex_flags) : dex_flags_(dex_flags) { |
| 190 | DCHECK_EQ(dex_flags_, (dex_flags_ & kValueBitMask) | (dex_flags_ & kDomainApiBitMask)); |
| 191 | } |
| 192 | |
| 193 | // Helpers for conveniently constructing ApiList instances. |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 194 | static ApiList Whitelist() { return ApiList(Value::kWhitelist); } |
| 195 | static ApiList Greylist() { return ApiList(Value::kGreylist); } |
| 196 | static ApiList Blacklist() { return ApiList(Value::kBlacklist); } |
| 197 | static ApiList GreylistMaxO() { return ApiList(Value::kGreylistMaxO); } |
David Brazdil | 80d1628 | 2018-11-01 09:55:09 +0000 | [diff] [blame] | 198 | static ApiList GreylistMaxP() { return ApiList(Value::kGreylistMaxP); } |
Artur Satayev | 201ffea | 2019-10-31 14:58:03 +0000 | [diff] [blame] | 199 | static ApiList GreylistMaxQ() { return ApiList(Value::kGreylistMaxQ); } |
Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 200 | static ApiList GreylistMaxR() { return ApiList(Value::kGreylistMaxR); } |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 201 | static ApiList CorePlatformApi() { return ApiList(DomainApi::kCorePlatformApi); } |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 202 | static ApiList TestApi() { return ApiList(DomainApi::kTestApi); } |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 203 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 204 | uint32_t GetDexFlags() const { return dex_flags_; } |
| 205 | uint32_t GetIntValue() const { return helper::ToUint(GetValue()) - helper::ToUint(Value::kMin); } |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 206 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 207 | // Returns the ApiList with a flag of a given name, or an empty ApiList if not matched. |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 208 | static ApiList FromName(const std::string& str) { |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 209 | for (uint32_t i = 0; i < kValueCount; ++i) { |
| 210 | if (str == kValueNames[i]) { |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 211 | return ApiList(helper::GetEnumAt<Value>(i)); |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 214 | for (uint32_t i = 0; i < kDomainApiCount; ++i) { |
| 215 | if (str == kDomainApiNames[i]) { |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 216 | return ApiList(helper::GetEnumAt<DomainApi>(i)); |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | return ApiList(); |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 220 | } |
| 221 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 222 | // Parses a vector of flag names into a single ApiList value. If successful, |
| 223 | // returns true and assigns the new ApiList to `out_api_list`. |
| 224 | static bool FromNames(std::vector<std::string>::iterator begin, |
| 225 | std::vector<std::string>::iterator end, |
| 226 | /* out */ ApiList* out_api_list) { |
| 227 | ApiList api_list; |
| 228 | for (std::vector<std::string>::iterator it = begin; it != end; it++) { |
| 229 | ApiList current = FromName(*it); |
| 230 | if (current.IsEmpty() || !api_list.CanCombineWith(current)) { |
Andrei Onea | 370a064 | 2019-03-01 17:48:27 +0000 | [diff] [blame] | 231 | if (ApiStubs::IsStubsFlag(*it)) { |
| 232 | // Ignore flags which correspond to the stubs from where the api |
| 233 | // originates (i.e. system-api, test-api, public-api), as they are not |
| 234 | // relevant at runtime |
| 235 | continue; |
| 236 | } |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 237 | return false; |
| 238 | } |
| 239 | api_list |= current; |
| 240 | } |
| 241 | if (out_api_list != nullptr) { |
| 242 | *out_api_list = api_list; |
| 243 | } |
| 244 | return true; |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 245 | } |
| 246 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 247 | bool operator==(const ApiList& other) const { return dex_flags_ == other.dex_flags_; } |
| 248 | bool operator!=(const ApiList& other) const { return !(*this == other); } |
Artur Satayev | 7acb846 | 2019-09-11 12:16:12 +0100 | [diff] [blame] | 249 | bool operator<(const ApiList& other) const { return dex_flags_ < other.dex_flags_; } |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 250 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 251 | // Returns true if combining this ApiList with `other` will succeed. |
| 252 | bool CanCombineWith(const ApiList& other) const { |
| 253 | const Value val1 = GetValue(); |
| 254 | const Value val2 = other.GetValue(); |
| 255 | return (val1 == val2) || (val1 == Value::kInvalid) || (val2 == Value::kInvalid); |
| 256 | } |
| 257 | |
| 258 | // Combine two ApiList instances. |
| 259 | ApiList operator|(const ApiList& other) { |
| 260 | // DomainApis are not mutually exclusive. Simply OR them. |
| 261 | const uint32_t domain_apis = GetDomainApis() | other.GetDomainApis(); |
| 262 | |
| 263 | // Values are mutually exclusive. Check if `this` and `other` have the same Value |
| 264 | // or if at most one is set. |
| 265 | const Value val1 = GetValue(); |
| 266 | const Value val2 = other.GetValue(); |
| 267 | if (val1 == val2) { |
| 268 | return ApiList(val1, domain_apis); |
| 269 | } else if (val1 == Value::kInvalid) { |
| 270 | return ApiList(val2, domain_apis); |
| 271 | } else if (val2 == Value::kInvalid) { |
| 272 | return ApiList(val1, domain_apis); |
| 273 | } else { |
| 274 | LOG(FATAL) << "Invalid combination of values " << Dumpable(ApiList(val1)) |
| 275 | << " and " << Dumpable(ApiList(val2)); |
| 276 | UNREACHABLE(); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | const ApiList& operator|=(const ApiList& other) { |
| 281 | (*this) = (*this) | other; |
| 282 | return *this; |
| 283 | } |
| 284 | |
| 285 | // Returns true if all flags set in `other` are also set in `this`. |
| 286 | bool Contains(const ApiList& other) const { |
| 287 | return ((other.GetValue() == Value::kInvalid) || (GetValue() == other.GetValue())) && |
| 288 | helper::MatchesBitMask(other.GetDomainApis(), GetDomainApis()); |
| 289 | } |
| 290 | |
| 291 | // Returns true whether the configuration is valid for runtime use. |
| 292 | bool IsValid() const { return GetValue() != Value::kInvalid; } |
| 293 | |
| 294 | // Returns true when no ApiList is specified and no domain_api flags either. |
| 295 | bool IsEmpty() const { return (GetValue() == Value::kInvalid) && (GetDomainApis() == 0); } |
| 296 | |
Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 297 | // Returns true if the ApiList is on blacklist. |
| 298 | bool IsBlacklisted() const { |
| 299 | return GetValue() == Value::kBlacklist; |
| 300 | } |
| 301 | |
| 302 | // Returns true if the ApiList is a test API. |
| 303 | bool IsTestApi() const { |
| 304 | return helper::MatchesBitMask(helper::ToBit(DomainApi::kTestApi), dex_flags_); |
| 305 | } |
| 306 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 307 | // Returns the maximum target SDK version allowed to access this ApiList. |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 308 | SdkVersion GetMaxAllowedSdkVersion() const { return kMaxSdkVersions[GetIntValue()]; } |
| 309 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 310 | void Dump(std::ostream& os) const { |
| 311 | bool is_first = true; |
| 312 | |
Artur Satayev | 39c399a | 2019-09-13 16:09:09 +0100 | [diff] [blame] | 313 | if (IsEmpty()) { |
| 314 | os << "invalid"; |
| 315 | return; |
| 316 | } |
| 317 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 318 | if (GetValue() != Value::kInvalid) { |
| 319 | os << kValueNames[GetIntValue()]; |
| 320 | is_first = false; |
| 321 | } |
| 322 | |
| 323 | const uint32_t domain_apis = GetDomainApis(); |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 324 | for (uint32_t i = 0; i < kDomainApiCount; i++) { |
| 325 | if (helper::MatchesBitMask(helper::ToBit(helper::GetEnumAt<DomainApi>(i)), domain_apis)) { |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 326 | if (is_first) { |
| 327 | is_first = false; |
| 328 | } else { |
| 329 | os << ","; |
| 330 | } |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 331 | os << kDomainApiNames[i]; |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
| 335 | DCHECK_EQ(IsEmpty(), is_first); |
| 336 | } |
| 337 | |
Artur Satayev | 39c399a | 2019-09-13 16:09:09 +0100 | [diff] [blame] | 338 | // Number of valid enum values in Value. |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 339 | static constexpr uint32_t kValueCount = helper::NumValues<Value>(); |
Artur Satayev | 39c399a | 2019-09-13 16:09:09 +0100 | [diff] [blame] | 340 | // Number of valid enum values in DomainApi. |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 341 | static constexpr uint32_t kDomainApiCount = helper::NumValues<DomainApi>(); |
Artur Satayev | 39c399a | 2019-09-13 16:09:09 +0100 | [diff] [blame] | 342 | // Total number of possible enum values, including invalid, in Value. |
| 343 | static constexpr uint32_t kValueSize = (1u << kValueBitSize) + 1; |
Mariia Feofanova | 4945b29 | 2019-09-04 17:49:42 +0100 | [diff] [blame] | 344 | |
| 345 | // Check min and max values are calculated correctly. |
| 346 | static_assert(Value::kMin == helper::GetEnumAt<Value>(0)); |
| 347 | static_assert(Value::kMax == helper::GetEnumAt<Value>(kValueCount - 1)); |
| 348 | |
| 349 | static_assert(DomainApi::kMin == helper::GetEnumAt<DomainApi>(0)); |
| 350 | static_assert(DomainApi::kMax == helper::GetEnumAt<DomainApi>(kDomainApiCount - 1)); |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | inline std::ostream& operator<<(std::ostream& os, ApiList value) { |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 354 | value.Dump(os); |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 355 | return os; |
| 356 | } |
| 357 | |
David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 358 | } // namespace hiddenapi |
| 359 | } // namespace art |
| 360 | |
| 361 | |
| 362 | #endif // ART_LIBARTBASE_BASE_HIDDENAPI_FLAGS_H_ |