@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,190 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import java.io.BufferedInputStream;
4
+ import java.io.BufferedReader;
5
+ import java.io.File;
6
+ import java.io.FileInputStream;
7
+ import java.io.FileOutputStream;
8
+ import java.io.IOException;
9
+ import java.io.InputStreamReader;
10
+ import java.io.PrintWriter;
11
+ import java.util.zip.ZipEntry;
12
+ import java.util.zip.ZipInputStream;
13
+
14
+ public class FileUtils {
15
+
16
+ private static final int WRITE_BUFFER_SIZE = 1024 * 8;
17
+
18
+ public static void copyDirectoryContents(String sourceDirectoryPath, String destinationDirectoryPath) throws IOException {
19
+ File sourceDir = new File(sourceDirectoryPath);
20
+ File destDir = new File(destinationDirectoryPath);
21
+ if (!destDir.exists()) {
22
+ destDir.mkdir();
23
+ }
24
+
25
+ for (File sourceFile : sourceDir.listFiles()) {
26
+ if (sourceFile.isDirectory()) {
27
+ copyDirectoryContents(
28
+ CodePushUtils.appendPathComponent(sourceDirectoryPath, sourceFile.getName()),
29
+ CodePushUtils.appendPathComponent(destinationDirectoryPath, sourceFile.getName()));
30
+ } else {
31
+ File destFile = new File(destDir, sourceFile.getName());
32
+ FileInputStream fromFileStream = null;
33
+ BufferedInputStream fromBufferedStream = null;
34
+ FileOutputStream destStream = null;
35
+ byte[] buffer = new byte[WRITE_BUFFER_SIZE];
36
+ try {
37
+ fromFileStream = new FileInputStream(sourceFile);
38
+ fromBufferedStream = new BufferedInputStream(fromFileStream);
39
+ destStream = new FileOutputStream(destFile);
40
+ int bytesRead;
41
+ while ((bytesRead = fromBufferedStream.read(buffer)) > 0) {
42
+ destStream.write(buffer, 0, bytesRead);
43
+ }
44
+ } finally {
45
+ try {
46
+ if (fromFileStream != null) fromFileStream.close();
47
+ if (fromBufferedStream != null) fromBufferedStream.close();
48
+ if (destStream != null) destStream.close();
49
+ } catch (IOException e) {
50
+ throw new CodePushUnknownException("Error closing IO resources.", e);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ public static void deleteDirectoryAtPath(String directoryPath) {
58
+ if (directoryPath == null) {
59
+ CodePushUtils.log("deleteDirectoryAtPath attempted with null directoryPath");
60
+ return;
61
+ }
62
+ File file = new File(directoryPath);
63
+ if (file.exists()) {
64
+ deleteFileOrFolderSilently(file);
65
+ }
66
+ }
67
+
68
+ public static void deleteFileAtPathSilently(String path) {
69
+ deleteFileOrFolderSilently(new File(path));
70
+ }
71
+
72
+ public static void deleteFileOrFolderSilently(File file) {
73
+ if (file.isDirectory()) {
74
+ File[] files = file.listFiles();
75
+ for (File fileEntry : files) {
76
+ if (fileEntry.isDirectory()) {
77
+ deleteFileOrFolderSilently(fileEntry);
78
+ } else {
79
+ fileEntry.delete();
80
+ }
81
+ }
82
+ }
83
+
84
+ if (!file.delete()) {
85
+ CodePushUtils.log("Error deleting file " + file.getName());
86
+ }
87
+ }
88
+
89
+ public static boolean fileAtPathExists(String filePath) {
90
+ return new File(filePath).exists();
91
+ }
92
+
93
+ public static void moveFile(File fileToMove, String newFolderPath, String newFileName) {
94
+ File newFolder = new File(newFolderPath);
95
+ if (!newFolder.exists()) {
96
+ newFolder.mkdirs();
97
+ }
98
+
99
+ File newFilePath = new File(newFolderPath, newFileName);
100
+ if (!fileToMove.renameTo(newFilePath)) {
101
+ throw new CodePushUnknownException("Unable to move file from " +
102
+ fileToMove.getAbsolutePath() + " to " + newFilePath.getAbsolutePath() + ".");
103
+ }
104
+ }
105
+
106
+ public static String readFileToString(String filePath) throws IOException {
107
+ FileInputStream fin = null;
108
+ BufferedReader reader = null;
109
+ try {
110
+ File fl = new File(filePath);
111
+ fin = new FileInputStream(fl);
112
+ reader = new BufferedReader(new InputStreamReader(fin));
113
+ StringBuilder sb = new StringBuilder();
114
+ String line = null;
115
+ while ((line = reader.readLine()) != null) {
116
+ sb.append(line).append("\n");
117
+ }
118
+
119
+ return sb.toString();
120
+ } finally {
121
+ if (reader != null) reader.close();
122
+ if (fin != null) fin.close();
123
+ }
124
+ }
125
+
126
+ public static void unzipFile(File zipFile, String destination) throws IOException {
127
+ FileInputStream fileStream = null;
128
+ BufferedInputStream bufferedStream = null;
129
+ ZipInputStream zipStream = null;
130
+ try {
131
+ fileStream = new FileInputStream(zipFile);
132
+ bufferedStream = new BufferedInputStream(fileStream);
133
+ zipStream = new ZipInputStream(bufferedStream);
134
+ ZipEntry entry;
135
+
136
+ File destinationFolder = new File(destination);
137
+ if (destinationFolder.exists()) {
138
+ deleteFileOrFolderSilently(destinationFolder);
139
+ }
140
+
141
+ destinationFolder.mkdirs();
142
+
143
+ byte[] buffer = new byte[WRITE_BUFFER_SIZE];
144
+ while ((entry = zipStream.getNextEntry()) != null) {
145
+ String fileName = entry.getName();
146
+ File file = new File(destinationFolder, fileName);
147
+ if (entry.isDirectory()) {
148
+ file.mkdirs();
149
+ } else {
150
+ File parent = file.getParentFile();
151
+ if (!parent.exists()) {
152
+ parent.mkdirs();
153
+ }
154
+
155
+ FileOutputStream fout = new FileOutputStream(file);
156
+ try {
157
+ int numBytesRead;
158
+ while ((numBytesRead = zipStream.read(buffer)) != -1) {
159
+ fout.write(buffer, 0, numBytesRead);
160
+ }
161
+ } finally {
162
+ fout.close();
163
+ }
164
+ }
165
+ long time = entry.getTime();
166
+ if (time > 0) {
167
+ file.setLastModified(time);
168
+ }
169
+ }
170
+ } finally {
171
+ try {
172
+ if (zipStream != null) zipStream.close();
173
+ if (bufferedStream != null) bufferedStream.close();
174
+ if (fileStream != null) fileStream.close();
175
+ } catch (IOException e) {
176
+ throw new CodePushUnknownException("Error closing IO resources.", e);
177
+ }
178
+ }
179
+ }
180
+
181
+ public static void writeStringToFile(String content, String filePath) throws IOException {
182
+ PrintWriter out = null;
183
+ try {
184
+ out = new PrintWriter(filePath);
185
+ out.print(content);
186
+ } finally {
187
+ if (out != null) out.close();
188
+ }
189
+ }
190
+ }
@@ -0,0 +1,17 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import com.facebook.react.ReactInstanceManager;
4
+
5
+ /**
6
+ * Provides access to a {@link ReactInstanceManager}.
7
+ *
8
+ * ReactNativeHost already implements this interface, if you make use of that react-native
9
+ * component (just add `implements ReactInstanceHolder`).
10
+ */
11
+ public interface ReactInstanceHolder {
12
+
13
+ /**
14
+ * Get the current {@link ReactInstanceManager} instance. May return null.
15
+ */
16
+ ReactInstanceManager getReactInstanceManager();
17
+ }
@@ -0,0 +1,173 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import android.content.Context;
4
+ import android.content.SharedPreferences;
5
+
6
+ import org.json.JSONArray;
7
+ import org.json.JSONException;
8
+ import org.json.JSONObject;
9
+
10
+ public class SettingsManager {
11
+
12
+ private SharedPreferences mSettings;
13
+
14
+ public SettingsManager(Context applicationContext) {
15
+ mSettings = applicationContext.getSharedPreferences(CodePushConstants.CODE_PUSH_PREFERENCES, 0);
16
+ }
17
+
18
+ public JSONArray getFailedUpdates() {
19
+ String failedUpdatesString = mSettings.getString(CodePushConstants.FAILED_UPDATES_KEY, null);
20
+ if (failedUpdatesString == null) {
21
+ return new JSONArray();
22
+ }
23
+
24
+ try {
25
+ return new JSONArray(failedUpdatesString);
26
+ } catch (JSONException e) {
27
+ // Unrecognized data format, clear and replace with expected format.
28
+ JSONArray emptyArray = new JSONArray();
29
+ mSettings.edit().putString(CodePushConstants.FAILED_UPDATES_KEY, emptyArray.toString()).commit();
30
+ return emptyArray;
31
+ }
32
+ }
33
+
34
+ public JSONObject getPendingUpdate() {
35
+ String pendingUpdateString = mSettings.getString(CodePushConstants.PENDING_UPDATE_KEY, null);
36
+ if (pendingUpdateString == null) {
37
+ return null;
38
+ }
39
+
40
+ try {
41
+ return new JSONObject(pendingUpdateString);
42
+ } catch (JSONException e) {
43
+ // Should not happen.
44
+ CodePushUtils.log("Unable to parse pending update metadata " + pendingUpdateString +
45
+ " stored in SharedPreferences");
46
+ return null;
47
+ }
48
+ }
49
+
50
+
51
+ public boolean isFailedHash(String packageHash) {
52
+ JSONArray failedUpdates = getFailedUpdates();
53
+ if (packageHash != null) {
54
+ for (int i = 0; i < failedUpdates.length(); i++) {
55
+ try {
56
+ JSONObject failedPackage = failedUpdates.getJSONObject(i);
57
+ String failedPackageHash = failedPackage.getString(CodePushConstants.PACKAGE_HASH_KEY);
58
+ if (packageHash.equals(failedPackageHash)) {
59
+ return true;
60
+ }
61
+ } catch (JSONException e) {
62
+ throw new CodePushUnknownException("Unable to read failedUpdates data stored in SharedPreferences.", e);
63
+ }
64
+ }
65
+ }
66
+
67
+ return false;
68
+ }
69
+
70
+ public boolean isPendingUpdate(String packageHash) {
71
+ JSONObject pendingUpdate = getPendingUpdate();
72
+
73
+ try {
74
+ return pendingUpdate != null &&
75
+ !pendingUpdate.getBoolean(CodePushConstants.PENDING_UPDATE_IS_LOADING_KEY) &&
76
+ (packageHash == null || pendingUpdate.getString(CodePushConstants.PENDING_UPDATE_HASH_KEY).equals(packageHash));
77
+ } catch (JSONException e) {
78
+ throw new CodePushUnknownException("Unable to read pending update metadata in isPendingUpdate.", e);
79
+ }
80
+ }
81
+
82
+ public void removeFailedUpdates() {
83
+ mSettings.edit().remove(CodePushConstants.FAILED_UPDATES_KEY).commit();
84
+ }
85
+
86
+ public void removePendingUpdate() {
87
+ mSettings.edit().remove(CodePushConstants.PENDING_UPDATE_KEY).commit();
88
+ }
89
+
90
+ public void saveFailedUpdate(JSONObject failedPackage) {
91
+ try {
92
+ if (isFailedHash(failedPackage.getString(CodePushConstants.PACKAGE_HASH_KEY))) {
93
+ // Do not need to add the package if it is already in the failedUpdates.
94
+ return;
95
+ }
96
+ } catch (JSONException e) {
97
+ throw new CodePushUnknownException("Unable to read package hash from package.", e);
98
+ }
99
+
100
+ String failedUpdatesString = mSettings.getString(CodePushConstants.FAILED_UPDATES_KEY, null);
101
+ JSONArray failedUpdates;
102
+ if (failedUpdatesString == null) {
103
+ failedUpdates = new JSONArray();
104
+ } else {
105
+ try {
106
+ failedUpdates = new JSONArray(failedUpdatesString);
107
+ } catch (JSONException e) {
108
+ // Should not happen.
109
+ throw new CodePushMalformedDataException("Unable to parse failed updates information " +
110
+ failedUpdatesString + " stored in SharedPreferences", e);
111
+ }
112
+ }
113
+
114
+ failedUpdates.put(failedPackage);
115
+ mSettings.edit().putString(CodePushConstants.FAILED_UPDATES_KEY, failedUpdates.toString()).commit();
116
+ }
117
+
118
+ public JSONObject getLatestRollbackInfo() {
119
+ String latestRollbackInfoString = mSettings.getString(CodePushConstants.LATEST_ROLLBACK_INFO_KEY, null);
120
+ if (latestRollbackInfoString == null) {
121
+ return null;
122
+ }
123
+
124
+ try {
125
+ return new JSONObject(latestRollbackInfoString);
126
+ } catch (JSONException e) {
127
+ // Should not happen.
128
+ CodePushUtils.log("Unable to parse latest rollback metadata " + latestRollbackInfoString +
129
+ " stored in SharedPreferences");
130
+ return null;
131
+ }
132
+ }
133
+
134
+ public void setLatestRollbackInfo(String packageHash) {
135
+ JSONObject latestRollbackInfo = getLatestRollbackInfo();
136
+ int count = 0;
137
+
138
+ if (latestRollbackInfo != null) {
139
+ try {
140
+ String latestRollbackPackageHash = latestRollbackInfo.getString(CodePushConstants.LATEST_ROLLBACK_PACKAGE_HASH_KEY);
141
+ if (latestRollbackPackageHash.equals(packageHash)) {
142
+ count = latestRollbackInfo.getInt(CodePushConstants.LATEST_ROLLBACK_COUNT_KEY);
143
+ }
144
+ } catch (JSONException e) {
145
+ CodePushUtils.log("Unable to parse latest rollback info.");
146
+ }
147
+ } else {
148
+ latestRollbackInfo = new JSONObject();
149
+ }
150
+
151
+ try {
152
+ latestRollbackInfo.put(CodePushConstants.LATEST_ROLLBACK_PACKAGE_HASH_KEY, packageHash);
153
+ latestRollbackInfo.put(CodePushConstants.LATEST_ROLLBACK_TIME_KEY, System.currentTimeMillis());
154
+ latestRollbackInfo.put(CodePushConstants.LATEST_ROLLBACK_COUNT_KEY, count + 1);
155
+ mSettings.edit().putString(CodePushConstants.LATEST_ROLLBACK_INFO_KEY, latestRollbackInfo.toString()).commit();
156
+ } catch (JSONException e) {
157
+ throw new CodePushUnknownException("Unable to save latest rollback info.", e);
158
+ }
159
+ }
160
+
161
+ public void savePendingUpdate(String packageHash, boolean isLoading) {
162
+ JSONObject pendingUpdate = new JSONObject();
163
+ try {
164
+ pendingUpdate.put(CodePushConstants.PENDING_UPDATE_HASH_KEY, packageHash);
165
+ pendingUpdate.put(CodePushConstants.PENDING_UPDATE_IS_LOADING_KEY, isLoading);
166
+ mSettings.edit().putString(CodePushConstants.PENDING_UPDATE_KEY, pendingUpdate.toString()).commit();
167
+ } catch (JSONException e) {
168
+ // Should not happen.
169
+ throw new CodePushUnknownException("Unable to save pending update.", e);
170
+ }
171
+ }
172
+
173
+ }
@@ -0,0 +1,20 @@
1
+ // Top-level build file where you can add configuration options common to all sub-projects/modules.
2
+
3
+ buildscript {
4
+ repositories {
5
+ jcenter()
6
+ }
7
+ dependencies {
8
+ classpath 'com.android.tools.build:gradle:1.3.0'
9
+
10
+ // NOTE: Do not place your application dependencies here; they belong
11
+ // in the individual module build.gradle files
12
+ }
13
+ }
14
+
15
+ allprojects {
16
+ repositories {
17
+ mavenLocal()
18
+ jcenter()
19
+ }
20
+ }
@@ -0,0 +1,113 @@
1
+ // Adapted from https://raw.githubusercontent.com/facebook/react-native/d16ff3bd8b92fa84a9007bf5ebedd8153e4c089d/react.gradle
2
+
3
+ import java.nio.file.Paths;
4
+
5
+ def config = project.hasProperty("react") ? project.react : [];
6
+ def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
7
+
8
+ // because elvis operator
9
+ def elvisFile(thing) {
10
+ return thing ? file(thing) : null;
11
+ }
12
+
13
+ void runBefore(String dependentTaskName, Task task) {
14
+ Task dependentTask = tasks.findByPath(dependentTaskName);
15
+ if (dependentTask != null) {
16
+ dependentTask.dependsOn task
17
+ }
18
+ }
19
+
20
+ gradle.projectsEvaluated {
21
+ android.buildTypes.each {
22
+ // to prevent incorrect long value restoration from strings.xml we need to wrap it with double quotes
23
+ // https://github.com/Microsoft/cordova-plugin-code-push/issues/264
24
+ it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
25
+ }
26
+
27
+ android.applicationVariants.all { variant ->
28
+ def nodeModulesPath;
29
+ if (config.root) {
30
+ nodeModulesPath = Paths.get(config.root, "/node_modules");
31
+ } else if (project.hasProperty('nodeModulesPath')) {
32
+ nodeModulesPath = project.nodeModulesPath
33
+ } else {
34
+ nodeModulesPath = "../../node_modules";
35
+ }
36
+
37
+ def targetName = variant.name.capitalize()
38
+ def targetPath = variant.dirName
39
+
40
+ def jsBundleDir;
41
+ def resourcesDir;
42
+ def jsBundleFile;
43
+
44
+ // Additional node commandline arguments
45
+ def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
46
+ def extraPackagerArgs = config.extraPackagerArgs ?: []
47
+
48
+ // Make this task run right after the bundle task
49
+ def generateBundledResourcesHash;
50
+
51
+ if (variant.hasProperty("bundleJsAndAssets")) {
52
+ def reactBundleTask = variant.bundleJsAndAssets
53
+ jsBundleDir = reactBundleTask.generatedAssetsFolders[0].absolutePath
54
+ resourcesDir = reactBundleTask.generatedResFolders[0].absolutePath
55
+ jsBundleFile = file("$jsBundleDir/$bundleAssetName")
56
+
57
+ generateBundledResourcesHash = tasks.create(
58
+ name: "generateBundledResourcesHash${targetName}",
59
+ type: Exec) {
60
+ commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir)
61
+
62
+ enabled config."bundleIn${targetName}" ||
63
+ config."bundleIn${variant.buildType.name.capitalize()}" ?:
64
+ targetName.toLowerCase().contains("release")
65
+ }
66
+ } else {
67
+ def jsBundleDirConfigName = "jsBundleDir${targetName}"
68
+ jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
69
+ file("$buildDir/intermediates/assets/${targetPath}")
70
+
71
+ def resourcesDirConfigName = "resourcesDir${targetName}"
72
+ resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
73
+ file("$buildDir/intermediates/res/merged/${targetPath}")
74
+
75
+ // In case version of 'Android Plugin for Gradle'' is lower than 1.3.0
76
+ // '$buildDir' has slightly different structure - 'merged' folder
77
+ // does not exists so '${targetPath}' folder contains directly in 'res' folder.
78
+ if (!resourcesDir.exists() && file("$buildDir/intermediates/res/${targetPath}").exists()) {
79
+ resourcesDir = file("$buildDir/intermediates/res/${targetPath}")
80
+ }
81
+
82
+ jsBundleFile = file("$jsBundleDir/$bundleAssetName")
83
+
84
+ def resourcesMapTempFileName = "CodePushResourcesMap-" + java.util.UUID.randomUUID().toString().substring(0,8) + ".json"
85
+
86
+ generateBundledResourcesHash = tasks.create(
87
+ name: "generateBundledResourcesHash${targetName}",
88
+ type: Exec) {
89
+ commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir, resourcesMapTempFileName)
90
+ }
91
+
92
+ // Make this task run right before the bundle task
93
+ def recordFilesBeforeBundleCommand = tasks.create(
94
+ name: "recordFilesBeforeBundleCommand${targetName}",
95
+ type: Exec) {
96
+ commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/recordFilesBeforeBundleCommand.js", resourcesDir, resourcesMapTempFileName)
97
+ }
98
+
99
+ recordFilesBeforeBundleCommand.dependsOn("merge${targetName}Resources")
100
+ recordFilesBeforeBundleCommand.dependsOn("merge${targetName}Assets")
101
+ runBefore("bundle${targetName}JsAndAssets", recordFilesBeforeBundleCommand)
102
+
103
+ // We need to generate and record the resources map, but we use it to generate the bundle hash
104
+ generateBundledResourcesHash.dependsOn("recordFilesBeforeBundleCommand${targetName}")
105
+ }
106
+
107
+ generateBundledResourcesHash.dependsOn("bundle${targetName}JsAndAssets")
108
+ runBefore("processArmeabi-v7a${targetName}Resources", generateBundledResourcesHash)
109
+ runBefore("processX86${targetName}Resources", generateBundledResourcesHash)
110
+ runBefore("processUniversal${targetName}Resources", generateBundledResourcesHash)
111
+ runBefore("process${targetName}Resources", generateBundledResourcesHash)
112
+ }
113
+ }
@@ -0,0 +1,5 @@
1
+ distributionBase=GRADLE_USER_HOME
2
+ distributionPath=wrapper/dists
3
+ zipStoreBase=GRADLE_USER_HOME
4
+ zipStorePath=wrapper/dists
5
+ distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
@@ -0,0 +1,20 @@
1
+ # Project-wide Gradle settings.
2
+
3
+ # IDE (e.g. Android Studio) users:
4
+ # Gradle settings configured through the IDE *will override*
5
+ # any settings specified in this file.
6
+
7
+ # For more details on how to configure your build environment visit
8
+ # http://www.gradle.org/docs/current/userguide/build_environment.html
9
+
10
+ # Specifies the JVM arguments used for the daemon process.
11
+ # The setting is particularly useful for tweaking memory settings.
12
+ # Default value: -Xmx10248m -XX:MaxPermSize=256m
13
+ # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14
+
15
+ # When configured, Gradle will run in incubating parallel mode.
16
+ # This option should only be used with decoupled projects. More details, visit
17
+ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18
+ # org.gradle.parallel=true
19
+
20
+ android.useDeprecatedNdk=true