react-native-update 10.59.2 → 10.60.0

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 (125) hide show
  1. package/README-CN.md +7 -7
  2. package/README.md +7 -6
  3. package/android/build.gradle +25 -33
  4. package/android/jni/Android.mk +16 -24
  5. package/android/lib/arm64-v8a/librnpushy.so +0 -0
  6. package/android/lib/armeabi-v7a/librnpushy.so +0 -0
  7. package/android/lib/x86/librnpushy.so +0 -0
  8. package/android/lib/x86_64/librnpushy.so +0 -0
  9. package/android/proguard.pro +9 -7
  10. package/android/src/main/java/cn/reactnative/modules/update/ApkInstaller.java +2 -7
  11. package/android/src/main/java/cn/reactnative/modules/update/ArchiveLimits.java +23 -6
  12. package/android/src/main/java/cn/reactnative/modules/update/BundledResourceCopier.java +50 -51
  13. package/android/src/main/java/cn/reactnative/modules/update/CleanupKeepNames.java +12 -13
  14. package/android/src/main/java/cn/reactnative/modules/update/CopyGroupResult.java +3 -0
  15. package/android/src/main/java/cn/reactnative/modules/update/CrashHold.java +22 -30
  16. package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +181 -332
  17. package/android/src/main/java/cn/reactnative/modules/update/DownloadTaskParams.java +3 -1
  18. package/android/src/main/java/cn/reactnative/modules/update/ErrorCodes.java +27 -0
  19. package/android/src/main/java/cn/reactnative/modules/update/FileOperationException.java +1 -1
  20. package/android/src/main/java/cn/reactnative/modules/update/FlowBridge.java +32 -8
  21. package/android/src/main/java/cn/reactnative/modules/update/HttpClients.java +63 -0
  22. package/android/src/main/java/cn/reactnative/modules/update/HttpUtils.java +0 -11
  23. package/android/src/main/java/cn/reactnative/modules/update/InstallRecord.java +66 -116
  24. package/android/src/main/java/cn/reactnative/modules/update/NativeCore.java +9 -1
  25. package/android/src/main/java/cn/reactnative/modules/update/PatchFailedException.java +1 -1
  26. package/android/src/main/java/cn/reactnative/modules/update/PushyRuntime.java +32 -60
  27. package/android/src/main/java/cn/reactnative/modules/update/ReactReloadManager.java +8 -23
  28. package/android/src/main/java/cn/reactnative/modules/update/SafeZipFile.java +42 -80
  29. package/android/src/main/java/cn/reactnative/modules/update/StateSerialRunner.java +22 -39
  30. package/android/src/main/java/cn/reactnative/modules/update/SyncCoordinator.java +176 -299
  31. package/android/src/main/java/cn/reactnative/modules/update/Threads.java +35 -0
  32. package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +242 -174
  33. package/android/src/main/java/cn/reactnative/modules/update/UpdateEventEmitter.java +1 -1
  34. package/android/src/main/java/cn/reactnative/modules/update/UpdateFileUtils.java +75 -17
  35. package/android/src/main/java/cn/reactnative/modules/update/{UpdateModuleImpl.java → UpdateModule.java} +113 -95
  36. package/android/src/main/java/cn/reactnative/modules/update/UpdatePackage.java +16 -19
  37. package/android/src/oldarch/cn/reactnative/modules/update/NativePushySpec.java +69 -0
  38. package/cpp/android_jni/archive_limits_jni.cpp +83 -0
  39. package/cpp/android_jni/install_record_jni.cpp +89 -0
  40. package/cpp/android_jni/jni_log.h +31 -0
  41. package/cpp/android_jni/jni_natives.h +40 -0
  42. package/cpp/android_jni/jni_registration.cpp +133 -0
  43. package/cpp/android_jni/jni_util.h +160 -0
  44. package/cpp/android_jni/update_core_android.cpp +450 -0
  45. package/cpp/android_jni/update_flow_jni.cpp +133 -0
  46. package/{android/jni → cpp/hpatch}/hpatch.c +5 -5
  47. package/{android/jni → cpp/hpatch}/hpatch.h +4 -1
  48. package/cpp/patch_core/archive_limits.cpp +194 -0
  49. package/cpp/patch_core/archive_limits.h +99 -10
  50. package/cpp/patch_core/archive_patch_core.cpp +96 -12
  51. package/cpp/patch_core/archive_patch_core.h +49 -0
  52. package/cpp/patch_core/digest.h +5 -4
  53. package/cpp/patch_core/error_codes.h +5 -3
  54. package/cpp/patch_core/install_record.cpp +430 -0
  55. package/cpp/patch_core/install_record.h +163 -9
  56. package/cpp/patch_core/patch_core.cpp +62 -16
  57. package/cpp/patch_core/patch_core.h +27 -7
  58. package/cpp/patch_core/patch_manifest.cpp +201 -0
  59. package/cpp/patch_core/patch_manifest.h +74 -0
  60. package/cpp/patch_core/state_ops.h +3 -3
  61. package/cpp/update_flow_core/flow_json.cpp +82 -8
  62. package/cpp/update_flow_core/flow_json.h +21 -0
  63. package/cpp/update_flow_core/native_config.cpp +456 -0
  64. package/cpp/update_flow_core/native_config.h +84 -0
  65. package/cpp/update_flow_core/native_round.cpp +326 -0
  66. package/cpp/update_flow_core/native_round.h +90 -0
  67. package/cpp/update_flow_core/update_flow_core.h +2 -2
  68. package/harmony/hvigor-plugin.ts +11 -19
  69. package/harmony/pushy/src/main/cpp/CMakeLists.txt +17 -26
  70. package/harmony/pushy/src/main/cpp/PushyPackage.h +2 -2
  71. package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +55 -94
  72. package/harmony/pushy/src/main/cpp/pushy.cpp +694 -517
  73. package/harmony/pushy/src/main/ets/ArchiveLimits.ts +48 -72
  74. package/harmony/pushy/src/main/ets/DownloadTask.ts +164 -404
  75. package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +1 -3
  76. package/harmony/pushy/src/main/ets/ErrorCodes.ts +1 -14
  77. package/harmony/pushy/src/main/ets/EventHub.ts +1 -1
  78. package/harmony/pushy/src/main/ets/InstallRecord.ts +52 -151
  79. package/harmony/pushy/src/main/ets/Logger.ts +20 -34
  80. package/harmony/pushy/src/main/ets/NativePatchCore.ts +116 -42
  81. package/harmony/pushy/src/main/ets/PushyConfiguration.ts +8 -85
  82. package/harmony/pushy/src/main/ets/PushyTurboModule.ts +11 -25
  83. package/harmony/pushy/src/main/ets/SaveFile.ts +99 -18
  84. package/harmony/pushy/src/main/ets/SyncCoordinator.ts +136 -335
  85. package/harmony/pushy/src/main/ets/Texts.ts +0 -4
  86. package/harmony/pushy/src/main/ets/UpdateContext.ts +106 -119
  87. package/harmony/pushy.har +0 -0
  88. package/ios/RCTPushy/RCTPushy+Launch.mm +185 -0
  89. package/ios/RCTPushy/RCTPushy.h +12 -0
  90. package/ios/RCTPushy/RCTPushy.mm +87 -2634
  91. package/ios/RCTPushy/RCTPushyCommon.h +34 -0
  92. package/ios/RCTPushy/RCTPushyConfiguration.h +0 -8
  93. package/ios/RCTPushy/RCTPushyConfiguration.mm +40 -121
  94. package/ios/RCTPushy/RCTPushyDownloader.mm +40 -37
  95. package/ios/RCTPushy/RCTPushyInstallRecord.mm +61 -0
  96. package/ios/RCTPushy/RCTPushyInstaller.mm +689 -0
  97. package/ios/RCTPushy/RCTPushyInternal.h +144 -0
  98. package/ios/RCTPushy/RCTPushyOrchestrator.mm +1001 -0
  99. package/ios/RCTPushy/RCTPushyState.mm +314 -0
  100. package/package.json +25 -23
  101. package/react-native-update.podspec +73 -82
  102. package/src/client.ts +361 -451
  103. package/src/context.ts +1 -1
  104. package/src/core.ts +35 -8
  105. package/src/endpoint.ts +0 -2
  106. package/src/error.ts +13 -32
  107. package/src/i18n.ts +18 -83
  108. package/src/locales/en.ts +0 -4
  109. package/src/locales/zh.ts +0 -4
  110. package/src/provider.tsx +60 -53
  111. package/src/telemetry.ts +0 -13
  112. package/src/type.ts +0 -15
  113. package/src/updateFlowCore.ts +116 -10
  114. package/src/utils.ts +49 -42
  115. package/android/src/main/java/cn/reactnative/modules/update/ArchivePatchPlanResult.java +0 -6
  116. package/android/src/main/java/cn/reactnative/modules/update/PushyConfiguration.java +0 -104
  117. package/android/src/main/java/cn/reactnative/modules/update/UiThreadRunner.java +0 -37
  118. package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +0 -121
  119. package/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +0 -125
  120. package/cpp/patch_core/jni_natives.h +0 -27
  121. package/cpp/patch_core/jni_registration.cpp +0 -103
  122. package/cpp/patch_core/jni_util.h +0 -60
  123. package/cpp/patch_core/patch_core_android.cpp +0 -97
  124. package/cpp/patch_core/update_core_android.cpp +0 -485
  125. package/cpp/update_flow_core/update_flow_jni.cpp +0 -150
