Skip to content

Commit

Permalink
[atlas-core]
Browse files Browse the repository at this point in the history
dp3 nativeElement 兼容
DelegateResource getLayout失败补偿
TintContentWrapper theme 不处理
DexReleaser埋点
Soloader fix
...
  • Loading branch information
关杰 committed Jun 29, 2017
1 parent 8feb282 commit c428e1e
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public BundleListing getBundleInfo(){
* Get all dependent bundles for the designated bundle
*/
public List<String> getDependencyForBundle(String bundleName){
if(mCurrentBundleListing==null){
if(mCurrentBundleListing==null || mCurrentBundleListing.getBundles()==null){
return null;
}
BundleListing.BundleInfo bundleInfo = mCurrentBundleListing.getBundles().get(bundleName);
Expand All @@ -310,7 +310,7 @@ public List<String> getDependencyForBundle(String bundleName){
}

public boolean isInternalBundle(String bundleName){
if(mCurrentBundleListing==null){
if(mCurrentBundleListing==null || mCurrentBundleListing.getBundles()==null){
return true;
}
BundleListing.BundleInfo info = mCurrentBundleListing.getBundles().get(bundleName);
Expand All @@ -322,7 +322,7 @@ public boolean isInternalBundle(String bundleName){
}

public String getBundleForComponet(String componentName){
if(mCurrentBundleListing==null){
if(mCurrentBundleListing==null || mCurrentBundleListing.getBundles()==null){
return null;
}
Iterator<Map.Entry<String, BundleListing.BundleInfo>> iterator = mCurrentBundleListing.getBundles().entrySet().iterator();
Expand Down Expand Up @@ -351,7 +351,7 @@ public String getBundleForComponet(String componentName){
}

public BundleListing.BundleInfo getBundleInfo(String name){
if(mCurrentBundleListing==null){
if(mCurrentBundleListing==null || mCurrentBundleListing.getBundles()==null){
return null;
}
BundleListing.BundleInfo info = mCurrentBundleListing.getBundles().get(name);
Expand All @@ -363,7 +363,7 @@ public BundleListing.BundleInfo getBundleInfo(String name){
}

private void updateBundleListingWithExtraInfo(){
if(mCurrentBundleListing==null){
if(mCurrentBundleListing==null || mCurrentBundleListing.getBundles()==null){
return;
}
String fileName = String.format("%s%s.json","bundleInfo-", WrapperUtil.getPackageInfo(RuntimeVariables.androidApplication).versionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ private static File getInstalledBundleInternal(String bundleName,String bundleUn
}

private static File createBundleStorage(String bundleName){
if(new File(STORAGE_LOCATION).getUsableSpace()>15*1024*1024){
if(new File(STORAGE_LOCATION).getUsableSpace()>10*1024*1024){
return new File(STORAGE_LOCATION,bundleName);
}else{
File externalStorageDir = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ public boolean isDexOpted() {
}

if (AtlasHacks.LexFile != null && AtlasHacks.LexFile.getmClass() != null) {
File lexFile = new File(revisionDir, BUNDLE_LEX_FILE);
File lexFile = new File(mappingInternalDirectory(), BUNDLE_LEX_FILE);
return lexFile.exists() && lexFile.length() > 0;
}
File odexFile = new File(revisionDir, BUNDLE_ODEX_FILE);
File odexFile = new File(mappingInternalDirectory(), BUNDLE_ODEX_FILE);
return odexFile.exists() && odexFile.length() > 0;
}

Expand All @@ -482,12 +482,12 @@ public synchronized void optDexFile() {
if (AtlasHacks.LexFile != null && AtlasHacks.LexFile.getmClass() != null) {
//yunos
// TODO: need also cover logic of filelocks for YunOS.
new DexClassLoader(bundleFile.getAbsolutePath(), revisionDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
new DexClassLoader(bundleFile.getAbsolutePath(), mappingInternalDirectory().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
isDexOptDone = true;
return;
}

File odexFile = new File(revisionDir, BUNDLE_ODEX_FILE);
File odexFile = new File(mappingInternalDirectory(), BUNDLE_ODEX_FILE);

long START = 0;
START = System.currentTimeMillis();
Expand All @@ -508,10 +508,9 @@ public synchronized void optDexFile() {
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0, interpretOnly);
// dexFile = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication, bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0, interpretOnly);
}else{
Method m=Class.forName("android.taobao.atlas.util.DexFileCompat")
Method m=Class.forName("android.taobao.atlas.startup.DexFileCompat")
.getDeclaredMethod("loadDex", Context.class,String.class,String.class,int.class);
dexFile= (DexFile) m.invoke(null,RuntimeVariables.androidApplication,bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0);
//dexFile = DexFileCompat.loadDex(RuntimeVariables.androidApplication,bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0);
}
}
if(Framework.isDeubgMode()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,6 @@ public static void injectResources(Application application, Resources resources)
final Object wrapper = wrappRef != null ? wrappRef.get() : null;
Field mTintResourcesField = TintContextWrapper.getDeclaredField("mResources");
mTintResourcesField.setAccessible(true);
Field mTintThemeField = TintContextWrapper.getDeclaredField("mTheme");
mTintThemeField.setAccessible(true);
mTintThemeField.set(wrapper,null);
Object obj = mTintResourcesField.get(wrapper);
Field mResourceField = findField(obj,"mResources");
mResourceField.set(obj,resources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,13 @@ public void updateBundleActivityResource(String bundleName){
if (wrapper != null && ((ContextWrapper)wrapper).getBaseContext() == activity) {
Field mTintResourcesField = TintContextWrapper.getDeclaredField("mResources");
mTintResourcesField.setAccessible(true);
Field mTintThemeField = TintContextWrapper.getDeclaredField("mTheme");
mTintThemeField.setAccessible(true);
mTintThemeField.set(wrapper,null);
mTintResourcesField.set(wrapper,null);
mTintResourcesField.set(wrapper,RuntimeVariables.delegateResources);
break;
}
}
}
} catch (Throwable e) {
e.printStackTrace();
//e.printStackTrace();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;

import org.xmlpull.v1.XmlPullParser;

import java.io.File;
import java.lang.reflect.Constructor;
Expand All @@ -243,6 +246,7 @@ public class DelegateResources extends Resources {
private static String sKernalPathPath = null;
private static String sAssetsPatchDir = null;
private Resources origin;
private HashMap<String,Resources> bundleResourceWalkRound = new HashMap<>();


/**
Expand Down Expand Up @@ -274,11 +278,55 @@ public XmlResourceParser getLayout(int id) throws NotFoundException {

}
if(result==null && exception!=null){
TypedValue value = new TypedValue();
Log.e("DelegateResources","compare:"+(this==RuntimeVariables.delegateResources));
getValue(id,value,true);
if(value!=null){
Log.e("DelegateResources",String.format("ID: %s|cookie: %s|string: %s",id,value.assetCookie,value.string));
try {
String assetsPath = (String) AssetManager.class.getMethod("getCookieName", int.class).invoke(getAssets(), value.assetCookie);
Log.e("DelegateResources","target Path: "+assetsPath);
if(!new File(assetsPath).exists()){
Log.e("DelegateResources","target Path is not exist");
}
XmlResourceParser parser = getLayoutWalkRound(assetsPath,id);
if(parser!=null){
Map<String, Object> detail = new HashMap<>();
detail.put("walkroundgetLayout", assetsPath);
AtlasMonitor.getInstance().report(AtlasMonitor.CONTAINER_DEXOPT_FAIL, detail, exception);
return parser;
}
}catch(Throwable e){
}
}

throw exception;
}
return result;
}

private XmlResourceParser getLayoutWalkRound(final String assetsPath,final int id){
try {
Resources res = bundleResourceWalkRound.get(assetsPath);
if(res==null) {
synchronized (assetsPath) {
if ((res = bundleResourceWalkRound.get(assetsPath)) == null) {
AssetManager newAssetManager = AssetManager.class.newInstance();
AtlasHacks.AssetManager_addAssetPath.invoke(newAssetManager, assetsPath);
res = new Resources(newAssetManager, getDisplayMetrics(), getConfiguration());
bundleResourceWalkRound.put(assetsPath, res);
}
}
}
if(res!=null) {
return res.getLayout(id);
}
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}

public Drawable getDrawable(int id, Theme theme) throws NotFoundException {
Drawable result = null;
NotFoundException exception = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package android.taobao.atlas.util;
package android.taobao.atlas.startup;

import android.content.Context;
import android.os.Build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ public NClassLoader(String dexPath, ClassLoader parent) {
super(dexPath, parent);
}

public static void replacePathClassLoader(Context base,ClassLoader original) throws Exception {
NClassLoader loader = new NClassLoader(".",original.getParent());

public static void replacePathClassLoader(Context base,ClassLoader original,NClassLoader target) throws Exception {
NClassLoader loader = target;
Field pathListField = findField(original, "pathList");
pathListField.setAccessible(true);
Object originPathListObject = pathListField.get(original);
Expand Down
Loading

0 comments on commit c428e1e

Please sign in to comment.