|
24 | 24 | public class CodePushUpdateManager { |
25 | 25 |
|
26 | 26 | private String mDocumentsDirectory; |
| 27 | + private boolean mEnableBinaryDiffUpdates; |
27 | 28 |
|
28 | | - public CodePushUpdateManager(String documentsDirectory) { |
| 29 | + public CodePushUpdateManager(String documentsDirectory, boolean enableBinaryDiffUpdates) { |
29 | 30 | mDocumentsDirectory = documentsDirectory; |
| 31 | + mEnableBinaryDiffUpdates = enableBinaryDiffUpdates; |
30 | 32 | } |
31 | 33 |
|
32 | 34 | private String getDownloadFilePath() { |
@@ -260,15 +262,17 @@ public void downloadPackage(JSONObject updatePackage, String expectedBundleFileN |
260 | 262 | if (isDiffUpdate) { |
261 | 263 | // Run patching after copyNecessaryFilesFromCurrentPackage() so patched output overwrites |
262 | 264 | // bytes copied in from the old package at the same paths. |
263 | | - if (diffManifest.getVersion() == 2) { |
| 265 | + if (diffManifest.getVersion() > 2 || diffManifest.getVersion() < 1) { |
| 266 | + throw new IOException("Diff manifest version " + diffManifest.getVersion() + " is not supported by this SDK version."); |
| 267 | + } else if (diffManifest.getVersion() == 2 && !mEnableBinaryDiffUpdates) { |
| 268 | + 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."); |
| 269 | + } else if (diffManifest.getVersion() == 2) { |
264 | 270 | String currentPackageFolderPath = getCurrentPackageFolderPath(); |
265 | 271 | if (currentPackageFolderPath == null) { |
266 | 272 | throw new CodePushInvalidUpdateException("Received a binary diff update, but no currently installed package exists to diff against (this is likely the first CodePush update for this app install). Diffing against the embedded app binary is not yet supported."); |
267 | 273 | } |
268 | 274 | BinaryDiffPatcher.applyBinaryDiffPatches(diffManifest, new File(currentPackageFolderPath), new File(unzippedFolderPath), new File(newUpdateFolderPath)); |
269 | 275 | FileUtils.deleteDirectoryAtPath(new File(newUpdateFolderPath, CodePushConstants.DIFF_PATCHES_FOLDER_NAME).getPath()); |
270 | | - } else if (diffManifest.getVersion() > 2) { |
271 | | - throw new IOException("Diff manifest version " + diffManifest.getVersion() + " is not supported by this SDK version."); |
272 | 276 | } |
273 | 277 | } |
274 | 278 |
|
|
0 commit comments