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 17 package dalvik.system; 18 19 /** 20 * A class loader that loads classes from {@code .jar} and {@code .apk} files 21 * containing a {@code classes.dex} entry. This can be used to execute code not 22 * installed as part of an application. 23 * 24 * <p>Prior to API level 26, this class loader requires an 25 * application-private, writable directory to cache optimized classes. 26 * Use {@code Context.getCodeCacheDir()} to create such a directory: 27 * <pre> {@code 28 * File dexOutputDir = context.getCodeCacheDir(); 29 * }</pre> 30 * 31 * <p><strong>Do not cache optimized classes on external storage.</strong> 32 * External storage does not provide access controls necessary to protect your 33 * application from code injection attacks. 34 */ 35 public class DexClassLoader extends BaseDexClassLoader { 36 /** 37 * Creates a {@code DexClassLoader} that finds interpreted and native 38 * code. Interpreted classes are found in a set of DEX files contained 39 * in Jar or APK files. 40 * 41 * <p>The path lists are separated using the character specified by the 42 * {@code path.separator} system property, which defaults to {@code :}. 43 * 44 * @param dexPath the list of jar/apk files containing classes and 45 * resources, delimited by {@code File.pathSeparator}, which 46 * defaults to {@code ":"} on Android 47 * @param optimizedDirectory this parameter is deprecated and has no effect since API level 26. 48 * @param librarySearchPath the list of directories containing native 49 * libraries, delimited by {@code File.pathSeparator}; may be 50 * {@code null} 51 * @param parent the parent class loader 52 */ DexClassLoader(String dexPath, String optimizedDirectory, String librarySearchPath, ClassLoader parent)53 public DexClassLoader(String dexPath, String optimizedDirectory, 54 String librarySearchPath, ClassLoader parent) { 55 super(dexPath, null, librarySearchPath, parent); 56 } 57 } 58