Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	atlas-demo/AtlasDemo/gradle.properties
  • Loading branch information
关杰 committed Jun 30, 2017
2 parents 4312f98 + daec0fa commit 68b7317
Show file tree
Hide file tree
Showing 350 changed files with 19,495 additions and 37,859 deletions.
4 changes: 2 additions & 2 deletions atlas-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// apply from: 'http://gitlab.alibaba-inc.com/android-build-system/buildscript/raw/master/mtl-publish.gradle'
apply from: 'http://gitlab.alibaba-inc.com/android-build-system/buildscript/raw/master/mtl-publish.gradle'

buildscript {

Expand All @@ -23,7 +23,7 @@ repositories {

group = 'com.taobao.android'
description = """atlas_core"""
version '5.0.7.11'
version '5.0.7.30'


sourceCompatibility = 1.7
Expand Down

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions atlas-core/src/main/java/android/taobao/atlas/framework/Atlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,18 @@
public class Atlas {

public static String sAPKSource ;
protected static Atlas instance;
public static boolean Downgrade_H5 = false;
public static boolean isDebug;

private Atlas(){
}

public static synchronized Atlas getInstance() {
if (instance == null) {
instance = new Atlas();
}
return instance;
private static class SingleTonHolder{
private final static Atlas INSTANCE = new Atlas();
}

public static Atlas getInstance() {
return SingleTonHolder.INSTANCE;
}

private BundleLifecycleHandler bundleLifecycleHandler;
Expand Down Expand Up @@ -314,12 +314,10 @@ public void init(Application application,boolean reset) throws AssertionArrayExc

public void startup(Application application,boolean isUpdated) {
if(!RuntimeVariables.safeMode) {
if(application.getPackageManager().equals("com.taobao.taobao")) {
try {
RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("setVerificationEnabled").invoke(RuntimeVariables.sDexLoadBooster, false);
} catch (Throwable e) {
e.printStackTrace();
}
try {
RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("setVerificationEnabled",boolean.class).invoke(RuntimeVariables.sDexLoadBooster, false);
} catch (Throwable e) {
e.printStackTrace();
}
if (!WrapperUtil.isDebugMode(application) && ApkUtils.isRootSystem()) {
Atlas.getInstance().addBundleListener(new SecurityHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,13 @@

package android.taobao.atlas.framework;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.taobao.atlas.bundleInfo.AtlasBundleInfoManager;
import android.taobao.atlas.framework.bundlestorage.BundleArchive;
import android.taobao.atlas.runtime.RuntimeVariables;
import android.taobao.atlas.runtime.DelegateResources;
import android.taobao.atlas.util.WrapperUtil;
import android.taobao.atlas.util.log.impl.AtlasMonitor;
import android.taobao.atlas.versionInfo.BaselineInfoManager;
import android.util.Log;
Expand All @@ -224,8 +227,10 @@
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class BundleImpl implements Bundle {

Expand Down Expand Up @@ -346,15 +351,15 @@ private synchronized void resolveBundle() throws BundleException {
if ( this.classloader == null){
// create the bundle classloader
List<String> dependencies = AtlasBundleInfoManager.instance().getDependencyForBundle(location);
String nativeLibDir = getArchive().getCurrentRevision().getRevisionDir().getAbsolutePath()+"/lib"+":"
String nativeLibDir = getArchive().getCurrentRevision().mappingInternalDirectory().getAbsolutePath()+"/lib"+":"
+ RuntimeVariables.androidApplication.getApplicationInfo().nativeLibraryDir+":"
+System.getProperty("java.library.path");
if(dependencies!=null) {
for (String str : dependencies) {
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(str);
if (impl != null) {
nativeLibDir += ":";
File dependencyLibDir = new File(impl.getArchive().getCurrentRevision().getRevisionDir(), "lib");
File dependencyLibDir = new File(impl.getArchive().getCurrentRevision().mappingInternalDirectory(), "lib");
nativeLibDir += dependencyLibDir;
}
}
Expand Down Expand Up @@ -502,6 +507,30 @@ public boolean checkResources(){
return true;
}

// public void updateValidBundleCache(){
// long lastUpdateTime = WrapperUtil.getPackageInfo(RuntimeVariables.androidApplication).lastUpdateTime;
// if(lastUpdateTime>0) {
// SharedPreferences preferences = RuntimeVariables.androidApplication.getSharedPreferences("valid_bundle_info"+"",0);
// Set<String> bundles = preferences.getStringSet(""+lastUpdateTime,new HashSet<String>());
// if(!bundles.contains(location)){
// bundles.add(location);
// preferences.edit().putStringSet(""+lastUpdateTime,bundles).apply();
// }
// }
// }
//
// public static boolean isBundleSuccessedInstalledBefore(String location){
// long lastUpdateTime = WrapperUtil.getPackageInfo(RuntimeVariables.androidApplication).lastUpdateTime;
// if(lastUpdateTime>0) {
// SharedPreferences preferences = RuntimeVariables.androidApplication.getSharedPreferences("valid_bundle_info"+"",0);
// Set<String> bundles = preferences.getStringSet(""+lastUpdateTime,null);
// if(bundles!=null && bundles.contains(location)){
// return true;
// }
// }
// return false;
// }


public boolean isDisabled(){
return disabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,14 @@ public boolean queueIdle() {
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
if (impl == null || !impl.checkValidate()) {
Log.d("BundleInstaller", "idle install bundle : " + bundleName);
BundleInstallerFetcher.obtainInstaller().installTransitivelySync(new String[]{bundleName});
if (listener != null) {
listener.onFinished();
}
BundleInstallerFetcher.obtainInstaller().installTransitivelyAsync(new String[]{bundleName},listener);
return true;
}
}
return true;
}
};
sBundleHandler.post(new Runnable() {
@Override
public void run() {
Looper.myQueue().addIdleHandler(sIdleHandler);
}
});
Looper.myQueue().addIdleHandler(sIdleHandler);
}
}

Expand Down Expand Up @@ -647,7 +639,7 @@ private void findBundleSource(String location) throws IOException{
if(!bundleFile.exists()){
bundleFile = new File(RuntimeVariables.androidApplication.getApplicationInfo().nativeLibraryDir,bundleFileName);
}
if(isBundleFileTimeStampMatched(location,bundleFile)){
if(isBundleFileMatched(location,bundleFile)){
mTmpBundleSourceFile = bundleFile;
Log.e("BundleInstaller","find valid bundle : "+bundleFile.getAbsolutePath());
}else{
Expand All @@ -660,25 +652,16 @@ private void findBundleSource(String location) throws IOException{
}
}

private boolean isBundleFileTimeStampMatched(String location,File file){
private boolean isBundleFileMatched(String location,File file){
if(!file.exists() || !AtlasBundleInfoManager.instance().isInternalBundle(location)){
return false;
}
if(file.lastModified() == getTimeStampInApk()){
return true;
}
return false;
}

private static long timeStampInApk = -11021836;
private synchronized long getTimeStampInApk(){
try {
if (timeStampInApk == -11021836) {
timeStampInApk = ApkUtils.getApk().getEntry("classes.dex").getTime();
}
}finally {
return timeStampInApk>0 ? timeStampInApk : 0;
BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(location);
if(info!=null && info.getSize()>0 && info.getSize()!=file.length()){
Log.e("BundleInstaller","wanted size: "+info.getSize()+"| realSize: "+file.length());
return false;
}
return true;
}

private Bundle installBundleFromApk(String bundleName) throws Exception{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,30 @@ public File getRevisionFile() {
return bundleFile;
}

public File mappingInternalDirectory(){
if(externalStorage){
File internalLibDir = new File(RuntimeVariables.androidApplication.getFilesDir(),String.format("storage/%s/%s",location,revisionDir.getName()));
int retryCount = 2;
do{
if(!internalLibDir.exists()){
internalLibDir.mkdirs();
}
if(internalLibDir.exists()){
break;
}
retryCount--;
}while(retryCount>0);
if(!internalLibDir.exists()){
Log.e("BundleArchiveRevision","create internal LibDir Failed : "+location);
}
return internalLibDir;
}else{
return revisionDir;
}
}

public File findSoLibrary(String libraryName){
File file = new File(String.format("%s%s%s%s",revisionDir,File.separator,"lib",File.separator),libraryName);
File file = new File(String.format("%s%s%s%s",mappingInternalDirectory(),File.separator,"lib",File.separator),libraryName);
if(file.exists() && file.isFile() && file.length()>0){
return file;
}
Expand Down Expand Up @@ -444,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 @@ -460,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 @@ -486,12 +508,14 @@ 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()){
optPatchDexFile();
}
//9月份版本明天发布先不集成
// isDexOptDone = checkDexValid(dexFile);
isDexOptDone = true;
Expand Down Expand Up @@ -582,7 +606,7 @@ public void installSoLib(File bundle) throws IOException{

private void extractEntry(ZipFile zip ,ZipEntry zipEntry) throws IOException{
String entryName = zipEntry.getName();
String targetPath = String.format("%s%s%s%s%s",revisionDir,File.separator,"lib",File.separator,
String targetPath = String.format("%s%s%s%s%s",mappingInternalDirectory(),File.separator,"lib",File.separator,
entryName.substring(entryName.lastIndexOf(File.separator)+1,entryName.length()));
if (zipEntry.isDirectory()) {
File decompressDirFile = new File(targetPath);
Expand Down Expand Up @@ -675,27 +699,30 @@ public String findLibrary(String name){
}

private Class findPatchClass(String clazz,ClassLoader cl){
if(patchDexFileForDebug==null){
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"),location);
File patchFile = new File(debugBundleDir,"patch.zip");
if(patchFile.exists()){
try {
// patchDexFileForDebug = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication,
// patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
//兼容7。0 动态部署过后不同classloader下对classcast
RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("loadDex",Context.class,String.class, String.class, int.class, boolean.class).invoke(
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
if(patchDexFileForDebug!=null){
return patchDexFileForDebug.loadClass(clazz,cl);
}
return null;
}

private void optPatchDexFile() {
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"), location);
File patchFile = new File(debugBundleDir,"patch.zip");
if(patchFile.exists()){
try {
// patchDexFileForDebug = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication,
// patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
//兼容7。0 动态部署过后不同classloader下对classcast
File internalDebugBundleDir = new File(new File(RuntimeVariables.androidApplication.getFilesDir(),"debug_storage"),location);
internalDebugBundleDir.mkdirs();
patchDexFileForDebug= (DexFile)RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("loadDex", Context.class, String.class, String.class, int.class, boolean.class).invoke(
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, patchFile.getAbsolutePath(), new File(internalDebugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}

public String getDebugPatchFilePath(){
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"),location);
File patchFile = new File(debugBundleDir,"patch.zip");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ public static void injectResources(Application application, Resources resources)
final Object newTypedArrayPool = typedArrayConstructor.newInstance(poolSize);
typedArrayPoolField.set(resources, newTypedArrayPool);
} catch (Throwable ignored) {
ignored.printStackTrace();
}
}
if(res!=null) {
Expand All @@ -491,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
Loading

0 comments on commit 68b7317

Please sign in to comment.