xref: /aosp_15_r20/art/libnativeloader/public_libraries.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2019 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBNATIVELOADER_PUBLIC_LIBRARIES_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_LIBNATIVELOADER_PUBLIC_LIBRARIES_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <algorithm>
21*795d594fSAndroid Build Coastguard Worker #include <map>
22*795d594fSAndroid Build Coastguard Worker #include <string>
23*795d594fSAndroid Build Coastguard Worker 
24*795d594fSAndroid Build Coastguard Worker #include <android-base/result.h>
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker namespace android::nativeloader {
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker using android::base::Result;
29*795d594fSAndroid Build Coastguard Worker 
30*795d594fSAndroid Build Coastguard Worker // These provide the list of libraries that are available to the namespace for apps.
31*795d594fSAndroid Build Coastguard Worker // Not all of the libraries are available to apps. Depending on the context,
32*795d594fSAndroid Build Coastguard Worker // e.g., if it is a vendor app or not, different set of libraries are made available.
33*795d594fSAndroid Build Coastguard Worker const std::string& preloadable_public_libraries();
34*795d594fSAndroid Build Coastguard Worker const std::string& default_public_libraries();
35*795d594fSAndroid Build Coastguard Worker const std::string& vendor_public_libraries();
36*795d594fSAndroid Build Coastguard Worker const std::string& product_public_libraries();
37*795d594fSAndroid Build Coastguard Worker const std::string& extended_public_libraries();
38*795d594fSAndroid Build Coastguard Worker const std::string& llndk_libraries_product();
39*795d594fSAndroid Build Coastguard Worker const std::string& llndk_libraries_vendor();
40*795d594fSAndroid Build Coastguard Worker const std::string& vndksp_libraries_product();
41*795d594fSAndroid Build Coastguard Worker const std::string& vndksp_libraries_vendor();
42*795d594fSAndroid Build Coastguard Worker const std::string& apex_jni_libraries(const std::string& apex_name);
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker // Returns the table of apexes and public libraries provided by the apexes.
45*795d594fSAndroid Build Coastguard Worker // For example, com_android_foo -> libfoo.so:libbar.so
46*795d594fSAndroid Build Coastguard Worker // Note that libfoo.so and libbar.so are listed in /system/etc/public.libraries.txt
47*795d594fSAndroid Build Coastguard Worker // but provided by com.android.foo APEX.
48*795d594fSAndroid Build Coastguard Worker const std::map<std::string, std::string>& apex_public_libraries();
49*795d594fSAndroid Build Coastguard Worker 
50*795d594fSAndroid Build Coastguard Worker std::string get_vndk_version(bool is_product_vndk);
51*795d594fSAndroid Build Coastguard Worker 
52*795d594fSAndroid Build Coastguard Worker // Returnes true if libnativeloader is running on devices and the device has
53*795d594fSAndroid Build Coastguard Worker // treblelized product partition. It returns false for host.
54*795d594fSAndroid Build Coastguard Worker // TODO: Remove this function and assume it is always true once when Mainline does not support any
55*795d594fSAndroid Build Coastguard Worker // devices launched with Q or below.
56*795d594fSAndroid Build Coastguard Worker bool is_product_treblelized();
57*795d594fSAndroid Build Coastguard Worker 
58*795d594fSAndroid Build Coastguard Worker // These are exported for testing
59*795d594fSAndroid Build Coastguard Worker namespace internal {
60*795d594fSAndroid Build Coastguard Worker 
61*795d594fSAndroid Build Coastguard Worker enum Bitness { ALL = 0, ONLY_32, ONLY_64 };
62*795d594fSAndroid Build Coastguard Worker 
63*795d594fSAndroid Build Coastguard Worker struct ConfigEntry {
64*795d594fSAndroid Build Coastguard Worker   std::string soname;
65*795d594fSAndroid Build Coastguard Worker   bool nopreload;
66*795d594fSAndroid Build Coastguard Worker   Bitness bitness;
67*795d594fSAndroid Build Coastguard Worker };
68*795d594fSAndroid Build Coastguard Worker 
69*795d594fSAndroid Build Coastguard Worker Result<std::vector<std::string>> ParseConfig(
70*795d594fSAndroid Build Coastguard Worker     const std::string& file_content,
71*795d594fSAndroid Build Coastguard Worker     const std::function<Result<bool>(const ConfigEntry& /* entry */)>& filter_fn);
72*795d594fSAndroid Build Coastguard Worker 
73*795d594fSAndroid Build Coastguard Worker // Parses apex.libraries.config.txt file generated by linkerconfig
74*795d594fSAndroid Build Coastguard Worker // and returns mapping of <apex namespace> to <library list> which matches <tag>.
75*795d594fSAndroid Build Coastguard Worker Result<std::map<std::string, std::string>> ParseApexLibrariesConfig(
76*795d594fSAndroid Build Coastguard Worker     const std::string& file_content, const std::string& tag);
77*795d594fSAndroid Build Coastguard Worker 
78*795d594fSAndroid Build Coastguard Worker }  // namespace internal
79*795d594fSAndroid Build Coastguard Worker 
80*795d594fSAndroid Build Coastguard Worker }  // namespace android::nativeloader
81*795d594fSAndroid Build Coastguard Worker 
82*795d594fSAndroid Build Coastguard Worker #endif  // ART_LIBNATIVELOADER_PUBLIC_LIBRARIES_H_
83