Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2016 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 package com.android.internal.os;
     18 
     19 import android.os.Trace;
     20 
     21 import dalvik.system.PathClassLoader;
     22 
     23 /**
     24  * Creates path class loaders.
     25  *
     26  * @hide
     27  */
     28 public class PathClassLoaderFactory {
     29     // Unconstructable
     30     private PathClassLoaderFactory() {}
     31 
     32     /**
     33      * Create a PathClassLoader and initialize a linker-namespace for it.
     34      *
     35      * @hide
     36      */
     37     public static PathClassLoader createClassLoader(String dexPath,
     38                                                     String librarySearchPath,
     39                                                     String libraryPermittedPath,
     40                                                     ClassLoader parent,
     41                                                     int targetSdkVersion,
     42                                                     boolean isNamespaceShared) {
     43         PathClassLoader pathClassloader = new PathClassLoader(dexPath, librarySearchPath, parent);
     44 
     45         Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "createClassloaderNamespace");
     46         String errorMessage = createClassloaderNamespace(pathClassloader,
     47                                                          targetSdkVersion,
     48                                                          librarySearchPath,
     49                                                          libraryPermittedPath,
     50                                                          isNamespaceShared);
     51         Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
     52 
     53         if (errorMessage != null) {
     54             throw new UnsatisfiedLinkError("Unable to create namespace for the classloader " +
     55                                            pathClassloader + ": " + errorMessage);
     56         }
     57 
     58         return pathClassloader;
     59     }
     60 
     61     private static native String createClassloaderNamespace(ClassLoader classLoader,
     62                                                             int targetSdkVersion,
     63                                                             String librarySearchPath,
     64                                                             String libraryPermittedPath,
     65                                                             boolean isNamespaceShared);
     66 }
     67