@bugsee/react-native 0.0.0-stage → 7.0.0-beta1

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 (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +552 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +944 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,287 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.bugsee.library.contracts.options.IssueSeverity;
7
+ import com.bugsee.library.contracts.options.IssueType;
8
+ import com.bugsee.library.contracts.reporting.Attachment;
9
+ import com.bugsee.library.contracts.reporting.Report;
10
+
11
+ import java.io.File;
12
+ import java.io.Serializable;
13
+ import java.util.ArrayList;
14
+ import java.util.Collections;
15
+ import java.util.HashMap;
16
+ import java.util.List;
17
+ import java.util.Map;
18
+
19
+ /**
20
+ * The {@code BugseeReport} operations, between the JS wire shape and the SDK's
21
+ * {@link Report}. Plain Java, so every rule here is unit-tested.
22
+ *
23
+ * <p>The SDK documents {@code Report} as safe from any thread, and its
24
+ * collections are synchronized, so these run on whatever thread the bridge
25
+ * calls them from.
26
+ */
27
+ final class ReportOps {
28
+
29
+ /** A patch or argument the JS contract does not allow; nothing was applied. */
30
+ static final class BadArgument extends Exception {
31
+ BadArgument(@NonNull final String message) {
32
+ super(message);
33
+ }
34
+ }
35
+
36
+ private ReportOps() {
37
+ }
38
+
39
+ /** {@code toString()}, the wire name ({@code "crash"}); {@code name()} is "Crash". */
40
+ @NonNull
41
+ static String typeOf(@NonNull final Report report) {
42
+ final IssueType type = report.getType();
43
+ return type == null ? "" : type.toString();
44
+ }
45
+
46
+ /**
47
+ * The snapshot {@code reportRead} returns. Keys and shapes match
48
+ * {@code BugseeReportSnapshot}; the JS side normalises anything missing.
49
+ */
50
+ @NonNull
51
+ static Map<String, Object> read(@NonNull final Report report) {
52
+ final Map<String, Object> result = new HashMap<>();
53
+ result.put("summary", report.getSummary());
54
+ result.put("description", report.getDescription());
55
+
56
+ // By value, never ordinal(): Critical is ordinal 3 and value 4.
57
+ final IssueSeverity severity = report.getSeverity();
58
+ result.put("severity", severity == null ? null : severity.getValue());
59
+
60
+ result.put("labels", new ArrayList<>(report.getLabels()));
61
+
62
+ final Map<String, Object> attributes = new HashMap<>();
63
+ for (final Map.Entry<String, Serializable> entry : report.getAttributes().entrySet()) {
64
+ final Object value = entry.getValue();
65
+ // The JS type is string | number | boolean; anything else has no
66
+ // representation there, and a toString would read as a real value.
67
+ if (value instanceof String || value instanceof Number || value instanceof Boolean) {
68
+ attributes.put(entry.getKey(), value);
69
+ }
70
+ }
71
+ result.put("attributes", attributes);
72
+
73
+ // Sorted here because the SDK build this is pinned to may predate
74
+ // bugsee-android#178, which sorts them at the source.
75
+ final List<Integer> displayIds = new ArrayList<>();
76
+ final List<Integer> sdkIds = report.getScreenshotDisplayIds();
77
+ if (sdkIds != null) {
78
+ for (final Integer id : sdkIds) {
79
+ if (id != null) {
80
+ displayIds.add(id);
81
+ }
82
+ }
83
+ }
84
+ Collections.sort(displayIds);
85
+ result.put("screenshotDisplayIds", displayIds);
86
+
87
+ final List<String> attachmentNames = new ArrayList<>();
88
+ for (final Attachment attachment : report.getAttachments()) {
89
+ final String name = attachment == null ? null : attachment.getName();
90
+ if (name != null) {
91
+ attachmentNames.add(name);
92
+ }
93
+ }
94
+ result.put("attachmentNames", attachmentNames);
95
+ return result;
96
+ }
97
+
98
+ /**
99
+ * Applies a {@code reportUpdate} patch: validates every field first, and
100
+ * only then touches the report, so a rejected patch changes nothing.
101
+ *
102
+ * <p>The JS side has validated the same rules before crossing; this is not
103
+ * a second opinion but the last line before the SDK, which would silently
104
+ * coerce what it does not understand (severity 0 becomes {@code VeryLow}).
105
+ */
106
+ static void apply(@NonNull final Report report, @NonNull final Map<String, Object> patch)
107
+ throws BadArgument {
108
+ for (final String key : patch.keySet()) {
109
+ switch (key) {
110
+ case "summary":
111
+ case "description":
112
+ case "severity":
113
+ case "labels":
114
+ case "clearAttributes":
115
+ case "attributes":
116
+ break;
117
+ default:
118
+ throw new BadArgument("update() received an unknown key \"" + key + "\"");
119
+ }
120
+ }
121
+
122
+ final boolean hasSummary = patch.containsKey("summary");
123
+ final String summary = optionalString(patch, "summary");
124
+ final boolean hasDescription = patch.containsKey("description");
125
+ final String description = optionalString(patch, "description");
126
+ final IssueSeverity severity = patch.containsKey("severity")
127
+ ? severity(patch.get("severity"))
128
+ : null;
129
+ final List<String> labels = patch.containsKey("labels")
130
+ ? labels(patch.get("labels"))
131
+ : null;
132
+ final boolean clearAttributes = patch.containsKey("clearAttributes");
133
+ if (clearAttributes && !Boolean.TRUE.equals(patch.get("clearAttributes"))) {
134
+ throw new BadArgument("clearAttributes must be true when present");
135
+ }
136
+ final Map<String, Object> attributes = patch.containsKey("attributes")
137
+ ? attributes(patch.get("attributes"))
138
+ : null;
139
+
140
+ // Everything is valid; nothing below can reject.
141
+ if (hasSummary) {
142
+ report.setSummary(summary);
143
+ }
144
+ if (hasDescription) {
145
+ report.setDescription(description);
146
+ }
147
+ if (severity != null) {
148
+ report.setSeverity(severity);
149
+ }
150
+ if (labels != null) {
151
+ // One call: clear-then-add would expose a label-less report between the two.
152
+ report.setLabels(labels);
153
+ }
154
+ if (clearAttributes) {
155
+ report.clearAllAttributes();
156
+ }
157
+ if (attributes != null) {
158
+ for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
159
+ if (entry.getValue() == null) {
160
+ report.removeAttribute(entry.getKey());
161
+ } else {
162
+ report.setAttribute(entry.getKey(), (Serializable) entry.getValue());
163
+ }
164
+ }
165
+ }
166
+ }
167
+
168
+ /**
169
+ * {@link #apply} on the JSON text {@code reportUpdate} receives, parsed by
170
+ * {@link BridgeJson} -- the transport that keeps a clearing {@code null}
171
+ * on both platforms. Text that is not a JSON object is a
172
+ * {@link BadArgument} like any malformed field, and applies nothing.
173
+ */
174
+ static void applyJson(@NonNull final Report report, @Nullable final String json)
175
+ throws BadArgument {
176
+ final Map<String, Object> patch;
177
+ try {
178
+ patch = BridgeJson.parseObject(json);
179
+ } catch (final BridgeJson.BadJson e) {
180
+ throw new BadArgument("update() patch is not a JSON object: " + e.getMessage());
181
+ }
182
+ apply(report, patch);
183
+ }
184
+
185
+ /** @return false when the SDK declined the file (it returned null). */
186
+ static boolean addFile(
187
+ @NonNull final Report report,
188
+ @NonNull final String path,
189
+ @NonNull final String name,
190
+ @Nullable final String mimeType,
191
+ final boolean move
192
+ ) {
193
+ return report.addAttachment(new File(path), name, mimeType, move) != null;
194
+ }
195
+
196
+ /** @return false when the SDK declined the data (it returned null). */
197
+ static boolean addData(
198
+ @NonNull final Report report,
199
+ @NonNull final byte[] data,
200
+ @NonNull final String name,
201
+ @Nullable final String mimeType
202
+ ) {
203
+ return report.addAttachment(data, name, mimeType) != null;
204
+ }
205
+
206
+ @Nullable
207
+ private static String optionalString(final Map<String, Object> patch, final String key)
208
+ throws BadArgument {
209
+ final Object value = patch.get(key);
210
+ if (value != null && !(value instanceof String)) {
211
+ throw new BadArgument(key + " must be a string or null");
212
+ }
213
+ return (String) value;
214
+ }
215
+
216
+ /**
217
+ * Checked 1..5 BEFORE the SDK sees it: the SDK's one-argument
218
+ * {@code fromIntValue} maps anything else to {@code VeryLow}, silently.
219
+ */
220
+ @NonNull
221
+ private static IssueSeverity severity(@Nullable final Object value) throws BadArgument {
222
+ if (value instanceof Number) {
223
+ final double number = ((Number) value).doubleValue();
224
+ if (number == Math.rint(number) && number >= 1 && number <= 5) {
225
+ return IssueSeverity.fromIntValue((int) number);
226
+ }
227
+ }
228
+ // Never the value itself: anything JSON allows can arrive here.
229
+ throw new BadArgument("severity must be an integer 1..5");
230
+ }
231
+
232
+ @NonNull
233
+ private static List<String> labels(@Nullable final Object value) throws BadArgument {
234
+ if (!(value instanceof List)) {
235
+ throw new BadArgument("labels must be an array of strings");
236
+ }
237
+ final List<String> result = new ArrayList<>();
238
+ for (final Object label : (List<?>) value) {
239
+ if (!(label instanceof String)) {
240
+ throw new BadArgument("labels must all be strings");
241
+ }
242
+ result.add((String) label);
243
+ }
244
+ return result;
245
+ }
246
+
247
+ @NonNull
248
+ private static Map<String, Object> attributes(@Nullable final Object value) throws BadArgument {
249
+ if (!(value instanceof Map)) {
250
+ throw new BadArgument("attributes must be a plain object");
251
+ }
252
+ final Map<String, Object> result = new HashMap<>();
253
+ for (final Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
254
+ final Object attribute = entry.getValue();
255
+ final boolean valid = attribute == null
256
+ || attribute instanceof String
257
+ || attribute instanceof Boolean
258
+ || (attribute instanceof Number && isFinite((Number) attribute));
259
+ if (!(entry.getKey() instanceof String) || !valid) {
260
+ throw new BadArgument("attribute \"" + entry.getKey()
261
+ + "\" must be a string, boolean, finite number or null");
262
+ }
263
+ // Parity with the JS proxy, which rejects it before crossing.
264
+ if (((String) entry.getKey()).isEmpty()) {
265
+ throw new BadArgument("attribute name must be a non-empty string");
266
+ }
267
+ result.put((String) entry.getKey(), attribute);
268
+ }
269
+ return result;
270
+ }
271
+
272
+ private static boolean isFinite(@NonNull final Number number) {
273
+ final double d = number.doubleValue();
274
+ return !Double.isNaN(d) && !Double.isInfinite(d);
275
+ }
276
+
277
+ /**
278
+ * The message a promise rejects with when a report operation faults with
279
+ * anything other than a {@link BadArgument}. Named by the operation only
280
+ * -- never the fault's own message, which can echo report content (a
281
+ * summary, an attribute value, a file path, an attachment name).
282
+ */
283
+ @NonNull
284
+ static String failureMessage(@NonNull final String operation) {
285
+ return operation + " failed";
286
+ }
287
+ }
@@ -0,0 +1,113 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import android.util.Log;
4
+
5
+ import androidx.annotation.NonNull;
6
+ import androidx.annotation.Nullable;
7
+
8
+ import java.util.concurrent.atomic.AtomicLong;
9
+ import java.util.concurrent.atomic.AtomicReference;
10
+
11
+ /**
12
+ * Serves the SDK's secure-rectangle pull, and uses each pull to keep the
13
+ * React root's display origin fresh.
14
+ *
15
+ * <p>The served rectangles are JS's measurements moved by the root's display
16
+ * origin, which {@link ReactRootOriginTracker} re-reads on a global layout, on
17
+ * resume and on a JS publish. None of those fires when the window moves
18
+ * without a relayout (freeform or desktop windowing, split-screen
19
+ * repositioning, picture-in-picture), and JS publishes only when a measurement
20
+ * changes. So the SDK's own pull, 2-3 times a second, also asks for a refresh.
21
+ * The refresh runs on the UI thread and lands in the store, and the NEXT pull
22
+ * serves it: a moved window is corrected within about one pull interval,
23
+ * whatever JS does. Without this, the region would be served at the window's
24
+ * old position and recorded in the clear where it now is.
25
+ *
26
+ * <p>The pull runs on the SDK's thread and must never block or throw there.
27
+ * Asking for a refresh only posts to the UI thread, at most once every
28
+ * {@link #ORIGIN_REFRESH_MIN_INTERVAL_MS}, and a failure to ask is logged and
29
+ * swallowed: the snapshot is served regardless.
30
+ *
31
+ * <p>Process-wide, like {@link SecureRectangleStore}: the wrapper the SDK pulls
32
+ * through is replaced mid-session, while the refresher belongs to whichever
33
+ * {@code BugseeModule} is live.
34
+ */
35
+ final class SecureRectanglePulls {
36
+
37
+ private static final String TAG = "BugseeRN";
38
+
39
+ /** The fastest the pull asks for an origin refresh. */
40
+ static final long ORIGIN_REFRESH_MIN_INTERVAL_MS = 100;
41
+
42
+ /** Milliseconds from a monotonic source. Injectable for tests. */
43
+ interface Clock {
44
+ long nowMs();
45
+ }
46
+
47
+ /** Before the first request: the first pull always asks. */
48
+ private static final long NEVER = Long.MIN_VALUE;
49
+
50
+ private static final SecureRectanglePulls SHARED = new SecureRectanglePulls(
51
+ SecureRectangleStore.shared(), () -> System.nanoTime() / 1_000_000L);
52
+
53
+ @NonNull
54
+ static SecureRectanglePulls shared() {
55
+ return SHARED;
56
+ }
57
+
58
+ private final SecureRectangleStore store;
59
+ private final Clock clock;
60
+ private final AtomicReference<Runnable> refresher = new AtomicReference<>();
61
+ private final AtomicLong lastRequestMs = new AtomicLong(NEVER);
62
+
63
+ SecureRectanglePulls(@NonNull final SecureRectangleStore store, @NonNull final Clock clock) {
64
+ this.store = store;
65
+ this.clock = clock;
66
+ }
67
+
68
+ /**
69
+ * Installs what a pull calls to ask for an origin refresh. It must only
70
+ * post to the UI thread, never touch a view itself: it runs on the SDK's
71
+ * pull thread.
72
+ */
73
+ void setRefresher(@NonNull final Runnable newRefresher) {
74
+ refresher.set(newRefresher);
75
+ }
76
+
77
+ /**
78
+ * Removes {@code expected}, if it is still the one installed. A reload can
79
+ * install the new module's refresher before the old module is
80
+ * invalidated, and an unconditional clear would then stop the live one.
81
+ */
82
+ void clearRefresher(@NonNull final Runnable expected) {
83
+ refresher.compareAndSet(expected, null);
84
+ }
85
+
86
+ /** The SDK's pull: the buffer for {@code display}, after asking for a refresh. */
87
+ @NonNull
88
+ int[] pull(final int display) {
89
+ requestOriginRefresh();
90
+ return store.snapshot(display);
91
+ }
92
+
93
+ private void requestOriginRefresh() {
94
+ final Runnable current = refresher.get();
95
+ if (current == null) {
96
+ return;
97
+ }
98
+ final long now = clock.nowMs();
99
+ final long last = lastRequestMs.get();
100
+ if (last != NEVER && now - last < ORIGIN_REFRESH_MIN_INTERVAL_MS) {
101
+ return;
102
+ }
103
+ // One winner per window when the SDK pulls several displays at once.
104
+ if (!lastRequestMs.compareAndSet(last, now)) {
105
+ return;
106
+ }
107
+ try {
108
+ current.run();
109
+ } catch (Throwable t) {
110
+ Log.w(TAG, "secure rectangles: could not schedule an origin refresh: " + t.getClass().getName());
111
+ }
112
+ }
113
+ }