Skip to content

Commit 68b7317

Browse files
author
关杰
committed
Merge branch 'dev'
# Conflicts: # atlas-demo/AtlasDemo/gradle.properties
2 parents 4312f98 + daec0fa commit 68b7317

File tree

350 files changed

+19495
-37859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

350 files changed

+19495
-37859
lines changed

atlas-core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
4-
// apply from: 'http://gitlab.alibaba-inc.com/android-build-system/buildscript/raw/master/mtl-publish.gradle'
4+
apply from: 'http://gitlab.alibaba-inc.com/android-build-system/buildscript/raw/master/mtl-publish.gradle'
55

66
buildscript {
77

@@ -23,7 +23,7 @@ repositories {
2323

2424
group = 'com.taobao.android'
2525
description = """atlas_core"""
26-
version '5.0.7.11'
26+
version '5.0.7.30'
2727

2828

2929
sourceCompatibility = 1.7

atlas-core/src/main/java/android/taobao/atlas/bundleInfo/AtlasBundleInfoManager.java

Lines changed: 90 additions & 238 deletions
Large diffs are not rendered by default.

atlas-core/src/main/java/android/taobao/atlas/framework/Atlas.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,18 @@
247247
public class Atlas {
248248

249249
public static String sAPKSource ;
250-
protected static Atlas instance;
251250
public static boolean Downgrade_H5 = false;
252251
public static boolean isDebug;
253252

254253
private Atlas(){
255254
}
256255

257-
public static synchronized Atlas getInstance() {
258-
if (instance == null) {
259-
instance = new Atlas();
260-
}
261-
return instance;
256+
private static class SingleTonHolder{
257+
private final static Atlas INSTANCE = new Atlas();
258+
}
259+
260+
public static Atlas getInstance() {
261+
return SingleTonHolder.INSTANCE;
262262
}
263263

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

315315
public void startup(Application application,boolean isUpdated) {
316316
if(!RuntimeVariables.safeMode) {
317-
if(application.getPackageManager().equals("com.taobao.taobao")) {
318-
try {
319-
RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("setVerificationEnabled").invoke(RuntimeVariables.sDexLoadBooster, false);
320-
} catch (Throwable e) {
321-
e.printStackTrace();
322-
}
317+
try {
318+
RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("setVerificationEnabled",boolean.class).invoke(RuntimeVariables.sDexLoadBooster, false);
319+
} catch (Throwable e) {
320+
e.printStackTrace();
323321
}
324322
if (!WrapperUtil.isDebugMode(application) && ApkUtils.isRootSystem()) {
325323
Atlas.getInstance().addBundleListener(new SecurityHandler());

atlas-core/src/main/java/android/taobao/atlas/framework/BundleImpl.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,13 @@
208208

209209
package android.taobao.atlas.framework;
210210

211+
import android.content.SharedPreferences;
212+
import android.preference.PreferenceManager;
211213
import android.taobao.atlas.bundleInfo.AtlasBundleInfoManager;
212214
import android.taobao.atlas.framework.bundlestorage.BundleArchive;
213215
import android.taobao.atlas.runtime.RuntimeVariables;
214216
import android.taobao.atlas.runtime.DelegateResources;
217+
import android.taobao.atlas.util.WrapperUtil;
215218
import android.taobao.atlas.util.log.impl.AtlasMonitor;
216219
import android.taobao.atlas.versionInfo.BaselineInfoManager;
217220
import android.util.Log;
@@ -224,8 +227,10 @@
224227
import java.io.InputStream;
225228
import java.net.URL;
226229
import java.util.HashMap;
230+
import java.util.HashSet;
227231
import java.util.List;
228232
import java.util.Map;
233+
import java.util.Set;
229234

230235
public final class BundleImpl implements Bundle {
231236

@@ -346,15 +351,15 @@ private synchronized void resolveBundle() throws BundleException {
346351
if ( this.classloader == null){
347352
// create the bundle classloader
348353
List<String> dependencies = AtlasBundleInfoManager.instance().getDependencyForBundle(location);
349-
String nativeLibDir = getArchive().getCurrentRevision().getRevisionDir().getAbsolutePath()+"/lib"+":"
354+
String nativeLibDir = getArchive().getCurrentRevision().mappingInternalDirectory().getAbsolutePath()+"/lib"+":"
350355
+ RuntimeVariables.androidApplication.getApplicationInfo().nativeLibraryDir+":"
351356
+System.getProperty("java.library.path");
352357
if(dependencies!=null) {
353358
for (String str : dependencies) {
354359
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(str);
355360
if (impl != null) {
356361
nativeLibDir += ":";
357-
File dependencyLibDir = new File(impl.getArchive().getCurrentRevision().getRevisionDir(), "lib");
362+
File dependencyLibDir = new File(impl.getArchive().getCurrentRevision().mappingInternalDirectory(), "lib");
358363
nativeLibDir += dependencyLibDir;
359364
}
360365
}
@@ -502,6 +507,30 @@ public boolean checkResources(){
502507
return true;
503508
}
504509

510+
// public void updateValidBundleCache(){
511+
// long lastUpdateTime = WrapperUtil.getPackageInfo(RuntimeVariables.androidApplication).lastUpdateTime;
512+
// if(lastUpdateTime>0) {
513+
// SharedPreferences preferences = RuntimeVariables.androidApplication.getSharedPreferences("valid_bundle_info"+"",0);
514+
// Set<String> bundles = preferences.getStringSet(""+lastUpdateTime,new HashSet<String>());
515+
// if(!bundles.contains(location)){
516+
// bundles.add(location);
517+
// preferences.edit().putStringSet(""+lastUpdateTime,bundles).apply();
518+
// }
519+
// }
520+
// }
521+
//
522+
// public static boolean isBundleSuccessedInstalledBefore(String location){
523+
// long lastUpdateTime = WrapperUtil.getPackageInfo(RuntimeVariables.androidApplication).lastUpdateTime;
524+
// if(lastUpdateTime>0) {
525+
// SharedPreferences preferences = RuntimeVariables.androidApplication.getSharedPreferences("valid_bundle_info"+"",0);
526+
// Set<String> bundles = preferences.getStringSet(""+lastUpdateTime,null);
527+
// if(bundles!=null && bundles.contains(location)){
528+
// return true;
529+
// }
530+
// }
531+
// return false;
532+
// }
533+
505534

506535
public boolean isDisabled(){
507536
return disabled;

atlas-core/src/main/java/android/taobao/atlas/framework/BundleInstaller.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -277,22 +277,14 @@ public boolean queueIdle() {
277277
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
278278
if (impl == null || !impl.checkValidate()) {
279279
Log.d("BundleInstaller", "idle install bundle : " + bundleName);
280-
BundleInstallerFetcher.obtainInstaller().installTransitivelySync(new String[]{bundleName});
281-
if (listener != null) {
282-
listener.onFinished();
283-
}
280+
BundleInstallerFetcher.obtainInstaller().installTransitivelyAsync(new String[]{bundleName},listener);
284281
return true;
285282
}
286283
}
287284
return true;
288285
}
289286
};
290-
sBundleHandler.post(new Runnable() {
291-
@Override
292-
public void run() {
293-
Looper.myQueue().addIdleHandler(sIdleHandler);
294-
}
295-
});
287+
Looper.myQueue().addIdleHandler(sIdleHandler);
296288
}
297289
}
298290

@@ -647,7 +639,7 @@ private void findBundleSource(String location) throws IOException{
647639
if(!bundleFile.exists()){
648640
bundleFile = new File(RuntimeVariables.androidApplication.getApplicationInfo().nativeLibraryDir,bundleFileName);
649641
}
650-
if(isBundleFileTimeStampMatched(location,bundleFile)){
642+
if(isBundleFileMatched(location,bundleFile)){
651643
mTmpBundleSourceFile = bundleFile;
652644
Log.e("BundleInstaller","find valid bundle : "+bundleFile.getAbsolutePath());
653645
}else{
@@ -660,25 +652,16 @@ private void findBundleSource(String location) throws IOException{
660652
}
661653
}
662654

663-
private boolean isBundleFileTimeStampMatched(String location,File file){
655+
private boolean isBundleFileMatched(String location,File file){
664656
if(!file.exists() || !AtlasBundleInfoManager.instance().isInternalBundle(location)){
665657
return false;
666658
}
667-
if(file.lastModified() == getTimeStampInApk()){
668-
return true;
669-
}
670-
return false;
671-
}
672-
673-
private static long timeStampInApk = -11021836;
674-
private synchronized long getTimeStampInApk(){
675-
try {
676-
if (timeStampInApk == -11021836) {
677-
timeStampInApk = ApkUtils.getApk().getEntry("classes.dex").getTime();
678-
}
679-
}finally {
680-
return timeStampInApk>0 ? timeStampInApk : 0;
659+
BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(location);
660+
if(info!=null && info.getSize()>0 && info.getSize()!=file.length()){
661+
Log.e("BundleInstaller","wanted size: "+info.getSize()+"| realSize: "+file.length());
662+
return false;
681663
}
664+
return true;
682665
}
683666

684667
private Bundle installBundleFromApk(String bundleName) throws Exception{

atlas-core/src/main/java/android/taobao/atlas/framework/bundlestorage/BundleArchiveRevision.java

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,30 @@ public File getRevisionFile() {
399399
return bundleFile;
400400
}
401401

402+
public File mappingInternalDirectory(){
403+
if(externalStorage){
404+
File internalLibDir = new File(RuntimeVariables.androidApplication.getFilesDir(),String.format("storage/%s/%s",location,revisionDir.getName()));
405+
int retryCount = 2;
406+
do{
407+
if(!internalLibDir.exists()){
408+
internalLibDir.mkdirs();
409+
}
410+
if(internalLibDir.exists()){
411+
break;
412+
}
413+
retryCount--;
414+
}while(retryCount>0);
415+
if(!internalLibDir.exists()){
416+
Log.e("BundleArchiveRevision","create internal LibDir Failed : "+location);
417+
}
418+
return internalLibDir;
419+
}else{
420+
return revisionDir;
421+
}
422+
}
423+
402424
public File findSoLibrary(String libraryName){
403-
File file = new File(String.format("%s%s%s%s",revisionDir,File.separator,"lib",File.separator),libraryName);
425+
File file = new File(String.format("%s%s%s%s",mappingInternalDirectory(),File.separator,"lib",File.separator),libraryName);
404426
if(file.exists() && file.isFile() && file.length()>0){
405427
return file;
406428
}
@@ -444,10 +466,10 @@ public boolean isDexOpted() {
444466
}
445467

446468
if (AtlasHacks.LexFile != null && AtlasHacks.LexFile.getmClass() != null) {
447-
File lexFile = new File(revisionDir, BUNDLE_LEX_FILE);
469+
File lexFile = new File(mappingInternalDirectory(), BUNDLE_LEX_FILE);
448470
return lexFile.exists() && lexFile.length() > 0;
449471
}
450-
File odexFile = new File(revisionDir, BUNDLE_ODEX_FILE);
472+
File odexFile = new File(mappingInternalDirectory(), BUNDLE_ODEX_FILE);
451473
return odexFile.exists() && odexFile.length() > 0;
452474
}
453475

@@ -460,12 +482,12 @@ public synchronized void optDexFile() {
460482
if (AtlasHacks.LexFile != null && AtlasHacks.LexFile.getmClass() != null) {
461483
//yunos
462484
// TODO: need also cover logic of filelocks for YunOS.
463-
new DexClassLoader(bundleFile.getAbsolutePath(), revisionDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
485+
new DexClassLoader(bundleFile.getAbsolutePath(), mappingInternalDirectory().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
464486
isDexOptDone = true;
465487
return;
466488
}
467489

468-
File odexFile = new File(revisionDir, BUNDLE_ODEX_FILE);
490+
File odexFile = new File(mappingInternalDirectory(), BUNDLE_ODEX_FILE);
469491

470492
long START = 0;
471493
START = System.currentTimeMillis();
@@ -486,12 +508,14 @@ public synchronized void optDexFile() {
486508
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0, interpretOnly);
487509
// dexFile = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication, bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0, interpretOnly);
488510
}else{
489-
Method m=Class.forName("android.taobao.atlas.util.DexFileCompat")
511+
Method m=Class.forName("android.taobao.atlas.startup.DexFileCompat")
490512
.getDeclaredMethod("loadDex", Context.class,String.class,String.class,int.class);
491513
dexFile= (DexFile) m.invoke(null,RuntimeVariables.androidApplication,bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0);
492-
//dexFile = DexFileCompat.loadDex(RuntimeVariables.androidApplication,bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0);
493514
}
494515
}
516+
if(Framework.isDeubgMode()){
517+
optPatchDexFile();
518+
}
495519
//9月份版本明天发布先不集成
496520
// isDexOptDone = checkDexValid(dexFile);
497521
isDexOptDone = true;
@@ -582,7 +606,7 @@ public void installSoLib(File bundle) throws IOException{
582606

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

677701
private Class findPatchClass(String clazz,ClassLoader cl){
678-
if(patchDexFileForDebug==null){
679-
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"),location);
680-
File patchFile = new File(debugBundleDir,"patch.zip");
681-
if(patchFile.exists()){
682-
try {
683-
// patchDexFileForDebug = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication,
684-
// patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
685-
//兼容7。0 动态部署过后不同classloader下对classcast
686-
RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("loadDex",Context.class,String.class, String.class, int.class, boolean.class).invoke(
687-
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
688-
} catch (Throwable e) {
689-
throw new RuntimeException(e);
690-
}
691-
}
692-
}
693702
if(patchDexFileForDebug!=null){
694703
return patchDexFileForDebug.loadClass(clazz,cl);
695704
}
696705
return null;
697706
}
698707

708+
private void optPatchDexFile() {
709+
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"), location);
710+
File patchFile = new File(debugBundleDir,"patch.zip");
711+
if(patchFile.exists()){
712+
try {
713+
// patchDexFileForDebug = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication,
714+
// patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
715+
//兼容7。0 动态部署过后不同classloader下对classcast
716+
File internalDebugBundleDir = new File(new File(RuntimeVariables.androidApplication.getFilesDir(),"debug_storage"),location);
717+
internalDebugBundleDir.mkdirs();
718+
patchDexFileForDebug= (DexFile)RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("loadDex", Context.class, String.class, String.class, int.class, boolean.class).invoke(
719+
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, patchFile.getAbsolutePath(), new File(internalDebugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
720+
} catch (Throwable e) {
721+
throw new RuntimeException(e);
722+
}
723+
}
724+
}
725+
699726
public String getDebugPatchFilePath(){
700727
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"),location);
701728
File patchFile = new File(debugBundleDir,"patch.zip");

atlas-core/src/main/java/android/taobao/atlas/hack/AndroidHack.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ public static void injectResources(Application application, Resources resources)
473473
final Object newTypedArrayPool = typedArrayConstructor.newInstance(poolSize);
474474
typedArrayPoolField.set(resources, newTypedArrayPool);
475475
} catch (Throwable ignored) {
476-
ignored.printStackTrace();
477476
}
478477
}
479478
if(res!=null) {
@@ -491,9 +490,6 @@ public static void injectResources(Application application, Resources resources)
491490
final Object wrapper = wrappRef != null ? wrappRef.get() : null;
492491
Field mTintResourcesField = TintContextWrapper.getDeclaredField("mResources");
493492
mTintResourcesField.setAccessible(true);
494-
Field mTintThemeField = TintContextWrapper.getDeclaredField("mTheme");
495-
mTintThemeField.setAccessible(true);
496-
mTintThemeField.set(wrapper,null);
497493
Object obj = mTintResourcesField.get(wrapper);
498494
Field mResourceField = findField(obj,"mResources");
499495
mResourceField.set(obj,resources);

0 commit comments

Comments
 (0)