blob: 47050cad80b16b09d4e6133480721cd2568ca9c4 [file] [log] [blame]
Orion Hodson9b16e342019-10-09 13:29:16 +01001/*
2 * Copyright (C) 2019 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 */
Nicolas Geoffray7ca8b672020-04-24 15:43:48 +010016
17#if defined(ART_TARGET_ANDROID)
18
Orion Hodson9b16e342019-10-09 13:29:16 +010019#include "library_namespaces.h"
20
21#include <dirent.h>
22#include <dlfcn.h>
23
24#include <regex>
25#include <string>
26#include <vector>
27
28#include <android-base/file.h>
29#include <android-base/logging.h>
30#include <android-base/macros.h>
31#include <android-base/properties.h>
Jooyung Han538f99a2020-03-03 00:46:50 +090032#include <android-base/result.h>
Orion Hodson9b16e342019-10-09 13:29:16 +010033#include <android-base/strings.h>
Orion Hodson6dc0a432020-02-06 14:28:28 +000034#include <nativehelper/scoped_utf_chars.h>
Orion Hodson9b16e342019-10-09 13:29:16 +010035
36#include "nativeloader/dlext_namespaces.h"
37#include "public_libraries.h"
38#include "utils.h"
39
Orion Hodson9b16e342019-10-09 13:29:16 +010040namespace android::nativeloader {
41
42namespace {
Jooyung Han538f99a2020-03-03 00:46:50 +090043
44constexpr const char* kApexPath = "/apex/";
45
Orion Hodson9b16e342019-10-09 13:29:16 +010046// The device may be configured to have the vendor libraries loaded to a separate namespace.
47// For historical reasons this namespace was named sphal but effectively it is intended
48// to use to load vendor libraries to separate namespace with controlled interface between
49// vendor and system namespaces.
50constexpr const char* kVendorNamespaceName = "sphal";
51constexpr const char* kVndkNamespaceName = "vndk";
Justin Yuneb4f08c2020-02-18 11:29:07 +090052constexpr const char* kVndkProductNamespaceName = "vndk_product";
Kiyoung Kim272b36d2020-02-19 16:08:47 +090053constexpr const char* kStatsdNamespaceName = "com_android_os_statsd";
Orion Hodson9b16e342019-10-09 13:29:16 +010054
55// classloader-namespace is a linker namespace that is created for the loaded
56// app. To be specific, it is created for the app classloader. When
57// System.load() is called from a Java class that is loaded from the
58// classloader, the classloader-namespace namespace associated with that
59// classloader is selected for dlopen. The namespace is configured so that its
60// search path is set to the app-local JNI directory and it is linked to the
Kiyoung Kim99c19ca2020-01-29 16:09:38 +090061// system namespace with the names of libs listed in the public.libraries.txt.
Orion Hodson9b16e342019-10-09 13:29:16 +010062// This way an app can only load its own JNI libraries along with the public libs.
63constexpr const char* kClassloaderNamespaceName = "classloader-namespace";
64// Same thing for vendor APKs.
65constexpr const char* kVendorClassloaderNamespaceName = "vendor-classloader-namespace";
Martin Stjernholm94fd9ea2019-10-24 16:57:34 +010066// If the namespace is shared then add this suffix to form
67// "classloader-namespace-shared" or "vendor-classloader-namespace-shared",
68// respectively. A shared namespace (cf. ANDROID_NAMESPACE_TYPE_SHARED) has
69// inherited all the libraries of the parent classloader namespace, or the
Kiyoung Kim99c19ca2020-01-29 16:09:38 +090070// system namespace for the main app classloader. It is used to give full
Martin Stjernholm94fd9ea2019-10-24 16:57:34 +010071// access to the platform libraries for apps bundled in the system image,
72// including their later updates installed in /data.
73constexpr const char* kSharedNamespaceSuffix = "-shared";
Orion Hodson9b16e342019-10-09 13:29:16 +010074
75// (http://b/27588281) This is a workaround for apps using custom classloaders and calling
76// System.load() with an absolute path which is outside of the classloader library search path.
77// This list includes all directories app is allowed to access this way.
78constexpr const char* kWhitelistedDirectories = "/data:/mnt/expand";
79
80constexpr const char* kVendorLibPath = "/vendor/" LIB;
81constexpr const char* kProductLibPath = "/product/" LIB ":/system/product/" LIB;
82
83const std::regex kVendorDexPathRegex("(^|:)/vendor/");
84const std::regex kProductDexPathRegex("(^|:)(/system)?/product/");
85
86// Define origin of APK if it is from vendor partition or product partition
Martin Stjernholm3bb009a2019-10-17 21:29:01 +010087using ApkOrigin = enum {
Orion Hodson9b16e342019-10-09 13:29:16 +010088 APK_ORIGIN_DEFAULT = 0,
89 APK_ORIGIN_VENDOR = 1,
90 APK_ORIGIN_PRODUCT = 2,
Martin Stjernholm3bb009a2019-10-17 21:29:01 +010091};
Orion Hodson9b16e342019-10-09 13:29:16 +010092
93jobject GetParentClassLoader(JNIEnv* env, jobject class_loader) {
94 jclass class_loader_class = env->FindClass("java/lang/ClassLoader");
95 jmethodID get_parent =
96 env->GetMethodID(class_loader_class, "getParent", "()Ljava/lang/ClassLoader;");
97
98 return env->CallObjectMethod(class_loader, get_parent);
99}
100
Jooyung Han538f99a2020-03-03 00:46:50 +0900101ApkOrigin GetApkOriginFromDexPath(const std::string& dex_path) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100102 ApkOrigin apk_origin = APK_ORIGIN_DEFAULT;
Jooyung Han538f99a2020-03-03 00:46:50 +0900103 if (std::regex_search(dex_path, kVendorDexPathRegex)) {
104 apk_origin = APK_ORIGIN_VENDOR;
105 }
106 if (std::regex_search(dex_path, kProductDexPathRegex)) {
107 LOG_ALWAYS_FATAL_IF(apk_origin == APK_ORIGIN_VENDOR,
108 "Dex path contains both vendor and product partition : %s",
109 dex_path.c_str());
Orion Hodson9b16e342019-10-09 13:29:16 +0100110
Jooyung Han538f99a2020-03-03 00:46:50 +0900111 apk_origin = APK_ORIGIN_PRODUCT;
Orion Hodson9b16e342019-10-09 13:29:16 +0100112 }
113 return apk_origin;
114}
115
116} // namespace
117
118void LibraryNamespaces::Initialize() {
119 // Once public namespace is initialized there is no
120 // point in running this code - it will have no effect
121 // on the current list of public libraries.
122 if (initialized_) {
123 return;
124 }
125
126 // android_init_namespaces() expects all the public libraries
127 // to be loaded so that they can be found by soname alone.
128 //
129 // TODO(dimitry): this is a bit misleading since we do not know
130 // if the vendor public library is going to be opened from /vendor/lib
131 // we might as well end up loading them from /system/lib or /product/lib
132 // For now we rely on CTS test to catch things like this but
133 // it should probably be addressed in the future.
134 for (const auto& soname : android::base::Split(preloadable_public_libraries(), ":")) {
135 LOG_ALWAYS_FATAL_IF(dlopen(soname.c_str(), RTLD_NOW | RTLD_NODELETE) == nullptr,
136 "Error preloading public library %s: %s", soname.c_str(), dlerror());
137 }
138}
139
Jiyong Park14626a72020-07-02 23:17:58 +0900140// "ALL" is a magic name that allows all public libraries even when the
141// target SDK is > 30. Currently this is used for (Java) shared libraries
142// which don't use <uses-native-library>
143// TODO(b/142191088) remove this hack
144static constexpr const char LIBRARY_ALL[] = "ALL";
145
146// Returns the colon-separated list of library names by filtering uses_libraries from
147// public_libraries. The returned names will actually be available to the app. If the app is pre-S
148// (<= 30), the filtering is not done; the entire public_libraries are provided.
149static const std::string filter_public_libraries(
150 uint32_t target_sdk_version, const std::vector<std::string>& uses_libraries,
151 const std::string& public_libraries) {
152 // Apps targeting Android 11 or earlier gets all public libraries
153 if (target_sdk_version <= 30) {
154 return public_libraries;
155 }
156 if (std::find(uses_libraries.begin(), uses_libraries.end(), LIBRARY_ALL) !=
157 uses_libraries.end()) {
158 return public_libraries;
159 }
160 std::vector<std::string> filtered;
161 std::vector<std::string> orig = android::base::Split(public_libraries, ":");
162 for (const auto& lib : uses_libraries) {
163 if (std::find(orig.begin(), orig.end(), lib) != orig.end()) {
164 filtered.emplace_back(lib);
165 }
166 }
167 return android::base::Join(filtered, ":");
168}
169
Orion Hodson9b16e342019-10-09 13:29:16 +0100170Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t target_sdk_version,
171 jobject class_loader, bool is_shared,
Jooyung Han538f99a2020-03-03 00:46:50 +0900172 jstring dex_path_j,
Orion Hodson9b16e342019-10-09 13:29:16 +0100173 jstring java_library_path,
Jiyong Park14626a72020-07-02 23:17:58 +0900174 jstring java_permitted_path,
175 jstring uses_library_list) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100176 std::string library_path; // empty string by default.
Jooyung Han538f99a2020-03-03 00:46:50 +0900177 std::string dex_path;
Orion Hodson9b16e342019-10-09 13:29:16 +0100178
179 if (java_library_path != nullptr) {
180 ScopedUtfChars library_path_utf_chars(env, java_library_path);
181 library_path = library_path_utf_chars.c_str();
182 }
183
Jooyung Han538f99a2020-03-03 00:46:50 +0900184 if (dex_path_j != nullptr) {
185 ScopedUtfChars dex_path_chars(env, dex_path_j);
186 dex_path = dex_path_chars.c_str();
187 }
188
Jiyong Park14626a72020-07-02 23:17:58 +0900189 std::vector<std::string> uses_libraries;
190 if (uses_library_list != nullptr) {
191 ScopedUtfChars names(env, uses_library_list);
192 uses_libraries = android::base::Split(names.c_str(), ":");
193 } else {
194 // uses_library_list could be nullptr when System.loadLibrary is called from a
195 // custom classloader. In that case, we don't know the list of public
196 // libraries because we don't know which apk the classloader is for. Only
197 // choices we can have are 1) allowing all public libs (as before), or 2)
198 // not allowing all but NDK libs. Here we take #1 because #2 would surprise
199 // developers unnecessarily.
200 // TODO(b/142191088) finalize the policy here. We could either 1) allow all
201 // public libs, 2) disallow any lib, or 3) use the libs that were granted to
202 // the first (i.e. app main) classloader.
203 uses_libraries.emplace_back(LIBRARY_ALL);
204 }
205
Jooyung Han538f99a2020-03-03 00:46:50 +0900206 ApkOrigin apk_origin = GetApkOriginFromDexPath(dex_path);
Orion Hodson9b16e342019-10-09 13:29:16 +0100207
208 // (http://b/27588281) This is a workaround for apps using custom
209 // classloaders and calling System.load() with an absolute path which
210 // is outside of the classloader library search path.
211 //
212 // This part effectively allows such a classloader to access anything
213 // under /data and /mnt/expand
214 std::string permitted_path = kWhitelistedDirectories;
215
216 if (java_permitted_path != nullptr) {
217 ScopedUtfChars path(env, java_permitted_path);
218 if (path.c_str() != nullptr && path.size() > 0) {
219 permitted_path = permitted_path + ":" + path.c_str();
220 }
221 }
222
223 LOG_ALWAYS_FATAL_IF(FindNamespaceByClassLoader(env, class_loader) != nullptr,
224 "There is already a namespace associated with this classloader");
225
226 std::string system_exposed_libraries = default_public_libraries();
Martin Stjernholm94fd9ea2019-10-24 16:57:34 +0100227 std::string namespace_name = kClassloaderNamespaceName;
Justin Yuneb4f08c2020-02-18 11:29:07 +0900228 ApkOrigin unbundled_app_origin = APK_ORIGIN_DEFAULT;
Orion Hodson9b16e342019-10-09 13:29:16 +0100229 if ((apk_origin == APK_ORIGIN_VENDOR ||
Justin Yun3db26d52019-12-16 14:09:39 +0900230 (apk_origin == APK_ORIGIN_PRODUCT &&
231 is_product_vndk_version_defined())) &&
Orion Hodson9b16e342019-10-09 13:29:16 +0100232 !is_shared) {
Justin Yuneb4f08c2020-02-18 11:29:07 +0900233 unbundled_app_origin = apk_origin;
Orion Hodson9b16e342019-10-09 13:29:16 +0100234 // For vendor / product apks, give access to the vendor / product lib even though
235 // they are treated as unbundled; the libs and apks are still bundled
236 // together in the vendor / product partition.
237 const char* origin_partition;
238 const char* origin_lib_path;
Justin Yun089c1352020-02-06 16:53:08 +0900239 const char* llndk_libraries;
Orion Hodson9b16e342019-10-09 13:29:16 +0100240
241 switch (apk_origin) {
242 case APK_ORIGIN_VENDOR:
243 origin_partition = "vendor";
244 origin_lib_path = kVendorLibPath;
Justin Yun089c1352020-02-06 16:53:08 +0900245 llndk_libraries = llndk_libraries_vendor().c_str();
Orion Hodson9b16e342019-10-09 13:29:16 +0100246 break;
247 case APK_ORIGIN_PRODUCT:
248 origin_partition = "product";
249 origin_lib_path = kProductLibPath;
Justin Yun089c1352020-02-06 16:53:08 +0900250 llndk_libraries = llndk_libraries_product().c_str();
Orion Hodson9b16e342019-10-09 13:29:16 +0100251 break;
252 default:
253 origin_partition = "unknown";
254 origin_lib_path = "";
Justin Yun089c1352020-02-06 16:53:08 +0900255 llndk_libraries = "";
Orion Hodson9b16e342019-10-09 13:29:16 +0100256 }
257 library_path = library_path + ":" + origin_lib_path;
258 permitted_path = permitted_path + ":" + origin_lib_path;
259
Justin Yun089c1352020-02-06 16:53:08 +0900260 // Also give access to LLNDK libraries since they are available to vendor or product
261 system_exposed_libraries = system_exposed_libraries + ":" + llndk_libraries;
Orion Hodson9b16e342019-10-09 13:29:16 +0100262
263 // Different name is useful for debugging
264 namespace_name = kVendorClassloaderNamespaceName;
265 ALOGD("classloader namespace configured for unbundled %s apk. library_path=%s",
266 origin_partition, library_path.c_str());
267 } else {
Jiyong Park14626a72020-07-02 23:17:58 +0900268 auto libs = filter_public_libraries(target_sdk_version, uses_libraries,
269 extended_public_libraries());
Orion Hodson9b16e342019-10-09 13:29:16 +0100270 // extended public libraries are NOT available to vendor apks, otherwise it
271 // would be system->vendor violation.
Jiyong Park14626a72020-07-02 23:17:58 +0900272 if (!libs.empty()) {
273 system_exposed_libraries = system_exposed_libraries + ':' + libs;
Orion Hodson9b16e342019-10-09 13:29:16 +0100274 }
275 }
276
Martin Stjernholm94fd9ea2019-10-24 16:57:34 +0100277 if (is_shared) {
278 // Show in the name that the namespace was created as shared, for debugging
279 // purposes.
280 namespace_name = namespace_name + kSharedNamespaceSuffix;
281 }
282
Orion Hodson9b16e342019-10-09 13:29:16 +0100283 // Create the app namespace
284 NativeLoaderNamespace* parent_ns = FindParentNamespaceByClassLoader(env, class_loader);
285 // Heuristic: the first classloader with non-empty library_path is assumed to
286 // be the main classloader for app
287 // TODO(b/139178525) remove this heuristic by determining this in LoadedApk (or its
288 // friends) and then passing it down to here.
289 bool is_main_classloader = app_main_namespace_ == nullptr && !library_path.empty();
290 // Policy: the namespace for the main classloader is also used as the
291 // anonymous namespace.
292 bool also_used_as_anonymous = is_main_classloader;
293 // Note: this function is executed with g_namespaces_mutex held, thus no
294 // racing here.
295 auto app_ns = NativeLoaderNamespace::Create(
296 namespace_name, library_path, permitted_path, parent_ns, is_shared,
Ryan Prichard232db5e2020-08-03 15:32:13 -0700297 target_sdk_version < 24 /* is_exempt_list_enabled */, also_used_as_anonymous);
Bernie Innocenti4bd58952020-02-06 15:43:57 +0900298 if (!app_ns.ok()) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100299 return app_ns.error();
300 }
301 // ... and link to other namespaces to allow access to some public libraries
302 bool is_bridged = app_ns->IsBridged();
303
Martin Stjernholmf0e99bd2020-02-11 22:57:14 +0000304 auto system_ns = NativeLoaderNamespace::GetSystemNamespace(is_bridged);
305 if (!system_ns.ok()) {
306 return system_ns.error();
Orion Hodson9b16e342019-10-09 13:29:16 +0100307 }
308
Martin Stjernholmf0e99bd2020-02-11 22:57:14 +0000309 auto linked = app_ns->Link(*system_ns, system_exposed_libraries);
Bernie Innocenti4bd58952020-02-06 15:43:57 +0900310 if (!linked.ok()) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100311 return linked.error();
312 }
313
Jooyung Hancd616d02020-09-01 14:53:23 +0900314 for (const auto&[apex_ns_name, public_libs] : apex_public_libraries()) {
315 auto ns = NativeLoaderNamespace::GetExportedNamespace(apex_ns_name, is_bridged);
316 // Even if APEX namespace is visible, it may not be available to bridged.
317 if (ns.ok()) {
318 linked = app_ns->Link(*ns, public_libs);
319 if (!linked.ok()) {
320 return linked.error();
321 }
Orion Hodson9b16e342019-10-09 13:29:16 +0100322 }
323 }
324
Justin Yuneb4f08c2020-02-18 11:29:07 +0900325 // Give access to VNDK-SP libraries from the 'vndk' namespace for unbundled vendor apps.
326 if (unbundled_app_origin == APK_ORIGIN_VENDOR && !vndksp_libraries_vendor().empty()) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100327 auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkNamespaceName, is_bridged);
Bernie Innocenti4bd58952020-02-06 15:43:57 +0900328 if (vndk_ns.ok()) {
Justin Yuneb4f08c2020-02-18 11:29:07 +0900329 linked = app_ns->Link(*vndk_ns, vndksp_libraries_vendor());
330 if (!linked.ok()) {
331 return linked.error();
332 }
333 }
334 }
335
336 // Give access to VNDK-SP libraries from the 'vndk_product' namespace for unbundled product apps.
337 if (unbundled_app_origin == APK_ORIGIN_PRODUCT && !vndksp_libraries_product().empty()) {
338 auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkProductNamespaceName, is_bridged);
339 if (vndk_ns.ok()) {
340 linked = app_ns->Link(*vndk_ns, vndksp_libraries_product());
Bernie Innocenti4bd58952020-02-06 15:43:57 +0900341 if (!linked.ok()) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100342 return linked.error();
343 }
344 }
345 }
346
Jooyung Han538f99a2020-03-03 00:46:50 +0900347 auto apex_ns_name = FindApexNamespaceName(dex_path);
348 if (apex_ns_name.ok()) {
349 const auto& jni_libs = apex_jni_libraries(*apex_ns_name);
350 if (jni_libs != "") {
351 auto apex_ns = NativeLoaderNamespace::GetExportedNamespace(*apex_ns_name, is_bridged);
352 if (apex_ns.ok()) {
Jooyung Hancd616d02020-09-01 14:53:23 +0900353 linked = app_ns->Link(*apex_ns, jni_libs);
354 if (!linked.ok()) {
Jooyung Han538f99a2020-03-03 00:46:50 +0900355 return linked.error();
356 }
357 }
358 }
359 }
360
Jeffrey Huang52575032020-02-11 17:33:45 -0800361 // Give access to StatsdAPI libraries
362 auto statsd_ns =
363 NativeLoaderNamespace::GetExportedNamespace(kStatsdNamespaceName, is_bridged);
364 if (statsd_ns.ok()) {
365 linked = app_ns->Link(*statsd_ns, statsd_public_libraries());
366 if (!linked.ok()) {
367 return linked.error();
368 }
369 }
370
Jiyong Park14626a72020-07-02 23:17:58 +0900371 auto vendor_libs = filter_public_libraries(target_sdk_version, uses_libraries,
372 vendor_public_libraries());
373 if (!vendor_libs.empty()) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100374 auto vendor_ns = NativeLoaderNamespace::GetExportedNamespace(kVendorNamespaceName, is_bridged);
Kiyoung Kim99c19ca2020-01-29 16:09:38 +0900375 // when vendor_ns is not configured, link to the system namespace
Martin Stjernholmf0e99bd2020-02-11 22:57:14 +0000376 auto target_ns = vendor_ns.ok() ? vendor_ns : system_ns;
Bernie Innocenti4bd58952020-02-06 15:43:57 +0900377 if (target_ns.ok()) {
Jiyong Park14626a72020-07-02 23:17:58 +0900378 linked = app_ns->Link(*target_ns, vendor_libs);
Bernie Innocenti4bd58952020-02-06 15:43:57 +0900379 if (!linked.ok()) {
Orion Hodson9b16e342019-10-09 13:29:16 +0100380 return linked.error();
381 }
382 }
383 }
384
Orion Hodsonc20ab9a2020-02-06 12:32:08 +0000385 auto& emplaced = namespaces_.emplace_back(
386 std::make_pair(env->NewWeakGlobalRef(class_loader), *app_ns));
Orion Hodson9b16e342019-10-09 13:29:16 +0100387 if (is_main_classloader) {
Orion Hodsonc20ab9a2020-02-06 12:32:08 +0000388 app_main_namespace_ = &emplaced.second;
Orion Hodson9b16e342019-10-09 13:29:16 +0100389 }
Orion Hodsonc20ab9a2020-02-06 12:32:08 +0000390 return &emplaced.second;
Orion Hodson9b16e342019-10-09 13:29:16 +0100391}
392
393NativeLoaderNamespace* LibraryNamespaces::FindNamespaceByClassLoader(JNIEnv* env,
394 jobject class_loader) {
395 auto it = std::find_if(namespaces_.begin(), namespaces_.end(),
396 [&](const std::pair<jweak, NativeLoaderNamespace>& value) {
397 return env->IsSameObject(value.first, class_loader);
398 });
399 if (it != namespaces_.end()) {
400 return &it->second;
401 }
402
403 return nullptr;
404}
405
406NativeLoaderNamespace* LibraryNamespaces::FindParentNamespaceByClassLoader(JNIEnv* env,
407 jobject class_loader) {
408 jobject parent_class_loader = GetParentClassLoader(env, class_loader);
409
410 while (parent_class_loader != nullptr) {
411 NativeLoaderNamespace* ns;
412 if ((ns = FindNamespaceByClassLoader(env, parent_class_loader)) != nullptr) {
413 return ns;
414 }
415
416 parent_class_loader = GetParentClassLoader(env, parent_class_loader);
417 }
418
419 return nullptr;
420}
421
Jooyung Han538f99a2020-03-03 00:46:50 +0900422base::Result<std::string> FindApexNamespaceName(const std::string& location) {
423 // Lots of implicit assumptions here: we expect `location` to be of the form:
424 // /apex/modulename/...
425 //
426 // And we extract from it 'modulename', and then apply mangling rule to get namespace name for it.
427 if (android::base::StartsWith(location, kApexPath)) {
428 size_t start_index = strlen(kApexPath);
429 size_t slash_index = location.find_first_of('/', start_index);
430 LOG_ALWAYS_FATAL_IF((slash_index == std::string::npos),
431 "Error finding namespace of apex: no slash in path %s", location.c_str());
432 std::string name = location.substr(start_index, slash_index - start_index);
433 std::replace(name.begin(), name.end(), '.', '_');
434 return name;
435 }
436 return base::Error();
437}
438
Orion Hodson9b16e342019-10-09 13:29:16 +0100439} // namespace android::nativeloader
Nicolas Geoffray7ca8b672020-04-24 15:43:48 +0100440
441#endif // defined(ART_TARGET_ANDROID)