From 7b3eb35bf89b0ea8d7a4c75d38695331fbcf2cae Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 24 Nov 2015 18:20:04 -0800 Subject: [PATCH] compare date of package --- ...ativePlatformAdapter.js => AlertAdapter.js | 0 CodePush.js | 2 +- .../microsoft/codepush/react/CodePush.java | 31 +++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) rename CodePushNativePlatformAdapter.js => AlertAdapter.js (100%) diff --git a/CodePushNativePlatformAdapter.js b/AlertAdapter.js similarity index 100% rename from CodePushNativePlatformAdapter.js rename to AlertAdapter.js diff --git a/CodePush.js b/CodePush.js index fea9889..9e96ddd 100644 --- a/CodePush.js +++ b/CodePush.js @@ -4,7 +4,7 @@ var requestFetchAdapter = require("./request-fetch-adapter.js"); var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager; var NativeCodePush = require("react-native").NativeModules.CodePush; var PackageMixins = require("./package-mixins")(NativeCodePush); -var { Alert } = require("./CodePushNativePlatformAdapter"); +var { Alert } = require("./AlertAdapter"); function checkForUpdate(deploymentKey = null) { var config, sdk; 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 abdd6cb..1903267 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 @@ -19,12 +19,14 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import org.json.JSONException; import org.json.JSONObject; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; @@ -34,6 +36,8 @@ import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; public class CodePush { @@ -51,6 +55,7 @@ public class CodePush { private final String ASSETS_BUNDLE_PREFIX = "assets://"; private final String CODE_PUSH_PREFERENCES = "CodePush"; private final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress"; + private final String RESOURCES_BUNDLE = "resources.arsc"; private CodePushPackage codePushPackage; private CodePushReactPackage codePushReactPackage; @@ -99,14 +104,34 @@ public class CodePush { public String getBundleUrl(String assetsBundleFileName) { this.assetsBundleFileName = assetsBundleFileName; String binaryJsBundleUrl = ASSETS_BUNDLE_PREFIX + assetsBundleFileName; + ZipFile applicationFile; + long binaryResourcesModifiedTime = -1; + + ApplicationInfo ai = null; try { - String packageFile = codePushPackage.getCurrentPackageBundlePath(); - if (packageFile == null) { + ai = applicationContext.getPackageManager().getApplicationInfo(applicationContext.getPackageName(), 0); + applicationFile = new ZipFile(ai.sourceDir); + ZipEntry classesDexEntry = applicationFile.getEntry(RESOURCES_BUNDLE); + binaryResourcesModifiedTime = classesDexEntry.getTime(); + applicationFile.close(); + } catch (PackageManager.NameNotFoundException | IOException e) { + throw new CodePushUnknownException("Error in getting file information about compiled resources", e); + } + + try { + String packageFilePath = codePushPackage.getCurrentPackageBundlePath(); + if (packageFilePath == null) { // There has not been any downloaded updates. return binaryJsBundleUrl; } - return packageFile; + File packageFile = new File(packageFilePath); + if (packageFile.lastModified() < binaryResourcesModifiedTime) { + // The binary version is newer. + return binaryJsBundleUrl; + } + + return packageFilePath; } catch (IOException e) { throw new CodePushUnknownException("Error in getting current package bundle path", e); }