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 ceafd545..0563b08a 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
@@ -70,7 +70,8 @@ public static String getServiceUrl() {
private CodePush(String deploymentKey, Context context, boolean isDebugMode) {
mContext = context.getApplicationContext();
- mUpdateManager = new CodePushUpdateManager(context.getFilesDir().getAbsolutePath());
+ boolean enableBinaryDiffUpdates = getBooleanCustomPropertyFromStringsIfExist("EnableBinaryDiffUpdates", false);
+ mUpdateManager = new CodePushUpdateManager(context.getFilesDir().getAbsolutePath(), enableBinaryDiffUpdates);
mTelemetryManager = new CodePushTelemetryManager(mContext);
mDeploymentKey = deploymentKey;
mIsDebugMode = isDebugMode;
@@ -156,6 +157,17 @@ private String getCustomPropertyFromStringsIfExist(String propertyName) {
return null;
}
+ private boolean getBooleanCustomPropertyFromStringsIfExist(String propertyName, boolean defaultValue) {
+ String packageName = mContext.getPackageName();
+ int resId = mContext.getResources().getIdentifier("CodePush" + propertyName, "bool", packageName);
+
+ if (resId != 0) {
+ return mContext.getResources().getBoolean(resId);
+ }
+
+ return defaultValue;
+ }
+
public void clearDebugCacheIfNeeded(boolean isLiveReloadEnabled) {
// for checking if we use LiveReload mode. In this case we should not remove ReactNativeDevBundle.js file
// because we get error with trying to get this after reloading. Issue: https://github.com/microsoft/react-native-code-push/issues/1272
diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java
index 7a16a360..34029c92 100644
--- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java
+++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java
@@ -24,9 +24,11 @@
public class CodePushUpdateManager {
private String mDocumentsDirectory;
+ private boolean mEnableBinaryDiffUpdates;
- public CodePushUpdateManager(String documentsDirectory) {
+ public CodePushUpdateManager(String documentsDirectory, boolean enableBinaryDiffUpdates) {
mDocumentsDirectory = documentsDirectory;
+ mEnableBinaryDiffUpdates = enableBinaryDiffUpdates;
}
private String getDownloadFilePath() {
@@ -260,12 +262,14 @@ public void downloadPackage(JSONObject updatePackage, String expectedBundleFileN
if (isDiffUpdate) {
// Run patching after copyNecessaryFilesFromCurrentPackage() so patched output overwrites
// bytes copied in from the old package at the same paths.
- if (diffManifest.getVersion() == 2) {
+ if (diffManifest.getVersion() > 2 || diffManifest.getVersion() < 1) {
+ throw new IOException("Diff manifest version " + diffManifest.getVersion() + " is not supported by this SDK version.");
+ } else if (diffManifest.getVersion() == 2 && !mEnableBinaryDiffUpdates) {
+ throw new IOException("Received a binary diff update, but binary diff updates are not enabled on this client. Set CodePushEnableBinaryDiffUpdates to true in strings.xml to enable them.");
+ } else if (diffManifest.getVersion() == 2) {
String currentPackageFolderPath = getCurrentPackageFolderPath();
BinaryDiffPatcher.applyBinaryDiffPatches(diffManifest, new File(currentPackageFolderPath), new File(unzippedFolderPath), new File(newUpdateFolderPath));
FileUtils.deleteDirectoryAtPath(new File(newUpdateFolderPath, CodePushConstants.DIFF_PATCHES_FOLDER_NAME).getPath());
- } else if (diffManifest.getVersion() > 2) {
- throw new IOException("Diff manifest version " + diffManifest.getVersion() + " is not supported by this SDK version.");
}
}
diff --git a/docs/api-android.md b/docs/api-android.md
index 092bfbb4..34120923 100644
--- a/docs/api-android.md
+++ b/docs/api-android.md
@@ -15,6 +15,11 @@ Since `autolinking` uses `react-native.config.js` to link plugins, constructors
https://yourcodepush.server.com
```
+- **Enable Binary Diff Updates** - switch for applying binary diff (bsdiff) patches during a diff update, off by default (at the moment). When disabled, only file-by-file diffing is applied (for example, skipping assets if only the main JS bundle changed, but that whole file is downloaded byte for byte). Add a `bool` resource named `CodePushEnableBinaryDiffUpdates` to `strings.xml` to turn it on:
+ ```xml
+ true
+ ```
+
The Java API is made available by importing the `com.microsoft.codepush.react.CodePush` class into your `MainActivity.java` file, and consists of a single public class named `CodePush`.
### Java API Reference (Android)