From 2424cf9a01f24695137e702e2d870541aa872e0d Mon Sep 17 00:00:00 2001 From: yangwei Date: Thu, 25 Aug 2016 14:23:17 +0800 Subject: [PATCH] add Nougat support --- .../ctrip/android/bundle/hack/SysHacks.java | 6 ++++- .../bundle/loader/BundlePathLoader.java | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/bundle/src/ctrip/android/bundle/hack/SysHacks.java b/bundle/src/ctrip/android/bundle/hack/SysHacks.java index bc88dc4..c91b03a 100644 --- a/bundle/src/ctrip/android/bundle/hack/SysHacks.java +++ b/bundle/src/ctrip/android/bundle/hack/SysHacks.java @@ -112,7 +112,11 @@ public static void allClasses() throws HackAssertionException { LoadedApk = Hack.into("android.app.LoadedApk"); } ActivityThread = Hack.into("android.app.ActivityThread"); - Resources = Hack.into(Resources.class); + if(Build.VERSION.SDK_INT >= 24) { + Resources = Hack.into("android.content.res.ResourcesImpl"); + } else { + Resources = Hack.into("android.content.res.Resources"); + } Application = Hack.into(Application.class); AssetManager = Hack.into(AssetManager.class); IPackageManager = Hack.into("android.content.pm.IPackageManager"); diff --git a/bundle/src/ctrip/android/bundle/loader/BundlePathLoader.java b/bundle/src/ctrip/android/bundle/loader/BundlePathLoader.java index d28401e..c35596d 100644 --- a/bundle/src/ctrip/android/bundle/loader/BundlePathLoader.java +++ b/bundle/src/ctrip/android/bundle/loader/BundlePathLoader.java @@ -45,7 +45,9 @@ public static void installBundleDexs(ClassLoader loader, File dexDir, List throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,InstantiationException, InvocationTargetException, NoSuchMethodException, IOException { if (!files.isEmpty()) { - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= 24) { + V24.install(loader, files, dexDir, isHotFix); + } else if (Build.VERSION.SDK_INT >= 23) { V23.install(loader, files, dexDir,isHotFix); }else if (Build.VERSION.SDK_INT >= 19) { V19.install(loader, files, dexDir,isHotFix); @@ -154,6 +156,28 @@ private static void expandFieldArray(Object instance, String fieldName, } } + private static final class V24 { + + private static void install(ClassLoader loader, List additionalClassPathEntries, + File optimizedDirectory,boolean isHotFix) + throws IllegalArgumentException, IllegalAccessException, + NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException { + + Field pathListField = findField(loader, "pathList"); + Object dexPathList = pathListField.get(loader); + Field dexElementField = findField(dexPathList, "dexElements"); + Object dexElements = dexElementField.get(dexPathList); + Class elementType = dexElementField.getType().getComponentType(); + Method loadDex = findMethod(dexPathList, "loadDexFile", File.class, File.class, ClassLoader.class, dexElementField.getType()); + Object dex = loadDex.invoke(dexPathList, additionalClassPathEntries.get(0), optimizedDirectory, loader, dexElements); + Constructor constructor = elementType.getConstructor(File.class, boolean.class, File.class, DexFile.class); + Object element = constructor.newInstance(new File(""), false, additionalClassPathEntries.get(0), dex); + Object[] newEles=new Object[1]; + newEles[0]=element; + expandFieldArray(dexPathList, "dexElements",newEles,isHotFix); + } + + } private static final class V23 {