Skip to content

Commit

Permalink
[atlas-core] walk round for get layout
Browse files Browse the repository at this point in the history
  • Loading branch information
关杰 committed Jun 30, 2017
1 parent c428e1e commit daec0fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
import android.os.Build;
import android.taobao.atlas.hack.AndroidHack;
import android.taobao.atlas.hack.AtlasHacks;
import android.taobao.atlas.util.ApkUtils;
import android.taobao.atlas.util.log.impl.AtlasMonitor;
import android.text.TextUtils;
import android.util.DisplayMetrics;
Expand All @@ -227,6 +228,7 @@
import org.xmlpull.v1.XmlPullParser;

import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.*;
Expand Down Expand Up @@ -279,7 +281,19 @@ public XmlResourceParser getLayout(int id) throws NotFoundException {
}
if(result==null && exception!=null){
TypedValue value = new TypedValue();
boolean flag = (this==RuntimeVariables.delegateResources);
Log.e("DelegateResources","compare:"+(this==RuntimeVariables.delegateResources));
if(!flag){
try{
XmlResourceParser parser = RuntimeVariables.delegateResources.getLayout(id);
if(parser!=null){
Map<String, Object> detail = new HashMap<>();
detail.put("walkroundgetLayout", "");
AtlasMonitor.getInstance().report("walkround_Runtimevariables", detail, exception);
return parser;
}
}catch (Throwable e){}
}
getValue(id,value,true);
if(value!=null){
Log.e("DelegateResources",String.format("ID: %s|cookie: %s|string: %s",id,value.assetCookie,value.string));
Expand All @@ -293,7 +307,7 @@ public XmlResourceParser getLayout(int id) throws NotFoundException {
if(parser!=null){
Map<String, Object> detail = new HashMap<>();
detail.put("walkroundgetLayout", assetsPath);
AtlasMonitor.getInstance().report(AtlasMonitor.CONTAINER_DEXOPT_FAIL, detail, exception);
AtlasMonitor.getInstance().report(AtlasMonitor.WALKROUND_GETLAYOUT, detail, exception);
return parser;
}
}catch(Throwable e){
Expand All @@ -312,7 +326,14 @@ private XmlResourceParser getLayoutWalkRound(final String assetsPath,final int i
synchronized (assetsPath) {
if ((res = bundleResourceWalkRound.get(assetsPath)) == null) {
AssetManager newAssetManager = AssetManager.class.newInstance();
AtlasHacks.AssetManager_addAssetPath.invoke(newAssetManager, assetsPath);
File walkroundBackupAsset = new File(RuntimeVariables.androidApplication.getFilesDir(),new File(assetsPath).getName()+".backup.zip");
if(!walkroundBackupAsset.exists() || walkroundBackupAsset.length() == new File(assetsPath).length()) {
if(walkroundBackupAsset.exists()){
walkroundBackupAsset.delete();
}
ApkUtils.copyInputStreamToFile(new FileInputStream(assetsPath), walkroundBackupAsset);
}
AtlasHacks.AssetManager_addAssetPath.invoke(newAssetManager, walkroundBackupAsset);
res = new Resources(newAssetManager, getDisplayMetrics(), getConfiguration());
bundleResourceWalkRound.put(assetsPath, res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static boolean checkloadKernalBundle(Application application,String curre
kernalBundle.patchKernalDex(application);
kernalBundle.patchKernalResource(application);
return true;
} catch (Exception e) {
} catch (Throwable e) {
e.printStackTrace();
kernalBundle = null;
deleteDirectory(kernalUpdateDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ public class AtlasMonitor {
public static final String CONTAINER_DEXOPT_FAIL = "container_dexopt_fail";
public static final String CONTAINER_APPEND_ASSETPATH_FAIL = "container_append_assetpath_fail";
public static final String CONTAINER_BUNDLEINFO_PARSE_FAIL = "container_bundleinfo_parse_fail";
public static final String WALKROUND_GETLAYOUT = "walkround_getlayout";


//动态部署稳定性stage
public static final String DD_BUNDLE_MISMATCH = "dd_bundle_mismatch";
Expand Down

0 comments on commit daec0fa

Please sign in to comment.