@@ -4,51 +4,64 @@ import {
4
4
  ERROR_FILE_OPERATION_FAILED,
5
5
  ERROR_DELTA_FAILED,
6
6
  createPushyError,
7
+ getErrorMessage,
7
8
  } from './ErrorCodes';
8
- import { isReservedEntryName } from './InstallRecord';
9
+ import NativePatchCore from './NativePatchCore';
9
10
 
10
- // ArkTS mirror of cpp/patch_core/archive_limits.h — keep in sync by hand
11
- // (harmony/pushy/src/test/check-constant-parity.js asserts the values match).
12
- // 损坏或恶意更新包的伤害上限:最多耗费有限的磁盘/内存/时间,绝不撑爆磁盘。
11
+ // 解压资源上限的计数规则(条目数、单条/总解压量、压缩比、保留名、符号链接、
12
+ // 未知长度下载的磁盘探测计划)只在 cpp/patch_core/archive_limits.h 里实现,
13
+ // 三端共用(这里经 NAPI)。下面只镜像本端仍需自己比较的常量,
14
+ // scripts/check-constant-parity.js 断言与头文件一致。
13
15
  export const MAX_ARCHIVE_BYTES = 512 * 1024 * 1024;
14
- export const MAX_TOTAL_UNCOMPRESSED_BYTES = 2048 * 1024 * 1024;
15
- export const MAX_ENTRY_BYTES = 512 * 1024 * 1024;
16
- export const MAX_ENTRIES = 20000;
17
- export const MAX_COMPRESSION_RATIO = 100;
18
- export const RATIO_CHECK_MIN_BYTES = 1 * 1024 * 1024;
19
16
  export const MAX_MANIFEST_BYTES = 16 * 1024 * 1024;
