1 /*
2  * Copyright (C) 2007 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 dalvik.system;
18 
19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
20 
21 import android.annotation.SystemApi;
22 
23 import libcore.util.NonNull;
24 import libcore.util.Nullable;
25 
26 /**
27  * Provides a simple {@link ClassLoader} implementation that operates on a list
28  * of files and directories in the local file system, but does not attempt to
29  * load classes from the network. Android uses this class for its system class
30  * loader and for its application class loader(s).
31  */
32 public class PathClassLoader extends BaseDexClassLoader {
33     /**
34      * Creates a {@code PathClassLoader} that operates on a given list of files
35      * and directories. This method is equivalent to calling
36      * {@link #PathClassLoader(String, String, ClassLoader)} with a
37      * {@code null} value for the second argument (see description there).
38      *
39      * @param dexPath the list of jar/apk files containing classes and
40      * resources, delimited by {@code File.pathSeparator}, which
41      * defaults to {@code ":"} on Android
42      * @param parent the parent class loader
43      */
PathClassLoader(String dexPath, ClassLoader parent)44     public PathClassLoader(String dexPath, ClassLoader parent) {
45         super(dexPath, null, null, parent);
46     }
47 
48     /**
49      * Creates a {@code PathClassLoader} that operates on two given
50      * lists of files and directories. The entries of the first list
51      * should be one of the following:
52      *
53      * <ul>
54      * <li>JAR/ZIP/APK files, possibly containing a "classes.dex" file as
55      * well as arbitrary resources.
56      * <li>Raw ".dex" files (not inside a zip file).
57      * </ul>
58      *
59      * The entries of the second list should be directories containing
60      * native library files.
61      *
62      * @param dexPath the list of jar/apk files containing classes and
63      * resources, delimited by {@code File.pathSeparator}, which
64      * defaults to {@code ":"} on Android
65      * @param librarySearchPath the list of directories containing native
66      * libraries, delimited by {@code File.pathSeparator}; may be
67      * {@code null}
68      * @param parent the parent class loader
69      */
PathClassLoader(String dexPath, String librarySearchPath, ClassLoader parent)70     public PathClassLoader(String dexPath, String librarySearchPath, ClassLoader parent) {
71         super(dexPath, null, librarySearchPath, parent);
72     }
73 
74     /**
75      * Creates a {@code PathClassLoader} that operates on two given
76      * lists of files and directories. The entries of the first list
77      * should be one of the following:
78      *
79      * <ul>
80      * <li>JAR/ZIP/APK files, possibly containing a "classes.dex" file as
81      * well as arbitrary resources.
82      * <li>Raw ".dex" files (not inside a zip file).
83      * </ul>
84      *
85      * The entries of the second list should be directories containing
86      * native library files.
87      *
88      * @param dexPath the list of jar/apk files containing classes and
89      * resources, delimited by {@code File.pathSeparator}, which
90      * defaults to {@code ":"} on Android
91      * @param librarySearchPath the list of directories containing native
92      * libraries, delimited by {@code File.pathSeparator}; may be
93      * {@code null}
94      * @param parent the parent class loader
95      * @param sharedLibraryLoaders class loaders of Java shared libraries
96      * used by this new class loader. The shared library loaders are always
97      * checked before the {@code dexPath} when looking
98      * up classes and resources.
99      *
100      * @hide
101      */
102     @SystemApi(client = MODULE_LIBRARIES)
103     @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
PathClassLoader( @onNull String dexPath, @Nullable String librarySearchPath, @Nullable ClassLoader parent, @Nullable ClassLoader[] sharedLibraryLoaders)104     public PathClassLoader(
105             @NonNull String dexPath, @Nullable String librarySearchPath, @Nullable ClassLoader parent,
106             @Nullable ClassLoader[] sharedLibraryLoaders) {
107         super(dexPath, librarySearchPath, parent, sharedLibraryLoaders);
108     }
109 }
110