初始化
//通过类加载进行初始化,没有对外暴露,对外只是暴露SystemInf
private SystemInf mInterface = null;
public boolean init(Context ctx) {
if (this.mInterface == null) {
try {
DexClassLoader cls_loader = ClassLoaderHelper.getCalssLoader(ctx);
if (cls_loader == null) {
return false;
}
Class myClass = cls_loader.loadClass("com.entrance.hwinf.SystemDevice");
this.mInterface = (SystemInf)myClass.newInstance();
} catch (Exception var4) {
Log.e("hwinf_SystemAdapter", "load class error: " + var4);
return false;
}
}
return this.mInterface.init(ctx);
}
类怎么加载呢
static DexClassLoader getCalssLoader(Context ctx) {
if (mClassLoader == null) {
File f1 = new File("/system/framework/com.entrance.hwdevice.jar");
File f2 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/com.entrance.hwdevice.jar");
String dex_path = null;
String tmpPath = ctx.getDir("jar", 0).getAbsolutePath();
if (f1.exists()) {
dex_path = f1.getAbsolutePath();
} else if (f2.exists()) {
dex_path = f2.getAbsolutePath();
}
if (dex_path == null) {
Log.w("hwinf_ClassLoader", "the com.entrance.hwdevice.jar not exist!");
return null;
}
Log.d("hwinf_ClassLoader", "jar url is: " + dex_path);
mClassLoader = new DexClassLoader(dex_path, tmpPath, (String)null, ctx.getClassLoader());
}
return mClassLoader;
}