20
17
  export const FREE_DISK_MARGIN_BYTES = 64 * 1024 * 1024;
21
- export const UNKNOWN_LENGTH_FREE_SPACE_PROBE_BYTES = 8 * 1024 * 1024;
22
18
 
23
19
  /**
24
- * 解压前的总量校验(zlib.getOriginalSize 给出的归档解压后总字节数)。
25
- * zlib.decompressFile 没有逐条钩子,C++ 头文件里的逐条压缩比在这里只能按
26
- * 整包近似:总解压量超过上限、或(总量大于 RATIO_CHECK_MIN_BYTES 时)总压缩
27
- * 比超过 MAX_COMPRESSION_RATIO 即拒绝——20MB 归档 100:1 的 2GB 载荷在解压前
28
- * 就被挡下,而不是先解出来再量。
20
+ * 解压前的整包校验(zlib.getOriginalSize 给出的归档解压后总字节数):总解压
21
+ * 量上限与整包压缩比(archive_limits::CheckUncompressedSize)。鸿蒙的 zlib
22
+ * 只提供整包解压量与整包解压,拿不到条目的压缩尺寸,逐条压缩比无从查起;
23
+ * 20MB 归档 100:1 的 2GB 载荷在解压前就被挡下,解压后 checkExtractedDirectory
24
+ * 再逐条核对。
29
25
  */
