@appzung/react-native-code-push 5.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/AlertAdapter.js +24 -0
  2. package/CONTRIBUTING.md +136 -0
  3. package/CodePush.js +666 -0
  4. package/CodePush.podspec +27 -0
  5. package/LICENSE.md +13 -0
  6. package/README.md +386 -0
  7. package/RestartManager.js +59 -0
  8. package/android/app/build.gradle +31 -0
  9. package/android/app/proguard-rules.pro +25 -0
  10. package/android/app/src/main/AndroidManifest.xml +10 -0
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
  17. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
  18. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
  19. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
  20. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
  21. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
  22. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
  23. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
  24. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
  25. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
  26. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
  27. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
  28. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
  29. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
  30. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
  31. package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
  32. package/android/build.gradle +20 -0
  33. package/android/codepush.gradle +113 -0
  34. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  35. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  36. package/android/gradle.properties +20 -0
  37. package/android/gradlew +164 -0
  38. package/android/gradlew.bat +90 -0
  39. package/android/settings.gradle +1 -0
  40. package/docs/api-android.md +65 -0
  41. package/docs/api-ios.md +31 -0
  42. package/docs/api-js.md +592 -0
  43. package/docs/multi-deployment-testing-android.md +107 -0
  44. package/docs/multi-deployment-testing-ios.md +53 -0
  45. package/docs/setup-android.md +406 -0
  46. package/docs/setup-ios.md +229 -0
  47. package/docs/setup-windows.md +65 -0
  48. package/gulpfile.js +302 -0
  49. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
  50. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
  51. package/ios/CodePush/Base64/README.md +47 -0
  52. package/ios/CodePush/CodePush.h +235 -0
  53. package/ios/CodePush/CodePush.m +1041 -0
  54. package/ios/CodePush/CodePushConfig.m +116 -0
  55. package/ios/CodePush/CodePushDownloadHandler.m +130 -0
  56. package/ios/CodePush/CodePushErrorUtils.m +20 -0
  57. package/ios/CodePush/CodePushPackage.m +598 -0
  58. package/ios/CodePush/CodePushTelemetryManager.m +175 -0
  59. package/ios/CodePush/CodePushUpdateUtils.m +376 -0
  60. package/ios/CodePush/CodePushUtils.m +9 -0
  61. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
  62. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
  63. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
  64. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
  65. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
  66. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
  67. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
  68. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
  69. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
  70. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
  71. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
  72. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
  73. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
  74. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
  75. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
  76. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
  77. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
  78. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
  79. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
  80. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
  81. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
  82. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
  83. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
  84. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
  85. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
  86. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
  87. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
  88. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
  89. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
  90. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
  91. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
  92. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
  93. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
  94. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
  95. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
  96. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
  97. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
  98. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
  99. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
  100. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
  101. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
  102. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
  103. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
  104. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
  105. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
  106. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
  107. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
  108. package/ios/CodePush/JWT/LICENSE +19 -0
  109. package/ios/CodePush/JWT/README.md +489 -0
  110. package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
  111. package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
  112. package/ios/CodePush/SSZipArchive/Common.h +81 -0
  113. package/ios/CodePush/SSZipArchive/README.md +1 -0
  114. package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
  115. package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
  116. package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
  117. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
  118. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
  119. package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
  120. package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
  121. package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
  122. package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
  123. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
  124. package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
  125. package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
  126. package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
  127. package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
  128. package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
  129. package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
  130. package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
  131. package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
  132. package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
  133. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
  134. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
  135. package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
  136. package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
  137. package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
  138. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
  139. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
  140. package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
  141. package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
  142. package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
  143. package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
  144. package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
  145. package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
  146. package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
  147. package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  148. package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  149. package/logging.js +6 -0
  150. package/package-mixins.js +69 -0
  151. package/package.json +47 -0
  152. package/request-fetch-adapter.js +52 -0
  153. package/scripts/generateBundledResourcesHash.js +125 -0
  154. package/scripts/getFilesInFolder.js +19 -0
  155. package/scripts/postlink/android/postlink.js +87 -0
  156. package/scripts/postlink/ios/postlink.js +116 -0
  157. package/scripts/postlink/run.js +11 -0
  158. package/scripts/postunlink/android/postunlink.js +74 -0
  159. package/scripts/postunlink/ios/postunlink.js +87 -0
  160. package/scripts/postunlink/run.js +11 -0
  161. package/scripts/recordFilesBeforeBundleCommand.js +41 -0
  162. package/scripts/tools/linkToolsAndroid.js +57 -0
  163. package/scripts/tools/linkToolsIos.js +130 -0
  164. package/typings/react-native-code-push.d.ts +446 -0
  165. package/windows/CodePush/CodePush.csproj +128 -0
  166. package/windows/CodePush/CodePushUtils.cs +47 -0
  167. package/windows/CodePush/FileUtils.cs +40 -0
  168. package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
  169. package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
  170. package/windows/CodePush/UpdateManager.cs +305 -0
  171. package/windows/CodePush/UpdateUtils.cs +46 -0
  172. package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
  173. package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
  174. package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
  175. package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
  176. package/windows/CodePush.Net46/FileUtils.cs +55 -0
  177. package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
  178. package/windows/CodePush.Net46/UpdateManager.cs +330 -0
  179. package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
  180. package/windows/CodePush.Net46/packages.config +5 -0
  181. package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
  182. package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
  183. package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
  184. package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
  185. package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
  186. package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
  187. package/windows/CodePush.Shared/InstallMode.cs +9 -0
  188. package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
  189. package/windows/CodePush.Shared/SettingsManager.cs +148 -0
  190. package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
  191. package/windows/CodePush.Shared/UpdateState.cs +9 -0
