mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-11 08:04:23 +08:00
feedback
This commit is contained in:
@@ -50,7 +50,6 @@ public class CodePush {
|
||||
|
||||
private final String ASSETS_BUNDLE_PREFIX = "assets://";
|
||||
private final String BINARY_MODIFIED_TIME_KEY = "binaryModifiedTime";
|
||||
private final String CODE_PUSH_HASH_FILE_NAME = "CodePushHash.json";
|
||||
private final String CODE_PUSH_PREFERENCES = "CodePush";
|
||||
private final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress";
|
||||
private final String FAILED_UPDATES_KEY = "CODE_PUSH_FAILED_UPDATES";
|
||||
@@ -70,9 +69,9 @@ public class CodePush {
|
||||
private CodePushTelemetryManager codePushTelemetryManager;
|
||||
|
||||
// Config properties.
|
||||
private String deploymentKey;
|
||||
private String appVersion;
|
||||
private int buildVersion;
|
||||
private String deploymentKey;
|
||||
private final String serverUrl = "https://codepush.azurewebsites.net/";
|
||||
|
||||
private Activity mainActivity;
|
||||
@@ -393,20 +392,6 @@ public class CodePush {
|
||||
asyncTask.execute();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getBinaryHash(Promise promise) {
|
||||
try {
|
||||
promise.resolve(CodePushUtils.getStringFromInputStream(mainActivity.getAssets().open(CODE_PUSH_HASH_FILE_NAME)));
|
||||
} catch (IOException e) {
|
||||
if (!isDebugMode) {
|
||||
// Only print this message in "Release" mode. In "Debug", we may not have the
|
||||
// hash if the build skips bundling the files.
|
||||
CodePushUtils.log("Unable to get the hash of the binary's bundled resources - \"codepush.gradle\" may have not been added to the build definition.");
|
||||
}
|
||||
promise.resolve("");
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getConfiguration(Promise promise) {
|
||||
WritableNativeMap configMap = new WritableNativeMap();
|
||||
@@ -417,6 +402,11 @@ public class CodePush {
|
||||
configMap.putString("clientUniqueId",
|
||||
Settings.Secure.getString(mainActivity.getContentResolver(),
|
||||
android.provider.Settings.Secure.ANDROID_ID));
|
||||
String binaryHash = CodePushUpdateUtils.getHashForBinaryContents(mainActivity, isDebugMode);
|
||||
if (binaryHash != null) {
|
||||
configMap.putString(PACKAGE_HASH_KEY, binaryHash);
|
||||
}
|
||||
|
||||
promise.resolve(configMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.microsoft.codepush.react;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Base64;
|
||||
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
@@ -21,6 +22,12 @@ import java.util.Collections;
|
||||
|
||||
public class CodePushUpdateUtils {
|
||||
|
||||
private static final String CODE_PUSH_HASH_FILE_NAME = "CodePushHash.json";
|
||||
|
||||
// These variables are used to cache the hash of the binary contents in memory.
|
||||
private static String binaryHash = null;
|
||||
private static boolean didLoadBinaryHash = false;
|
||||
|
||||
private static void addContentsOfFolderToManifest(String folderPath, String pathPrefix, ArrayList<String> manifest) {
|
||||
File folder = new File(folderPath);
|
||||
File[] folderFiles = folder.listFiles();
|
||||
@@ -102,6 +109,25 @@ public class CodePushUpdateUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getHashForBinaryContents(Activity mainActivity, boolean isDebugMode) {
|
||||
if (!didLoadBinaryHash) {
|
||||
didLoadBinaryHash = true;
|
||||
try {
|
||||
binaryHash = CodePushUtils.getStringFromInputStream(mainActivity.getAssets().open(CODE_PUSH_HASH_FILE_NAME));
|
||||
} catch (IOException e) {
|
||||
if (!isDebugMode) {
|
||||
// Only print this message in "Release" mode. In "Debug", we may not have the
|
||||
// hash if the build skips bundling the files.
|
||||
CodePushUtils.log("Unable to get the hash of the binary's bundled resources - \"codepush.gradle\" may have not been added to the build definition.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return binaryHash;
|
||||
}
|
||||
|
||||
public static void verifyHashForDiffUpdate(String folderPath, String expectedHash) {
|
||||
ArrayList<String> updateContentsManifest = new ArrayList<String>();
|
||||
addContentsOfFolderToManifest(folderPath, "", updateContentsManifest);
|
||||
|
||||
Reference in New Issue
Block a user