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