@@ -0,0 +1,175 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import android.content.Context;
4
+ import android.content.SharedPreferences;
5
+
6
+ import com.facebook.react.bridge.Arguments;
7
+ import com.facebook.react.bridge.ReadableMap;
8
+ import com.facebook.react.bridge.WritableMap;
9
+
10
+ import org.json.JSONException;
11
+ import org.json.JSONObject;
12
+
13
+ public class CodePushTelemetryManager {
14
+ private SharedPreferences mSettings;
15
+ private final String APP_VERSION_KEY = "appVersion";
16
+ private final String DEPLOYMENT_FAILED_STATUS = "DeploymentFailed";
17
+ private final String DEPLOYMENT_KEY_KEY = "deploymentKey";
18
+ private final String DEPLOYMENT_SUCCEEDED_STATUS = "DeploymentSucceeded";
19
+ private final String LABEL_KEY = "label";
20
+ private final String LAST_DEPLOYMENT_REPORT_KEY = "CODE_PUSH_LAST_DEPLOYMENT_REPORT";
21
+ private final String PACKAGE_KEY = "package";
22
+ private final String PREVIOUS_DEPLOYMENT_KEY_KEY = "previousDeploymentKey";
23
+ private final String PREVIOUS_LABEL_OR_APP_VERSION_KEY = "previousLabelOrAppVersion";
24
+ private final String RETRY_DEPLOYMENT_REPORT_KEY = "CODE_PUSH_RETRY_DEPLOYMENT_REPORT";
25
+ private final String STATUS_KEY = "status";
26
+
27
+ public CodePushTelemetryManager(Context applicationContext) {
28
+ mSettings = applicationContext.getSharedPreferences(CodePushConstants.CODE_PUSH_PREFERENCES, 0);
29
+ }
30
+
31
+ public WritableMap getBinaryUpdateReport(String appVersion) {
32
+ String previousStatusReportIdentifier = this.getPreviousStatusReportIdentifier();
33
+ WritableMap reportMap = null;
34
+ if (previousStatusReportIdentifier == null) {
35
+ this.clearRetryStatusReport();
36
+ reportMap = Arguments.createMap();
37
+ reportMap.putString(APP_VERSION_KEY, appVersion);
38
+ } else if (!previousStatusReportIdentifier.equals(appVersion)) {
39
+ this.clearRetryStatusReport();
40
+ reportMap = Arguments.createMap();
41
+ if (this.isStatusReportIdentifierCodePushLabel(previousStatusReportIdentifier)) {
42
+ String previousDeploymentKey = this.getDeploymentKeyFromStatusReportIdentifier(previousStatusReportIdentifier);
43
+ String previousLabel = this.getVersionLabelFromStatusReportIdentifier(previousStatusReportIdentifier);
44
+ reportMap.putString(APP_VERSION_KEY, appVersion);
45
+ reportMap.putString(PREVIOUS_DEPLOYMENT_KEY_KEY, previousDeploymentKey);
46
+ reportMap.putString(PREVIOUS_LABEL_OR_APP_VERSION_KEY, previousLabel);
47
+ } else {
48
+ // Previous status report was with a binary app version.
49
+ reportMap.putString(APP_VERSION_KEY, appVersion);
50
+ reportMap.putString(PREVIOUS_LABEL_OR_APP_VERSION_KEY, previousStatusReportIdentifier);
51
+ }
52
+ }
53
+
54
+ return reportMap;
55
+ }
56
+
57
+ public WritableMap getRetryStatusReport() {
58
+ String retryStatusReportString = mSettings.getString(RETRY_DEPLOYMENT_REPORT_KEY, null);
59
+ if (retryStatusReportString != null) {
60
+ clearRetryStatusReport();
61
+ try {
62
+ JSONObject retryStatusReport = new JSONObject(retryStatusReportString);
63
+ return CodePushUtils.convertJsonObjectToWritable(retryStatusReport);
64
+ } catch (JSONException e) {
65
+ e.printStackTrace();
66
+ }
67
+ }
68
+
69
+ return null;
70
+ }
71
+
72
+ public WritableMap getRollbackReport(WritableMap lastFailedPackage) {
73
+ WritableMap reportMap = Arguments.createMap();
74
+ reportMap.putMap(PACKAGE_KEY, lastFailedPackage);
75
+ reportMap.putString(STATUS_KEY, DEPLOYMENT_FAILED_STATUS);
76
+ return reportMap;
77
+ }
78
+
79
+ public WritableMap getUpdateReport(WritableMap currentPackage) {
80
+ String currentPackageIdentifier = this.getPackageStatusReportIdentifier(currentPackage);
81
+ String previousStatusReportIdentifier = this.getPreviousStatusReportIdentifier();
82
+ WritableMap reportMap = null;
83
+ if (currentPackageIdentifier != null) {
84
+ if (previousStatusReportIdentifier == null) {
85
+ this.clearRetryStatusReport();
86
+ reportMap = Arguments.createMap();
87
+ reportMap.putMap(PACKAGE_KEY, currentPackage);
88
+ reportMap.putString(STATUS_KEY, DEPLOYMENT_SUCCEEDED_STATUS);
89
+ } else if (!previousStatusReportIdentifier.equals(currentPackageIdentifier)) {
90
+ this.clearRetryStatusReport();
91
+ reportMap = Arguments.createMap();
92
+ if (this.isStatusReportIdentifierCodePushLabel(previousStatusReportIdentifier)) {
93
+ String previousDeploymentKey = this.getDeploymentKeyFromStatusReportIdentifier(previousStatusReportIdentifier);
94
+ String previousLabel = this.getVersionLabelFromStatusReportIdentifier(previousStatusReportIdentifier);
95
+ reportMap.putMap(PACKAGE_KEY, currentPackage);
96
+ reportMap.putString(STATUS_KEY, DEPLOYMENT_SUCCEEDED_STATUS);
97
+ reportMap.putString(PREVIOUS_DEPLOYMENT_KEY_KEY, previousDeploymentKey);
98
+ reportMap.putString(PREVIOUS_LABEL_OR_APP_VERSION_KEY, previousLabel);
99
+ } else {
100
+ // Previous status report was with a binary app version.
101
+ reportMap.putMap(PACKAGE_KEY, currentPackage);
102
+ reportMap.putString(STATUS_KEY, DEPLOYMENT_SUCCEEDED_STATUS);
103
+ reportMap.putString(PREVIOUS_LABEL_OR_APP_VERSION_KEY, previousStatusReportIdentifier);
104
+ }
105
+ }
106
+ }
107
+
108
+ return reportMap;
109
+ }
110
+
111
+ public void recordStatusReported(ReadableMap statusReport) {
112
+ // We don't need to record rollback reports, so exit early if that's what was specified.
113
+ if (statusReport.hasKey(STATUS_KEY) && DEPLOYMENT_FAILED_STATUS.equals(statusReport.getString(STATUS_KEY))) {
114
+ return;
115
+ }
116
+
117
+ if (statusReport.hasKey(APP_VERSION_KEY)) {
118
+ saveStatusReportedForIdentifier(statusReport.getString(APP_VERSION_KEY));
119
+ } else if (statusReport.hasKey(PACKAGE_KEY)) {
120
+ String packageIdentifier = getPackageStatusReportIdentifier(statusReport.getMap(PACKAGE_KEY));
121
+ saveStatusReportedForIdentifier(packageIdentifier);
122
+ }
123
+ }
124
+
125
+ public void saveStatusReportForRetry(ReadableMap statusReport) {
126
+ JSONObject statusReportJSON = CodePushUtils.convertReadableToJsonObject(statusReport);
127
+ mSettings.edit().putString(RETRY_DEPLOYMENT_REPORT_KEY, statusReportJSON.toString()).commit();
128
+ }
129
+
130
+ private void clearRetryStatusReport() {
131
+ mSettings.edit().remove(RETRY_DEPLOYMENT_REPORT_KEY).commit();
132
+ }
133
+
134
+ private String getDeploymentKeyFromStatusReportIdentifier(String statusReportIdentifier) {
135
+ String[] parsedIdentifier = statusReportIdentifier.split(":");
136
+ if (parsedIdentifier.length > 0) {
137
+ return parsedIdentifier[0];
138
+ } else {
139
+ return null;
140
+ }
141
+ }
142
+
143
+ private String getPackageStatusReportIdentifier(ReadableMap updatePackage) {
144
+ // Because deploymentKeys can be dynamically switched, we use a
145
+ // combination of the deploymentKey and label as the packageIdentifier.
146
+ String deploymentKey = CodePushUtils.tryGetString(updatePackage, DEPLOYMENT_KEY_KEY);
147
+ String label = CodePushUtils.tryGetString(updatePackage, LABEL_KEY);
148
+ if (deploymentKey != null && label != null) {
149
+ return deploymentKey + ":" + label;
150
+ } else {
151
+ return null;
152
+ }
153
+ }
154
+
155
+ private String getPreviousStatusReportIdentifier() {
156
+ return mSettings.getString(LAST_DEPLOYMENT_REPORT_KEY, null);
157
+ }
158
+
159
+ private String getVersionLabelFromStatusReportIdentifier(String statusReportIdentifier) {
160
+ String[] parsedIdentifier = statusReportIdentifier.split(":");
161
+ if (parsedIdentifier.length > 1) {
162
+ return parsedIdentifier[1];
163
+ } else {
164
+ return null;
165
+ }
166
+ }
167
+
168
+ private boolean isStatusReportIdentifierCodePushLabel(String statusReportIdentifier) {
169
+ return statusReportIdentifier != null && statusReportIdentifier.contains(":");
170
+ }
171
+
172
+ private void saveStatusReportedForIdentifier(String appVersionOrPackageIdentifier) {
173
+ mSettings.edit().putString(LAST_DEPLOYMENT_REPORT_KEY, appVersionOrPackageIdentifier).commit();
174
+ }
175
+ }
@@ -0,0 +1,12 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ class CodePushUnknownException extends RuntimeException {
4
+
5
+ public CodePushUnknownException(String message, Throwable cause) {
6
+ super(message, cause);
7
+ }
8
+
9
+ public CodePushUnknownException(String message) {
10
+ super(message);
11
+ }
12
+ }
@@ -0,0 +1,369 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import org.json.JSONObject;
4
+
5
+ import java.io.BufferedInputStream;
6
+ import java.io.BufferedOutputStream;
7
+ import java.io.File;
8
+ import java.io.FileOutputStream;
9
+ import java.io.IOException;
10
+ import java.net.HttpURLConnection;
11
+ import java.net.MalformedURLException;
12
+ import java.net.URL;
13
+ import java.nio.ByteBuffer;
14
+
15
+ public class CodePushUpdateManager {
16
+
17
+ private String mDocumentsDirectory;
18
+
19
+ public CodePushUpdateManager(String documentsDirectory) {
20
+ mDocumentsDirectory = documentsDirectory;
21
+ }
22
+
23
+ private String getDownloadFilePath() {
24
+ return CodePushUtils.appendPathComponent(getCodePushPath(), CodePushConstants.DOWNLOAD_FILE_NAME);
25
+ }
26
+
27
+ private String getUnzippedFolderPath() {
28
+ return CodePushUtils.appendPathComponent(getCodePushPath(), CodePushConstants.UNZIPPED_FOLDER_NAME);
29
+ }
30
+
31
+ private String getDocumentsDirectory() {
32
+ return mDocumentsDirectory;
33
+ }
34
+
35
+ private String getCodePushPath() {
36
+ String codePushPath = CodePushUtils.appendPathComponent(getDocumentsDirectory(), CodePushConstants.CODE_PUSH_FOLDER_PREFIX);
37
+ if (CodePush.isUsingTestConfiguration()) {
38
+ codePushPath = CodePushUtils.appendPathComponent(codePushPath, "TestPackages");
39
+ }
40
+
41
+ return codePushPath;
42
+ }
43
+
44
+ private String getStatusFilePath() {
45
+ return CodePushUtils.appendPathComponent(getCodePushPath(), CodePushConstants.STATUS_FILE);
46
+ }
47
+
48
+ public JSONObject getCurrentPackageInfo() {
49
+ String statusFilePath = getStatusFilePath();
50
+ if (!FileUtils.fileAtPathExists(statusFilePath)) {
51
+ return new JSONObject();
52
+ }
53
+
54
+ try {
55
+ return CodePushUtils.getJsonObjectFromFile(statusFilePath);
56
+ } catch (IOException e) {
57
+ // Should not happen.
58
+ throw new CodePushUnknownException("Error getting current package info", e);
59
+ }
60
+ }
61
+
62
+ public void updateCurrentPackageInfo(JSONObject packageInfo) {
63
+ try {
64
+ CodePushUtils.writeJsonToFile(packageInfo, getStatusFilePath());
65
+ } catch (IOException e) {
66
+ // Should not happen.
67
+ throw new CodePushUnknownException("Error updating current package info", e);
68
+ }
69
+ }
70
+
71
+ public String getCurrentPackageFolderPath() {
72
+ JSONObject info = getCurrentPackageInfo();
73
+ String packageHash = info.optString(CodePushConstants.CURRENT_PACKAGE_KEY, null);
74
+ if (packageHash == null) {
75
+ return null;
76
+ }
77
+
78
+ return getPackageFolderPath(packageHash);
79
+ }
80
+
81
+ public String getCurrentPackageBundlePath(String bundleFileName) {
82
+ String packageFolder = getCurrentPackageFolderPath();
83
+ if (packageFolder == null) {
84
+ return null;
85
+ }
86
+
87
+ JSONObject currentPackage = getCurrentPackage();
88
+ if (currentPackage == null) {
89
+ return null;
90
+ }
91
+
92
+ String relativeBundlePath = currentPackage.optString(CodePushConstants.RELATIVE_BUNDLE_PATH_KEY, null);
93
+ if (relativeBundlePath == null) {
94
+ return CodePushUtils.appendPathComponent(packageFolder, bundleFileName);
95
+ } else {
96
+ return CodePushUtils.appendPathComponent(packageFolder, relativeBundlePath);
97
+ }
98
+ }
99
+
100
+ public String getPackageFolderPath(String packageHash) {
101
+ return CodePushUtils.appendPathComponent(getCodePushPath(), packageHash);
102
+ }
103
+
104
+ public String getCurrentPackageHash() {
105
+ JSONObject info = getCurrentPackageInfo();
106
+ return info.optString(CodePushConstants.CURRENT_PACKAGE_KEY, null);
107
+ }
108
+
109
+ public String getPreviousPackageHash() {
110
+ JSONObject info = getCurrentPackageInfo();
111
+ return info.optString(CodePushConstants.PREVIOUS_PACKAGE_KEY, null);
112
+ }
113
+
114
+ public JSONObject getCurrentPackage() {
115
+ String packageHash = getCurrentPackageHash();
116
+ if (packageHash == null) {
117
+ return null;
118
+ }
119
+
120
+ return getPackage(packageHash);
121
+ }
122
+
123
+ public JSONObject getPreviousPackage() {
124
+ String packageHash = getPreviousPackageHash();
125
+ if (packageHash == null) {
126
+ return null;
127
+ }
128
+
129
+ return getPackage(packageHash);
130
+ }
131
+
132
+ public JSONObject getPackage(String packageHash) {
133
+ String folderPath = getPackageFolderPath(packageHash);
134
+ String packageFilePath = CodePushUtils.appendPathComponent(folderPath, CodePushConstants.PACKAGE_FILE_NAME);
135
+ try {
136
+ return CodePushUtils.getJsonObjectFromFile(packageFilePath);
137
+ } catch (IOException e) {
138
+ return null;
139
+ }
140
+ }
141
+
142
+ public void downloadPackage(JSONObject updatePackage, String expectedBundleFileName,
143
+ DownloadProgressCallback progressCallback,
144
+ String stringPublicKey) throws IOException {
145
+ String newUpdateHash = updatePackage.optString(CodePushConstants.PACKAGE_HASH_KEY, null);
146
+ String newUpdateFolderPath = getPackageFolderPath(newUpdateHash);
147
+ String newUpdateMetadataPath = CodePushUtils.appendPathComponent(newUpdateFolderPath, CodePushConstants.PACKAGE_FILE_NAME);
148
+ if (FileUtils.fileAtPathExists(newUpdateFolderPath)) {
149
+ // This removes any stale data in newPackageFolderPath that could have been left
150
+ // uncleared due to a crash or error during the download or install process.
151
+ FileUtils.deleteDirectoryAtPath(newUpdateFolderPath);
152
+ }
153
+
154
+ String downloadUrlString = updatePackage.optString(CodePushConstants.DOWNLOAD_URL_KEY, null);
155
+ HttpURLConnection connection = null;
156
+ BufferedInputStream bin = null;
157
+ FileOutputStream fos = null;
158
+ BufferedOutputStream bout = null;
159
+ File downloadFile = null;
160
+ boolean isZip = false;
161
+
162
+ // Download the file while checking if it is a zip and notifying client of progress.
163
+ try {
164
+ URL downloadUrl = new URL(downloadUrlString);
165
+ connection = (HttpURLConnection) (downloadUrl.openConnection());
166
+ connection.setRequestProperty("Accept-Encoding", "identity");
167
+ bin = new BufferedInputStream(connection.getInputStream());
168
+
169
+ long totalBytes = connection.getContentLength();
170
+ long receivedBytes = 0;
171
+
172
+ File downloadFolder = new File(getCodePushPath());
173
+ downloadFolder.mkdirs();
174
+ downloadFile = new File(downloadFolder, CodePushConstants.DOWNLOAD_FILE_NAME);
175
+ fos = new FileOutputStream(downloadFile);
176
+ bout = new BufferedOutputStream(fos, CodePushConstants.DOWNLOAD_BUFFER_SIZE);
177
+ byte[] data = new byte[CodePushConstants.DOWNLOAD_BUFFER_SIZE];
178
+ byte[] header = new byte[4];
179
+
180
+ int numBytesRead = 0;
181
+ while ((numBytesRead = bin.read(data, 0, CodePushConstants.DOWNLOAD_BUFFER_SIZE)) >= 0) {
182
+ if (receivedBytes < 4) {
183
+ for (int i = 0; i < numBytesRead; i++) {
184
+ int headerOffset = (int) (receivedBytes) + i;
185
+ if (headerOffset >= 4) {
186
+ break;
187
+ }
188
+
189
+ header[headerOffset] = data[i];
190
+ }
191
+ }
192
+
193
+ receivedBytes += numBytesRead;
194
+ bout.write(data, 0, numBytesRead);
195
+ progressCallback.call(new DownloadProgress(totalBytes, receivedBytes));
196
+ }
197
+
198
+ if (totalBytes != receivedBytes) {
199
+ throw new CodePushUnknownException("Received " + receivedBytes + " bytes, expected " + totalBytes);
200
+ }
201
+
202
+ isZip = ByteBuffer.wrap(header).getInt() == 0x504b0304;
203
+ } catch (MalformedURLException e) {
204
+ throw new CodePushMalformedDataException(downloadUrlString, e);
205
+ } finally {
206
+ try {
207
+ if (bout != null) bout.close();
208
+ if (fos != null) fos.close();
209
+ if (bin != null) bin.close();
210
+ if (connection != null) connection.disconnect();
211
+ } catch (IOException e) {
212
+ throw new CodePushUnknownException("Error closing IO resources.", e);
213
+ }
214
+ }
215
+
216
+ if (isZip) {
217
+ // Unzip the downloaded file and then delete the zip
218
+ String unzippedFolderPath = getUnzippedFolderPath();
219
+ FileUtils.unzipFile(downloadFile, unzippedFolderPath);
220
+ FileUtils.deleteFileOrFolderSilently(downloadFile);
221
+
222
+ // Merge contents with current update based on the manifest
223
+ String diffManifestFilePath = CodePushUtils.appendPathComponent(unzippedFolderPath,
224
+ CodePushConstants.DIFF_MANIFEST_FILE_NAME);
225
+ boolean isDiffUpdate = FileUtils.fileAtPathExists(diffManifestFilePath);
226
+ if (isDiffUpdate) {
227
+ String currentPackageFolderPath = getCurrentPackageFolderPath();
228
+ CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, newUpdateFolderPath);
229
+ File diffManifestFile = new File(diffManifestFilePath);
230
+ diffManifestFile.delete();
231
+ }
232
+
233
+ FileUtils.copyDirectoryContents(unzippedFolderPath, newUpdateFolderPath);
234
+ FileUtils.deleteFileAtPathSilently(unzippedFolderPath);
235
+
236
+ // For zip updates, we need to find the relative path to the jsBundle and save it in the
237
+ // metadata so that we can find and run it easily the next time.
238
+ String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath, expectedBundleFileName);
239
+
240
+ if (relativeBundlePath == null) {
241
+ throw new CodePushInvalidUpdateException("Update is invalid - A JS bundle file named \"" + expectedBundleFileName + "\" could not be found within the downloaded contents. Please check that you are releasing your CodePush updates using the exact same JS bundle file name that was shipped with your app's binary.");
242
+ } else {
243
+ if (FileUtils.fileAtPathExists(newUpdateMetadataPath)) {
244
+ File metadataFileFromOldUpdate = new File(newUpdateMetadataPath);
245
+ metadataFileFromOldUpdate.delete();
246
+ }
247
+
248
+ if (isDiffUpdate) {
249
+ CodePushUtils.log("Applying diff update.");
250
+ } else {
251
+ CodePushUtils.log("Applying full update.");
252
+ }
253
+
254
+ boolean isSignatureVerificationEnabled = (stringPublicKey != null);
255
+
256
+ String signaturePath = CodePushUpdateUtils.getSignatureFilePath(newUpdateFolderPath);
257
+ boolean isSignatureAppearedInBundle = FileUtils.fileAtPathExists(signaturePath);
258
+
259
+ if (isSignatureVerificationEnabled) {
260
+ if (isSignatureAppearedInBundle) {
261
+ CodePushUpdateUtils.verifyFolderHash(newUpdateFolderPath, newUpdateHash);
262
+ CodePushUpdateUtils.verifyUpdateSignature(newUpdateFolderPath, newUpdateHash, stringPublicKey);
263
+ } else {
264
+ throw new CodePushInvalidUpdateException(
265
+ "Error! Public key was provided but there is no JWT signature within app bundle to verify. " +
266
+ "Possible reasons, why that might happen: \n" +
267
+ "1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.\n" +
268
+ "2. You've been released CodePush bundle update without providing --privateKeyPath option."
269
+ );
270
+ }
271
+ } else {
272
+ if (isSignatureAppearedInBundle) {
273
+ CodePushUtils.log(
274
+ "Warning! JWT signature exists in codepush update but code integrity check couldn't be performed because there is no public key configured. " +
275
+ "Please ensure that public key is properly configured within your application."
276
+ );
277
+ CodePushUpdateUtils.verifyFolderHash(newUpdateFolderPath, newUpdateHash);
278
+ } else {
279
+ if (isDiffUpdate) {
280
+ CodePushUpdateUtils.verifyFolderHash(newUpdateFolderPath, newUpdateHash);
281
+ }
282
+ }
283
+ }
284
+
285
+ CodePushUtils.setJSONValueForKey(updatePackage, CodePushConstants.RELATIVE_BUNDLE_PATH_KEY, relativeBundlePath);
286
+ }
287
+ } else {
288
+ // File is a jsbundle, move it to a folder with the packageHash as its name
289
+ FileUtils.moveFile(downloadFile, newUpdateFolderPath, expectedBundleFileName);
290
+ }
291
+
292
+ // Save metadata to the folder.
293
+ CodePushUtils.writeJsonToFile(updatePackage, newUpdateMetadataPath);
294
+ }
295
+
296
+ public void installPackage(JSONObject updatePackage, boolean removePendingUpdate) {
297
+ String packageHash = updatePackage.optString(CodePushConstants.PACKAGE_HASH_KEY, null);
298
+ JSONObject info = getCurrentPackageInfo();
299
+
300
+ String currentPackageHash = info.optString(CodePushConstants.CURRENT_PACKAGE_KEY, null);
301
+ if (packageHash != null && packageHash.equals(currentPackageHash)) {
302
+ // The current package is already the one being installed, so we should no-op.
303
+ return;
304
+ }
305
+
306
+ if (removePendingUpdate) {
307
+ String currentPackageFolderPath = getCurrentPackageFolderPath();
308
+ if (currentPackageFolderPath != null) {
309
+ FileUtils.deleteDirectoryAtPath(currentPackageFolderPath);
310
+ }
311
+ } else {
312
+ String previousPackageHash = getPreviousPackageHash();
313
+ if (previousPackageHash != null && !previousPackageHash.equals(packageHash)) {
314
+ FileUtils.deleteDirectoryAtPath(getPackageFolderPath(previousPackageHash));
315
+ }
316
+
317
+ CodePushUtils.setJSONValueForKey(info, CodePushConstants.PREVIOUS_PACKAGE_KEY, info.optString(CodePushConstants.CURRENT_PACKAGE_KEY, null));
318
+ }
319
+
320
+ CodePushUtils.setJSONValueForKey(info, CodePushConstants.CURRENT_PACKAGE_KEY, packageHash);
321
+ updateCurrentPackageInfo(info);
322
+ }
323
+
324
+ public void rollbackPackage() {
325
+ JSONObject info = getCurrentPackageInfo();
326
+ String currentPackageFolderPath = getCurrentPackageFolderPath();
327
+ FileUtils.deleteDirectoryAtPath(currentPackageFolderPath);
328
+ CodePushUtils.setJSONValueForKey(info, CodePushConstants.CURRENT_PACKAGE_KEY, info.optString(CodePushConstants.PREVIOUS_PACKAGE_KEY, null));
329
+ CodePushUtils.setJSONValueForKey(info, CodePushConstants.PREVIOUS_PACKAGE_KEY, null);
330
+ updateCurrentPackageInfo(info);
331
+ }
332
+
333
+ public void downloadAndReplaceCurrentBundle(String remoteBundleUrl, String bundleFileName) throws IOException {
334
+ URL downloadUrl;
335
+ HttpURLConnection connection = null;
336
+ BufferedInputStream bin = null;
337
+ FileOutputStream fos = null;
338
+ BufferedOutputStream bout = null;
339
+ try {
340
+ downloadUrl = new URL(remoteBundleUrl);
341
+ connection = (HttpURLConnection) (downloadUrl.openConnection());
342
+ bin = new BufferedInputStream(connection.getInputStream());
343
+ File downloadFile = new File(getCurrentPackageBundlePath(bundleFileName));
344
+ downloadFile.delete();
345
+ fos = new FileOutputStream(downloadFile);
346
+ bout = new BufferedOutputStream(fos, CodePushConstants.DOWNLOAD_BUFFER_SIZE);
347
+ byte[] data = new byte[CodePushConstants.DOWNLOAD_BUFFER_SIZE];
348
+ int numBytesRead = 0;
349
+ while ((numBytesRead = bin.read(data, 0, CodePushConstants.DOWNLOAD_BUFFER_SIZE)) >= 0) {
350
+ bout.write(data, 0, numBytesRead);
351
+ }
352
+ } catch (MalformedURLException e) {
353
+ throw new CodePushMalformedDataException(remoteBundleUrl, e);
354
+ } finally {
355
+ try {
356
+ if (bout != null) bout.close();
357
+ if (fos != null) fos.close();
358
+ if (bin != null) bin.close();
359
+ if (connection != null) connection.disconnect();
360
+ } catch (IOException e) {
361
+ throw new CodePushUnknownException("Error closing IO resources.", e);
362
+ }
363
+ }
364
+ }
365
+
366
+ public void clearUpdates() {
367
+ FileUtils.deleteDirectoryAtPath(getCodePushPath());
368
+ }
369
+ }
@@ -0,0 +1,15 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ public enum CodePushUpdateState {
4
+ RUNNING(0),
5
+ PENDING(1),
6
+ LATEST(2);
7
+
8
+ private final int value;
9
+ CodePushUpdateState(int value) {
10
+ this.value = value;
11
+ }
12
+ public int getValue() {
13
+ return this.value;
14
+ }
15
+ }