From e27968e32ebbdf8b50abc1b76f8e0b8e768508fe Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Sat, 12 Mar 2016 15:15:40 -0800 Subject: [PATCH] Android implementation --- .../java/com/microsoft/codepush/react/CodePush.java | 2 +- .../microsoft/codepush/react/CodePushPackage.java | 4 ++-- .../codepush/react/CodePushUpdateUtils.java | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 2ac9e48..edced16 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -365,7 +365,7 @@ public class CodePush { try { WritableMap mutableUpdatePackage = CodePushUtils.convertReadableMapToWritableMap(updatePackage); mutableUpdatePackage.putString(BINARY_MODIFIED_TIME_KEY, "" + getBinaryResourcesModifiedTime()); - codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, new DownloadProgressCallback() { + codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, CodePush.this.assetsBundleFileName, new DownloadProgressCallback() { @Override public void call(DownloadProgress downloadProgress) { getReactApplicationContext() diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java index 60a9569..a5c8f84 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java @@ -151,7 +151,7 @@ public class CodePushPackage { } } - public void downloadPackage(Context applicationContext, ReadableMap updatePackage, + public void downloadPackage(Context applicationContext, ReadableMap updatePackage, String expectedBundleFileName, DownloadProgressCallback progressCallback) throws IOException { String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY); String newUpdateFolderPath = getPackageFolderPath(newUpdateHash); @@ -243,7 +243,7 @@ public class CodePushPackage { // For zip updates, we need to find the relative path to the jsBundle and save it in the // metadata so that we can find and run it easily the next time. - String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath); + String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath, expectedBundleFileName); if (relativeBundlePath == null) { throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package."); diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java index f30e188..99dde10 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java @@ -79,24 +79,20 @@ public class CodePushUpdateUtils { } } - public static String findJSBundleInUpdateContents(String folderPath) { + public static String findJSBundleInUpdateContents(String folderPath, String expectedFileName) { File folder = new File(folderPath); File[] folderFiles = folder.listFiles(); for (File file : folderFiles) { String fullFilePath = CodePushUtils.appendPathComponent(folderPath, file.getName()); if (file.isDirectory()) { - String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath); + String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath, expectedFileName); if (mainBundlePathInSubFolder != null) { return CodePushUtils.appendPathComponent(file.getName(), mainBundlePathInSubFolder); } } else { String fileName = file.getName(); - int dotIndex = fileName.lastIndexOf("."); - if (dotIndex >= 0) { - String fileExtension = fileName.substring(dotIndex + 1); - if (fileExtension.equals("bundle") || fileExtension.equals("js") || fileExtension.equals("jsbundle")) { - return fileName; - } + if (fileName.equals(expectedFileName)) { + return fileName; } } }