blob: 353b5fcf0963d831a3c99ce09471145d78fc97ad [file] [log] [blame]
Jiyong Park6291da22019-04-26 18:55:48 +09001/*
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 */
16#pragma once
17#if !defined(__ANDROID__)
18#error "Not available for host"
19#endif
20
21#include "native_loader_namespace.h"
22
23#include <list>
24#include <string>
25
26#include "jni.h"
27
28namespace android {
29
30// LibraryNamespaces is a singleton object that manages NativeLoaderNamespace
31// objects for an app process. Its main job is to create (and configure) a new
32// NativeLoaderNamespace object for a Java ClassLoader, and to find an existing
33// object for a given ClassLoader.
34class LibraryNamespaces {
35 public:
36 LibraryNamespaces() : initialized_(false) {}
37
38 LibraryNamespaces(LibraryNamespaces&&) = default;
39 LibraryNamespaces(const LibraryNamespaces&) = delete;
40 LibraryNamespaces& operator=(const LibraryNamespaces&) = delete;
41
42 void Initialize();
43 void Reset() { namespaces_.clear(); }
44 NativeLoaderNamespace* Create(JNIEnv* env, uint32_t target_sdk_version, jobject class_loader,
45 bool is_shared, jstring dex_path, jstring java_library_path,
46 jstring java_permitted_path, std::string* error_msg);
47 NativeLoaderNamespace* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader);
48
49 private:
50 bool InitPublicNamespace(const char* library_path, std::string* error_msg);
51 NativeLoaderNamespace* FindParentNamespaceByClassLoader(JNIEnv* env, jobject class_loader);
52
53 bool initialized_;
54 std::list<std::pair<jweak, NativeLoaderNamespace>> namespaces_;
55 std::string system_public_libraries_;
56 std::string runtime_public_libraries_;
57 std::string vendor_public_libraries_;
58 std::string oem_public_libraries_;
59 std::string product_public_libraries_;
60 std::string system_llndk_libraries_;
61 std::string system_vndksp_libraries_;
62};
63
64} // namespace android