From 33af795f1cd5faeaa6f9af9cc574fe2e0aa7c98e Mon Sep 17 00:00:00 2001 From: "seven.tang" Date: Tue, 17 Oct 2017 10:06:11 +0800 Subject: [PATCH] Use bundle.json to set so application boot sequence "order": 1 will be loaded firstly. Order means group. --- .../net/wequick/small/ApkBundleLauncher.java | 18 ++++++++++++++++-- .../main/java/net/wequick/small/Bundle.java | 12 ++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Android/DevSample/small/src/main/java/net/wequick/small/ApkBundleLauncher.java b/Android/DevSample/small/src/main/java/net/wequick/small/ApkBundleLauncher.java index f4e36bf4..81c9d447 100644 --- a/Android/DevSample/small/src/main/java/net/wequick/small/ApkBundleLauncher.java +++ b/Android/DevSample/small/src/main/java/net/wequick/small/ApkBundleLauncher.java @@ -56,6 +56,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -91,15 +92,24 @@ public class ApkBundleLauncher extends SoBundleLauncher { private static final String FILE_DEX = "bundle.dex"; private static final String STUB_QUEUE_RESTORE_KEY = "small.stubQueue"; - private static class LoadedApk { + private static class LoadedApk implements Comparable { public String packageName; public File packagePath; public String applicationName; + public int order; public String path; public DexFile dexFile; public File optDexFile; public File libraryPath; public boolean nonResources; /** no resources.arsc */ + + @Override + public int compareTo(Object o) { + if (o instanceof LoadedApk) { + return order - ((LoadedApk) o).order; + } + return order; + } } private static ConcurrentHashMap sLoadedApks; @@ -800,7 +810,10 @@ public void postSetUp() { } // Trigger all the bundle application `onCreate' event - for (final LoadedApk apk : apks) { + List apkList = new ArrayList<>(apks); + //noinspection unchecked + Collections.sort(apkList); + for (final LoadedApk apk : apkList) { String bundleApplicationName = apk.applicationName; if (bundleApplicationName == null) continue; @@ -880,6 +893,7 @@ public void loadBundle(Bundle bundle) { if (pluginInfo.applicationInfo != null) { apk.applicationName = pluginInfo.applicationInfo.className; } + apk.order = bundle.getOrder(); apk.packagePath = bundle.getExtractPath(); apk.optDexFile = new File(apk.packagePath, FILE_DEX); diff --git a/Android/DevSample/small/src/main/java/net/wequick/small/Bundle.java b/Android/DevSample/small/src/main/java/net/wequick/small/Bundle.java index 628faf93..2ba7cd2a 100644 --- a/Android/DevSample/small/src/main/java/net/wequick/small/Bundle.java +++ b/Android/DevSample/small/src/main/java/net/wequick/small/Bundle.java @@ -100,6 +100,8 @@ private static final class Manifest { private Intent mIntent; private String type; private String path; + //Launch application order. + private int order; private String query; private HashMap rules; private int versionCode; @@ -527,6 +529,12 @@ private void initWithMap(JSONObject map) throws JSONException { this.type = map.getString("type"); } + if (map.has("order")) { + this.order = Integer.parseInt(map.getString("order")); + } else { + //Default means don't care the order, so put it at last. + this.order = Integer.MAX_VALUE; + } this.rules = new HashMap(); String entrancePath = DEFAULT_ENTRANCE_PATH; if (map.has("rules")) { @@ -591,6 +599,10 @@ protected Uri getUri() { return uri; } + protected int getOrder() { + return order; + } + protected void setURL(URL url) { this.url = url; }