Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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.");
}
}

Expand Down
5 changes: 5 additions & 0 deletions docs/api-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Since `autolinking` uses `react-native.config.js` to link plugins, constructors
<string moduleConfig="true" name="CodePushServerUrl">https://yourcodepush.server.com</string>
```

- **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
<bool moduleConfig="true" name="CodePushEnableBinaryDiffUpdates">true</bool>
```

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)
Expand Down