| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +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 | #include "hidden_api.h" |
| 18 | |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 19 | #include <fstream> |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 20 | #include <sstream> |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 21 | |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 22 | #include "android-base/stringprintf.h" |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 23 | #include "base/file_utils.h" |
| David Brazdil | 2bb2fbd | 2018-11-13 18:24:26 +0000 | [diff] [blame] | 24 | #include "base/sdk_version.h" |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 25 | #include "base/stl_util.h" |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 26 | #include "common_runtime_test.h" |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 27 | #include "jni/jni_internal.h" |
| David Brazdil | 1f9d3c3 | 2018-05-02 16:53:06 +0100 | [diff] [blame] | 28 | #include "proxy_test.h" |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 29 | #include "well_known_classes.h" |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 33 | using android::base::StringPrintf; |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 34 | using hiddenapi::detail::MemberSignature; |
| David Brazdil | f50ac10 | 2018-10-17 18:00:06 +0100 | [diff] [blame] | 35 | using hiddenapi::detail::ShouldDenyAccessToMemberImpl; |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 36 | |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 37 | // Should be the same as dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_P_HIDDEN_APIS and |
| 38 | // dalvik.system.VMRuntime.HIDE_MAXTARGETSDK_Q_HIDDEN_APIS. |
| 39 | static constexpr uint64_t kHideMaxtargetsdkPHiddenApis = 149997251; |
| 40 | static constexpr uint64_t kHideMaxtargetsdkQHiddenApis = 149994052; |
| 41 | |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 42 | class HiddenApiTest : public CommonRuntimeTest { |
| 43 | protected: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 44 | void SetUp() override { |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 45 | // Do the normal setup. |
| 46 | CommonRuntimeTest::SetUp(); |
| 47 | self_ = Thread::Current(); |
| 48 | self_->TransitionFromSuspendedToRunnable(); |
| David Brazdil | 1f9d3c3 | 2018-05-02 16:53:06 +0100 | [diff] [blame] | 49 | jclass_loader_ = LoadDex("HiddenApiSignatures"); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 50 | bool started = runtime_->Start(); |
| 51 | CHECK(started); |
| 52 | |
| 53 | class1_field1_ = getArtField("mypackage/packagea/Class1", "field1", "I"); |
| 54 | class1_field12_ = getArtField("mypackage/packagea/Class1", "field12", "I"); |
| 55 | class1_init_ = getArtMethod("mypackage/packagea/Class1", "<init>", "()V"); |
| 56 | class1_method1_ = getArtMethod("mypackage/packagea/Class1", "method1", "()V"); |
| 57 | class1_method1_i_ = getArtMethod("mypackage/packagea/Class1", "method1", "(I)V"); |
| 58 | class1_method12_ = getArtMethod("mypackage/packagea/Class1", "method12", "()V"); |
| 59 | class12_field1_ = getArtField("mypackage/packagea/Class12", "field1", "I"); |
| 60 | class12_method1_ = getArtMethod("mypackage/packagea/Class12", "method1", "()V"); |
| 61 | class2_field1_ = getArtField("mypackage/packagea/Class2", "field1", "I"); |
| 62 | class2_method1_ = getArtMethod("mypackage/packagea/Class2", "method1", "()V"); |
| 63 | class2_method1_i_ = getArtMethod("mypackage/packagea/Class2", "method1", "(I)V"); |
| 64 | class3_field1_ = getArtField("mypackage/packageb/Class3", "field1", "I"); |
| 65 | class3_method1_ = getArtMethod("mypackage/packageb/Class3", "method1", "()V"); |
| 66 | class3_method1_i_ = getArtMethod("mypackage/packageb/Class3", "method1", "(I)V"); |
| 67 | } |
| 68 | |
| 69 | ArtMethod* getArtMethod(const char* class_name, const char* name, const char* signature) { |
| 70 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 71 | jclass klass = env->FindClass(class_name); |
| 72 | jmethodID method_id = env->GetMethodID(klass, name, signature); |
| 73 | ArtMethod* art_method = jni::DecodeArtMethod(method_id); |
| 74 | return art_method; |
| 75 | } |
| 76 | |
| 77 | ArtField* getArtField(const char* class_name, const char* name, const char* signature) { |
| 78 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 79 | jclass klass = env->FindClass(class_name); |
| 80 | jfieldID field_id = env->GetFieldID(klass, name, signature); |
| 81 | ArtField* art_field = jni::DecodeArtField(field_id); |
| 82 | return art_field; |
| 83 | } |
| 84 | |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 85 | void setChangeIdState(uint64_t change, bool enabled) { |
| Andrei Onea | 037d282 | 2020-11-19 00:20:04 +0000 | [diff] [blame^] | 86 | CompatFramework& compat_framework = runtime_->GetCompatFramework(); |
| 87 | std::set<uint64_t> disabled_changes = compat_framework.GetDisabledCompatChanges(); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 88 | if (enabled) { |
| 89 | disabled_changes.erase(change); |
| 90 | } else { |
| 91 | disabled_changes.insert(change); |
| 92 | } |
| Andrei Onea | 037d282 | 2020-11-19 00:20:04 +0000 | [diff] [blame^] | 93 | compat_framework.SetDisabledCompatChanges(disabled_changes); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| David Brazdil | f50ac10 | 2018-10-17 18:00:06 +0100 | [diff] [blame] | 96 | bool ShouldDenyAccess(hiddenapi::ApiList list) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 97 | // Choose parameters such that there are no side effects (AccessMethod::kNone) |
| 98 | // and that the member is not on the exemptions list (here we choose one which |
| 99 | // is not even in boot class path). |
| 100 | return ShouldDenyAccessToMemberImpl(/* member= */ class1_field1_, |
| 101 | list, |
| 102 | /* access_method= */ hiddenapi::AccessMethod::kNone); |
| 103 | } |
| 104 | |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 105 | protected: |
| 106 | Thread* self_; |
| David Brazdil | 1f9d3c3 | 2018-05-02 16:53:06 +0100 | [diff] [blame] | 107 | jobject jclass_loader_; |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 108 | ArtField* class1_field1_; |
| 109 | ArtField* class1_field12_; |
| 110 | ArtMethod* class1_init_; |
| 111 | ArtMethod* class1_method1_; |
| 112 | ArtMethod* class1_method1_i_; |
| 113 | ArtMethod* class1_method12_; |
| 114 | ArtField* class12_field1_; |
| 115 | ArtMethod* class12_method1_; |
| 116 | ArtField* class2_field1_; |
| 117 | ArtMethod* class2_method1_; |
| 118 | ArtMethod* class2_method1_i_; |
| 119 | ArtField* class3_field1_; |
| 120 | ArtMethod* class3_method1_; |
| 121 | ArtMethod* class3_method1_i_; |
| 122 | }; |
| 123 | |
| Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame] | 124 | TEST_F(HiddenApiTest, CheckGetActionFromRuntimeFlags) { |
| David Brazdil | f50ac10 | 2018-10-17 18:00:06 +0100 | [diff] [blame] | 125 | ScopedObjectAccess soa(self_); |
| 126 | |
| Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame] | 127 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kJustWarn); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 128 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 129 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 130 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetR()), false); |
| 131 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), false); |
| 132 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), false); |
| 133 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), false); |
| 134 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), false); |
| Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame] | 135 | |
| David Brazdil | f50ac10 | 2018-10-17 18:00:06 +0100 | [diff] [blame] | 136 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 137 | runtime_->SetTargetSdkVersion( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 138 | static_cast<uint32_t>(hiddenapi::ApiList::MaxTargetO().GetMaxAllowedSdkVersion())); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 139 | setChangeIdState(kHideMaxtargetsdkPHiddenApis, false); |
| 140 | setChangeIdState(kHideMaxtargetsdkQHiddenApis, false); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 141 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 142 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 143 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetR()), false); |
| 144 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), false); |
| 145 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), false); |
| 146 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), false); |
| 147 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), true); |
| Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame] | 148 | |
| David Brazdil | f50ac10 | 2018-10-17 18:00:06 +0100 | [diff] [blame] | 149 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| David Brazdil | dcfa89b | 2018-10-31 11:04:10 +0000 | [diff] [blame] | 150 | runtime_->SetTargetSdkVersion( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 151 | static_cast<uint32_t>(hiddenapi::ApiList::MaxTargetO().GetMaxAllowedSdkVersion()) + 1); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 152 | setChangeIdState(kHideMaxtargetsdkPHiddenApis, false); |
| 153 | setChangeIdState(kHideMaxtargetsdkQHiddenApis, false); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 154 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 155 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 156 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetR()), false); |
| 157 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), false); |
| 158 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), false); |
| 159 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), true); |
| 160 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), true); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 161 | setChangeIdState(kHideMaxtargetsdkQHiddenApis, true); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 162 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 163 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 164 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), true); |
| 165 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), false); |
| 166 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), true); |
| 167 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), true); |
| David Brazdil | 80d1628 | 2018-11-01 09:55:09 +0000 | [diff] [blame] | 168 | |
| 169 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| 170 | runtime_->SetTargetSdkVersion( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 171 | static_cast<uint32_t>(hiddenapi::ApiList::MaxTargetP().GetMaxAllowedSdkVersion()) + 1); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 172 | setChangeIdState(kHideMaxtargetsdkPHiddenApis, true); |
| 173 | setChangeIdState(kHideMaxtargetsdkQHiddenApis, false); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 174 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 175 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 176 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetR()), false); |
| 177 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), false); |
| 178 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), true); |
| 179 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), true); |
| 180 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), true); |
| Artur Satayev | 201ffea | 2019-10-31 14:58:03 +0000 | [diff] [blame] | 181 | |
| 182 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| 183 | runtime_->SetTargetSdkVersion( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 184 | static_cast<uint32_t>(hiddenapi::ApiList::MaxTargetQ().GetMaxAllowedSdkVersion()) + 1); |
| atrost | 2dea079 | 2020-02-25 20:11:47 +0000 | [diff] [blame] | 185 | setChangeIdState(kHideMaxtargetsdkPHiddenApis, true); |
| 186 | setChangeIdState(kHideMaxtargetsdkQHiddenApis, true); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 187 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 188 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 189 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetR()), false); |
| 190 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), true); |
| 191 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), true); |
| 192 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), true); |
| 193 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), true); |
| Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 194 | |
| 195 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| 196 | runtime_->SetTargetSdkVersion( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 197 | static_cast<uint32_t>(hiddenapi::ApiList::MaxTargetR().GetMaxAllowedSdkVersion()) + 1); |
| Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 198 | setChangeIdState(kHideMaxtargetsdkPHiddenApis, true); |
| 199 | setChangeIdState(kHideMaxtargetsdkQHiddenApis, true); |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 200 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Sdk()), false); |
| 201 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Unsupported()), false); |
| 202 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetR()), true); |
| 203 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetQ()), true); |
| 204 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetP()), true); |
| 205 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::MaxTargetO()), true); |
| 206 | ASSERT_EQ(ShouldDenyAccess(hiddenapi::ApiList::Blocked()), true); |
| Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 209 | TEST_F(HiddenApiTest, CheckTestApiEnforcement) { |
| 210 | ScopedObjectAccess soa(self_); |
| 211 | |
| 212 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| 213 | runtime_->SetTargetSdkVersion( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 214 | static_cast<uint32_t>(hiddenapi::ApiList::MaxTargetR().GetMaxAllowedSdkVersion()) + 1); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 215 | |
| 216 | // Default case where all TestApis are treated like non-TestApi. |
| 217 | runtime_->SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); |
| 218 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 219 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Sdk()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 220 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 221 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Unsupported()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 222 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 223 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetR()), true); |
| Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 224 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 225 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetQ()), true); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 226 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 227 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetP()), true); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 228 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 229 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetO()), true); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 230 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 231 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Blocked()), true); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 232 | |
| 233 | // A case where we want to allow access to TestApis. |
| 234 | runtime_->SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kDisabled); |
| 235 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 236 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Sdk()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 237 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 238 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Unsupported()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 239 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 240 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetR()), false); |
| Artur Satayev | b708fc1 | 2020-05-20 17:48:19 +0100 | [diff] [blame] | 241 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 242 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetQ()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 243 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 244 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetP()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 245 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 246 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::MaxTargetO()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 247 | ASSERT_EQ( |
| Andrei Onea | fc12a6c | 2020-07-29 19:52:34 +0100 | [diff] [blame] | 248 | ShouldDenyAccess(hiddenapi::ApiList::TestApi() | hiddenapi::ApiList::Blocked()), false); |
| Artur Satayev | 267366c | 2019-10-31 14:59:26 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 251 | TEST_F(HiddenApiTest, CheckMembersRead) { |
| 252 | ASSERT_NE(nullptr, class1_field1_); |
| 253 | ASSERT_NE(nullptr, class1_field12_); |
| 254 | ASSERT_NE(nullptr, class1_init_); |
| 255 | ASSERT_NE(nullptr, class1_method1_); |
| 256 | ASSERT_NE(nullptr, class1_method1_i_); |
| 257 | ASSERT_NE(nullptr, class1_method12_); |
| 258 | ASSERT_NE(nullptr, class12_field1_); |
| 259 | ASSERT_NE(nullptr, class12_method1_); |
| 260 | ASSERT_NE(nullptr, class2_field1_); |
| 261 | ASSERT_NE(nullptr, class2_method1_); |
| 262 | ASSERT_NE(nullptr, class2_method1_i_); |
| 263 | ASSERT_NE(nullptr, class3_field1_); |
| 264 | ASSERT_NE(nullptr, class3_method1_); |
| 265 | ASSERT_NE(nullptr, class3_method1_i_); |
| 266 | } |
| 267 | |
| 268 | TEST_F(HiddenApiTest, CheckEverythingMatchesL) { |
| 269 | ScopedObjectAccess soa(self_); |
| 270 | std::string prefix("L"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 271 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 272 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 273 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 274 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 275 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 276 | ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 277 | ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 278 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 279 | ASSERT_TRUE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 280 | ASSERT_TRUE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 281 | ASSERT_TRUE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
| 282 | ASSERT_TRUE(MemberSignature(class3_field1_).DoesPrefixMatch(prefix)); |
| 283 | ASSERT_TRUE(MemberSignature(class3_method1_).DoesPrefixMatch(prefix)); |
| 284 | ASSERT_TRUE(MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | TEST_F(HiddenApiTest, CheckPackageMatch) { |
| 288 | ScopedObjectAccess soa(self_); |
| 289 | std::string prefix("Lmypackage/packagea/"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 290 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 291 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 292 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 293 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 294 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 295 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 296 | ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 297 | ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 298 | ASSERT_TRUE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 299 | ASSERT_TRUE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 300 | ASSERT_TRUE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
| 301 | ASSERT_FALSE(MemberSignature(class3_field1_).DoesPrefixMatch(prefix)); |
| 302 | ASSERT_FALSE(MemberSignature(class3_method1_).DoesPrefixMatch(prefix)); |
| 303 | ASSERT_FALSE(MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | TEST_F(HiddenApiTest, CheckClassMatch) { |
| 307 | ScopedObjectAccess soa(self_); |
| 308 | std::string prefix("Lmypackage/packagea/Class1"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 309 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 310 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 311 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 312 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 313 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 314 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 315 | ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 316 | ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 317 | ASSERT_FALSE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 318 | ASSERT_FALSE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 319 | ASSERT_FALSE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | TEST_F(HiddenApiTest, CheckClassExactMatch) { |
| 323 | ScopedObjectAccess soa(self_); |
| 324 | std::string prefix("Lmypackage/packagea/Class1;"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 325 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 326 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 327 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 328 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 329 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 330 | ASSERT_FALSE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 331 | ASSERT_FALSE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 332 | ASSERT_FALSE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 333 | ASSERT_FALSE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 334 | ASSERT_FALSE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | TEST_F(HiddenApiTest, CheckMethodMatch) { |
| 338 | ScopedObjectAccess soa(self_); |
| 339 | std::string prefix("Lmypackage/packagea/Class1;->method1"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 340 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 341 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 342 | ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 343 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 344 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 345 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 346 | ASSERT_FALSE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 347 | ASSERT_FALSE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | TEST_F(HiddenApiTest, CheckMethodExactMatch) { |
| 351 | ScopedObjectAccess soa(self_); |
| 352 | std::string prefix("Lmypackage/packagea/Class1;->method1("); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 353 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 354 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 355 | ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 356 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 357 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 358 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | TEST_F(HiddenApiTest, CheckMethodSignatureMatch) { |
| 362 | ScopedObjectAccess soa(self_); |
| 363 | std::string prefix("Lmypackage/packagea/Class1;->method1(I)"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 364 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 365 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 366 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 367 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 368 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | TEST_F(HiddenApiTest, CheckMethodSignatureAndReturnMatch) { |
| 372 | ScopedObjectAccess soa(self_); |
| 373 | std::string prefix("Lmypackage/packagea/Class1;->method1()V"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 374 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 375 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 376 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 377 | ASSERT_FALSE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 378 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | TEST_F(HiddenApiTest, CheckFieldMatch) { |
| 382 | ScopedObjectAccess soa(self_); |
| 383 | std::string prefix("Lmypackage/packagea/Class1;->field1"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 384 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 385 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 386 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 387 | ASSERT_FALSE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 388 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | TEST_F(HiddenApiTest, CheckFieldExactMatch) { |
| 392 | ScopedObjectAccess soa(self_); |
| 393 | std::string prefix("Lmypackage/packagea/Class1;->field1:"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 394 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 395 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 396 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | TEST_F(HiddenApiTest, CheckFieldTypeMatch) { |
| 400 | ScopedObjectAccess soa(self_); |
| 401 | std::string prefix("Lmypackage/packagea/Class1;->field1:I"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 402 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 403 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 404 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | TEST_F(HiddenApiTest, CheckConstructorMatch) { |
| 408 | ScopedObjectAccess soa(self_); |
| 409 | std::string prefix("Lmypackage/packagea/Class1;-><init>"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 410 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 411 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | TEST_F(HiddenApiTest, CheckConstructorExactMatch) { |
| 415 | ScopedObjectAccess soa(self_); |
| 416 | std::string prefix("Lmypackage/packagea/Class1;-><init>()V"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 417 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 418 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | TEST_F(HiddenApiTest, CheckMethodSignatureTrailingCharsNoMatch) { |
| 422 | ScopedObjectAccess soa(self_); |
| 423 | std::string prefix("Lmypackage/packagea/Class1;->method1()Vfoo"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 424 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | TEST_F(HiddenApiTest, CheckConstructorTrailingCharsNoMatch) { |
| 428 | ScopedObjectAccess soa(self_); |
| 429 | std::string prefix("Lmypackage/packagea/Class1;-><init>()Vfoo"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 430 | ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | TEST_F(HiddenApiTest, CheckFieldTrailingCharsNoMatch) { |
| 434 | ScopedObjectAccess soa(self_); |
| 435 | std::string prefix("Lmypackage/packagea/Class1;->field1:Ifoo"); |
| Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 436 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| David Brazdil | 1f9d3c3 | 2018-05-02 16:53:06 +0100 | [diff] [blame] | 439 | TEST_F(HiddenApiTest, CheckMemberSignatureForProxyClass) { |
| 440 | ScopedObjectAccess soa(self_); |
| 441 | StackHandleScope<4> hs(soa.Self()); |
| 442 | Handle<mirror::ClassLoader> class_loader( |
| 443 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader_))); |
| 444 | |
| 445 | // Find interface we will create a proxy for. |
| 446 | Handle<mirror::Class> h_iface(hs.NewHandle( |
| 447 | class_linker_->FindClass(soa.Self(), "Lmypackage/packagea/Interface;", class_loader))); |
| 448 | ASSERT_TRUE(h_iface != nullptr); |
| 449 | |
| 450 | // Create the proxy class. |
| Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 451 | std::vector<Handle<mirror::Class>> interfaces; |
| 452 | interfaces.push_back(h_iface); |
| David Brazdil | 1f9d3c3 | 2018-05-02 16:53:06 +0100 | [diff] [blame] | 453 | Handle<mirror::Class> proxyClass = hs.NewHandle(proxy_test::GenerateProxyClass( |
| 454 | soa, jclass_loader_, runtime_->GetClassLinker(), "$Proxy1234", interfaces)); |
| 455 | ASSERT_TRUE(proxyClass != nullptr); |
| 456 | ASSERT_TRUE(proxyClass->IsProxyClass()); |
| 457 | ASSERT_TRUE(proxyClass->IsInitialized()); |
| 458 | |
| 459 | // Find the "method" virtual method. |
| 460 | ArtMethod* method = nullptr; |
| 461 | for (auto& m : proxyClass->GetDeclaredVirtualMethods(kRuntimePointerSize)) { |
| 462 | if (strcmp("method", m.GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetName()) == 0) { |
| 463 | method = &m; |
| 464 | break; |
| 465 | } |
| 466 | } |
| 467 | ASSERT_TRUE(method != nullptr); |
| 468 | |
| 469 | // Find the "interfaces" static field. This is generated for all proxies. |
| 470 | ArtField* field = nullptr; |
| 471 | for (size_t i = 0; i < proxyClass->NumStaticFields(); ++i) { |
| 472 | ArtField* f = proxyClass->GetStaticField(i); |
| 473 | if (strcmp("interfaces", f->GetName()) == 0) { |
| 474 | field = f; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | ASSERT_TRUE(field != nullptr); |
| 479 | |
| 480 | // Test the signature. We expect the signature from the interface class. |
| 481 | std::ostringstream ss_method; |
| David Brazdil | 6a1dab4 | 2019-02-28 18:45:15 +0000 | [diff] [blame] | 482 | MemberSignature(method->GetInterfaceMethodIfProxy(kRuntimePointerSize)).Dump(ss_method); |
| David Brazdil | 1f9d3c3 | 2018-05-02 16:53:06 +0100 | [diff] [blame] | 483 | ASSERT_EQ("Lmypackage/packagea/Interface;->method()V", ss_method.str()); |
| 484 | |
| 485 | // Test the signature. We expect the signature of the proxy class. |
| 486 | std::ostringstream ss_field; |
| 487 | MemberSignature(field).Dump(ss_field); |
| 488 | ASSERT_EQ("L$Proxy1234;->interfaces:[Ljava/lang/Class;", ss_field.str()); |
| 489 | } |
| 490 | |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 491 | static bool Copy(const std::string& src, const std::string& dst, /*out*/ std::string* error_msg) { |
| 492 | std::ifstream src_stream(src, std::ios::binary); |
| 493 | std::ofstream dst_stream(dst, std::ios::binary); |
| 494 | dst_stream << src_stream.rdbuf(); |
| 495 | src_stream.close(); |
| 496 | dst_stream.close(); |
| 497 | if (src_stream.good() && dst_stream.good()) { |
| 498 | return true; |
| 499 | } else { |
| 500 | *error_msg = "Copy " + src + " => " + dst + " (src_good=" |
| 501 | + (src_stream.good() ? "true" : "false") + ", dst_good=" |
| 502 | + (dst_stream.good() ? "true" : "false") + ")"; |
| 503 | return false; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | static bool LoadDexFiles(const std::string& path, |
| 508 | ScopedObjectAccess& soa, |
| 509 | /* out */ std::vector<std::unique_ptr<const DexFile>>* dex_files, |
| 510 | /* out */ ObjPtr<mirror::ClassLoader>* class_loader, |
| 511 | /* out */ std::string* error_msg) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 512 | if (!ArtDexFileLoader().Open(path.c_str(), |
| 513 | path, |
| 514 | /* verify= */ true, |
| 515 | /* verify_checksum= */ true, |
| 516 | error_msg, |
| 517 | dex_files)) { |
| 518 | return false; |
| 519 | } |
| 520 | |
| 521 | ClassLinker* const linker = Runtime::Current()->GetClassLinker(); |
| 522 | |
| 523 | StackHandleScope<2> hs(soa.Self()); |
| 524 | Handle<mirror::Class> h_class = hs.NewHandle(soa.Decode<mirror::Class>( |
| 525 | WellKnownClasses::dalvik_system_PathClassLoader)); |
| 526 | Handle<mirror::ClassLoader> h_loader = hs.NewHandle(linker->CreateWellKnownClassLoader( |
| 527 | soa.Self(), |
| 528 | MakeNonOwningPointerVector(*dex_files), |
| 529 | h_class, |
| 530 | /* parent_loader= */ ScopedNullHandle<mirror::ClassLoader>(), |
| 531 | /* shared_libraries= */ ScopedNullHandle<mirror::ObjectArray<mirror::ClassLoader>>())); |
| 532 | for (const auto& dex_file : *dex_files) { |
| 533 | linker->RegisterDexFile(*dex_file.get(), h_loader.Get()); |
| 534 | } |
| 535 | |
| 536 | *class_loader = h_loader.Get(); |
| 537 | return true; |
| 538 | } |
| 539 | |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 540 | static bool Remove(const std::string& path, /*out*/ std::string* error_msg) { |
| 541 | if (TEMP_FAILURE_RETRY(remove(path.c_str())) == 0) { |
| 542 | return true; |
| 543 | } |
| 544 | *error_msg = StringPrintf("Unable to remove(\"%s\"): %s", path.c_str(), strerror(errno)); |
| 545 | return false; |
| 546 | } |
| 547 | |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 548 | static bool CheckAllDexFilesInDomain(ObjPtr<mirror::ClassLoader> loader, |
| 549 | const std::vector<std::unique_ptr<const DexFile>>& dex_files, |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 550 | hiddenapi::Domain expected_domain, |
| 551 | /* out */ std::string* error_msg) |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 552 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 553 | for (const auto& dex_file : dex_files) { |
| 554 | hiddenapi::AccessContext context(loader, dex_file.get()); |
| 555 | if (context.GetDomain() != expected_domain) { |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 556 | std::stringstream ss; |
| 557 | ss << dex_file->GetLocation() << ": access context domain does not match " |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 558 | << "(expected=" << static_cast<uint32_t>(expected_domain) |
| 559 | << ", actual=" << static_cast<uint32_t>(context.GetDomain()) << ")"; |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 560 | *error_msg = ss.str(); |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 561 | return false; |
| 562 | } |
| 563 | if (dex_file->GetHiddenapiDomain() != expected_domain) { |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 564 | std::stringstream ss; |
| 565 | ss << dex_file->GetLocation() << ": dex file domain does not match " |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 566 | << "(expected=" << static_cast<uint32_t>(expected_domain) |
| 567 | << ", actual=" << static_cast<uint32_t>(dex_file->GetHiddenapiDomain()) << ")"; |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 568 | *error_msg = ss.str(); |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 569 | return false; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | return true; |
| 574 | } |
| 575 | |
| 576 | TEST_F(HiddenApiTest, DexDomain_DataDir) { |
| 577 | // Load file from a non-system directory and check that it is not flagged as framework. |
| 578 | std::string data_location_path = android_data_ + "/foo.jar"; |
| 579 | ASSERT_FALSE(LocationIsOnSystemFramework(data_location_path.c_str())); |
| 580 | |
| 581 | ScopedObjectAccess soa(Thread::Current()); |
| 582 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 583 | std::string error_msg; |
| 584 | ObjPtr<mirror::ClassLoader> class_loader; |
| 585 | |
| 586 | ASSERT_TRUE(Copy(GetTestDexFileName("Main"), data_location_path, &error_msg)) << error_msg; |
| 587 | ASSERT_TRUE(LoadDexFiles(data_location_path, soa, &dex_files, &class_loader, &error_msg)) |
| 588 | << error_msg; |
| 589 | ASSERT_GE(dex_files.size(), 1u); |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 590 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 591 | dex_files, |
| 592 | hiddenapi::Domain::kApplication, |
| 593 | &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 594 | |
| 595 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 596 | ASSERT_TRUE(Remove(data_location_path, &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | TEST_F(HiddenApiTest, DexDomain_SystemDir) { |
| 600 | // Load file from a system, non-framework directory and check that it is not flagged as framework. |
| 601 | std::string system_location_path = GetAndroidRoot() + "/foo.jar"; |
| 602 | ASSERT_FALSE(LocationIsOnSystemFramework(system_location_path.c_str())); |
| 603 | |
| 604 | ScopedObjectAccess soa(Thread::Current()); |
| 605 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 606 | std::string error_msg; |
| 607 | ObjPtr<mirror::ClassLoader> class_loader; |
| 608 | |
| 609 | ASSERT_TRUE(Copy(GetTestDexFileName("Main"), system_location_path, &error_msg)) << error_msg; |
| 610 | ASSERT_TRUE(LoadDexFiles(system_location_path, soa, &dex_files, &class_loader, &error_msg)) |
| 611 | << error_msg; |
| 612 | ASSERT_GE(dex_files.size(), 1u); |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 613 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 614 | dex_files, |
| 615 | hiddenapi::Domain::kApplication, |
| 616 | &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 617 | |
| 618 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 619 | ASSERT_TRUE(Remove(system_location_path, &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 622 | TEST_F(HiddenApiTest, DexDomain_SystemExtDir) { |
| 623 | // Load file from a system_ext, non-framework directory and check that it is not flagged as framework. |
| 624 | std::string system_ext_location_path = android_system_ext_ + "/foo.jar"; |
| 625 | ASSERT_FALSE(LocationIsOnSystemExtFramework(system_ext_location_path.c_str())); |
| 626 | |
| 627 | ScopedObjectAccess soa(Thread::Current()); |
| 628 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 629 | std::string error_msg; |
| 630 | ObjPtr<mirror::ClassLoader> class_loader; |
| 631 | |
| 632 | ASSERT_TRUE(Copy(GetTestDexFileName("Main"), system_ext_location_path, &error_msg)) << error_msg; |
| 633 | ASSERT_TRUE(LoadDexFiles(system_ext_location_path, soa, &dex_files, &class_loader, &error_msg)) |
| 634 | << error_msg; |
| 635 | ASSERT_GE(dex_files.size(), 1u); |
| 636 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 637 | dex_files, |
| 638 | hiddenapi::Domain::kApplication, |
| 639 | &error_msg)) << error_msg; |
| 640 | |
| 641 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 642 | ASSERT_TRUE(Remove(system_ext_location_path, &error_msg)) << error_msg; |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 645 | TEST_F(HiddenApiTest, DexDomain_SystemFrameworkDir) { |
| 646 | // Load file from a system/framework directory and check that it is flagged as a framework dex. |
| David Srbecky | 7400a54 | 2020-07-09 13:40:57 +0100 | [diff] [blame] | 647 | std::filesystem::create_directory(GetAndroidRoot() + "/framework"); |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 648 | std::string system_framework_location_path = GetAndroidRoot() + "/framework/foo.jar"; |
| 649 | ASSERT_TRUE(LocationIsOnSystemFramework(system_framework_location_path.c_str())); |
| 650 | |
| 651 | ScopedObjectAccess soa(Thread::Current()); |
| 652 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 653 | std::string error_msg; |
| 654 | ObjPtr<mirror::ClassLoader> class_loader; |
| 655 | |
| 656 | ASSERT_TRUE(Copy(GetTestDexFileName("Main"), system_framework_location_path, &error_msg)) |
| 657 | << error_msg; |
| 658 | ASSERT_TRUE(LoadDexFiles(system_framework_location_path, |
| 659 | soa, |
| 660 | &dex_files, |
| 661 | &class_loader, |
| 662 | &error_msg)) << error_msg; |
| 663 | ASSERT_GE(dex_files.size(), 1u); |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 664 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 665 | dex_files, |
| 666 | hiddenapi::Domain::kPlatform, |
| 667 | &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 668 | |
| 669 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 670 | ASSERT_TRUE(Remove(system_framework_location_path, &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 673 | TEST_F(HiddenApiTest, DexDomain_SystemExtFrameworkDir) { |
| 674 | // Load file from a system_ext/framework directory and check that it is flagged as a framework dex. |
| 675 | std::string system_ext_framework_location_path = android_system_ext_ + "/framework/foo.jar"; |
| 676 | ASSERT_TRUE(LocationIsOnSystemExtFramework(system_ext_framework_location_path.c_str())); |
| 677 | |
| 678 | ScopedObjectAccess soa(Thread::Current()); |
| 679 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 680 | std::string error_msg; |
| 681 | ObjPtr<mirror::ClassLoader> class_loader; |
| 682 | |
| 683 | ASSERT_TRUE(Copy(GetTestDexFileName("Main"), system_ext_framework_location_path, &error_msg)) |
| 684 | << error_msg; |
| 685 | ASSERT_TRUE(LoadDexFiles(system_ext_framework_location_path, |
| 686 | soa, |
| 687 | &dex_files, |
| 688 | &class_loader, |
| 689 | &error_msg)) << error_msg; |
| 690 | ASSERT_GE(dex_files.size(), 1u); |
| 691 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 692 | dex_files, |
| 693 | hiddenapi::Domain::kPlatform, |
| 694 | &error_msg)) << error_msg; |
| 695 | |
| 696 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 697 | ASSERT_TRUE(Remove(system_ext_framework_location_path, &error_msg)) << error_msg; |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 700 | TEST_F(HiddenApiTest, DexDomain_DataDir_MultiDex) { |
| 701 | // Load multidex file from a non-system directory and check that it is not flagged as framework. |
| 702 | std::string data_multi_location_path = android_data_ + "/multifoo.jar"; |
| 703 | ASSERT_FALSE(LocationIsOnSystemFramework(data_multi_location_path.c_str())); |
| 704 | |
| 705 | ScopedObjectAccess soa(Thread::Current()); |
| 706 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 707 | std::string error_msg; |
| 708 | ObjPtr<mirror::ClassLoader> class_loader; |
| 709 | |
| 710 | ASSERT_TRUE(Copy(GetTestDexFileName("MultiDex"), data_multi_location_path, &error_msg)) |
| 711 | << error_msg; |
| 712 | ASSERT_TRUE(LoadDexFiles(data_multi_location_path, soa, &dex_files, &class_loader, &error_msg)) |
| 713 | << error_msg; |
| 714 | ASSERT_GE(dex_files.size(), 1u); |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 715 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 716 | dex_files, |
| 717 | hiddenapi::Domain::kApplication, |
| 718 | &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 719 | |
| 720 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 721 | ASSERT_TRUE(Remove(data_multi_location_path, &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | TEST_F(HiddenApiTest, DexDomain_SystemDir_MultiDex) { |
| 725 | // Load multidex file from a system, non-framework directory and check that it is not flagged |
| 726 | // as framework. |
| 727 | std::string system_multi_location_path = GetAndroidRoot() + "/multifoo.jar"; |
| 728 | ASSERT_FALSE(LocationIsOnSystemFramework(system_multi_location_path.c_str())); |
| 729 | |
| 730 | ScopedObjectAccess soa(Thread::Current()); |
| 731 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 732 | std::string error_msg; |
| 733 | ObjPtr<mirror::ClassLoader> class_loader; |
| 734 | |
| 735 | ASSERT_TRUE(Copy(GetTestDexFileName("MultiDex"), system_multi_location_path, &error_msg)) |
| 736 | << error_msg; |
| 737 | ASSERT_TRUE(LoadDexFiles(system_multi_location_path, soa, &dex_files, &class_loader, &error_msg)) |
| 738 | << error_msg; |
| 739 | ASSERT_GT(dex_files.size(), 1u); |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 740 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 741 | dex_files, |
| 742 | hiddenapi::Domain::kApplication, |
| 743 | &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 744 | |
| 745 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 746 | ASSERT_TRUE(Remove(system_multi_location_path, &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 749 | TEST_F(HiddenApiTest, DexDomain_SystemExtDir_MultiDex) { |
| 750 | // Load multidex file from a system_ext, non-framework directory and check that it is not flagged |
| 751 | // as framework. |
| 752 | std::string system_ext_multi_location_path = android_system_ext_ + "/multifoo.jar"; |
| 753 | ASSERT_FALSE(LocationIsOnSystemExtFramework(system_ext_multi_location_path.c_str())); |
| 754 | |
| 755 | ScopedObjectAccess soa(Thread::Current()); |
| 756 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 757 | std::string error_msg; |
| 758 | ObjPtr<mirror::ClassLoader> class_loader; |
| 759 | |
| 760 | ASSERT_TRUE(Copy(GetTestDexFileName("MultiDex"), system_ext_multi_location_path, &error_msg)) |
| 761 | << error_msg; |
| 762 | ASSERT_TRUE(LoadDexFiles(system_ext_multi_location_path, soa, &dex_files, &class_loader, &error_msg)) |
| 763 | << error_msg; |
| 764 | ASSERT_GT(dex_files.size(), 1u); |
| 765 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 766 | dex_files, |
| 767 | hiddenapi::Domain::kApplication, |
| 768 | &error_msg)) << error_msg; |
| 769 | |
| 770 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 771 | ASSERT_TRUE(Remove(system_ext_multi_location_path, &error_msg)) << error_msg; |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 774 | TEST_F(HiddenApiTest, DexDomain_SystemFrameworkDir_MultiDex) { |
| 775 | // Load multidex file from a system/framework directory and check that it is flagged as a |
| 776 | // framework dex. |
| 777 | std::string system_framework_multi_location_path = GetAndroidRoot() + "/framework/multifoo.jar"; |
| 778 | ASSERT_TRUE(LocationIsOnSystemFramework(system_framework_multi_location_path.c_str())); |
| 779 | |
| 780 | ScopedObjectAccess soa(Thread::Current()); |
| 781 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 782 | std::string error_msg; |
| 783 | ObjPtr<mirror::ClassLoader> class_loader; |
| 784 | |
| 785 | ASSERT_TRUE(Copy(GetTestDexFileName("MultiDex"), |
| 786 | system_framework_multi_location_path, |
| 787 | &error_msg)) << error_msg; |
| 788 | ASSERT_TRUE(LoadDexFiles(system_framework_multi_location_path, |
| 789 | soa, |
| 790 | &dex_files, |
| 791 | &class_loader, |
| 792 | &error_msg)) << error_msg; |
| 793 | ASSERT_GT(dex_files.size(), 1u); |
| David Brazdil | bfaba28 | 2019-03-15 11:35:51 +0000 | [diff] [blame] | 794 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 795 | dex_files, |
| 796 | hiddenapi::Domain::kPlatform, |
| 797 | &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 798 | |
| 799 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 800 | ASSERT_TRUE(Remove(system_framework_multi_location_path, &error_msg)) << error_msg; |
| David Brazdil | a5c3a80 | 2019-03-08 14:59:41 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 803 | TEST_F(HiddenApiTest, DexDomain_SystemExtFrameworkDir_MultiDex) { |
| 804 | // Load multidex file from a system_ext/framework directory and check that it is flagged as a |
| 805 | // framework dex. |
| 806 | std::string system_ext_framework_multi_location_path = android_system_ext_ + "/framework/multifoo.jar"; |
| 807 | ASSERT_TRUE(LocationIsOnSystemExtFramework(system_ext_framework_multi_location_path.c_str())); |
| 808 | |
| 809 | ScopedObjectAccess soa(Thread::Current()); |
| 810 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 811 | std::string error_msg; |
| 812 | ObjPtr<mirror::ClassLoader> class_loader; |
| 813 | |
| 814 | ASSERT_TRUE(Copy(GetTestDexFileName("MultiDex"), |
| 815 | system_ext_framework_multi_location_path, |
| 816 | &error_msg)) << error_msg; |
| 817 | ASSERT_TRUE(LoadDexFiles(system_ext_framework_multi_location_path, |
| 818 | soa, |
| 819 | &dex_files, |
| 820 | &class_loader, |
| 821 | &error_msg)) << error_msg; |
| 822 | ASSERT_GT(dex_files.size(), 1u); |
| 823 | ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, |
| 824 | dex_files, |
| 825 | hiddenapi::Domain::kPlatform, |
| 826 | &error_msg)) << error_msg; |
| 827 | |
| 828 | dex_files.clear(); |
| Orion Hodson | 9735ccc | 2020-07-20 13:05:04 +0100 | [diff] [blame] | 829 | ASSERT_TRUE(Remove(system_ext_framework_multi_location_path, &error_msg)) << error_msg; |
| Chris Gross | 5477b8e | 2020-04-24 09:36:45 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 832 | } // namespace art |