1 /*
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 
18 #include "linkerconfig/namespace.h"
19 
20 using namespace android::linkerconfig::modules;
21 
CreateNamespaceWithPaths(const std::string & name,bool is_isolated,bool is_visible)22 inline Namespace CreateNamespaceWithPaths(const std::string& name,
23                                           bool is_isolated, bool is_visible) {
24   Namespace ns(name, is_isolated, is_visible);
25   ns.AddSearchPath("/search_path1");
26   ns.AddSearchPath("/apex/search_path2");
27   ns.AddPermittedPath("/permitted_path1");
28   ns.AddPermittedPath("/apex/permitted_path2");
29 
30   return ns;
31 }
32 
CreateNamespaceWithLinks(const std::string & name,bool is_isolated,bool is_visible,const std::string & target_1,const std::string & target_2)33 inline Namespace CreateNamespaceWithLinks(const std::string& name,
34                                           bool is_isolated, bool is_visible,
35                                           const std::string& target_1,
36                                           const std::string& target_2) {
37   Namespace ns = CreateNamespaceWithPaths(name, is_isolated, is_visible);
38   auto& link = ns.GetLink(target_1);
39   link.AddSharedLib("lib1.so", "lib2.so", "lib3.so");
40 
41   ns.GetLink(target_2).AllowAllSharedLibs();
42   return ns;
43 }
44