Skip to content

Commit

Permalink
[atlas-core]安装到sdcard时so仍然安装在内部存储
Browse files Browse the repository at this point in the history
  • Loading branch information
关杰 committed Jun 22, 2017
1 parent 6b54a75 commit 838fc9b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,9 @@ private void findBundleSource(String location) throws IOException{
}

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

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()>10*1024*1024){
if(new File(STORAGE_LOCATION).getUsableSpace()>5*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 @@ -399,8 +399,30 @@ public File getRevisionFile() {
return bundleFile;
}

private File mappingInternalDirectory(){
if(externalStorage){
File internalLibDir = new File(RuntimeVariables.androidApplication.getFilesDir(),String.format("storage/%s",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 @@ -585,7 +607,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
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
import android.os.Looper;
import android.taobao.atlas.startup.patch.releaser.BundleReleaser;
import android.text.TextUtils;
import android.util.Log;

import dalvik.system.DexFile;
import java.io.*;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -255,7 +257,7 @@ public KernalBundleArchive(Context context, File bundleDir,String version,long d
if (revisionDir==null || !revisionDir.exists()) {
throw new IOException("can not find kernal bundle");
}
libraryDirectory = new File(revisionDir,"lib");
libraryDirectory = new File(mappingInternalDirectory(),"lib");
File bundleFile = new File(revisionDir, BUNDLE_NAME);
boolean success = new KernalBundleRelease(revisionDir,true).release(bundleFile,true);
if (!success||odexFile == null){
Expand Down Expand Up @@ -285,7 +287,7 @@ public KernalBundleArchive(final File bundleDir, File file,String version,long d
hasResources = true;
}
zip.close();
libraryDirectory = new File(revisionDir, "lib");
libraryDirectory = new File(mappingInternalDirectory(), "lib");
boolean success = new KernalBundleRelease(revisionDir,false).release(bundleFile,false);
if (!success||odexFile == null){
throw new IOException("process mainDex failed!");
Expand Down Expand Up @@ -419,6 +421,15 @@ public static void copyInputStreamToFile(InputStream input, File file) throws IO
}
}

private File mappingInternalDirectory(){
if(!revisionDir.getAbsolutePath().startsWith(KernalConstants.baseContext.getFilesDir().getAbsolutePath())){
File internalLibDir = new File(KernalConstants.baseContext.getFilesDir(),String.format("storage/%s",revisionDir.getName()));
return internalLibDir;
}else{
return revisionDir;
}
}

/**
* 写这个类而不用匿名内部类的原因:
* 如果之前发生过动态部署,则再次进行update的时候饮用的第二个内部类与Archive不同于同一个dex,会引发PRE_VERIFY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@
package android.taobao.atlas.startup.patch.releaser;

import android.os.Build;
import android.taobao.atlas.startup.patch.KernalConstants;
import android.util.Log;

import java.io.*;
import java.util.Enumeration;
Expand Down Expand Up @@ -240,7 +242,7 @@ public static boolean releaseLibs(File apkFile, File reversionDir) throws IOExce
while(numAttempts<3 && !isExtractionSuccessful) {
numAttempts++;
try {
String targetPath = String.format("%s%s%s%s%s", reversionDir, File.separator, "lib", File.separator,
String targetPath = String.format("%s%s%s%s%s", mappingInternalDirectory(reversionDir), 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 @@ -282,4 +284,26 @@ public static boolean releaseLibs(File apkFile, File reversionDir) throws IOExce

return true;
}

private static File mappingInternalDirectory(File revisionDir){
if(!revisionDir.getAbsolutePath().startsWith(KernalConstants.baseContext.getFilesDir().getAbsolutePath())){
File internalLibDir = new File(KernalConstants.baseContext.getFilesDir(),String.format("storage/%s",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 : com.taobao.maindex");
}
return internalLibDir;
}else{
return revisionDir;
}
}
}

0 comments on commit 838fc9b

Please sign in to comment.