use of dalvik.system.DexClassLoader in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method makeWimaxStateTracker.
/**
* Loads external WiMAX library and registers as system service, returning a
* {@link NetworkStateTracker} for WiMAX. Caller is still responsible for
* invoking {@link NetworkStateTracker#startMonitoring(Context, Handler)}.
*/
private static NetworkStateTracker makeWimaxStateTracker(Context context, Handler trackerHandler) {
// Initialize Wimax
DexClassLoader wimaxClassLoader;
Class wimaxStateTrackerClass = null;
Class wimaxServiceClass = null;
Class wimaxManagerClass;
String wimaxJarLocation;
String wimaxLibLocation;
String wimaxManagerClassName;
String wimaxServiceClassName;
String wimaxStateTrackerClassName;
NetworkStateTracker wimaxStateTracker = null;
boolean isWimaxEnabled = context.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
if (isWimaxEnabled) {
try {
wimaxJarLocation = context.getResources().getString(com.android.internal.R.string.config_wimaxServiceJarLocation);
wimaxLibLocation = context.getResources().getString(com.android.internal.R.string.config_wimaxNativeLibLocation);
wimaxManagerClassName = context.getResources().getString(com.android.internal.R.string.config_wimaxManagerClassname);
wimaxServiceClassName = context.getResources().getString(com.android.internal.R.string.config_wimaxServiceClassname);
wimaxStateTrackerClassName = context.getResources().getString(com.android.internal.R.string.config_wimaxStateTrackerClassname);
if (DBG)
log("wimaxJarLocation: " + wimaxJarLocation);
wimaxClassLoader = new DexClassLoader(wimaxJarLocation, new ContextWrapper(context).getCacheDir().getAbsolutePath(), wimaxLibLocation, ClassLoader.getSystemClassLoader());
try {
wimaxManagerClass = wimaxClassLoader.loadClass(wimaxManagerClassName);
wimaxStateTrackerClass = wimaxClassLoader.loadClass(wimaxStateTrackerClassName);
wimaxServiceClass = wimaxClassLoader.loadClass(wimaxServiceClassName);
} catch (ClassNotFoundException ex) {
loge("Exception finding Wimax classes: " + ex.toString());
return null;
}
} catch (Resources.NotFoundException ex) {
loge("Wimax Resources does not exist!!! ");
return null;
}
try {
if (DBG)
log("Starting Wimax Service... ");
Constructor wmxStTrkrConst = wimaxStateTrackerClass.getConstructor(new Class[] { Context.class, Handler.class });
wimaxStateTracker = (NetworkStateTracker) wmxStTrkrConst.newInstance(context, trackerHandler);
Constructor wmxSrvConst = wimaxServiceClass.getDeclaredConstructor(new Class[] { Context.class, wimaxStateTrackerClass });
wmxSrvConst.setAccessible(true);
IBinder svcInvoker = (IBinder) wmxSrvConst.newInstance(context, wimaxStateTracker);
wmxSrvConst.setAccessible(false);
ServiceManager.addService(WimaxManagerConstants.WIMAX_SERVICE, svcInvoker);
} catch (Exception ex) {
loge("Exception creating Wimax classes: " + ex.toString());
return null;
}
} else {
loge("Wimax is not enabled or not added to the network attributes!!! ");
return null;
}
return wimaxStateTracker;
}
use of dalvik.system.DexClassLoader in project VirtualAPK by didi.
the class LoadedPlugin method createClassLoader.
private static ClassLoader createClassLoader(Context context, File apk, File libsDir, ClassLoader parent) {
File dexOutputDir = context.getDir(Constants.OPTIMIZE_DIR, Context.MODE_PRIVATE);
String dexOutputPath = dexOutputDir.getAbsolutePath();
DexClassLoader loader = new DexClassLoader(apk.getAbsolutePath(), dexOutputPath, libsDir.getAbsolutePath(), parent);
if (Constants.COMBINE_CLASSLOADER) {
try {
DexUtil.insertDex(loader);
} catch (Exception e) {
e.printStackTrace();
}
}
return loader;
}
use of dalvik.system.DexClassLoader in project blog_resource by Guolei1130.
the class MainActivity method loadExtApk.
private void loadExtApk() {
String apkPath = new File("/sdcard/plugin_1.apk").getPath();
File dexOptOutDir = new File(getFilesDir(), "dexopt");
if (!dexOptOutDir.exists()) {
boolean result = dexOptOutDir.mkdir();
if (!result) {
Log.e(TAG, "loadExtJar: create out dir error");
}
}
String dexOptOutDr = dexOptOutDir.getPath();
ClassLoader classLoader = null;
if (Constants.isDalvik()) {
classLoader = new DexClassLoader(apkPath, dexOptOutDr, null, ClassLoader.getSystemClassLoader());
} else {
classLoader = new PathClassLoader(apkPath, ClassLoader.getSystemClassLoader());
}
try {
Class userClz = classLoader.loadClass("com.guolei.plugin_1.People");
Object user = userClz.getConstructor(String.class, int.class).newInstance("guolei", 24);
Method method = userClz.getDeclaredMethod("toString");
method.setAccessible(true);
String msg = (String) method.invoke(user);
Log.e(TAG, "loadExtApk: " + msg);
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
use of dalvik.system.DexClassLoader in project AndroidLife by CaMnter.
the class Server method handleHotSwapPatch.
/**
* 热部署 加载补丁
*
* 1. 将补丁文件 保存为 /data/data/.../files/instant-run/dex-temp/reload0x????.dex
* 2. 然后 通过 此 dex 去创建一个 DexClassLoader
* 3. 通过创建的 DexClassLoader 去寻找内部的 AppPatchesLoaderImpl类
* 4. 进而获取 getPatchedClasses 方法,得到 String[] classes
* 5. 然后打 String[] classes 的 Log
* 6. AppPatchesLoaderImpl 向上转为 PatchesLoader 类型
* 7. 调用 ( AppPatchesLoaderImpl )PatchesLoader.load() 方法打上 $override 和 $change 标记位
*
* @param updateMode 更新模式
* @param patch 补丁
* @return 更新模式
*/
private int handleHotSwapPatch(int updateMode, @NonNull ApplicationPatch patch) {
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Received incremental code patch");
}
try {
String dexFile = FileManager.writeTempDexFile(patch.getBytes());
if (dexFile == null) {
Log.e(LOG_TAG, "No file to write the code to");
return updateMode;
} else if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Reading live code from " + dexFile);
}
String nativeLibraryPath = FileManager.getNativeLibraryFolder().getPath();
DexClassLoader dexClassLoader = new DexClassLoader(dexFile, mApplication.getCacheDir().getPath(), nativeLibraryPath, getClass().getClassLoader());
// we should transform this process with an interface/impl
Class<?> aClass = Class.forName("com.android.tools.fd.runtime.AppPatchesLoaderImpl", true, dexClassLoader);
try {
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Got the patcher class " + aClass);
}
PatchesLoader loader = (PatchesLoader) aClass.newInstance();
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Got the patcher instance " + loader);
}
String[] getPatchedClasses = (String[]) aClass.getDeclaredMethod("getPatchedClasses").invoke(loader);
if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
Log.v(LOG_TAG, "Got the list of classes ");
for (String getPatchedClass : getPatchedClasses) {
Log.v(LOG_TAG, "class " + getPatchedClass);
}
}
if (!loader.load()) {
updateMode = UPDATE_MODE_COLD_SWAP;
}
} catch (Exception e) {
Log.e(LOG_TAG, "Couldn't apply code changes", e);
e.printStackTrace();
updateMode = UPDATE_MODE_COLD_SWAP;
}
} catch (Throwable e) {
Log.e(LOG_TAG, "Couldn't apply code changes", e);
updateMode = UPDATE_MODE_COLD_SWAP;
}
return updateMode;
}
use of dalvik.system.DexClassLoader in project AndroidLife by CaMnter.
the class SmartApplication method loadDex.
private void loadDex() {
try {
String dir = null;
final File cacheDir = this.getExternalCacheDir();
final File filesDir = this.getExternalFilesDir("");
if (cacheDir != null) {
dir = cacheDir.getAbsolutePath();
} else {
if (filesDir != null) {
dir = filesDir.getAbsolutePath();
}
}
if (TextUtils.isEmpty(dir))
return;
// assets 的 single-resources-plugin.apk 拷贝到 /storage/sdcard0/Android/data/[package name]/cache
// 或者 /storage/sdcard0/Android/data/[package name]/files
final File dexPath = new File(dir + File.separator + "single-resources-plugin.apk");
final String dexAbsolutePath = dexPath.getAbsolutePath();
AssetsUtils.copyAssets(this, "single-resources-plugin.apk", dexAbsolutePath);
// /data/data/[package name]/app_single-resources-plugin
final File optimizedDirectory = this.getDir("single-resources-plugin", MODE_PRIVATE);
this.dexClassLoader = new DexClassLoader(dexPath.getAbsolutePath(), optimizedDirectory.getAbsolutePath(), null, this.getClassLoader());
this.dexAbsolutePath = dexAbsolutePath;
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations