diff options
author | 2018-10-23 12:50:02 +0100 | |
---|---|---|
committer | 2018-10-30 11:04:29 +0000 | |
commit | 47cd272d15f41109b3dacb21cfa509d18a03e011 (patch) | |
tree | f2693adde283631362b3acc2c573d7280632621f | |
parent | 6e32b0059b4c3073c601018da3ca315ad568525a (diff) |
Remove HiddenApiAccessFlags, move content to hiddenapi::
Hiddenapi code in runtime/ has all code in the hiddenapi:: namespace
instead of using a class as a wrapper. Refactor HiddenApiAccessFlags
for consistency. Also turn ApiList into `enum class` for stricter
type checks.
Test: m test-art
Change-Id: Ifb3c443ea43860476abd4fd3d4934cd14e2cdcc1
-rw-r--r-- | libdexfile/dex/class_accessor-inl.h | 4 | ||||
-rw-r--r-- | libdexfile/dex/dex_file_verifier.cc | 2 | ||||
-rw-r--r-- | libdexfile/dex/hidden_api_access_flags.h | 75 | ||||
-rw-r--r-- | runtime/art_field.h | 4 | ||||
-rw-r--r-- | runtime/art_method-inl.h | 16 | ||||
-rw-r--r-- | runtime/art_method.cc | 4 | ||||
-rw-r--r-- | runtime/art_method.h | 2 | ||||
-rw-r--r-- | runtime/class_linker.cc | 8 | ||||
-rw-r--r-- | runtime/hidden_api.cc | 19 | ||||
-rw-r--r-- | runtime/hidden_api.h | 14 | ||||
-rw-r--r-- | runtime/hidden_api_test.cc | 32 | ||||
-rw-r--r-- | tools/hiddenapi/hiddenapi.cc | 21 | ||||
-rw-r--r-- | tools/hiddenapi/hiddenapi_test.cc | 86 | ||||
-rw-r--r-- | tools/veridex/hidden_api.h | 14 | ||||
-rw-r--r-- | tools/veridex/hidden_api_finder.cc | 14 | ||||
-rw-r--r-- | tools/veridex/precise_hidden_api_finder.cc | 8 | ||||
-rw-r--r-- | tools/veridex/veridex.cc | 9 |
17 files changed, 166 insertions, 166 deletions
diff --git a/libdexfile/dex/class_accessor-inl.h b/libdexfile/dex/class_accessor-inl.h index 40bca564ae..e9e3a98224 100644 --- a/libdexfile/dex/class_accessor-inl.h +++ b/libdexfile/dex/class_accessor-inl.h @@ -65,7 +65,7 @@ inline void ClassAccessor::Method::Read() { code_off_ = DecodeUnsignedLeb128(&ptr_pos_); if (hiddenapi_ptr_pos_ != nullptr) { hiddenapi_flags_ = DecodeUnsignedLeb128(&hiddenapi_ptr_pos_); - DCHECK(HiddenApiAccessFlags::AreValidFlags(hiddenapi_flags_)); + DCHECK(hiddenapi::AreValidFlags(hiddenapi_flags_)); } } @@ -74,7 +74,7 @@ inline void ClassAccessor::Field::Read() { access_flags_ = DecodeUnsignedLeb128(&ptr_pos_); if (hiddenapi_ptr_pos_ != nullptr) { hiddenapi_flags_ = DecodeUnsignedLeb128(&hiddenapi_ptr_pos_); - DCHECK(HiddenApiAccessFlags::AreValidFlags(hiddenapi_flags_)); + DCHECK(hiddenapi::AreValidFlags(hiddenapi_flags_)); } } diff --git a/libdexfile/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc index 43471c3116..4d33cd59f7 100644 --- a/libdexfile/dex/dex_file_verifier.cc +++ b/libdexfile/dex/dex_file_verifier.cc @@ -1632,7 +1632,7 @@ bool DexFileVerifier::CheckIntraHiddenapiClassData() { failure = true; return; } - if (!HiddenApiAccessFlags::AreValidFlags(decoded_flags)) { + if (!hiddenapi::AreValidFlags(decoded_flags)) { ErrorStringPrintf("Hiddenapi class data flags invalid (%u) for %s %i", decoded_flags, member_type, member.GetIndex()); failure = true; diff --git a/libdexfile/dex/hidden_api_access_flags.h b/libdexfile/dex/hidden_api_access_flags.h index 837056be80..fd5c8654c3 100644 --- a/libdexfile/dex/hidden_api_access_flags.h +++ b/libdexfile/dex/hidden_api_access_flags.h @@ -21,8 +21,6 @@ #include "base/macros.h" #include "dex/modifiers.h" -namespace art { - /* This class is used for encoding and decoding access flags of class members * from the boot class path. These access flags might contain additional two bits * of information on whether the given class member should be hidden from apps @@ -38,64 +36,65 @@ namespace art { * the ApiList enum values. * */ -class HiddenApiAccessFlags { - public: - enum ApiList { - kWhitelist = 0, - kLightGreylist, - kDarkGreylist, - kBlacklist, - kNoList, - }; - static ALWAYS_INLINE ApiList DecodeFromRuntime(uint32_t runtime_access_flags) { - // This is used in the fast path, only DCHECK here. - DCHECK_EQ(runtime_access_flags & kAccIntrinsic, 0u); - uint32_t int_value = (runtime_access_flags & kAccHiddenApiBits) >> kAccFlagsShift; - return static_cast<ApiList>(int_value); - } +namespace art { +namespace hiddenapi { - static ALWAYS_INLINE uint32_t EncodeForRuntime(uint32_t runtime_access_flags, ApiList value) { - CHECK_EQ(runtime_access_flags & kAccIntrinsic, 0u); +enum class ApiList { + kWhitelist = 0, + kLightGreylist, + kDarkGreylist, + kBlacklist, + kNoList, +}; - uint32_t hidden_api_flags = static_cast<uint32_t>(value) << kAccFlagsShift; - CHECK_EQ(hidden_api_flags & ~kAccHiddenApiBits, 0u); +static const int kAccFlagsShift = CTZ(kAccHiddenApiBits); +static_assert(IsPowerOfTwo((kAccHiddenApiBits >> kAccFlagsShift) + 1), + "kAccHiddenApiBits are not continuous"); - runtime_access_flags &= ~kAccHiddenApiBits; - return runtime_access_flags | hidden_api_flags; - } +inline ApiList DecodeFromRuntime(uint32_t runtime_access_flags) { + // This is used in the fast path, only DCHECK here. + DCHECK_EQ(runtime_access_flags & kAccIntrinsic, 0u); + uint32_t int_value = (runtime_access_flags & kAccHiddenApiBits) >> kAccFlagsShift; + return static_cast<ApiList>(int_value); +} - static ALWAYS_INLINE bool AreValidFlags(uint32_t flags) { - return flags <= static_cast<uint32_t>(kBlacklist); - } +inline uint32_t EncodeForRuntime(uint32_t runtime_access_flags, ApiList value) { + CHECK_EQ(runtime_access_flags & kAccIntrinsic, 0u); - private: - static const int kAccFlagsShift = CTZ(kAccHiddenApiBits); - static_assert(IsPowerOfTwo((kAccHiddenApiBits >> kAccFlagsShift) + 1), - "kAccHiddenApiBits are not continuous"); -}; + uint32_t hidden_api_flags = static_cast<uint32_t>(value) << kAccFlagsShift; + CHECK_EQ(hidden_api_flags & ~kAccHiddenApiBits, 0u); + + runtime_access_flags &= ~kAccHiddenApiBits; + return runtime_access_flags | hidden_api_flags; +} + +inline bool AreValidFlags(uint32_t flags) { + return flags <= static_cast<uint32_t>(ApiList::kBlacklist); +} -inline std::ostream& operator<<(std::ostream& os, HiddenApiAccessFlags::ApiList value) { +inline std::ostream& operator<<(std::ostream& os, ApiList value) { switch (value) { - case HiddenApiAccessFlags::kWhitelist: + case ApiList::kWhitelist: os << "whitelist"; break; - case HiddenApiAccessFlags::kLightGreylist: + case ApiList::kLightGreylist: os << "light greylist"; break; - case HiddenApiAccessFlags::kDarkGreylist: + case ApiList::kDarkGreylist: os << "dark greylist"; break; - case HiddenApiAccessFlags::kBlacklist: + case ApiList::kBlacklist: os << "blacklist"; break; - case HiddenApiAccessFlags::kNoList: + case ApiList::kNoList: os << "no list"; break; } return os; } +} // namespace hiddenapi } // namespace art diff --git a/runtime/art_field.h b/runtime/art_field.h index 5afd000b05..dc7f985b91 100644 --- a/runtime/art_field.h +++ b/runtime/art_field.h @@ -180,8 +180,8 @@ class ArtField final { return (GetAccessFlags() & kAccVolatile) != 0; } - HiddenApiAccessFlags::ApiList GetHiddenApiAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_) { - return HiddenApiAccessFlags::DecodeFromRuntime(GetAccessFlags()); + hiddenapi::ApiList GetHiddenApiAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_) { + return hiddenapi::DecodeFromRuntime(GetAccessFlags()); } // Returns an instance field with this offset in the given class or null if not found. diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index f693524a6c..e9c17eeab5 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -367,7 +367,7 @@ inline bool ArtMethod::HasSingleImplementation() { return (GetAccessFlags() & kAccSingleImplementation) != 0; } -inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags() +inline hiddenapi::ApiList ArtMethod::GetHiddenApiAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_) { if (UNLIKELY(IsIntrinsic())) { switch (static_cast<Intrinsics>(GetIntrinsic())) { @@ -407,7 +407,7 @@ inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags() // Note that the DCHECK currently won't fail if the dex methods are // whitelisted, e.g. in the core image (b/77733081). As a result, we // might print warnings but we won't change the semantics. - return HiddenApiAccessFlags::kLightGreylist; + return hiddenapi::ApiList::kLightGreylist; case Intrinsics::kStringNewStringFromBytes: case Intrinsics::kStringNewStringFromChars: case Intrinsics::kStringNewStringFromString: @@ -417,7 +417,7 @@ inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags() case Intrinsics::kMemoryPokeIntNative: case Intrinsics::kMemoryPokeLongNative: case Intrinsics::kMemoryPokeShortNative: - return HiddenApiAccessFlags::kDarkGreylist; + return hiddenapi::ApiList::kDarkGreylist; case Intrinsics::kVarHandleFullFence: case Intrinsics::kVarHandleAcquireFence: case Intrinsics::kVarHandleReleaseFence: @@ -460,13 +460,13 @@ inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags() // whitelisted, e.g. in the core image (b/77733081). Given that they are // exclusively VarHandle intrinsics, they should not be used outside // tests that do not enable hidden API checks. - return HiddenApiAccessFlags::kBlacklist; + return hiddenapi::ApiList::kBlacklist; default: // Remaining intrinsics are public API. We DCHECK that in SetIntrinsic(). - return HiddenApiAccessFlags::kWhitelist; + return hiddenapi::ApiList::kWhitelist; } } else { - return HiddenApiAccessFlags::DecodeFromRuntime(GetAccessFlags()); + return hiddenapi::DecodeFromRuntime(GetAccessFlags()); } } @@ -492,7 +492,7 @@ inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { bool is_default_conflict = IsDefaultConflicting(); bool is_compilable = IsCompilable(); bool must_count_locks = MustCountLocks(); - HiddenApiAccessFlags::ApiList hidden_api_flags = GetHiddenApiAccessFlags(); + hiddenapi::ApiList hidden_api_flags = GetHiddenApiAccessFlags(); SetAccessFlags(new_value); DCHECK_EQ(java_flags, (GetAccessFlags() & kAccJavaFlagsMask)); DCHECK_EQ(is_constructor, IsConstructor()); @@ -512,7 +512,7 @@ inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { // these because (a) warnings on greylist do not change semantics, and // (b) only VarHandle intrinsics are blacklisted at the moment and they // should not be used outside tests with disabled API checks. - if (hidden_api_flags != HiddenApiAccessFlags::kWhitelist) { + if (hidden_api_flags != hiddenapi::ApiList::kWhitelist) { DCHECK_EQ(hidden_api_flags, GetHiddenApiAccessFlags()) << PrettyMethod(); } } else { diff --git a/runtime/art_method.cc b/runtime/art_method.cc index 4a19b108ab..9bf31edd52 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -688,13 +688,13 @@ void ArtMethod::SetNotIntrinsic() { } // Query the hidden API access flags of the intrinsic. - HiddenApiAccessFlags::ApiList intrinsic_api_list = GetHiddenApiAccessFlags(); + hiddenapi::ApiList intrinsic_api_list = GetHiddenApiAccessFlags(); // Clear intrinsic-related access flags. ClearAccessFlags(kAccIntrinsic | kAccIntrinsicBits); // Re-apply hidden API access flags now that the method is not an intrinsic. - SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(GetAccessFlags(), intrinsic_api_list)); + SetAccessFlags(hiddenapi::EncodeForRuntime(GetAccessFlags(), intrinsic_api_list)); DCHECK_EQ(GetHiddenApiAccessFlags(), intrinsic_api_list); } diff --git a/runtime/art_method.h b/runtime/art_method.h index 18ddcc05c5..e56f3fd6bc 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -326,7 +326,7 @@ class ArtMethod final { AddAccessFlags(kAccMustCountLocks); } - HiddenApiAccessFlags::ApiList GetHiddenApiAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_); + hiddenapi::ApiList GetHiddenApiAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_); // Returns true if this method could be overridden by a default method. bool IsOverridableByDefaultMethod() REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 0247e4e076..151f7b8565 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -3395,8 +3395,8 @@ void ClassLinker::LoadField(const ClassAccessor::Field& field, // also set its runtime hidden API access flags. uint32_t access_flags = field.GetAccessFlags(); if (klass->IsBootStrapClassLoaded()) { - access_flags = HiddenApiAccessFlags::EncodeForRuntime( - access_flags, static_cast<HiddenApiAccessFlags::ApiList>(field.GetHiddenapiFlags())); + access_flags = hiddenapi::EncodeForRuntime( + access_flags, static_cast<hiddenapi::ApiList>(field.GetHiddenapiFlags())); } dst->SetAccessFlags(access_flags); } @@ -3418,8 +3418,8 @@ void ClassLinker::LoadMethod(const DexFile& dex_file, // also set its runtime hidden API access flags. uint32_t access_flags = method.GetAccessFlags(); if (klass->IsBootStrapClassLoaded()) { - access_flags = HiddenApiAccessFlags::EncodeForRuntime( - access_flags, static_cast<HiddenApiAccessFlags::ApiList>(method.GetHiddenapiFlags())); + access_flags = hiddenapi::EncodeForRuntime( + access_flags, static_cast<hiddenapi::ApiList>(method.GetHiddenapiFlags())); } if (UNLIKELY(strcmp("finalize", method_name) == 0)) { diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc index 5729800bb0..f3552765c5 100644 --- a/runtime/hidden_api.cc +++ b/runtime/hidden_api.cc @@ -60,14 +60,14 @@ static inline std::ostream& operator<<(std::ostream& os, AccessMethod value) { return os; } -static constexpr bool EnumsEqual(EnforcementPolicy policy, HiddenApiAccessFlags::ApiList apiList) { +static constexpr bool EnumsEqual(EnforcementPolicy policy, hiddenapi::ApiList apiList) { return static_cast<int>(policy) == static_cast<int>(apiList); } // GetMemberAction-related static_asserts. static_assert( - EnumsEqual(EnforcementPolicy::kDarkGreyAndBlackList, HiddenApiAccessFlags::kDarkGreylist) && - EnumsEqual(EnforcementPolicy::kBlacklistOnly, HiddenApiAccessFlags::kBlacklist), + EnumsEqual(EnforcementPolicy::kDarkGreyAndBlackList, hiddenapi::ApiList::kDarkGreylist) && + EnumsEqual(EnforcementPolicy::kBlacklistOnly, hiddenapi::ApiList::kBlacklist), "Mismatch between EnforcementPolicy and ApiList enums"); static_assert( EnforcementPolicy::kJustWarn < EnforcementPolicy::kDarkGreyAndBlackList && @@ -133,8 +133,7 @@ void MemberSignature::Dump(std::ostream& os) const { } } -void MemberSignature::WarnAboutAccess(AccessMethod access_method, - HiddenApiAccessFlags::ApiList list) { +void MemberSignature::WarnAboutAccess(AccessMethod access_method, hiddenapi::ApiList list) { LOG(WARNING) << "Accessing hidden " << (type_ == kField ? "field " : "method ") << Dumpable<MemberSignature>(*this) << " (" << list << ", " << access_method << ")"; } @@ -200,14 +199,14 @@ template<typename T> static ALWAYS_INLINE void MaybeWhitelistMember(Runtime* runtime, T* member) REQUIRES_SHARED(Locks::mutator_lock_) { if (CanUpdateMemberAccessFlags(member) && runtime->ShouldDedupeHiddenApiWarnings()) { - member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime( - member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist)); + member->SetAccessFlags(hiddenapi::EncodeForRuntime( + member->GetAccessFlags(), hiddenapi::ApiList::kWhitelist)); } } template<typename T> Action GetMemberActionImpl(T* member, - HiddenApiAccessFlags::ApiList api_list, + hiddenapi::ApiList api_list, Action action, AccessMethod access_method) { DCHECK_NE(action, kAllow); @@ -276,11 +275,11 @@ Action GetMemberActionImpl(T* member, // Need to instantiate this. template Action GetMemberActionImpl<ArtField>(ArtField* member, - HiddenApiAccessFlags::ApiList api_list, + hiddenapi::ApiList api_list, Action action, AccessMethod access_method); template Action GetMemberActionImpl<ArtMethod>(ArtMethod* member, - HiddenApiAccessFlags::ApiList api_list, + hiddenapi::ApiList api_list, Action action, AccessMethod access_method); } // namespace detail diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h index c16e7f347e..57f1a599cf 100644 --- a/runtime/hidden_api.h +++ b/runtime/hidden_api.h @@ -68,8 +68,8 @@ enum AccessContextFlags { kAccessDenied = 1 << 1, }; -inline Action GetActionFromAccessFlags(HiddenApiAccessFlags::ApiList api_list) { - if (api_list == HiddenApiAccessFlags::kWhitelist) { +inline Action GetActionFromAccessFlags(ApiList api_list) { + if (api_list == ApiList::kWhitelist) { return kAllow; } @@ -85,9 +85,9 @@ inline Action GetActionFromAccessFlags(HiddenApiAccessFlags::ApiList api_list) { } DCHECK(policy >= EnforcementPolicy::kDarkGreyAndBlackList); // The logic below relies on equality of values in the enums EnforcementPolicy and - // HiddenApiAccessFlags::ApiList, and their ordering. Assertions are in hidden_api.cc. + // ApiList, and their ordering. Assertions are in hidden_api.cc. if (static_cast<int>(policy) > static_cast<int>(api_list)) { - return api_list == HiddenApiAccessFlags::kDarkGreylist + return api_list == ApiList::kDarkGreylist ? kAllowButWarnAndToast : kAllowButWarn; } else { @@ -144,14 +144,14 @@ class MemberSignature { bool IsExempted(const std::vector<std::string>& exemptions); - void WarnAboutAccess(AccessMethod access_method, HiddenApiAccessFlags::ApiList list); + void WarnAboutAccess(AccessMethod access_method, ApiList list); void LogAccessToEventLog(AccessMethod access_method, Action action_taken); }; template<typename T> Action GetMemberActionImpl(T* member, - HiddenApiAccessFlags::ApiList api_list, + ApiList api_list, Action action, AccessMethod access_method) REQUIRES_SHARED(Locks::mutator_lock_); @@ -208,7 +208,7 @@ inline Action GetMemberAction(T* member, // cannot change Java semantics. We should, however, decode the access flags // once and use it throughout this function, otherwise we may get inconsistent // results, e.g. print whitelist warnings (b/78327881). - HiddenApiAccessFlags::ApiList api_list = member->GetHiddenApiAccessFlags(); + ApiList api_list = member->GetHiddenApiAccessFlags(); Action action = GetActionFromAccessFlags(member->GetHiddenApiAccessFlags()); if (action == kAllow) { diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc index 4c7efe666f..1727af016c 100644 --- a/runtime/hidden_api_test.cc +++ b/runtime/hidden_api_test.cc @@ -89,39 +89,39 @@ class HiddenApiTest : public CommonRuntimeTest { TEST_F(HiddenApiTest, CheckGetActionFromRuntimeFlags) { runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kNoChecks); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kWhitelist), hiddenapi::kAllow); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kLightGreylist), hiddenapi::kAllow); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kDarkGreylist), hiddenapi::kAllow); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kBlacklist), hiddenapi::kAllow); + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kWhitelist), hiddenapi::kAllow); + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kLightGreylist), hiddenapi::kAllow); + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kDarkGreylist), hiddenapi::kAllow); + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kBlacklist), hiddenapi::kAllow); runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kJustWarn); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kWhitelist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kWhitelist), hiddenapi::kAllow); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kLightGreylist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kLightGreylist), hiddenapi::kAllowButWarn); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kDarkGreylist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kDarkGreylist), hiddenapi::kAllowButWarn); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kBlacklist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kBlacklist), hiddenapi::kAllowButWarn); runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kDarkGreyAndBlackList); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kWhitelist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kWhitelist), hiddenapi::kAllow); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kLightGreylist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kLightGreylist), hiddenapi::kAllowButWarn); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kDarkGreylist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kDarkGreylist), hiddenapi::kDeny); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kBlacklist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kBlacklist), hiddenapi::kDeny); runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kBlacklistOnly); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kWhitelist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kWhitelist), hiddenapi::kAllow); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kLightGreylist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kLightGreylist), hiddenapi::kAllowButWarn); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kDarkGreylist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kDarkGreylist), hiddenapi::kAllowButWarnAndToast); - ASSERT_EQ(GetActionFromAccessFlags(HiddenApiAccessFlags::kBlacklist), + ASSERT_EQ(GetActionFromAccessFlags(hiddenapi::ApiList::kBlacklist), hiddenapi::kDeny); } diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc index 06bea1a3bf..f61b3e8038 100644 --- a/tools/hiddenapi/hiddenapi.cc +++ b/tools/hiddenapi/hiddenapi.cc @@ -599,9 +599,10 @@ class HiddenapiClassDataBuilder final { // Append flags at the end of the data struct. This should be called // between BeginClassDef and EndClassDef in the order of appearance of // fields/methods in the class data stream. - void WriteFlags(uint32_t flags) { - EncodeUnsignedLeb128(&data_, flags); - class_def_has_non_zero_flags_ |= (flags != 0u); + void WriteFlags(hiddenapi::ApiList flags) { + uint32_t uint_flags = static_cast<uint32_t>(flags); + EncodeUnsignedLeb128(&data_, uint_flags); + class_def_has_non_zero_flags_ |= (uint_flags != 0u); } // Return backing data, assuming that all flags have been written. @@ -931,10 +932,10 @@ class HiddenApi final { } // Load dex signatures. - std::map<std::string, HiddenApiAccessFlags::ApiList> api_list; - OpenApiFile(light_greylist_path_, api_list, HiddenApiAccessFlags::kLightGreylist); - OpenApiFile(dark_greylist_path_, api_list, HiddenApiAccessFlags::kDarkGreylist); - OpenApiFile(blacklist_path_, api_list, HiddenApiAccessFlags::kBlacklist); + std::map<std::string, hiddenapi::ApiList> api_list; + OpenApiFile(light_greylist_path_, api_list, hiddenapi::ApiList::kLightGreylist); + OpenApiFile(dark_greylist_path_, api_list, hiddenapi::ApiList::kDarkGreylist); + OpenApiFile(blacklist_path_, api_list, hiddenapi::ApiList::kBlacklist); // Iterate over input dex files and insert HiddenapiClassData sections. for (size_t i = 0; i < boot_dex_paths_.size(); ++i) { @@ -954,7 +955,7 @@ class HiddenApi final { // TODO: Load whitelist and CHECK that entry was found. auto it = api_list.find(boot_member.GetApiEntry()); builder.WriteFlags( - (it == api_list.end()) ? HiddenApiAccessFlags::kWhitelist : it->second); + (it == api_list.end()) ? hiddenapi::ApiList::kWhitelist : it->second); }; auto fn_field = [&](const ClassAccessor::Field& boot_field) { fn_shared(DexMember(boot_class, boot_field)); @@ -974,8 +975,8 @@ class HiddenApi final { } void OpenApiFile(const std::string& path, - std::map<std::string, HiddenApiAccessFlags::ApiList>& api_list, - HiddenApiAccessFlags::ApiList membership) { + std::map<std::string, hiddenapi::ApiList>& api_list, + hiddenapi::ApiList membership) { if (path.empty()) { return; } diff --git a/tools/hiddenapi/hiddenapi_test.cc b/tools/hiddenapi/hiddenapi_test.cc index cdf797e598..0010b78436 100644 --- a/tools/hiddenapi/hiddenapi_test.cc +++ b/tools/hiddenapi/hiddenapi_test.cc @@ -124,15 +124,15 @@ class HiddenApiTest : public CommonRuntimeTest { return *found; } - HiddenApiAccessFlags::ApiList GetFieldHiddenFlags(const char* name, - uint32_t expected_visibility, - const DexFile::ClassDef& class_def, - const DexFile& dex_file) { + hiddenapi::ApiList GetFieldHiddenFlags(const char* name, + uint32_t expected_visibility, + const DexFile::ClassDef& class_def, + const DexFile& dex_file) { ClassAccessor accessor(dex_file, class_def, /* parse hiddenapi flags */ true); CHECK(accessor.HasClassData()) << "Class " << accessor.GetDescriptor() << " has no data"; if (!accessor.HasHiddenapiClassData()) { - return HiddenApiAccessFlags::kWhitelist; + return hiddenapi::ApiList::kWhitelist; } for (const ClassAccessor::Field& field : accessor.GetFields()) { @@ -141,7 +141,7 @@ class HiddenApiTest : public CommonRuntimeTest { const uint32_t actual_visibility = field.GetAccessFlags() & kAccVisibilityFlags; CHECK_EQ(actual_visibility, expected_visibility) << "Field " << name << " in class " << accessor.GetDescriptor(); - return static_cast<HiddenApiAccessFlags::ApiList>(field.GetHiddenapiFlags()); + return static_cast<hiddenapi::ApiList>(field.GetHiddenapiFlags()); } } @@ -150,16 +150,16 @@ class HiddenApiTest : public CommonRuntimeTest { UNREACHABLE(); } - HiddenApiAccessFlags::ApiList GetMethodHiddenFlags(const char* name, - uint32_t expected_visibility, - bool expected_native, - const DexFile::ClassDef& class_def, - const DexFile& dex_file) { + hiddenapi::ApiList GetMethodHiddenFlags(const char* name, + uint32_t expected_visibility, + bool expected_native, + const DexFile::ClassDef& class_def, + const DexFile& dex_file) { ClassAccessor accessor(dex_file, class_def, /* parse hiddenapi flags */ true); CHECK(accessor.HasClassData()) << "Class " << accessor.GetDescriptor() << " has no data"; if (!accessor.HasHiddenapiClassData()) { - return HiddenApiAccessFlags::kWhitelist; + return hiddenapi::ApiList::kWhitelist; } for (const ClassAccessor::Method& method : accessor.GetMethods()) { @@ -170,7 +170,7 @@ class HiddenApiTest : public CommonRuntimeTest { const uint32_t actual_visibility = method.GetAccessFlags() & kAccVisibilityFlags; CHECK_EQ(actual_visibility, expected_visibility) << "Method " << name << " in class " << accessor.GetDescriptor(); - return static_cast<HiddenApiAccessFlags::ApiList>(method.GetHiddenapiFlags()); + return static_cast<hiddenapi::ApiList>(method.GetHiddenapiFlags()); } } @@ -179,20 +179,20 @@ class HiddenApiTest : public CommonRuntimeTest { UNREACHABLE(); } - HiddenApiAccessFlags::ApiList GetIFieldHiddenFlags(const DexFile& dex_file) { + hiddenapi::ApiList GetIFieldHiddenFlags(const DexFile& dex_file) { return GetFieldHiddenFlags("ifield", kAccPublic, FindClass("LMain;", dex_file), dex_file); } - HiddenApiAccessFlags::ApiList GetSFieldHiddenFlags(const DexFile& dex_file) { + hiddenapi::ApiList GetSFieldHiddenFlags(const DexFile& dex_file) { return GetFieldHiddenFlags("sfield", kAccPrivate, FindClass("LMain;", dex_file), dex_file); } - HiddenApiAccessFlags::ApiList GetIMethodHiddenFlags(const DexFile& dex_file) { + hiddenapi::ApiList GetIMethodHiddenFlags(const DexFile& dex_file) { return GetMethodHiddenFlags( "imethod", 0, /* expected_native= */ false, FindClass("LMain;", dex_file), dex_file); } - HiddenApiAccessFlags::ApiList GetSMethodHiddenFlags(const DexFile& dex_file) { + hiddenapi::ApiList GetSMethodHiddenFlags(const DexFile& dex_file) { return GetMethodHiddenFlags("smethod", kAccPublic, /* expected_native= */ false, @@ -200,7 +200,7 @@ class HiddenApiTest : public CommonRuntimeTest { dex_file); } - HiddenApiAccessFlags::ApiList GetINMethodHiddenFlags(const DexFile& dex_file) { + hiddenapi::ApiList GetINMethodHiddenFlags(const DexFile& dex_file) { return GetMethodHiddenFlags("inmethod", kAccPublic, /* expected_native= */ true, @@ -208,7 +208,7 @@ class HiddenApiTest : public CommonRuntimeTest { dex_file); } - HiddenApiAccessFlags::ApiList GetSNMethodHiddenFlags(const DexFile& dex_file) { + hiddenapi::ApiList GetSNMethodHiddenFlags(const DexFile& dex_file) { return GetMethodHiddenFlags("snmethod", kAccProtected, /* expected_native= */ true, @@ -224,7 +224,7 @@ TEST_F(HiddenApiTest, InstanceFieldNoMatch) { OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetIFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kWhitelist, GetIFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceFieldLightGreylistMatch) { @@ -234,7 +234,7 @@ TEST_F(HiddenApiTest, InstanceFieldLightGreylistMatch) { OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetIFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kLightGreylist, GetIFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceFieldDarkGreylistMatch) { @@ -244,7 +244,7 @@ TEST_F(HiddenApiTest, InstanceFieldDarkGreylistMatch) { OpenStream(blacklist) << "LMain;->ifield:LBadType3;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetIFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kDarkGreylist, GetIFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceFieldBlacklistMatch) { @@ -254,7 +254,7 @@ TEST_F(HiddenApiTest, InstanceFieldBlacklistMatch) { OpenStream(blacklist) << "LMain;->ifield:I" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetIFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kBlacklist, GetIFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceFieldTwoListsMatch1) { @@ -291,7 +291,7 @@ TEST_F(HiddenApiTest, StaticFieldNoMatch) { OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetSFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kWhitelist, GetSFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticFieldLightGreylistMatch) { @@ -301,7 +301,7 @@ TEST_F(HiddenApiTest, StaticFieldLightGreylistMatch) { OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetSFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kLightGreylist, GetSFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticFieldDarkGreylistMatch) { @@ -311,7 +311,7 @@ TEST_F(HiddenApiTest, StaticFieldDarkGreylistMatch) { OpenStream(blacklist) << "LMain;->sfield:LBadType3;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetSFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kDarkGreylist, GetSFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticFieldBlacklistMatch) { @@ -321,7 +321,7 @@ TEST_F(HiddenApiTest, StaticFieldBlacklistMatch) { OpenStream(blacklist) << "LMain;->sfield:Ljava/lang/Object;" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetSFieldHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kBlacklist, GetSFieldHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticFieldTwoListsMatch1) { @@ -358,7 +358,7 @@ TEST_F(HiddenApiTest, InstanceMethodNoMatch) { OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetIMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kWhitelist, GetIMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceMethodLightGreylistMatch) { @@ -368,7 +368,7 @@ TEST_F(HiddenApiTest, InstanceMethodLightGreylistMatch) { OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetIMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kLightGreylist, GetIMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceMethodDarkGreylistMatch) { @@ -378,7 +378,7 @@ TEST_F(HiddenApiTest, InstanceMethodDarkGreylistMatch) { OpenStream(blacklist) << "LMain;->imethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetIMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kDarkGreylist, GetIMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceMethodBlacklistMatch) { @@ -388,7 +388,7 @@ TEST_F(HiddenApiTest, InstanceMethodBlacklistMatch) { OpenStream(blacklist) << "LMain;->imethod(J)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetIMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kBlacklist, GetIMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceMethodTwoListsMatch1) { @@ -425,7 +425,7 @@ TEST_F(HiddenApiTest, StaticMethodNoMatch) { OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetSMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kWhitelist, GetSMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticMethodLightGreylistMatch) { @@ -435,7 +435,7 @@ TEST_F(HiddenApiTest, StaticMethodLightGreylistMatch) { OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetSMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kLightGreylist, GetSMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticMethodDarkGreylistMatch) { @@ -445,7 +445,7 @@ TEST_F(HiddenApiTest, StaticMethodDarkGreylistMatch) { OpenStream(blacklist) << "LMain;->smethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetSMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kDarkGreylist, GetSMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticMethodBlacklistMatch) { @@ -455,7 +455,7 @@ TEST_F(HiddenApiTest, StaticMethodBlacklistMatch) { OpenStream(blacklist) << "LMain;->smethod(Ljava/lang/Object;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetSMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kBlacklist, GetSMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticMethodTwoListsMatch1) { @@ -492,7 +492,7 @@ TEST_F(HiddenApiTest, InstanceNativeMethodNoMatch) { OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetINMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kWhitelist, GetINMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceNativeMethodLightGreylistMatch) { @@ -502,7 +502,7 @@ TEST_F(HiddenApiTest, InstanceNativeMethodLightGreylistMatch) { OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetINMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kLightGreylist, GetINMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceNativeMethodDarkGreylistMatch) { @@ -512,7 +512,7 @@ TEST_F(HiddenApiTest, InstanceNativeMethodDarkGreylistMatch) { OpenStream(blacklist) << "LMain;->inmethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetINMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kDarkGreylist, GetINMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceNativeMethodBlacklistMatch) { @@ -522,7 +522,7 @@ TEST_F(HiddenApiTest, InstanceNativeMethodBlacklistMatch) { OpenStream(blacklist) << "LMain;->inmethod(C)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetINMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kBlacklist, GetINMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, InstanceNativeMethodTwoListsMatch1) { @@ -559,7 +559,7 @@ TEST_F(HiddenApiTest, StaticNativeMethodNoMatch) { OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kWhitelist, GetSNMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kWhitelist, GetSNMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticNativeMethodLightGreylistMatch) { @@ -569,7 +569,7 @@ TEST_F(HiddenApiTest, StaticNativeMethodLightGreylistMatch) { OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kLightGreylist, GetSNMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kLightGreylist, GetSNMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticNativeMethodDarkGreylistMatch) { @@ -579,7 +579,7 @@ TEST_F(HiddenApiTest, StaticNativeMethodDarkGreylistMatch) { OpenStream(blacklist) << "LMain;->snmethod(LBadType3;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kDarkGreylist, GetSNMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kDarkGreylist, GetSNMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticNativeMethodBlacklistMatch) { @@ -589,7 +589,7 @@ TEST_F(HiddenApiTest, StaticNativeMethodBlacklistMatch) { OpenStream(blacklist) << "LMain;->snmethod(Ljava/lang/Integer;)V" << std::endl; auto dex_file = RunHiddenApi(light_greylist, dark_greylist, blacklist, {}, &dex); ASSERT_NE(dex_file.get(), nullptr); - ASSERT_EQ(HiddenApiAccessFlags::kBlacklist, GetSNMethodHiddenFlags(*dex_file)); + ASSERT_EQ(hiddenapi::ApiList::kBlacklist, GetSNMethodHiddenFlags(*dex_file)); } TEST_F(HiddenApiTest, StaticNativeMethodTwoListsMatch1) { diff --git a/tools/veridex/hidden_api.h b/tools/veridex/hidden_api.h index 68485bdbd5..da9f058cb4 100644 --- a/tools/veridex/hidden_api.h +++ b/tools/veridex/hidden_api.h @@ -43,22 +43,22 @@ class HiddenApi { FillList(whitelist, whitelist_); } - HiddenApiAccessFlags::ApiList GetApiList(const std::string& name) const { + hiddenapi::ApiList GetApiList(const std::string& name) const { if (IsInList(name, blacklist_)) { - return HiddenApiAccessFlags::kBlacklist; + return hiddenapi::ApiList::kBlacklist; } else if (IsInList(name, dark_greylist_)) { - return HiddenApiAccessFlags::kDarkGreylist; + return hiddenapi::ApiList::kDarkGreylist; } else if (IsInList(name, light_greylist_)) { - return HiddenApiAccessFlags::kLightGreylist; + return hiddenapi::ApiList::kLightGreylist; } else if (IsInList(name, whitelist_)) { - return HiddenApiAccessFlags::kWhitelist; + return hiddenapi::ApiList::kWhitelist; } else { - return HiddenApiAccessFlags::kNoList; + return hiddenapi::ApiList::kNoList; } } bool IsInAnyList(const std::string& name) const { - return GetApiList(name) != HiddenApiAccessFlags::kNoList; + return GetApiList(name) != hiddenapi::ApiList::kNoList; } static std::string GetApiMethodName(const DexFile& dex_file, uint32_t method_index); diff --git a/tools/veridex/hidden_api_finder.cc b/tools/veridex/hidden_api_finder.cc index a8c53b31f5..e24d151069 100644 --- a/tools/veridex/hidden_api_finder.cc +++ b/tools/veridex/hidden_api_finder.cc @@ -179,8 +179,8 @@ void HiddenApiFinder::Dump(std::ostream& os, // Dump methods from hidden APIs linked against. for (const std::pair<const std::string, std::vector<MethodReference>>& pair : method_locations_) { - HiddenApiAccessFlags::ApiList api_list = hidden_api_.GetApiList(pair.first); - stats->api_counts[api_list]++; + hiddenapi::ApiList api_list = hidden_api_.GetApiList(pair.first); + stats->api_counts[static_cast<unsigned>(api_list)]++; os << "#" << ++stats->count << ": Linking " << api_list << " " << pair.first << " use(s):"; os << std::endl; HiddenApiFinder::DumpReferences(os, pair.second); @@ -190,8 +190,8 @@ void HiddenApiFinder::Dump(std::ostream& os, // Dump fields from hidden APIs linked against. for (const std::pair<const std::string, std::vector<MethodReference>>& pair : field_locations_) { - HiddenApiAccessFlags::ApiList api_list = hidden_api_.GetApiList(pair.first); - stats->api_counts[api_list]++; + hiddenapi::ApiList api_list = hidden_api_.GetApiList(pair.first); + stats->api_counts[static_cast<unsigned>(api_list)]++; os << "#" << ++stats->count << ": Linking " << api_list << " " << pair.first << " use(s):"; os << std::endl; HiddenApiFinder::DumpReferences(os, pair.second); @@ -203,9 +203,9 @@ void HiddenApiFinder::Dump(std::ostream& os, for (const std::string& cls : classes_) { for (const std::string& name : strings_) { std::string full_name = cls + "->" + name; - HiddenApiAccessFlags::ApiList api_list = hidden_api_.GetApiList(full_name); - stats->api_counts[api_list]++; - if (api_list != HiddenApiAccessFlags::kNoList) { + hiddenapi::ApiList api_list = hidden_api_.GetApiList(full_name); + stats->api_counts[static_cast<unsigned>(api_list)]++; + if (api_list != hiddenapi::ApiList::kNoList) { stats->reflection_count++; os << "#" << ++stats->count << ": Reflection " << api_list << " " << full_name << " potential use(s):"; diff --git a/tools/veridex/precise_hidden_api_finder.cc b/tools/veridex/precise_hidden_api_finder.cc index 9e02cbf696..6aef89f7ee 100644 --- a/tools/veridex/precise_hidden_api_finder.cc +++ b/tools/veridex/precise_hidden_api_finder.cc @@ -91,8 +91,8 @@ void PreciseHiddenApiFinder::Dump(std::ostream& os, HiddenApiStats* stats) { std::string cls(info.cls.ToString()); std::string name(info.name.ToString()); std::string full_name = cls + "->" + name; - HiddenApiAccessFlags::ApiList api_list = hidden_api_.GetApiList(full_name); - if (api_list != HiddenApiAccessFlags::kNoList) { + hiddenapi::ApiList api_list = hidden_api_.GetApiList(full_name); + if (api_list != hiddenapi::ApiList::kNoList) { named_uses[full_name].push_back(ref); } } @@ -101,8 +101,8 @@ void PreciseHiddenApiFinder::Dump(std::ostream& os, HiddenApiStats* stats) { for (auto& it : named_uses) { ++stats->reflection_count; const std::string& full_name = it.first; - HiddenApiAccessFlags::ApiList api_list = hidden_api_.GetApiList(full_name); - stats->api_counts[api_list]++; + hiddenapi::ApiList api_list = hidden_api_.GetApiList(full_name); + stats->api_counts[static_cast<unsigned>(api_list)]++; os << "#" << ++stats->count << ": Reflection " << api_list << " " << full_name << " use(s):"; os << std::endl; for (const MethodReference& ref : it.second) { diff --git a/tools/veridex/veridex.cc b/tools/veridex/veridex.cc index 7206c7d1e3..179e391219 100644 --- a/tools/veridex/veridex.cc +++ b/tools/veridex/veridex.cc @@ -271,16 +271,17 @@ class Veridex { const VeridexOptions& options) { static const char* kPrefix = " "; if (options.only_report_sdk_uses) { - os << stats.api_counts[HiddenApiAccessFlags::kWhitelist] << " SDK API uses." << std::endl; + os << stats.api_counts[static_cast<unsigned>(hiddenapi::ApiList::kWhitelist)] + << " SDK API uses." << std::endl; } else { os << stats.count << " hidden API(s) used: " << stats.linking_count << " linked against, " << stats.reflection_count << " through reflection" << std::endl; - os << kPrefix << stats.api_counts[HiddenApiAccessFlags::kBlacklist] + os << kPrefix << stats.api_counts[static_cast<unsigned>(hiddenapi::ApiList::kBlacklist)] << " in blacklist" << std::endl; - os << kPrefix << stats.api_counts[HiddenApiAccessFlags::kDarkGreylist] + os << kPrefix << stats.api_counts[static_cast<unsigned>(hiddenapi::ApiList::kDarkGreylist)] << " in dark greylist" << std::endl; - os << kPrefix << stats.api_counts[HiddenApiAccessFlags::kLightGreylist] + os << kPrefix << stats.api_counts[static_cast<unsigned>(hiddenapi::ApiList::kLightGreylist)] << " in light greylist" << std::endl; } } |