From 379cfe14ab4d62c545b0f58bb7994c8578ad0021 Mon Sep 17 00:00:00 2001 From: Sergey Akhalkov Date: Tue, 31 Jan 2017 13:18:46 +0300 Subject: [PATCH] CodePush: changed implementation of `getBinaryResourcesModifiedTime` method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/Microsoft/react-native-code-push/issues/650 --- .../microsoft/codepush/react/CodePush.java | 21 ++++++------------- .../codepush/react/CodePushConstants.java | 1 + android/codepush.gradle | 3 +++ 3 files changed, 10 insertions(+), 15 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 16bb84bf8..ec4b95c56 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 @@ -104,22 +104,13 @@ public String getAssetsBundleFileName() { } long getBinaryResourcesModifiedTime() { - ZipFile applicationFile = null; try { - ApplicationInfo ai = this.mContext.getPackageManager().getApplicationInfo(this.mContext.getPackageName(), 0); - applicationFile = new ZipFile(ai.sourceDir); - ZipEntry classesDexEntry = applicationFile.getEntry(CodePushConstants.RESOURCES_BUNDLE); - return classesDexEntry.getTime(); - } catch (PackageManager.NameNotFoundException | IOException e) { - throw new CodePushUnknownException("Error in getting file information about compiled resources", e); - } finally { - if (applicationFile != null) { - try { - applicationFile.close(); - } catch (IOException e) { - throw new CodePushUnknownException("Error in closing application file.", e); - } - } + String packageName = this.mContext.getPackageName(); + int codePushApkBuildTimeId = this.mContext.getResources().getIdentifier(CodePushConstants.CODE_PUSH_APK_BUILD_TIME_KEY, "string", packageName); + String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId); + return Long.parseLong(codePushApkBuildTime); + } catch (Exception e) { + throw new CodePushUnknownException("Error in getting binary resources modified time", e); } } diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java index 898d26478..ea9640fdf 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java @@ -25,4 +25,5 @@ public class CodePushConstants { public static final String RESOURCES_BUNDLE = "resources.arsc"; public static final String STATUS_FILE = "codepush.json"; public static final String UNZIPPED_FOLDER_NAME = "unzipped"; + public static final String CODE_PUSH_APK_BUILD_TIME_KEY = "CODE_PUSH_APK_BUILD_TIME"; } diff --git a/android/codepush.gradle b/android/codepush.gradle index 60d814461..6711a3a87 100644 --- a/android/codepush.gradle +++ b/android/codepush.gradle @@ -16,6 +16,9 @@ void runBefore(String dependentTaskName, Task task) { gradle.projectsEvaluated { def buildTypes = android.buildTypes.collect { type -> type.name } + android.buildTypes.each { + it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", Long.toString(System.currentTimeMillis()) + } def productFlavors = android.productFlavors.collect { flavor -> flavor.name } if (!productFlavors) productFlavors.add('') def nodeModulesPath;