package android.app;
public
class
ApplicationLoaders {
public static ApplicationLoaders getDefault() {
return
gApplicationLoaders;
}
ClassLoader getClassLoader(String
zip
,
int
targetSdkVersion, boolean isBundled,
String librarySearchPath, String libraryPermittedPath,
ClassLoader parent, String classLoaderName) {
/
/
For normal usage the cache key used
is
the same as the
zip
path.
/
/
=
=
=
=
=
=
=
=
=
=
>>> 调用另一个getClassLoader <<<
=
=
=
=
=
=
=
=
=
=
return
getClassLoader(
zip
, targetSdkVersion, isBundled, librarySearchPath,
libraryPermittedPath, parent,
zip
, classLoaderName);
}
private ClassLoader getClassLoader(String
zip
,
int
targetSdkVersion, boolean isBundled,
String librarySearchPath, String libraryPermittedPath,
ClassLoader parent, String cacheKey,
String classLoaderName) {
/
*
*
This
is
the parent we use
if
they
pass
"null"
in
. In theory
*
this should be the
"system"
class
loader;
in
practice we
*
don't use that
and
can happily (
and
more efficiently) use the
*
bootstrap
class
loader.
*
/
ClassLoader baseParent
=
ClassLoader.getSystemClassLoader().getParent();
synchronized (mLoaders) {
if
(parent
=
=
null) {
parent
=
baseParent;
}
/
*
*
If we're one step up
from
the base
class
loader, find
*
something
in
our cache. Otherwise, we create a whole
*
new ClassLoader
for
the
zip
archive.
*
/
if
(parent
=
=
baseParent) {
ClassLoader loader
=
mLoaders.get(cacheKey);
if
(loader !
=
null) {
return
loader;
}
/
/
...省略,chinamima
/
/
=
=
=
=
=
=
=
=
=
=
>>> 工厂模式生成PathClassLoader实例 <<<
=
=
=
=
=
=
=
=
=
=
ClassLoader classloader
=
ClassLoaderFactory.createClassLoader(
zip
, librarySearchPath, libraryPermittedPath, parent,
targetSdkVersion, isBundled, classLoaderName);
/
/
...省略,chinamima
mLoaders.put(cacheKey, classloader);
return
classloader;
}
/
/
=
=
=
=
=
=
=
=
=
=
>>> 工厂模式生成PathClassLoader实例 <<<
=
=
=
=
=
=
=
=
=
=
ClassLoader loader
=
ClassLoaderFactory.createClassLoader(
zip
, null, parent, classLoaderName);
return
loader;
}
}
private final ArrayMap<String, ClassLoader> mLoaders
=
new ArrayMap<>();
private static final ApplicationLoaders gApplicationLoaders
=
new ApplicationLoaders();