blob: 103cfacbcc5f35a690e8a860f56e0c68762355a7 [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
Jiyong Park40a60772019-05-03 16:21:31 +090021#define LOG_TAG "nativeloader"
22
Jiyong Park6291da22019-04-26 18:55:48 +090023#include "native_loader_namespace.h"
24
25#include <list>
26#include <string>
27
28#include "jni.h"
Jiyong Parkf8802e52019-05-03 16:34:56 +090029#include "utils.h"
Jiyong Park6291da22019-04-26 18:55:48 +090030
Jiyong Park40a60772019-05-03 16:21:31 +090031namespace android::nativeloader {
Jiyong Park6291da22019-04-26 18:55:48 +090032
33// LibraryNamespaces is a singleton object that manages NativeLoaderNamespace
34// objects for an app process. Its main job is to create (and configure) a new
35// NativeLoaderNamespace object for a Java ClassLoader, and to find an existing
36// object for a given ClassLoader.
37class LibraryNamespaces {
38 public:
39 LibraryNamespaces() : initialized_(false) {}
40
41 LibraryNamespaces(LibraryNamespaces&&) = default;
42 LibraryNamespaces(const LibraryNamespaces&) = delete;
43 LibraryNamespaces& operator=(const LibraryNamespaces&) = delete;
44
45 void Initialize();
46 void Reset() { namespaces_.clear(); }
47 NativeLoaderNamespace* Create(JNIEnv* env, uint32_t target_sdk_version, jobject class_loader,
48 bool is_shared, jstring dex_path, jstring java_library_path,
49 jstring java_permitted_path, std::string* error_msg);
50 NativeLoaderNamespace* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader);
51
52 private:
53 bool InitPublicNamespace(const char* library_path, std::string* error_msg);
54 NativeLoaderNamespace* FindParentNamespaceByClassLoader(JNIEnv* env, jobject class_loader);
55
56 bool initialized_;
57 std::list<std::pair<jweak, NativeLoaderNamespace>> namespaces_;
Jiyong Park6291da22019-04-26 18:55:48 +090058};
59
Jiyong Park40a60772019-05-03 16:21:31 +090060} // namespace android::nativeloader