diff options
| -rw-r--r-- | runtime/hidden_api.cc | 19 | ||||
| -rw-r--r-- | runtime/hidden_api_test.cc | 30 |
2 files changed, 47 insertions, 2 deletions
diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc index 6a9bdf6c79..b2a15506b2 100644 --- a/runtime/hidden_api.cc +++ b/runtime/hidden_api.cc @@ -34,6 +34,12 @@ namespace art { namespace hiddenapi { +// Should be the same as dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_P_HIDDEN_APIS and +// dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_Q_HIDDEN_APIS. +// Corresponds to bug ids. +static constexpr uint64_t kHideMaxtargetsdkPHiddenApis = 149997251; +static constexpr uint64_t kHideMaxtargetsdkQHiddenApis = 149994052; + // Set to true if we should always print a warning in logcat for all hidden API accesses, not just // dark grey and black. This can be set to true for developer preview / beta builds, but should be // false for public release builds. @@ -457,8 +463,17 @@ bool ShouldDenyAccessToMemberImpl(T* member, ApiList api_list, AccessMethod acce if (testApiPolicy == EnforcementPolicy::kDisabled && api_list.IsTestApi()) { deny_access = false; } else { - deny_access = IsSdkVersionSetAndMoreThan(runtime->GetTargetSdkVersion(), - api_list.GetMaxAllowedSdkVersion()); + switch (api_list.GetMaxAllowedSdkVersion()) { + case SdkVersion::kP: + deny_access = runtime->isChangeEnabled(kHideMaxtargetsdkPHiddenApis); + break; + case SdkVersion::kQ: + deny_access = runtime->isChangeEnabled(kHideMaxtargetsdkQHiddenApis); + break; + default: + deny_access = IsSdkVersionSetAndMoreThan(runtime->GetTargetSdkVersion(), + api_list.GetMaxAllowedSdkVersion()); + } } } diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc index 145bb07676..b9214ffb54 100644 --- a/runtime/hidden_api_test.cc +++ b/runtime/hidden_api_test.cc @@ -32,6 +32,11 @@ namespace art { 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. +static constexpr uint64_t kHideMaxtargetsdkPHiddenApis = 149997251; +static constexpr uint64_t kHideMaxtargetsdkQHiddenApis = 149994052; + class HiddenApiTest : public CommonRuntimeTest { protected: void SetUp() override { @@ -75,6 +80,16 @@ class HiddenApiTest : public CommonRuntimeTest { return art_field; } + void setChangeIdState(uint64_t change, bool enabled) { + std::set<uint64_t> disabled_changes = runtime_->GetDisabledCompatChanges(); + if (enabled) { + disabled_changes.erase(change); + } else { + disabled_changes.insert(change); + } + runtime_->SetDisabledCompatChanges(disabled_changes); + } + bool ShouldDenyAccess(hiddenapi::ApiList list) REQUIRES_SHARED(Locks::mutator_lock_) { // Choose parameters such that there are no side effects (AccessMethod::kNone) // and that the member is not on the exemptions list (here we choose one which @@ -117,6 +132,8 @@ TEST_F(HiddenApiTest, CheckGetActionFromRuntimeFlags) { runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); runtime_->SetTargetSdkVersion( static_cast<uint32_t>(hiddenapi::ApiList::GreylistMaxO().GetMaxAllowedSdkVersion())); + setChangeIdState(kHideMaxtargetsdkPHiddenApis, false); + setChangeIdState(kHideMaxtargetsdkQHiddenApis, false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Whitelist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Greylist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxQ()), false); @@ -127,16 +144,27 @@ TEST_F(HiddenApiTest, CheckGetActionFromRuntimeFlags) { runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); runtime_->SetTargetSdkVersion( static_cast<uint32_t>(hiddenapi::ApiList::GreylistMaxO().GetMaxAllowedSdkVersion()) + 1); + setChangeIdState(kHideMaxtargetsdkPHiddenApis, false); + setChangeIdState(kHideMaxtargetsdkQHiddenApis, false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Whitelist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Greylist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxQ()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxP()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxO()), true); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blacklist()), true); + setChangeIdState(kHideMaxtargetsdkQHiddenApis, true); + ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Whitelist()), false); + ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Greylist()), false); + ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxQ()), true); + ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxP()), false); + ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxO()), true); + ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blacklist()), true); runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); runtime_->SetTargetSdkVersion( static_cast<uint32_t>(hiddenapi::ApiList::GreylistMaxP().GetMaxAllowedSdkVersion()) + 1); + setChangeIdState(kHideMaxtargetsdkPHiddenApis, true); + setChangeIdState(kHideMaxtargetsdkQHiddenApis, false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Whitelist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Greylist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxQ()), false); @@ -147,6 +175,8 @@ TEST_F(HiddenApiTest, CheckGetActionFromRuntimeFlags) { runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); runtime_->SetTargetSdkVersion( static_cast<uint32_t>(hiddenapi::ApiList::GreylistMaxQ().GetMaxAllowedSdkVersion()) + 1); + setChangeIdState(kHideMaxtargetsdkPHiddenApis, true); + setChangeIdState(kHideMaxtargetsdkQHiddenApis, true); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Whitelist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Greylist()), false); ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::GreylistMaxQ()), true); |