ART: Refactor hidden_api
Add hidden_api.cc, move handling of hidden fields there. Also
remove an unnecessary include that meant hidden_api was imported
into too many compilation units, and fix transitive includes.
Bug: 73896556
Test: mmma art
Test: m test-art-host
Change-Id: Ie47e11abcea68e326c410bab215ebbfbf049051b
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 4736fd3..c0f1c36 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -87,6 +87,7 @@
"gc/space/zygote_space.cc",
"gc/task_processor.cc",
"gc/verification.cc",
+ "hidden_api.cc",
"hprof/hprof.cc",
"image.cc",
"index_bss_mapping.cc",
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 2110d04..412834c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -72,6 +72,7 @@
#include "gc/space/space-inl.h"
#include "gc_root-inl.h"
#include "handle_scope-inl.h"
+#include "hidden_api.h"
#include "image-inl.h"
#include "imt_conflict_table.h"
#include "imtable-inl.h"
diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc
new file mode 100644
index 0000000..f0b36a0
--- /dev/null
+++ b/runtime/hidden_api.cc
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hidden_api.h"
+
+#include "base/dumpable.h"
+
+namespace art {
+namespace hiddenapi {
+
+static inline std::ostream& operator<<(std::ostream& os, AccessMethod value) {
+ switch (value) {
+ case kReflection:
+ os << "reflection";
+ break;
+ case kJNI:
+ os << "JNI";
+ break;
+ case kLinking:
+ os << "linking";
+ break;
+ }
+ return os;
+}
+
+static constexpr bool EnumsEqual(EnforcementPolicy policy, HiddenApiAccessFlags::ApiList apiList) {
+ return static_cast<int>(policy) == static_cast<int>(apiList);
+}
+
+// GetMemberAction-related static_asserts.
+static_assert(
+ EnumsEqual(EnforcementPolicy::kAllLists, HiddenApiAccessFlags::kLightGreylist) &&
+ EnumsEqual(EnforcementPolicy::kDarkGreyAndBlackList, HiddenApiAccessFlags::kDarkGreylist) &&
+ EnumsEqual(EnforcementPolicy::kBlacklistOnly, HiddenApiAccessFlags::kBlacklist),
+ "Mismatch between EnforcementPolicy and ApiList enums");
+static_assert(
+ EnforcementPolicy::kAllLists < EnforcementPolicy::kDarkGreyAndBlackList &&
+ EnforcementPolicy::kDarkGreyAndBlackList < EnforcementPolicy::kBlacklistOnly,
+ "EnforcementPolicy values ordering not correct");
+
+namespace detail {
+
+MemberSignature::MemberSignature(ArtField* field) {
+ member_type_ = "field";
+ signature_parts_ = {
+ field->GetDeclaringClass()->GetDescriptor(&tmp_),
+ "->",
+ field->GetName(),
+ ":",
+ field->GetTypeDescriptor()
+ };
+}
+
+MemberSignature::MemberSignature(ArtMethod* method) {
+ member_type_ = "method";
+ signature_parts_ = {
+ method->GetDeclaringClass()->GetDescriptor(&tmp_),
+ "->",
+ method->GetName(),
+ method->GetSignature().ToString()
+ };
+}
+
+bool MemberSignature::DoesPrefixMatch(const std::string& prefix) const {
+ size_t pos = 0;
+ for (const std::string& part : signature_parts_) {
+ size_t count = std::min(prefix.length() - pos, part.length());
+ if (prefix.compare(pos, count, part, 0, count) == 0) {
+ pos += count;
+ } else {
+ return false;
+ }
+ }
+ // We have a complete match if all parts match (we exit the loop without
+ // returning) AND we've matched the whole prefix.
+ return pos == prefix.length();
+}
+
+bool MemberSignature::IsExempted(const std::vector<std::string>& exemptions) {
+ for (const std::string& exemption : exemptions) {
+ if (DoesPrefixMatch(exemption)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void MemberSignature::Dump(std::ostream& os) const {
+ for (std::string part : signature_parts_) {
+ os << part;
+ }
+}
+
+void MemberSignature::WarnAboutAccess(AccessMethod access_method,
+ HiddenApiAccessFlags::ApiList list) {
+ LOG(WARNING) << "Accessing hidden " << member_type_ << " " << Dumpable<MemberSignature>(*this)
+ << " (" << list << ", " << access_method << ")";
+}
+
+template<typename T>
+bool ShouldBlockAccessToMemberImpl(T* member, Action action, AccessMethod access_method) {
+ // Get the signature, we need it later.
+ MemberSignature member_signature(member);
+
+ Runtime* runtime = Runtime::Current();
+
+ if (action == kDeny) {
+ // If we were about to deny, check for an exemption first.
+ // Exempted APIs are treated as light grey list.
+ if (member_signature.IsExempted(runtime->GetHiddenApiExemptions())) {
+ action = kAllowButWarn;
+ // Avoid re-examining the exemption list next time.
+ // Note this results in the warning below showing "light greylist", which
+ // seems like what one would expect. Exemptions effectively add new members to
+ // the light greylist.
+ member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
+ member->GetAccessFlags(), HiddenApiAccessFlags::kLightGreylist));
+ }
+ }
+
+ // Print a log message with information about this class member access.
+ // We do this regardless of whether we block the access or not.
+ member_signature.WarnAboutAccess(access_method,
+ HiddenApiAccessFlags::DecodeFromRuntime(member->GetAccessFlags()));
+
+ if (action == kDeny) {
+ // Block access
+ return true;
+ }
+
+ // Allow access to this member but print a warning.
+ DCHECK(action == kAllowButWarn || action == kAllowButWarnAndToast);
+
+ // Depending on a runtime flag, we might move the member into whitelist and
+ // skip the warning the next time the member is accessed.
+ if (runtime->ShouldDedupeHiddenApiWarnings()) {
+ member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
+ member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist));
+ }
+
+ // If this action requires a UI warning, set the appropriate flag.
+ if (action == kAllowButWarnAndToast || runtime->ShouldAlwaysSetHiddenApiWarningFlag()) {
+ runtime->SetPendingHiddenApiWarning(true);
+ }
+
+ return false;
+}
+
+// Need to instantiate this.
+template bool ShouldBlockAccessToMemberImpl<ArtField>(ArtField* member,
+ Action action,
+ AccessMethod access_method);
+template bool ShouldBlockAccessToMemberImpl<ArtMethod>(ArtMethod* member,
+ Action action,
+ AccessMethod access_method);
+
+} // namespace detail
+} // namespace hiddenapi
+} // namespace art
diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h
index 0e6f159..cc6c146 100644
--- a/runtime/hidden_api.h
+++ b/runtime/hidden_api.h
@@ -19,7 +19,7 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
-#include "base/dumpable.h"
+#include "base/mutex.h"
#include "dex/hidden_api_access_flags.h"
#include "mirror/class-inl.h"
#include "reflection.h"
@@ -58,25 +58,6 @@
kLinking,
};
-inline std::ostream& operator<<(std::ostream& os, AccessMethod value) {
- switch (value) {
- case kReflection:
- os << "reflection";
- break;
- case kJNI:
- os << "JNI";
- break;
- case kLinking:
- os << "linking";
- break;
- }
- return os;
-}
-
-static constexpr bool EnumsEqual(EnforcementPolicy policy, HiddenApiAccessFlags::ApiList apiList) {
- return static_cast<int>(policy) == static_cast<int>(apiList);
-}
-
inline Action GetMemberAction(uint32_t access_flags) {
EnforcementPolicy policy = Runtime::Current()->GetHiddenApiEnforcementPolicy();
if (policy == EnforcementPolicy::kNoChecks) {
@@ -89,16 +70,7 @@
return kAllow;
}
// The logic below relies on equality of values in the enums EnforcementPolicy and
- // HiddenApiAccessFlags::ApiList, and their ordering. Assert that this is as expected.
- static_assert(
- EnumsEqual(EnforcementPolicy::kAllLists, HiddenApiAccessFlags::kLightGreylist) &&
- EnumsEqual(EnforcementPolicy::kDarkGreyAndBlackList, HiddenApiAccessFlags::kDarkGreylist) &&
- EnumsEqual(EnforcementPolicy::kBlacklistOnly, HiddenApiAccessFlags::kBlacklist),
- "Mismatch between EnforcementPolicy and ApiList enums");
- static_assert(
- EnforcementPolicy::kAllLists < EnforcementPolicy::kDarkGreyAndBlackList &&
- EnforcementPolicy::kDarkGreyAndBlackList < EnforcementPolicy::kBlacklistOnly,
- "EnforcementPolicy values ordering not correct");
+ // HiddenApiAccessFlags::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
? kAllowButWarnAndToast
@@ -108,6 +80,8 @@
}
}
+// Implementation details. DO NOT ACCESS DIRECTLY.
+namespace detail {
// Class to encapsulate the signature of a member (ArtField or ArtMethod). This
// is used as a helper when matching prefixes, and when logging the signature.
@@ -118,69 +92,45 @@
std::string tmp_;
public:
- explicit MemberSignature(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_) {
- member_type_ = "field";
- signature_parts_ = {
- field->GetDeclaringClass()->GetDescriptor(&tmp_),
- "->",
- field->GetName(),
- ":",
- field->GetTypeDescriptor()
- };
- }
+ explicit MemberSignature(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_);
+ explicit MemberSignature(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
- explicit MemberSignature(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
- member_type_ = "method";
- signature_parts_ = {
- method->GetDeclaringClass()->GetDescriptor(&tmp_),
- "->",
- method->GetName(),
- method->GetSignature().ToString()
- };
- }
+ void Dump(std::ostream& os) const;
- const std::vector<std::string>& Parts() const {
- return signature_parts_;
- }
-
- void Dump(std::ostream& os) const {
- for (std::string part : signature_parts_) {
- os << part;
- }
- }
// Performs prefix match on this member. Since the full member signature is
// composed of several parts, we match each part in turn (rather than
// building the entire thing in memory and performing a simple prefix match)
- bool DoesPrefixMatch(const std::string& prefix) const {
- size_t pos = 0;
- for (const std::string& part : signature_parts_) {
- size_t count = std::min(prefix.length() - pos, part.length());
- if (prefix.compare(pos, count, part, 0, count) == 0) {
- pos += count;
- } else {
- return false;
- }
- }
- // We have a complete match if all parts match (we exit the loop without
- // returning) AND we've matched the whole prefix.
- return pos == prefix.length();
- }
+ bool DoesPrefixMatch(const std::string& prefix) const;
- bool IsExempted(const std::vector<std::string>& exemptions) {
- for (const std::string& exemption : exemptions) {
- if (DoesPrefixMatch(exemption)) {
- return true;
- }
- }
- return false;
- }
+ bool IsExempted(const std::vector<std::string>& exemptions);
- void WarnAboutAccess(AccessMethod access_method, HiddenApiAccessFlags::ApiList list) {
- LOG(WARNING) << "Accessing hidden " << member_type_ << " " << Dumpable<MemberSignature>(*this)
- << " (" << list << ", " << access_method << ")";
- }
+ void WarnAboutAccess(AccessMethod access_method, HiddenApiAccessFlags::ApiList list);
};
+template<typename T>
+bool ShouldBlockAccessToMemberImpl(T* member,
+ Action action,
+ AccessMethod access_method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+// Returns true if the caller is either loaded by the boot strap class loader or comes from
+// a dex file located in ${ANDROID_ROOT}/framework/.
+ALWAYS_INLINE
+inline bool IsCallerInPlatformDex(ObjPtr<mirror::ClassLoader> caller_class_loader,
+ ObjPtr<mirror::DexCache> caller_dex_cache)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (caller_class_loader.IsNull()) {
+ return true;
+ } else if (caller_dex_cache.IsNull()) {
+ return false;
+ } else {
+ const DexFile* caller_dex_file = caller_dex_cache->GetDexFile();
+ return caller_dex_file != nullptr && caller_dex_file->IsPlatformDexFile();
+ }
+}
+
+} // namespace detail
+
// Returns true if access to `member` should be denied to the caller of the
// reflective query. The decision is based on whether the caller is in the
// platform or not. Because different users of this function determine this
@@ -209,72 +159,13 @@
}
// Member is hidden and caller is not in the platform.
-
- // Get the signature, we need it later.
- MemberSignature member_signature(member);
-
- Runtime* runtime = Runtime::Current();
-
- if (action == kDeny) {
- // If we were about to deny, check for an exemption first.
- // Exempted APIs are treated as light grey list.
- if (member_signature.IsExempted(runtime->GetHiddenApiExemptions())) {
- action = kAllowButWarn;
- // Avoid re-examining the exemption list next time.
- // Note this results in the warning below showing "light greylist", which
- // seems like what one would expect. Exemptions effectively add new members to
- // the light greylist.
- member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
- member->GetAccessFlags(), HiddenApiAccessFlags::kLightGreylist));
- }
- }
-
- // Print a log message with information about this class member access.
- // We do this regardless of whether we block the access or not.
- member_signature.WarnAboutAccess(access_method,
- HiddenApiAccessFlags::DecodeFromRuntime(member->GetAccessFlags()));
-
- if (action == kDeny) {
- // Block access
- return true;
- }
-
- // Allow access to this member but print a warning.
- DCHECK(action == kAllowButWarn || action == kAllowButWarnAndToast);
-
- // Depending on a runtime flag, we might move the member into whitelist and
- // skip the warning the next time the member is accessed.
- if (runtime->ShouldDedupeHiddenApiWarnings()) {
- member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
- member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist));
- }
-
- // If this action requires a UI warning, set the appropriate flag.
- if (action == kAllowButWarnAndToast || runtime->ShouldAlwaysSetHiddenApiWarningFlag()) {
- runtime->SetPendingHiddenApiWarning(true);
- }
-
- return false;
-}
-
-// Returns true if the caller is either loaded by the boot strap class loader or comes from
-// a dex file located in ${ANDROID_ROOT}/framework/.
-inline bool IsCallerInPlatformDex(ObjPtr<mirror::ClassLoader> caller_class_loader,
- ObjPtr<mirror::DexCache> caller_dex_cache)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- if (caller_class_loader.IsNull()) {
- return true;
- } else if (caller_dex_cache.IsNull()) {
- return false;
- } else {
- const DexFile* caller_dex_file = caller_dex_cache->GetDexFile();
- return caller_dex_file != nullptr && caller_dex_file->IsPlatformDexFile();
- }
+ return detail::ShouldBlockAccessToMemberImpl(member, action, access_method);
}
inline bool IsCallerInPlatformDex(ObjPtr<mirror::Class> caller)
REQUIRES_SHARED(Locks::mutator_lock_) {
- return !caller.IsNull() && IsCallerInPlatformDex(caller->GetClassLoader(), caller->GetDexCache());
+ return !caller.IsNull() &&
+ detail::IsCallerInPlatformDex(caller->GetClassLoader(), caller->GetDexCache());
}
// Returns true if access to `member` should be denied to a caller loaded with
@@ -286,7 +177,7 @@
ObjPtr<mirror::DexCache> caller_dex_cache,
AccessMethod access_method)
REQUIRES_SHARED(Locks::mutator_lock_) {
- bool caller_in_platform = IsCallerInPlatformDex(caller_class_loader, caller_dex_cache);
+ bool caller_in_platform = detail::IsCallerInPlatformDex(caller_class_loader, caller_dex_cache);
return ShouldBlockAccessToMember(member,
/* thread */ nullptr,
[caller_in_platform] (Thread*) { return caller_in_platform; },
diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc
index 190d2cb..5a31dd4 100644
--- a/runtime/hidden_api_test.cc
+++ b/runtime/hidden_api_test.cc
@@ -21,6 +21,8 @@
namespace art {
+using hiddenapi::detail::MemberSignature;
+
class HiddenApiTest : public CommonRuntimeTest {
protected:
void SetUp() OVERRIDE {
@@ -102,172 +104,172 @@
TEST_F(HiddenApiTest, CheckEverythingMatchesL) {
ScopedObjectAccess soa(self_);
std::string prefix("L");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class3_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class3_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class3_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class3_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckPackageMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class3_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class3_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class3_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class3_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckClassMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckClassExactMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckMethodMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->method1");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckMethodExactMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->method1(");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckMethodSignatureMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->method1(I)");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckMethodSignatureAndReturnMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->method1()V");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckFieldMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->field1");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckFieldExactMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->field1:");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckFieldTypeMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->field1:I");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckConstructorMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;-><init>");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckConstructorExactMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;-><init>()V");
- ASSERT_TRUE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckMethodSignatureTrailingCharsNoMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->method1()Vfoo");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckConstructorTrailingCharsNoMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;-><init>()Vfoo");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_init_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix));
}
TEST_F(HiddenApiTest, CheckFieldTrailingCharsNoMatch) {
ScopedObjectAccess soa(self_);
std::string prefix("Lmypackage/packagea/Class1;->field1:Ifoo");
- ASSERT_FALSE(hiddenapi::MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
+ ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix));
}
} // namespace art
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index f0898f4..72b3179 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -31,7 +31,6 @@
#include "dex/invoke_type.h"
#include "dex_cache.h"
#include "gc/heap-inl.h"
-#include "hidden_api.h"
#include "iftable.h"
#include "subtype_check.h"
#include "object-inl.h"
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index d9a5096..cf0a72a 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -27,6 +27,7 @@
#include "base/mutex.h"
#include "base/runtime_debug.h"
#include "debugger.h"
+#include "hidden_api.h"
#include "java_vm_ext.h"
#include "jit/jit.h"
#include "jni_internal.h"
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index bb76e61..00ccc19 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -86,6 +86,7 @@
#include "gc/space/space-inl.h"
#include "gc/system_weak.h"
#include "handle_scope-inl.h"
+#include "hidden_api.h"
#include "image-inl.h"
#include "instrumentation.h"
#include "intern_table.h"