Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 7b3eb35

Browse files
committed
compare date of package
1 parent c5ec811 commit 7b3eb35

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
File renamed without changes.

CodePush.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var requestFetchAdapter = require("./request-fetch-adapter.js");
44
var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
55
var NativeCodePush = require("react-native").NativeModules.CodePush;
66
var PackageMixins = require("./package-mixins")(NativeCodePush);
7-
var { Alert } = require("./CodePushNativePlatformAdapter");
7+
var { Alert } = require("./AlertAdapter");
88

99
function checkForUpdate(deploymentKey = null) {
1010
var config, sdk;

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import android.content.Context;
2020
import android.content.Intent;
2121
import android.content.SharedPreferences;
22+
import android.content.pm.ApplicationInfo;
2223
import android.content.pm.PackageInfo;
2324
import android.content.pm.PackageManager;
2425

2526
import org.json.JSONException;
2627
import org.json.JSONObject;
2728

29+
import java.io.File;
2830
import java.io.IOException;
2931
import java.util.ArrayList;
3032
import java.util.Calendar;
@@ -34,6 +36,8 @@
3436
import java.util.Map;
3537
import java.util.Timer;
3638
import java.util.TimerTask;
39+
import java.util.zip.ZipEntry;
40+
import java.util.zip.ZipFile;
3741

3842
public class CodePush {
3943

@@ -51,6 +55,7 @@ public class CodePush {
5155
private final String ASSETS_BUNDLE_PREFIX = "assets://";
5256
private final String CODE_PUSH_PREFERENCES = "CodePush";
5357
private final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress";
58+
private final String RESOURCES_BUNDLE = "resources.arsc";
5459

5560
private CodePushPackage codePushPackage;
5661
private CodePushReactPackage codePushReactPackage;
@@ -99,14 +104,34 @@ public String getDocumentsDirectory() {
99104
public String getBundleUrl(String assetsBundleFileName) {
100105
this.assetsBundleFileName = assetsBundleFileName;
101106
String binaryJsBundleUrl = ASSETS_BUNDLE_PREFIX + assetsBundleFileName;
107+
ZipFile applicationFile;
108+
long binaryResourcesModifiedTime = -1;
109+
110+
ApplicationInfo ai = null;
111+
try {
112+
ai = applicationContext.getPackageManager().getApplicationInfo(applicationContext.getPackageName(), 0);
113+
applicationFile = new ZipFile(ai.sourceDir);
114+
ZipEntry classesDexEntry = applicationFile.getEntry(RESOURCES_BUNDLE);
115+
binaryResourcesModifiedTime = classesDexEntry.getTime();
116+
applicationFile.close();
117+
} catch (PackageManager.NameNotFoundException | IOException e) {
118+
throw new CodePushUnknownException("Error in getting file information about compiled resources", e);
119+
}
120+
102121
try {
103-
String packageFile = codePushPackage.getCurrentPackageBundlePath();
104-
if (packageFile == null) {
122+
String packageFilePath = codePushPackage.getCurrentPackageBundlePath();
123+
if (packageFilePath == null) {
105124
// There has not been any downloaded updates.
106125
return binaryJsBundleUrl;
107126
}
108127

109-
return packageFile;
128+
File packageFile = new File(packageFilePath);
129+
if (packageFile.lastModified() < binaryResourcesModifiedTime) {
130+
// The binary version is newer.
131+
return binaryJsBundleUrl;
132+
}
133+
134+
return packageFilePath;
110135
} catch (IOException e) {
111136
throw new CodePushUnknownException("Error in getting current package bundle path", e);
112137
}

0 commit comments

Comments
 (0)