@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,395 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import android.content.Context;
4
+ import android.content.pm.PackageInfo;
5
+ import android.content.pm.PackageManager;
6
+ import android.content.res.Resources;
7
+
8
+ import com.facebook.react.ReactInstanceManager;
9
+ import com.facebook.react.ReactPackage;
10
+ import com.facebook.react.bridge.JavaScriptModule;
11
+ import com.facebook.react.bridge.NativeModule;
12
+ import com.facebook.react.bridge.ReactApplicationContext;
13
+ import com.facebook.react.devsupport.DevInternalSettings;
14
+ import com.facebook.react.devsupport.interfaces.DevSupportManager;
15
+ import com.facebook.react.uimanager.ViewManager;
16
+
17
+ import org.json.JSONException;
18
+ import org.json.JSONObject;
19
+
20
+ import java.io.File;
21
+ import java.util.ArrayList;
22
+ import java.util.List;
23
+
24
+ public class CodePush implements ReactPackage {
25
+
26
+ private static boolean sIsRunningBinaryVersion = false;
27
+ private static boolean sNeedToReportRollback = false;
28
+ private static boolean sTestConfigurationFlag = false;
29
+ private static String sAppVersion = null;
30
+
31
+ private boolean mDidUpdate = false;
32
+
33
+ private String mAssetsBundleFileName;
34
+
35
+ // Helper classes.
36
+ private CodePushUpdateManager mUpdateManager;
37
+ private CodePushTelemetryManager mTelemetryManager;
38
+ private SettingsManager mSettingsManager;
39
+
40
+ // Config properties.
41
+ private String mDeploymentKey;
42
+ private static String mServerUrl = "https://codepush.appzung.com/";
43
+
44
+ private Context mContext;
45
+ private final boolean mIsDebugMode;
46
+
47
+ private static String mPublicKey;
48
+
49
+ private static ReactInstanceHolder mReactInstanceHolder;
50
+ private static CodePush mCurrentInstance;
51
+
52
+ public CodePush(String deploymentKey, Context context) {
53
+ this(deploymentKey, context, false);
54
+ }
55
+
56
+ public static String getServiceUrl() {
57
+ return mServerUrl;
58
+ }
59
+
60
+ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
61
+ mContext = context.getApplicationContext();
62
+
63
+ mUpdateManager = new CodePushUpdateManager(context.getFilesDir().getAbsolutePath());
64
+ mTelemetryManager = new CodePushTelemetryManager(mContext);
65
+ mDeploymentKey = deploymentKey;
66
+ mIsDebugMode = isDebugMode;
67
+ mSettingsManager = new SettingsManager(mContext);
68
+
69
+ if (sAppVersion == null) {
70
+ try {
71
+ PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
72
+ sAppVersion = pInfo.versionName;
73
+ } catch (PackageManager.NameNotFoundException e) {
74
+ throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
75
+ }
76
+ }
77
+
78
+ mCurrentInstance = this;
79
+
80
+ clearDebugCacheIfNeeded(null);
81
+ initializeUpdateAfterRestart();
82
+ }
83
+
84
+ public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl) {
85
+ this(deploymentKey, context, isDebugMode);
86
+ mServerUrl = serverUrl;
87
+ }
88
+
89
+ public CodePush(String deploymentKey, Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
90
+ this(deploymentKey, context, isDebugMode);
91
+
92
+ mPublicKey = getPublicKeyByResourceDescriptor(publicKeyResourceDescriptor);
93
+ }
94
+
95
+ public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
96
+ this(deploymentKey, context, isDebugMode);
97
+
98
+ if (publicKeyResourceDescriptor != null) {
99
+ mPublicKey = getPublicKeyByResourceDescriptor(publicKeyResourceDescriptor);
100
+ }
101
+
102
+ mServerUrl = serverUrl;
103
+ }
104
+
105
+ private String getPublicKeyByResourceDescriptor(int publicKeyResourceDescriptor){
106
+ String publicKey;
107
+ try {
108
+ publicKey = mContext.getString(publicKeyResourceDescriptor);
109
+ } catch (Resources.NotFoundException e) {
110
+ throw new CodePushInvalidPublicKeyException(
111
+ "Unable to get public key, related resource descriptor " +
112
+ publicKeyResourceDescriptor +
113
+ " can not be found", e
114
+ );
115
+ }
116
+
117
+ if (publicKey.isEmpty()) {
118
+ throw new CodePushInvalidPublicKeyException("Specified public key is empty");
119
+ }
120
+ return publicKey;
121
+ }
122
+
123
+ public void clearDebugCacheIfNeeded(ReactInstanceManager instanceManager) {
124
+ boolean isLiveReloadEnabled = false;
125
+
126
+ // Use instanceManager for checking if we use LiveRelaod mode. In this case we should not remove ReactNativeDevBundle.js file
127
+ // because we get error with trying to get this after reloading. Issue: https://github.com/Microsoft/react-native-code-push/issues/1272
128
+ if (instanceManager != null) {
129
+ DevSupportManager devSupportManager = instanceManager.getDevSupportManager();
130
+ if (devSupportManager != null) {
131
+ DevInternalSettings devInternalSettings = (DevInternalSettings)devSupportManager.getDevSettings();
132
+ isLiveReloadEnabled = devInternalSettings.isReloadOnJSChangeEnabled();
133
+ }
134
+ }
135
+
136
+ if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled) {
137
+ // This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
138
+ File cachedDevBundle = new File(mContext.getFilesDir(), "ReactNativeDevBundle.js");
139
+ if (cachedDevBundle.exists()) {
140
+ cachedDevBundle.delete();
141
+ }
142
+ }
143
+ }
144
+
145
+ public boolean didUpdate() {
146
+ return mDidUpdate;
147
+ }
148
+
149
+ public String getAppVersion() {
150
+ return sAppVersion;
151
+ }
152
+
153
+ public String getAssetsBundleFileName() {
154
+ return mAssetsBundleFileName;
155
+ }
156
+
157
+ public String getPublicKey() {
158
+ return mPublicKey;
159
+ }
160
+
161
+ long getBinaryResourcesModifiedTime() {
162
+ try {
163
+ String packageName = this.mContext.getPackageName();
164
+ int codePushApkBuildTimeId = this.mContext.getResources().getIdentifier(CodePushConstants.CODE_PUSH_APK_BUILD_TIME_KEY, "string", packageName);
165
+ // replace double quotes needed for correct restoration of long value from strings.xml
166
+ // https://github.com/Microsoft/cordova-plugin-code-push/issues/264
167
+ String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId).replaceAll("\"","");
168
+ return Long.parseLong(codePushApkBuildTime);
169
+ } catch (Exception e) {
170
+ throw new CodePushUnknownException("Error in getting binary resources modified time", e);
171
+ }
172
+ }
173
+
174
+ public String getPackageFolder() {
175
+ JSONObject codePushLocalPackage = mUpdateManager.getCurrentPackage();
176
+ if (codePushLocalPackage == null) {
177
+ return null;
178
+ }
179
+ return mUpdateManager.getPackageFolderPath(codePushLocalPackage.optString("packageHash"));
180
+ }
181
+
182
+ @Deprecated
183
+ public static String getBundleUrl() {
184
+ return getJSBundleFile();
185
+ }
186
+
187
+ @Deprecated
188
+ public static String getBundleUrl(String assetsBundleFileName) {
189
+ return getJSBundleFile(assetsBundleFileName);
190
+ }
191
+
192
+ public Context getContext() {
193
+ return mContext;
194
+ }
195
+
196
+ public String getDeploymentKey() {
197
+ return mDeploymentKey;
198
+ }
199
+
200
+ public static String getJSBundleFile() {
201
+ return CodePush.getJSBundleFile(CodePushConstants.DEFAULT_JS_BUNDLE_NAME);
202
+ }
203
+
204
+ public static String getJSBundleFile(String assetsBundleFileName) {
205
+ if (mCurrentInstance == null) {
206
+ throw new CodePushNotInitializedException("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?");
207
+ }
208
+
209
+ return mCurrentInstance.getJSBundleFileInternal(assetsBundleFileName);
210
+ }
211
+
212
+ public String getJSBundleFileInternal(String assetsBundleFileName) {
213
+ this.mAssetsBundleFileName = assetsBundleFileName;
214
+ String binaryJsBundleUrl = CodePushConstants.ASSETS_BUNDLE_PREFIX + assetsBundleFileName;
215
+
216
+ String packageFilePath = null;
217
+ try {
218
+ packageFilePath = mUpdateManager.getCurrentPackageBundlePath(this.mAssetsBundleFileName);
219
+ } catch (CodePushMalformedDataException e) {
220
+ // We need to recover the app in case 'codepush.json' is corrupted
221
+ CodePushUtils.log(e.getMessage());
222
+ clearUpdates();
223
+ }
224
+
225
+ if (packageFilePath == null) {
226
+ // There has not been any downloaded updates.
227
+ CodePushUtils.logBundleUrl(binaryJsBundleUrl);
228
+ sIsRunningBinaryVersion = true;
229
+ return binaryJsBundleUrl;
230
+ }
231
+
232
+ JSONObject packageMetadata = this.mUpdateManager.getCurrentPackage();
233
+ if (isPackageBundleLatest(packageMetadata)) {
234
+ CodePushUtils.logBundleUrl(packageFilePath);
235
+ sIsRunningBinaryVersion = false;
236
+ return packageFilePath;
237
+ } else {
238
+ // The binary version is newer.
239
+ this.mDidUpdate = false;
240
+ if (!this.mIsDebugMode || hasBinaryVersionChanged(packageMetadata)) {
241
+ this.clearUpdates();
242
+ }
243
+
244
+ CodePushUtils.logBundleUrl(binaryJsBundleUrl);
245
+ sIsRunningBinaryVersion = true;
246
+ return binaryJsBundleUrl;
247
+ }
248
+ }
249
+
250
+ public String getServerUrl() {
251
+ return mServerUrl;
252
+ }
253
+
254
+ void initializeUpdateAfterRestart() {
255
+ // Reset the state which indicates that
256
+ // the app was just freshly updated.
257
+ mDidUpdate = false;
258
+
259
+ JSONObject pendingUpdate = mSettingsManager.getPendingUpdate();
260
+ if (pendingUpdate != null) {
261
+ JSONObject packageMetadata = this.mUpdateManager.getCurrentPackage();
262
+ if (packageMetadata == null || !isPackageBundleLatest(packageMetadata) && hasBinaryVersionChanged(packageMetadata)) {
263
+ CodePushUtils.log("Skipping initializeUpdateAfterRestart(), binary version is newer");
264
+ return;
265
+ }
266
+
267
+ try {
268
+ boolean updateIsLoading = pendingUpdate.getBoolean(CodePushConstants.PENDING_UPDATE_IS_LOADING_KEY);
269
+ if (updateIsLoading) {
270
+ // Pending update was initialized, but notifyApplicationReady was not called.
271
+ // Therefore, deduce that it is a broken update and rollback.
272
+ CodePushUtils.log("Update did not finish loading the last time, rolling back to a previous version.");
273
+ sNeedToReportRollback = true;
274
+ rollbackPackage();
275
+ } else {
276
+ // There is in fact a new update running for the first
277
+ // time, so update the local state to ensure the client knows.
278
+ mDidUpdate = true;
279
+
280
+ // Mark that we tried to initialize the new update, so that if it crashes,
281
+ // we will know that we need to rollback when the app next starts.
282
+ mSettingsManager.savePendingUpdate(pendingUpdate.getString(CodePushConstants.PENDING_UPDATE_HASH_KEY),
283
+ /* isLoading */true);
284
+ }
285
+ } catch (JSONException e) {
286
+ // Should not happen.
287
+ throw new CodePushUnknownException("Unable to read pending update metadata stored in SharedPreferences", e);
288
+ }
289
+ }
290
+ }
291
+
292
+ void invalidateCurrentInstance() {
293
+ mCurrentInstance = null;
294
+ }
295
+
296
+ boolean isDebugMode() {
297
+ return mIsDebugMode;
298
+ }
299
+
300
+ boolean isRunningBinaryVersion() {
301
+ return sIsRunningBinaryVersion;
302
+ }
303
+
304
+ private boolean isPackageBundleLatest(JSONObject packageMetadata) {
305
+ try {
306
+ Long binaryModifiedDateDuringPackageInstall = null;
307
+ String binaryModifiedDateDuringPackageInstallString = packageMetadata.optString(CodePushConstants.BINARY_MODIFIED_TIME_KEY, null);
308
+ if (binaryModifiedDateDuringPackageInstallString != null) {
309
+ binaryModifiedDateDuringPackageInstall = Long.parseLong(binaryModifiedDateDuringPackageInstallString);
310
+ }
311
+ String packageAppVersion = packageMetadata.optString("appVersion", null);
312
+ long binaryResourcesModifiedTime = this.getBinaryResourcesModifiedTime();
313
+ return binaryModifiedDateDuringPackageInstall != null &&
314
+ binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
315
+ (isUsingTestConfiguration() || sAppVersion.equals(packageAppVersion));
316
+ } catch (NumberFormatException e) {
317
+ throw new CodePushUnknownException("Error in reading binary modified date from package metadata", e);
318
+ }
319
+ }
320
+
321
+ private boolean hasBinaryVersionChanged(JSONObject packageMetadata) {
322
+ String packageAppVersion = packageMetadata.optString("appVersion", null);
323
+ return !sAppVersion.equals(packageAppVersion);
324
+ }
325
+
326
+ boolean needToReportRollback() {
327
+ return sNeedToReportRollback;
328
+ }
329
+
330
+ public static void overrideAppVersion(String appVersionOverride) {
331
+ sAppVersion = appVersionOverride;
332
+ }
333
+
334
+ private void rollbackPackage() {
335
+ JSONObject failedPackage = mUpdateManager.getCurrentPackage();
336
+ mSettingsManager.saveFailedUpdate(failedPackage);
337
+ mUpdateManager.rollbackPackage();
338
+ mSettingsManager.removePendingUpdate();
339
+ }
340
+
341
+ public void setNeedToReportRollback(boolean needToReportRollback) {
342
+ CodePush.sNeedToReportRollback = needToReportRollback;
343
+ }
344
+
345
+ /* The below 3 methods are used for running tests.*/
346
+ public static boolean isUsingTestConfiguration() {
347
+ return sTestConfigurationFlag;
348
+ }
349
+
350
+ public void setDeploymentKey(String deploymentKey) {
351
+ mDeploymentKey = deploymentKey;
352
+ }
353
+
354
+ public static void setUsingTestConfiguration(boolean shouldUseTestConfiguration) {
355
+ sTestConfigurationFlag = shouldUseTestConfiguration;
356
+ }
357
+
358
+ public void clearUpdates() {
359
+ mUpdateManager.clearUpdates();
360
+ mSettingsManager.removePendingUpdate();
361
+ mSettingsManager.removeFailedUpdates();
362
+ }
363
+
364
+ public static void setReactInstanceHolder(ReactInstanceHolder reactInstanceHolder) {
365
+ mReactInstanceHolder = reactInstanceHolder;
366
+ }
367
+
368
+ static ReactInstanceManager getReactInstanceManager() {
369
+ if (mReactInstanceHolder == null) {
370
+ return null;
371
+ }
372
+ return mReactInstanceHolder.getReactInstanceManager();
373
+ }
374
+
375
+ @Override
376
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
377
+ CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);
378
+ CodePushDialog dialogModule = new CodePushDialog(reactApplicationContext);
379
+
380
+ List<NativeModule> nativeModules = new ArrayList<>();
381
+ nativeModules.add(codePushModule);
382
+ nativeModules.add(dialogModule);
383
+ return nativeModules;
384
+ }
385
+
386
+ // Deprecated in RN v0.47.
387
+ public List<Class<? extends JavaScriptModule>> createJSModules() {
388
+ return new ArrayList<>();
389
+ }
390
+
391
+ @Override
392
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
393
+ return new ArrayList<>();
394
+ }
395
+ }
@@ -0,0 +1,37 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import android.content.Context;
4
+
5
+ public class CodePushBuilder {
6
+ private String mDeploymentKey;
7
+ private Context mContext;
8
+
9
+ private boolean mIsDebugMode;
10
+ private String mServerUrl;
11
+ private Integer mPublicKeyResourceDescriptor;
12
+
13
+ public CodePushBuilder(String deploymentKey, Context context) {
14
+ this.mDeploymentKey = deploymentKey;
15
+ this.mContext = context;
16
+ this.mServerUrl = CodePush.getServiceUrl();
17
+ }
18
+
19
+ public CodePushBuilder setIsDebugMode(boolean isDebugMode) {
20
+ this.mIsDebugMode = isDebugMode;
21
+ return this;
22
+ }
23
+
24
+ public CodePushBuilder setServerUrl(String serverUrl) {
25
+ this.mServerUrl = serverUrl;
26
+ return this;
27
+ }
28
+
29
+ public CodePushBuilder setPublicKeyResourceDescriptor(int publicKeyResourceDescriptor) {
30
+ this.mPublicKeyResourceDescriptor = publicKeyResourceDescriptor;
31
+ return this;
32
+ }
33
+
34
+ public CodePush build() {
35
+ return new CodePush(this.mDeploymentKey, this.mContext, this.mIsDebugMode, this.mServerUrl, this.mPublicKeyResourceDescriptor);
36
+ }
37
+ }
@@ -0,0 +1,34 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ public class CodePushConstants {
4
+ public static final String ASSETS_BUNDLE_PREFIX = "assets://";
5
+ public static final String BINARY_MODIFIED_TIME_KEY = "binaryModifiedTime";
6
+ public static final String CODE_PUSH_FOLDER_PREFIX = "CodePush";
7
+ public static final String CODE_PUSH_HASH_FILE_NAME = "CodePushHash";
8
+ public static final String CODE_PUSH_OLD_HASH_FILE_NAME = "CodePushHash.json";
9
+ public static final String CODE_PUSH_PREFERENCES = "CodePush";
10
+ public static final String CURRENT_PACKAGE_KEY = "currentPackage";
11
+ public static final String DEFAULT_JS_BUNDLE_NAME = "index.android.bundle";
12
+ public static final String DIFF_MANIFEST_FILE_NAME = "hotcodepush.json";
13
+ public static final int DOWNLOAD_BUFFER_SIZE = 1024 * 256;
14
+ public static final String DOWNLOAD_FILE_NAME = "download.zip";
15
+ public static final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress";
16
+ public static final String DOWNLOAD_URL_KEY = "downloadUrl";
17
+ public static final String FAILED_UPDATES_KEY = "CODE_PUSH_FAILED_UPDATES";
18
+ public static final String PACKAGE_FILE_NAME = "app.json";
19
+ public static final String PACKAGE_HASH_KEY = "packageHash";
20
+ public static final String PENDING_UPDATE_HASH_KEY = "hash";
21
+ public static final String PENDING_UPDATE_IS_LOADING_KEY = "isLoading";
22
+ public static final String PENDING_UPDATE_KEY = "CODE_PUSH_PENDING_UPDATE";
23
+ public static final String PREVIOUS_PACKAGE_KEY = "previousPackage";
24
+ public static final String REACT_NATIVE_LOG_TAG = "ReactNative";
25
+ public static final String RELATIVE_BUNDLE_PATH_KEY = "bundlePath";
26
+ public static final String STATUS_FILE = "codepush.json";
27
+ public static final String UNZIPPED_FOLDER_NAME = "unzipped";
28
+ public static final String CODE_PUSH_APK_BUILD_TIME_KEY = "CODE_PUSH_APK_BUILD_TIME";
29
+ public static final String BUNDLE_JWT_FILE = ".codepushrelease";
30
+ public static final String LATEST_ROLLBACK_INFO_KEY = "LATEST_ROLLBACK_INFO";
31
+ public static final String LATEST_ROLLBACK_PACKAGE_HASH_KEY = "packageHash";
32
+ public static final String LATEST_ROLLBACK_TIME_KEY = "time";
33
+ public static final String LATEST_ROLLBACK_COUNT_KEY = "count";
34
+ }
@@ -0,0 +1,102 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import android.app.Activity;
4
+ import android.app.AlertDialog;
5
+ import android.content.DialogInterface;
6
+
7
+ import com.facebook.react.bridge.Callback;
8
+ import com.facebook.react.bridge.LifecycleEventListener;
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
11
+ import com.facebook.react.bridge.ReactMethod;
12
+
13
+ public class CodePushDialog extends ReactContextBaseJavaModule{
14
+
15
+ public CodePushDialog(ReactApplicationContext reactContext) {
16
+ super(reactContext);
17
+ }
18
+
19
+ @ReactMethod
20
+ public void showDialog(final String title, final String message, final String button1Text,
21
+ final String button2Text, final Callback successCallback, Callback errorCallback) {
22
+ Activity currentActivity = getCurrentActivity();
23
+ if (currentActivity == null || currentActivity.isFinishing()) {
24
+ // If getCurrentActivity is null, it could be because the app is backgrounded,
25
+ // so we show the dialog when the app resumes)
26
+ getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
27
+ @Override
28
+ public void onHostResume() {
29
+ Activity currentActivity = getCurrentActivity();
30
+ if (currentActivity != null) {
31
+ getReactApplicationContext().removeLifecycleEventListener(this);
32
+ showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);
33
+ }
34
+ }
35
+
36
+ @Override
37
+ public void onHostPause() {
38
+
39
+ }
40
+
41
+ @Override
42
+ public void onHostDestroy() {
43
+
44
+ }
45
+ });
46
+ } else {
47
+ showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);
48
+ }
49
+ }
50
+
51
+ private void showDialogInternal(String title, String message, String button1Text,
52
+ String button2Text, final Callback successCallback, Activity currentActivity) {
53
+ AlertDialog.Builder builder = new AlertDialog.Builder(currentActivity);
54
+
55
+ builder.setCancelable(false);
56
+
57
+ DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
58
+ @Override
59
+ public void onClick(DialogInterface dialog, int which) {
60
+ try {
61
+ dialog.cancel();
62
+ switch (which) {
63
+ case DialogInterface.BUTTON_POSITIVE:
64
+ successCallback.invoke(0);
65
+ break;
66
+ case DialogInterface.BUTTON_NEGATIVE:
67
+ successCallback.invoke(1);
68
+ break;
69
+ default:
70
+ throw new CodePushUnknownException("Unknown button ID pressed.");
71
+ }
72
+ } catch (Throwable e) {
73
+ CodePushUtils.log(e);
74
+ }
75
+ }
76
+ };
77
+
78
+ if (title != null) {
79
+ builder.setTitle(title);
80
+ }
81
+
82
+ if (message != null) {
83
+ builder.setMessage(message);
84
+ }
85
+
86
+ if (button1Text != null) {
87
+ builder.setPositiveButton(button1Text, clickListener);
88
+ }
89
+
90
+ if (button2Text != null) {
91
+ builder.setNegativeButton(button2Text, clickListener);
92
+ }
93
+
94
+ AlertDialog dialog = builder.create();
95
+ dialog.show();
96
+ }
97
+
98
+ @Override
99
+ public String getName() {
100
+ return "CodePushDialog";
101
+ }
102
+ }
@@ -0,0 +1,16 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ public enum CodePushInstallMode {
4
+ IMMEDIATE(0),
5
+ ON_NEXT_RESTART(1),
6
+ ON_NEXT_RESUME(2),
7
+ ON_NEXT_SUSPEND(3);
8
+
9
+ private final int value;
10
+ CodePushInstallMode(int value) {
11
+ this.value = value;
12
+ }
13
+ public int getValue() {
14
+ return this.value;
15
+ }
16
+ }
@@ -0,0 +1,12 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ class CodePushInvalidPublicKeyException extends RuntimeException {
4
+
5
+ public CodePushInvalidPublicKeyException(String message, Throwable cause) {
6
+ super(message, cause);
7
+ }
8
+
9
+ public CodePushInvalidPublicKeyException(String message) {
10
+ super(message);
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ public class CodePushInvalidUpdateException extends RuntimeException {
4
+ public CodePushInvalidUpdateException(String message) {
5
+ super(message);
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import java.net.MalformedURLException;
4
+
5
+ public class CodePushMalformedDataException extends RuntimeException {
6
+ public CodePushMalformedDataException(String path, Throwable cause) {
7
+ super("Unable to parse contents of " + path + ", the file may be corrupted.", cause);
8
+ }
9
+ public CodePushMalformedDataException(String url, MalformedURLException cause) {
10
+ super("The package has an invalid downloadUrl: " + url, cause);
11
+ }
12
+ }