1/* 2 * Copyright 2017 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 17/* 18 * Copyright 2017 The Netty Project 19 * 20 * The Netty Project licenses this file to you under the Apache License, 21 * version 2.0 (the "License"); you may not use this file except in compliance 22 * with the License. You may obtain a copy of the License at: 23 * 24 * http://www.apache.org/licenses/LICENSE-2.0 25 * 26 * Unless required by applicable law or agreed to in writing, software 27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 29 * License for the specific language governing permissions and limitations 30 * under the License. 31 */ 32package org.conscrypt; 33 34/** 35 * A Utility to Call the {@link System#load(String)} or {@link System#loadLibrary(String)}. 36 * Because the {@link System#load(String)} and {@link System#loadLibrary(String)} are both 37 * CallerSensitive, it will load the native library into its caller's {@link ClassLoader}. 38 * In OSGi environment, we need this helper to delegate the calling to {@link System#load(String)} 39 * and it should be as simple as possible. It will be injected into the native library's 40 * ClassLoader when it is undefined. And therefore, when the defined new helper is invoked, 41 * the native library would be loaded into the native library's ClassLoader, not the 42 * caller's ClassLoader. 43 */ 44final class NativeLibraryUtil { 45 /** 46 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}. 47 * @param libName - The native library path or name 48 * @param absolute - Whether the native library will be loaded by path or by name 49 */ 50 public static void loadLibrary(String libName, boolean absolute) { 51 if (absolute) { 52 System.load(libName); 53 } else { 54 System.loadLibrary(libName); 55 } 56 } 57 58 private NativeLibraryUtil() { 59 // Utility 60 } 61}