From e8034cd15bba1d49eb4311006a50bc608927dbbe Mon Sep 17 00:00:00 2001 From: sunkuan Date: Wed, 18 Nov 2015 10:17:18 +0800 Subject: [PATCH] Add loadBundle method in BundleCore & Framework. --- .../ctrip/android/bundle/framework/BundleCore.java | 3 +++ .../src/ctrip/android/bundle/framework/Framework.java | 9 +++++++++ .../ctrip/android/sample/BundleBaseApplication.java | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/bundle/src/ctrip/android/bundle/framework/BundleCore.java b/bundle/src/ctrip/android/bundle/framework/BundleCore.java index 7cd6ef4..9ddc7c4 100644 --- a/bundle/src/ctrip/android/bundle/framework/BundleCore.java +++ b/bundle/src/ctrip/android/bundle/framework/BundleCore.java @@ -121,6 +121,9 @@ public Bundle installBundle(String location, InputStream inputStream) throws Bun return Framework.installNewBundle(location, inputStream); } + public Bundle loadBundle(String location) throws Exception { + return Framework.loadBundle(location); + } public void updateBundle(String location, InputStream inputStream) throws BundleException { Bundle bundle = Framework.getBundle(location); diff --git a/bundle/src/ctrip/android/bundle/framework/Framework.java b/bundle/src/ctrip/android/bundle/framework/Framework.java index e1a5c24..a869b19 100644 --- a/bundle/src/ctrip/android/bundle/framework/Framework.java +++ b/bundle/src/ctrip/android/bundle/framework/Framework.java @@ -227,5 +227,14 @@ static BundleImpl installNewBundle(String location, InputStream inputStream) thr return bundleImpl; } + static BundleImpl loadBundle(String location) throws Exception { + BundleImpl bundleImpl = (BundleImpl) getBundle(location); + if (bundleImpl != null) { + return bundleImpl; + } + bundleImpl = new BundleImpl(new File(location)); + bundles.put(location, bundleImpl); + return bundleImpl; + } } diff --git a/sample/src/ctrip/android/sample/BundleBaseApplication.java b/sample/src/ctrip/android/sample/BundleBaseApplication.java index 05ad4a6..65c4892 100644 --- a/sample/src/ctrip/android/sample/BundleBaseApplication.java +++ b/sample/src/ctrip/android/sample/BundleBaseApplication.java @@ -45,6 +45,17 @@ public void onCreate() { BundleCore.getInstance().startup(properties); if (isDexInstalled) { HotPatchManager.getInstance().run(); + File libsPath = new File(getFilesDir() + "/storage/"); + try { + for (File bundleDir : libsPath.listFiles()){ + if (!bundleDir.isDirectory()){ //Skip meta file. + continue; + } + BundleCore.getInstance().loadBundle(bundleDir.getAbsolutePath()); + } + } catch (Exception e){ + e.printStackTrace(); + } BundleCore.getInstance().run(); } else { new Thread(new Runnable() {