From 6f46d99cd8ed313919dc42d281bcc73cb19a84f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E6=9D=B0?= Date: Fri, 21 Apr 2017 12:07:07 +0800 Subject: [PATCH] [atlas-core]7.0 avoid app image | 4.4 ContextImpl fix --- atlas-core/build.gradle | 2 +- .../java/android/taobao/atlas/hack/AtlasHacks.java | 8 +------- .../newcomponent/service/BaseDelegateService.java | 11 ++++++++--- .../taobao/atlas/startup/KernalVersionManager.java | 3 ++- .../taobao/atlas/startup/patch/KernalBundle.java | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/atlas-core/build.gradle b/atlas-core/build.gradle index 2351ba37e..7e794b6ef 100644 --- a/atlas-core/build.gradle +++ b/atlas-core/build.gradle @@ -25,7 +25,7 @@ repositories { group = 'com.taobao.android' description = """atlas_core""" -version '5.0.6-rc37' +version '5.0.6-rc38' sourceCompatibility = 1.7 diff --git a/atlas-core/src/main/java/android/taobao/atlas/hack/AtlasHacks.java b/atlas-core/src/main/java/android/taobao/atlas/hack/AtlasHacks.java index bf997c3fa..d86e310b9 100644 --- a/atlas-core/src/main/java/android/taobao/atlas/hack/AtlasHacks.java +++ b/atlas-core/src/main/java/android/taobao/atlas/hack/AtlasHacks.java @@ -318,8 +318,6 @@ public class AtlasHacks extends HackDeclaration implements AssertionFailureHandl public static HackedMethod AssetManager_getResourceIdentifier; public static HackedMethod AssetManager_ensureStringBlocks; public static HackedMethod ContextImpl_setOuterContext; - public static HackedMethod ContextImpl_init; - public static HackedMethod ContextImpl_createAppContext; public static HackedMethod Service_attach; public static HackedMethod ActivityThread_installContentProviders; public static HackedMethod ActivityThread_installProvider; @@ -462,11 +460,7 @@ public static void allMethods() throws HackAssertionException { PackageParser$Component_getComponentName = PackageParser$Component.method("getComponentName"); ClassLoader_findLibrary = ClassLoader.method("findLibrary", String.class); ContextImpl_setOuterContext = ContextImpl.method("setOuterContext",Context.class); - if(Build.VERSION.SDK_INT>=19){ - ContextImpl_createAppContext = ContextImpl.method("createAppContext",ActivityThread.getmClass(),LoadedApk.getmClass()); - }else{ - ContextImpl_init = ContextImpl.method("init",LoadedApk.getmClass(), IBinder.class,ActivityThread.getmClass()); - } + if (LexFile != null && LexFile.getmClass() !=null ) { LexFile_loadLex = LexFile.method("loadLex", String.class, int.class); LexFile_loadClass = LexFile.method("loadClass", String.class, java.lang.ClassLoader.class); diff --git a/atlas-core/src/main/java/android/taobao/atlas/runtime/newcomponent/service/BaseDelegateService.java b/atlas-core/src/main/java/android/taobao/atlas/runtime/newcomponent/service/BaseDelegateService.java index c3d86d13f..b9a95bf36 100644 --- a/atlas-core/src/main/java/android/taobao/atlas/runtime/newcomponent/service/BaseDelegateService.java +++ b/atlas-core/src/main/java/android/taobao/atlas/runtime/newcomponent/service/BaseDelegateService.java @@ -15,6 +15,7 @@ import android.os.RemoteException; import android.taobao.atlas.hack.AndroidHack; import android.taobao.atlas.hack.AtlasHacks; +import android.taobao.atlas.hack.Hack; import android.taobao.atlas.runtime.ContextImplHook; import android.taobao.atlas.runtime.RuntimeVariables; import android.taobao.atlas.runtime.newcomponent.activity.ActivityBridge; @@ -166,12 +167,16 @@ private AdditionalServiceRecord handleCreateService(ComponentName componentName) Object activityThread = AndroidHack.getActivityThread(); Object loadedApk = AndroidHack.getLoadedApk(RuntimeVariables.androidApplication,activityThread,RuntimeVariables.androidApplication.getPackageName()); - if(Build.VERSION.SDK_INT>=21) { - contextImpl = AtlasHacks.ContextImpl_createAppContext.invoke(AtlasHacks.ContextImpl.getmClass(),activityThread,loadedApk); + Hack.HackedMethod ContextImpl_createAppContext = AtlasHacks.ContextImpl.method("createAppContext",AtlasHacks.ActivityThread.getmClass(),AtlasHacks.LoadedApk.getmClass()); + if(ContextImpl_createAppContext.getMethod()!=null){ + contextImpl = ContextImpl_createAppContext.invoke(AtlasHacks.ContextImpl.getmClass(),activityThread,loadedApk); }else{ + Hack.HackedMethod ContextImpl_init = AtlasHacks.ContextImpl.method("init",AtlasHacks.LoadedApk.getmClass(), IBinder.class,AtlasHacks.ActivityThread.getmClass()); contextImpl = AtlasHacks.ContextImpl.getmClass().newInstance(); - AtlasHacks.ContextImpl_init.invoke(contextImpl, loadedApk,null,activityThread); + ContextImpl_init.invoke(contextImpl, loadedApk,null,activityThread); + } + Object gDefault = null; if(Build.VERSION.SDK_INT>25 || (Build.VERSION.SDK_INT==25&&Build.VERSION.PREVIEW_SDK_INT>0)){ gDefault=AtlasHacks.ActivityManager_IActivityManagerSingleton.get(AtlasHacks.ActivityManager.getmClass()); diff --git a/atlas-core/src/main/java/android/taobao/atlas/startup/KernalVersionManager.java b/atlas-core/src/main/java/android/taobao/atlas/startup/KernalVersionManager.java index 820860977..e86aaed05 100644 --- a/atlas-core/src/main/java/android/taobao/atlas/startup/KernalVersionManager.java +++ b/atlas-core/src/main/java/android/taobao/atlas/startup/KernalVersionManager.java @@ -330,8 +330,9 @@ public void init(){ input.close(); } catch (Throwable e) { updateMonitor(KernalConstants.DD_BASELINEINFO_FAIL, e==null?"":e.getMessage()); - rollbackHardly(); killChildProcesses(KernalConstants.baseContext); + BASELINEINFO.delete(); + rollbackHardly(); android.os.Process.killProcess(Process.myPid()); } } diff --git a/atlas-core/src/main/java/android/taobao/atlas/startup/patch/KernalBundle.java b/atlas-core/src/main/java/android/taobao/atlas/startup/patch/KernalBundle.java index afd10c647..4906e83ce 100644 --- a/atlas-core/src/main/java/android/taobao/atlas/startup/patch/KernalBundle.java +++ b/atlas-core/src/main/java/android/taobao/atlas/startup/patch/KernalBundle.java @@ -351,9 +351,9 @@ public KernalBundle(final File bundleDir,String process,String installedVersion) public void patchKernalDex() throws Exception { DexFile[] dexFile = archive.getOdexFile(); - if (dexFile != null || archive.getLibraryDirectory().exists()) { + if ((dexFile != null&&dexFile.length>0) || archive.getLibraryDirectory().exists()) { installKernalBundle(KernalConstants.baseContext.getClassLoader(),archive); - Class FrameworkPropertiesClazz = KernalConstants.baseContext.getClassLoader().loadClass("android.taobao.atlas.framework.FrameworkProperties"); + Class FrameworkPropertiesClazz = archive.getOdexFile()[0].loadClass("android.taobao.atlas.framework.FrameworkProperties",ClassLoader.getSystemClassLoader()); Field versionField = FrameworkPropertiesClazz.getDeclaredField("version"); versionField.setAccessible(true); String version = (String)versionField.get(FrameworkPropertiesClazz.newInstance());