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