forked from alibaba/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
458 changed files
with
58,053 additions
and
20,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/.idea/libraries | ||
!.idea/codeStyleSettings.xml | ||
.DS_Store | ||
/build/ | ||
#/build | ||
/captures | ||
.vscode/ | ||
|
||
|
Submodule 3.6
deleted from
606e79
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
atlas-core/src/main/java/android/support/multidex/DexElementsMaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package android.support.multidex; | ||
|
||
import android.util.Log; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.FutureTask; | ||
|
||
/** | ||
* Created by jingchaoqinjc on 18/3/4. | ||
*/ | ||
|
||
public class DexElementsMaker implements IDexElementsMaker { | ||
|
||
private static final String TAG = "DexElementsMaker"; | ||
|
||
final ArrayList<File> files; | ||
final IDexElementsMethodInvoker invoker; | ||
|
||
DexElementsMaker(ArrayList<File> files, IDexElementsMethodInvoker invoker) { | ||
this.files = files; | ||
this.invoker = invoker; | ||
} | ||
|
||
@Override | ||
public Object[] make() throws IllegalAccessException, InvocationTargetException, | ||
NoSuchMethodException { | ||
|
||
if (files.size() <= 1) { | ||
return invoker.invoke(files); | ||
} | ||
|
||
//通过算法,将文件分解成大小相似的文件集,使得每个文件集在加载的时候时间相似 | ||
ArrayList<ArrayList<File>> filesList = makeFilesList(); | ||
|
||
int size = filesList.size(); | ||
FutureTask<Object[]>[] futureTasks = new FutureTask[size]; | ||
for (int i = 0; i < size; i++) { | ||
futureTasks[i] = new FutureTask<Object[]>(new DexElementsCallable(i, filesList.get(i), invoker)); | ||
} | ||
|
||
//其他任务在子线程里完成,加速加载 | ||
for (int i = 1; i < size; i++) { | ||
new Thread(futureTasks[i]).start(); | ||
} | ||
//一个任务在主线程完成,充分利用主线程资源 | ||
futureTasks[0].run(); | ||
|
||
ArrayList<Object[]> objectsList = new ArrayList<Object[]>(); | ||
int objectsTotalLength = 0; | ||
|
||
try { | ||
for (int i = 0; i < size; i++) { | ||
Object[] objects = futureTasks[i].get(); | ||
if (objects == null) throw new RuntimeException("Illegal Action"); | ||
|
||
objectsTotalLength += objects.length; | ||
objectsList.add(objects); | ||
} | ||
|
||
Object[] objects = new Object[objectsTotalLength]; | ||
|
||
int offset = 0; | ||
for (Object[] subObjects : objectsList) { | ||
if (subObjects != null) { | ||
System.arraycopy(subObjects, 0, objects, offset, subObjects.length); | ||
offset += subObjects.length; | ||
} | ||
} | ||
|
||
return objects; | ||
} catch (Exception e) { | ||
|
||
} | ||
|
||
return invoker.invoke(files); | ||
} | ||
|
||
private long getMaxFileLength() { | ||
long max = 0; | ||
for (File file : files) { | ||
if (file != null) { | ||
long length = file.length(); | ||
max = length > max ? length : max; | ||
} | ||
} | ||
return max; | ||
} | ||
|
||
private ArrayList<ArrayList<File>> makeFilesList() { | ||
ArrayList<ArrayList<File>> filesList = new ArrayList<ArrayList<File>>(); | ||
|
||
long maxFileLength = getMaxFileLength(); | ||
long subTotalLength = 0; | ||
ArrayList<File> subFiles = new ArrayList<File>(); | ||
filesList.add(subFiles); | ||
|
||
for (File file : files) { | ||
if (file != null) { | ||
long subLength = file.length(); | ||
if (subLength + subTotalLength > maxFileLength) { | ||
subTotalLength = 0; | ||
subFiles = new ArrayList<File>(); | ||
filesList.add(subFiles); | ||
} | ||
|
||
subFiles.add(file); | ||
subTotalLength += subLength; | ||
} | ||
} | ||
|
||
return filesList; | ||
} | ||
|
||
private static class DexElementsCallable implements Callable<Object[]> { | ||
final int id; | ||
final ArrayList<File> files; | ||
final IDexElementsMethodInvoker invoker; | ||
|
||
private DexElementsCallable(int id, ArrayList<File> files, IDexElementsMethodInvoker invoker) { | ||
this.id = id; | ||
this.files = files; | ||
this.invoker = invoker; | ||
} | ||
|
||
@Override | ||
public Object[] call() throws Exception { | ||
try { | ||
long startTime = System.currentTimeMillis(); | ||
Object[] objects = invoker.invoke(files); | ||
long endTime = System.currentTimeMillis(); | ||
Log.i(TAG, "cost " + id + " time:" + (endTime - startTime)); | ||
return objects; | ||
} catch (Exception e) { | ||
|
||
} | ||
return null; | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
atlas-core/src/main/java/android/support/multidex/DexElementsMethodInvokerV14.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package android.support.multidex; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by jingchaoqinjc on 18/3/4. | ||
*/ | ||
|
||
public class DexElementsMethodInvokerV14 implements IDexElementsMethodInvoker { | ||
|
||
final Object dexPathList; | ||
final File optimizedDirectory; | ||
final Method makeDexElements; | ||
|
||
public DexElementsMethodInvokerV14(Object dexPathList, File optimizedDirectory, Method makeDexElements) { | ||
this.dexPathList = dexPathList; | ||
this.optimizedDirectory = optimizedDirectory; | ||
this.makeDexElements = makeDexElements; | ||
} | ||
|
||
@Override | ||
public Object[] invoke(ArrayList<File> files) throws InvocationTargetException, IllegalAccessException { | ||
return (Object[]) makeDexElements.invoke(dexPathList, files, optimizedDirectory); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
atlas-core/src/main/java/android/support/multidex/DexElementsMethodInvokerV19.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package android.support.multidex; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by jingchaoqinjc on 18/3/4. | ||
*/ | ||
|
||
public class DexElementsMethodInvokerV19 implements IDexElementsMethodInvoker { | ||
|
||
final Object dexPathList; | ||
final File optimizedDirectory; | ||
final ArrayList<IOException> suppressedExceptions; | ||
final Method makeDexElements; | ||
|
||
public DexElementsMethodInvokerV19(Object dexPathList, File optimizedDirectory, ArrayList<IOException> suppressedExceptions, Method makeDexElements) { | ||
this.dexPathList = dexPathList; | ||
this.optimizedDirectory = optimizedDirectory; | ||
this.suppressedExceptions = suppressedExceptions; | ||
this.makeDexElements = makeDexElements; | ||
} | ||
|
||
@Override | ||
public Object[] invoke(ArrayList<File> files) throws InvocationTargetException, IllegalAccessException { | ||
return (Object[]) makeDexElements.invoke(dexPathList, files, optimizedDirectory, suppressedExceptions); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
atlas-core/src/main/java/android/support/multidex/IDexElementsMaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package android.support.multidex; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
/** | ||
* Created by jingchaoqinjc on 18/3/4. | ||
*/ | ||
|
||
public interface IDexElementsMaker { | ||
|
||
Object[] make() throws IllegalAccessException, InvocationTargetException, | ||
NoSuchMethodException; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
atlas-core/src/main/java/android/support/multidex/IDexElementsMethodInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package android.support.multidex; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by jingchaoqinjc on 18/3/4. | ||
*/ | ||
|
||
public interface IDexElementsMethodInvoker { | ||
|
||
public Object[] invoke(ArrayList<File> files) throws InvocationTargetException, IllegalAccessException; | ||
|
||
} |
Oops, something went wrong.