30
26
  export function checkUncompressedSize(
31
27
  archiveBytes: number,
32
28
  uncompressedBytes: number,
33
29
  ): void {
34
- if (uncompressedBytes > MAX_TOTAL_UNCOMPRESSED_BYTES) {
30
+ const reason = NativePatchCore.checkUncompressedSize(
31
+ archiveBytes,
32
+ uncompressedBytes,
33
+ );
34
+ if (reason !== undefined) {
35
+ throw createPushyError(ERROR_DELTA_FAILED, reason);
36
+ }
37
+ }
38
+
39
+ // 解压量取不到时拒绝的专属错误细节:与"超限"拒绝区分开,日志与遥测里一眼
40
+ // 可辨(典型原因:设备 zlib 不认该归档格式/归档损坏)。不做任何放行回退。
41
+ export const ORIGINAL_SIZE_UNAVAILABLE = 'archive expansion size unavailable';
42
+
43
+ /**
44
+ * zlib.getOriginalSize 的结果校验。failure 非 undefined 表示调用本身抛错
45
+ * (其消息);否则校验返回值必须是有限非负数。任何一种都拒绝归档:不知道
46
+ * 展开量就放行,等于允许一个 20MB 的归档在解压后的统计跑到之前先写满磁盘。
47
+ */
48
+ export function checkOriginalSize(
49
+ size: number | undefined,
50
+ failure?: string,
51
+ ): number {
52
+ if (failure !== undefined) {
35
53
  throw createPushyError(
36
54
  ERROR_DELTA_FAILED,
37
- `archive expands beyond ${MAX_TOTAL_UNCOMPRESSED_BYTES} bytes ` +
38
- `(${uncompressedBytes})`,
55
+ `${ORIGINAL_SIZE_UNAVAILABLE}: getOriginalSize failed: ${failure}`,
39
56
  );
40
57
  }
41
- if (
42
- uncompressedBytes > RATIO_CHECK_MIN_BYTES &&
43
- archiveBytes > 0 &&
44
- uncompressedBytes > archiveBytes * MAX_COMPRESSION_RATIO
45
- ) {
58
+ if (typeof size !== 'number' || !Number.isFinite(size) || size < 0) {
46
59
  throw createPushyError(
47
60
  ERROR_DELTA_FAILED,
48
- `archive compression ratio exceeds ${MAX_COMPRESSION_RATIO}:1 ` +
49
- `(${uncompressedBytes}/${archiveBytes})`,
61
+ `${ORIGINAL_SIZE_UNAVAILABLE}: getOriginalSize returned ${String(size)}`,
50
62
  );
51
63
  }
64
+ return size;
52
65
  }
53
66
 
54
67
  /**
@@ -85,55 +98,18 @@ export async function ensureFreeSpace(
85
98
  }
86
99
  }
87
100
 
88
- export interface DirectoryMeasure {
89
- entries: number;
90
- bytes: number;
91
- }
92
-
93
101
  /**
94
- * 递归统计目录里的条目数与总字节数;两者任一超过上限立即抛错(不必扫完)。
95
- * 同一趟遍历里拒绝任意深度的 `.pushy-` 保留条目(完成记录只能由 SDK 写)。
102
+ * 解压后在 native 工作线程逐条核对刚解压的目录(archive_limits::
103
+ * CheckExtractedDirectory):条目数、单条大小、总字节数与整包压缩比,拒绝
104
+ * 任意深度的 `.pushy-` 保留条目(完成记录只能由 SDK 写)与符号链接。
96
105
  */
97
- export async function measureExtractedDirectory(
106
+ export async function checkExtractedDirectory(
98
107
  directory: string,
99
- acc: DirectoryMeasure = { entries: 0, bytes: 0 },
100
- ): Promise<DirectoryMeasure> {
101
- const names = (await fileIo.listFile(directory)).filter(
102
- name => name !== '.' && name !== '..',
103
- );
104
- for (const name of names) {
105
- if (isReservedEntryName(name)) {
106
- throw createPushyError(
107
- ERROR_DELTA_FAILED,
108
- `archive contains reserved entry ${name}`,
109
- );
110
- }
111
- const path = `${directory}/${name}`;
112
- const stat = await fileIo.stat(path);
113
- acc.entries += 1;
114
- if (acc.entries > MAX_ENTRIES) {
115
- throw createPushyError(
116
- ERROR_DELTA_FAILED,
117
- `archive has too many entries (> ${MAX_ENTRIES})`,
118
- );
119
- }
120
- if (stat.isDirectory()) {
121
- await measureExtractedDirectory(path, acc);
122
- continue;
123
- }
124
- if (stat.size > MAX_ENTRY_BYTES) {
125
- throw createPushyError(
126
- ERROR_DELTA_FAILED,
127
- `archive entry too large: ${name} (${stat.size} bytes)`,
128
- );
129
- }
130
- acc.bytes += stat.size;
131
- if (acc.bytes > MAX_TOTAL_UNCOMPRESSED_BYTES) {
132
- throw createPushyError(
133
- ERROR_DELTA_FAILED,
134
- `archive expands beyond ${MAX_TOTAL_UNCOMPRESSED_BYTES} bytes`,
135
- );
136
- }
108
+ archiveBytes: number,
109
+ ): Promise<void> {
110
+ try {
111
+ await NativePatchCore.checkExtractedDirectory(directory, archiveBytes);
112
+ } catch (e) {
113
+ throw createPushyError(ERROR_DELTA_FAILED, getErrorMessage(e));
137
114
  }
138
- return acc;
139
115
  }