DexClassLoader.java revision 86cc92ed3ded99ef0b1f6875a8bd885b5ba9c294
1/*
2 * Copyright (C) 2008 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
17package dalvik.system;
18
19import java.io.File;
20
21/**
22 * A class loader that loads classes from {@code .jar} and {@code .apk} files
23 * containing a {@code classes.dex} entry. This can be used to execute code not
24 * installed as part of an application.
25 *
26 * <p>This class loader requires an application-private, writable directory to
27 * cache optimized classes. Use {@code Context.getCodeCacheDir()} to create
28 * such a directory: <pre>   {@code
29 *   File dexOutputDir = context.getCodeCacheDir();
30 * }</pre>
31 *
32 * <p><strong>Do not cache optimized classes on external storage.</strong>
33 * External storage does not provide access controls necessary to protect your
34 * application from code injection attacks.
35 */
36public class DexClassLoader extends BaseDexClassLoader {
37    /**
38     * Creates a {@code DexClassLoader} that finds interpreted and native
39     * code.  Interpreted classes are found in a set of DEX files contained
40     * in Jar or APK files.
41     *
42     * <p>The path lists are separated using the character specified by the
43     * {@code path.separator} system property, which defaults to {@code :}.
44     *
45     * @param dexPath the list of jar/apk files containing classes and
46     *     resources, delimited by {@code File.pathSeparator}, which
47     *     defaults to {@code ":"} on Android
48     * @param optimizedDirectory directory where optimized dex files
49     *     should be written; must not be {@code null}
50     * @param librarySearchPath the list of directories containing native
51     *     libraries, delimited by {@code File.pathSeparator}; may be
52     *     {@code null}
53     * @param parent the parent class loader
54     *
55     * This method will be deprecated in the next release
56     */
57    public DexClassLoader(String dexPath, String optimizedDirectory,
58            String librarySearchPath, ClassLoader parent) {
59        super(dexPath, new File(optimizedDirectory), false, librarySearchPath, null, parent);
60    }
61
62    /**
63     * Creates a {@code DexClassLoader} that finds interpreted and native
64     * code.  Interpreted classes are found in a set of DEX files contained
65     * in Jar or APK files.
66     *
67     * <p>The path lists are separated using the character specified by the
68     * {@code path.separator} system property, which defaults to {@code :}.
69     *
70     * @param dexPath the list of jar/apk files containing classes and
71     *     resources, delimited by {@code File.pathSeparator}, which
72     *     defaults to {@code ":"} on Android
73     * @param optimizedDirectory directory where optimized dex files
74     *     should be written; must not be {@code null}
75     * @param librarySearchPath the list of directories containing native
76     *     libraries, delimited by {@code File.pathSeparator}; may be
77     *     {@code null}
78     * @param libraryPermittedPath Allowing open native libraries under
79     * 		 directories in this list. The list is delimited by
80     *     {@code File.pathSeparator}. Note that the classloader
81     *     is implicitly allowed to open libraries from the
82     *     directories on librarySearchPath. Directories from this list
83     *     are NOT used to search for the native library;
84     *     may be {@code null}
85     * @param parent the parent class loader
86     *
87     * @hide
88     */
89    public DexClassLoader(String dexPath, String optimizedDirectory,
90            String librarySearchPath, String libraryPermittedPath, ClassLoader parent) {
91        super(dexPath, new File(optimizedDirectory), false, librarySearchPath,
92              libraryPermittedPath, parent);
93    }
94}
95