summaryrefslogtreecommitdiff
path: root/runtime/hidden_api_test.cc
diff options
context:
space:
mode:
author Pedro Loureiro <pedroql@google.com> 2020-11-24 16:44:12 +0000
committer Pedro Loureiro <pedroql@google.com> 2020-11-25 20:19:58 +0000
commitf7fcb98ab4740db9d9d8ed7652b89928a2e56f60 (patch)
tree5a76fa96e391474345314eac31a6b5e95ec4e10b /runtime/hidden_api_test.cc
parent23c926d12f8333d2ca59d6b321064cb9d831f0ad (diff)
Check if app has ALLOW_TEST_API_ACCESS change id
Allow apps with the change id ALLOW_TEST_API_ACCESS enabled to access methods annotated with @TestAPi Test: m test-art-host-gtest-art_runtime_tests Fixes: 166236554 Change-Id: I78776443dd0b76d8cba24ddfbfb83c3b50b346ab
Diffstat (limited to 'runtime/hidden_api_test.cc')
-rw-r--r--runtime/hidden_api_test.cc26
1 files changed, 24 insertions, 2 deletions
diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc
index 6a002e5704..cfdba4552e 100644
--- a/runtime/hidden_api_test.cc
+++ b/runtime/hidden_api_test.cc
@@ -34,10 +34,12 @@ using android::base::StringPrintf;
using hiddenapi::detail::MemberSignature;
using hiddenapi::detail::ShouldDenyAccessToMemberImpl;
-// Should be the same as dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_P_HIDDEN_APIS and
-// dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_Q_HIDDEN_APIS.
+// Should be the same as dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_P_HIDDEN_APIS,
+// dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_Q_HIDDEN_APIS, and
+// dalvik.system.VMRuntime.EXEMPT_TEST_API_ACCESS_VERIFICATION.
static constexpr uint64_t kHideMaxtargetsdkPHiddenApis = 149997251;
static constexpr uint64_t kHideMaxtargetsdkQHiddenApis = 149994052;
+static constexpr uint64_t kAllowTestApiAccess = 166236554;
class HiddenApiTest : public CommonRuntimeTest {
protected:
@@ -215,6 +217,7 @@ TEST_F(HiddenApiTest, CheckTestApiEnforcement) {
// Default case where all TestApis are treated like non-TestApi.
runtime_->SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled);
+ setChangeIdState(kAllowTestApiAccess, false);
ASSERT_EQ(
ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Sdk()), false);
ASSERT_EQ(
@@ -232,6 +235,25 @@ TEST_F(HiddenApiTest, CheckTestApiEnforcement) {
// A case where we want to allow access to TestApis.
runtime_->SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kDisabled);
+ setChangeIdState(kAllowTestApiAccess, false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Sdk()), false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Unsupported()), false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetR()), false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetQ()), false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetP()), false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetO()), false);
+ ASSERT_EQ(
+ ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Blocked()), false);
+
+ // A second case where we want to allow access to TestApis.
+ runtime_->SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled);
+ setChangeIdState(kAllowTestApiAccess, true);
ASSERT_EQ(
ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Sdk()), false);
ASSERT_EQ(