Skip to content

Commit

Permalink
[atlas-core]7.0 avoid app image | 4.4 ContextImpl fix
Browse files Browse the repository at this point in the history
  • Loading branch information
关杰 committed Apr 21, 2017
1 parent 27930c0 commit 6f46d99
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion atlas-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 6f46d99

Please sign in to comment.