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

Commit 4df7235

Browse files
CodePush: changed implementation of getBinaryResourcesModifiedTime method (#683)
Due to “the last modified date on all files in an apk now have the time stamp of 'Fri, Nov 30 1979 00:00:00'” (https://code.google.com/p/android/issues/detail?id=220039) we have to store apk build time value in `app/src/main/res/values/strings.xml` file and use it further in `getBinaryResourcesModifiedTime` method Fix #650
1 parent 3da57cd commit 4df7235

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,13 @@ public String getAssetsBundleFileName() {
104104
}
105105

106106
long getBinaryResourcesModifiedTime() {
107-
ZipFile applicationFile = null;
108107
try {
109-
ApplicationInfo ai = this.mContext.getPackageManager().getApplicationInfo(this.mContext.getPackageName(), 0);
110-
applicationFile = new ZipFile(ai.sourceDir);
111-
ZipEntry classesDexEntry = applicationFile.getEntry(CodePushConstants.RESOURCES_BUNDLE);
112-
return classesDexEntry.getTime();
113-
} catch (PackageManager.NameNotFoundException | IOException e) {
114-
throw new CodePushUnknownException("Error in getting file information about compiled resources", e);
115-
} finally {
116-
if (applicationFile != null) {
117-
try {
118-
applicationFile.close();
119-
} catch (IOException e) {
120-
throw new CodePushUnknownException("Error in closing application file.", e);
121-
}
122-
}
108+
String packageName = this.mContext.getPackageName();
109+
int codePushApkBuildTimeId = this.mContext.getResources().getIdentifier(CodePushConstants.CODE_PUSH_APK_BUILD_TIME_KEY, "string", packageName);
110+
String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId);
111+
return Long.parseLong(codePushApkBuildTime);
112+
} catch (Exception e) {
113+
throw new CodePushUnknownException("Error in getting binary resources modified time", e);
123114
}
124115
}
125116

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public class CodePushConstants {
2525
public static final String RESOURCES_BUNDLE = "resources.arsc";
2626
public static final String STATUS_FILE = "codepush.json";
2727
public static final String UNZIPPED_FOLDER_NAME = "unzipped";
28+
public static final String CODE_PUSH_APK_BUILD_TIME_KEY = "CODE_PUSH_APK_BUILD_TIME";
2829
}

android/codepush.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ void runBefore(String dependentTaskName, Task task) {
1616

1717
gradle.projectsEvaluated {
1818
def buildTypes = android.buildTypes.collect { type -> type.name }
19+
android.buildTypes.each {
20+
it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", Long.toString(System.currentTimeMillis())
21+
}
1922
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
2023
if (!productFlavors) productFlavors.add('')
2124
def nodeModulesPath;

0 commit comments

Comments
 (0)