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

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 +557 -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 +962 -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,127 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import androidx.annotation.Nullable;
4
+
5
+ import com.bugsee.library.contracts.reporting.Report;
6
+
7
+ /**
8
+ * The one created report this process may have outstanding.
9
+ *
10
+ * <p>A slot is taken by {@link #reserve()} or {@link #tryReserve()} and held
11
+ * until {@link #fulfil} stores a report, {@link #fulfil} is given null,
12
+ * {@link #take} removes the report, or {@link #clear} drops whatever is
13
+ * there. A second reserve while the slot is taken returns false. Handles are
14
+ * {@code cr-<n>}, numbered from 1 for the life of the process, and are not
15
+ * reused after a take or a clear.
16
+ *
17
+ * <p>{@link #clear()} does not cancel an SDK listener that is already in
18
+ * flight. Each reservation carries a stamp, and {@link #fulfil} ignores any
19
+ * stamp that is not the current one, so that listener cannot store its report
20
+ * into a reservation opened afterwards or free that reservation.
21
+ */
22
+ final class CreatedReports {
23
+
24
+ private static final CreatedReports SHARED = new CreatedReports();
25
+
26
+ /** True from a successful reserve until that reservation is ended. */
27
+ private boolean creating;
28
+
29
+ /**
30
+ * Stamp of the open reservation. {@code 0} is never a live stamp: it is
31
+ * what {@link #tryReserve()} returns when busy, and what {@link #clear()}
32
+ * and a finished {@link #fulfil} leave behind so every earlier stamp misses.
33
+ */
34
+ private int currentStamp;
35
+
36
+ /** Next stamp to issue. Skips {@code 0}, which means "not admitted". */
37
+ private int nextStamp = 1;
38
+
39
+ @Nullable
40
+ private Report report;
41
+
42
+ @Nullable
43
+ private String handle;
44
+
45
+ /** Next suffix. Never reset: a handle is fresh for the process. */
46
+ private int next = 1;
47
+
48
+ static CreatedReports shared() {
49
+ return SHARED;
50
+ }
51
+
52
+ /** Package-private so a test can build an instance that is not {@link #shared()}. */
53
+ CreatedReports() {
54
+ }
55
+
56
+ /** False while a created report is outstanding or being created. */
57
+ synchronized boolean reserve() {
58
+ return tryReserve() != 0;
59
+ }
60
+
61
+ /**
62
+ * {@code 0} when a report is outstanding or being created. Otherwise the
63
+ * stamp {@link #fulfil} must present to end this reservation.
64
+ */
65
+ synchronized int tryReserve() {
66
+ if (creating || report != null) {
67
+ return 0;
68
+ }
69
+ creating = true;
70
+ currentStamp = nextStamp;
71
+ nextStamp += 1;
72
+ if (nextStamp == 0) {
73
+ nextStamp = 1;
74
+ }
75
+ return currentStamp;
76
+ }
77
+
78
+ /**
79
+ * Ends the reservation {@code stamp} names. A report gets {@code cr-<n>}
80
+ * and holds the slot. Null frees the slot and mints nothing. A stamp that
81
+ * is not the current one, including every stamp issued before
82
+ * {@link #clear()}, changes nothing and returns null.
83
+ */
84
+ @Nullable
85
+ synchronized String fulfil(final int stamp, @Nullable final Report created) {
86
+ if (!creating || stamp == 0 || stamp != currentStamp) {
87
+ return null;
88
+ }
89
+ creating = false;
90
+ currentStamp = 0;
91
+ if (created == null) {
92
+ return null;
93
+ }
94
+ handle = "cr-" + next;
95
+ next += 1;
96
+ report = created;
97
+ return handle;
98
+ }
99
+
100
+ @Nullable
101
+ synchronized Report get(final String handleId) {
102
+ if (report != null && handleId != null && handleId.equals(handle)) {
103
+ return report;
104
+ }
105
+ return null;
106
+ }
107
+
108
+ /** Removes the report and frees the slot. An unknown handle removes nothing. */
109
+ @Nullable
110
+ synchronized Report take(final String handleId) {
111
+ final Report created = get(handleId);
112
+ if (created == null) {
113
+ return null;
114
+ }
115
+ report = null;
116
+ handle = null;
117
+ return created;
118
+ }
119
+
120
+ /** Drops the slot and makes every stamp issued so far fail {@link #fulfil}. */
121
+ synchronized void clear() {
122
+ creating = false;
123
+ report = null;
124
+ handle = null;
125
+ currentStamp = 0;
126
+ }
127
+ }
@@ -0,0 +1,375 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import android.util.Log;
7
+
8
+ import com.bugsee.library.contracts.internal.DataRequestTypes;
9
+
10
+ import java.nio.charset.StandardCharsets;
11
+ import java.util.Map;
12
+ import java.util.concurrent.ConcurrentHashMap;
13
+ import java.util.concurrent.ScheduledFuture;
14
+ import java.util.concurrent.ScheduledThreadPoolExecutor;
15
+ import java.util.concurrent.TimeUnit;
16
+ import java.util.concurrent.atomic.AtomicBoolean;
17
+ import java.util.concurrent.atomic.AtomicLong;
18
+ import java.util.concurrent.atomic.AtomicReference;
19
+
20
+ /**
21
+ * Answers the SDK's {@link DataRequestTypes#VIEW_HIERARCHY} data request from
22
+ * JS, through a table of opaque handles -- the same shape as {@link
23
+ * ReportHandlerBridge}, which this mirrors.
24
+ *
25
+ * <p>Every {@link #request} ends in exactly one reply to the SDK's callback,
26
+ * whichever of JS, the deadline, or a detach gets there first, guarded by one
27
+ * {@link AtomicBoolean} per outstanding request. The deadline ({@link
28
+ * #DEADLINE_MS}) is kept comfortably under the SDK's own budget ({@link
29
+ * DataRequestTypes#VIEW_HIERARCHY_TIMEOUT_MS}): a JS reply that lands after
30
+ * this bridge's own deadline has already fired finds its entry gone and is
31
+ * dropped (by {@link #complete} returning {@code false}), but the bridge's
32
+ * own {@code null} reply reaches the SDK comfortably before the SDK's own
33
+ * timeout would otherwise fire -- every outcome is logged either way (the
34
+ * plan's Phase 6 "Log lines").
35
+ *
36
+ * <p>Like {@link ReportHandlerBridge}, this outlives any one React instance:
37
+ * the wrapper that calls in is registered at process start, while the module
38
+ * that receives {@code onDataRequest} comes and goes with the JS runtime.
39
+ */
40
+ final class DataRequestBridge {
41
+
42
+ private static final String TAG = "BugseeRN";
43
+
44
+ /** Mirrors the SDK's own constant, rather than duplicating its value. */
45
+ static final String VIEW_HIERARCHY = DataRequestTypes.VIEW_HIERARCHY;
46
+
47
+ /**
48
+ * Comfortably under {@link DataRequestTypes#VIEW_HIERARCHY_TIMEOUT_MS}
49
+ * (500 ms): JS must get a chance to reply before the SDK's own timeout
50
+ * fires and starts ignoring it.
51
+ */
52
+ static final long DEADLINE_MS = 450;
53
+
54
+ /** What the module implements to emit {@code onDataRequest}. */
55
+ interface Sink {
56
+ void onDataRequest(String requestId, String type, int originX, int originY);
57
+ }
58
+
59
+ /** The React root's current display origin. Called on the requesting (main) thread. */
60
+ interface OriginSource {
61
+ @Nullable
62
+ int[] currentOrigin();
63
+ }
64
+
65
+ /** What {@link #request} calls back with the answer. */
66
+ interface Reply {
67
+ void onResult(@Nullable String data);
68
+ }
69
+
70
+ interface Cancellable {
71
+ void cancel();
72
+ }
73
+
74
+ /** Arms a request's deadline. Injectable so tests control time. */
75
+ interface Scheduler {
76
+ Cancellable schedule(Runnable task, long delayMs);
77
+ }
78
+
79
+ /** Its own interface: {@code java.util.function} needs API 24, minSdk is 21. */
80
+ interface Clock {
81
+ long nowMs();
82
+ }
83
+
84
+ /**
85
+ * Where the one-line outcome of every request goes. Logcat in production,
86
+ * where the device tests match these lines (the plan's Phase 6 "Log
87
+ * lines"); injectable so the JVM tests can pin the exact formats too.
88
+ */
89
+ interface OutcomeLog {
90
+ void line(String message);
91
+ }
92
+
93
+ private static final class Entry {
94
+ final String id;
95
+ final Reply reply;
96
+ /** The sink this request was emitted to; its detach completes it. */
97
+ final Sink owner;
98
+ /** Taken on entry to {@link #request}, before any check. */
99
+ final long startMs;
100
+ /** The exactly-once guard. Whoever flips it runs the reply. */
101
+ final AtomicBoolean done = new AtomicBoolean();
102
+ volatile Cancellable timer;
103
+
104
+ Entry(final String id, final Reply reply, final Sink owner, final long startMs) {
105
+ this.id = id;
106
+ this.reply = reply;
107
+ this.owner = owner;
108
+ this.startMs = startMs;
109
+ }
110
+ }
111
+
112
+ private static final DataRequestBridge SHARED =
113
+ new DataRequestBridge(new DaemonScheduler(), () -> System.nanoTime() / 1_000_000L);
114
+
115
+ @NonNull
116
+ static DataRequestBridge shared() {
117
+ return SHARED;
118
+ }
119
+
120
+ private final Scheduler scheduler;
121
+ private final Clock clock;
122
+ private final OutcomeLog outcomes;
123
+ private final AtomicReference<Sink> sink = new AtomicReference<>();
124
+ @Nullable
125
+ private volatile OriginSource origin;
126
+ private final Map<String, Entry> entries = new ConcurrentHashMap<>();
127
+ private final AtomicLong counter = new AtomicLong();
128
+ private volatile boolean viewTreeEnabled;
129
+
130
+ DataRequestBridge(@NonNull final Scheduler scheduler, @NonNull final Clock clock) {
131
+ this(scheduler, clock, message -> Log.i(TAG, message));
132
+ }
133
+
134
+ DataRequestBridge(
135
+ @NonNull final Scheduler scheduler,
136
+ @NonNull final Clock clock,
137
+ @NonNull final OutcomeLog outcomes
138
+ ) {
139
+ this.scheduler = scheduler;
140
+ this.clock = clock;
141
+ this.outcomes = outcomes;
142
+ }
143
+
144
+ /**
145
+ * The attached runtime's anchor mounted ({@code true}) or unmounted
146
+ * ({@code false}). A caller that is not the attached sink is ignored.
147
+ * The flag is process-wide, and a reload can still run the old module's
148
+ * last {@code setViewTreeEnabled(false)} after the new module has
149
+ * attached and enabled — the same window {@link #detach} already
150
+ * identity-checks. Applying that write would leave the live runtime at
151
+ * {@code by=no-js} until its anchor count passed through zero again.
152
+ */
153
+ void setViewTreeEnabled(@NonNull final Sink caller, final boolean enabled) {
154
+ if (sink.get() == caller) {
155
+ viewTreeEnabled = enabled;
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Attaches the module of a new JS runtime, which has not enabled the view
161
+ * tree yet -- that only happens once its own anchor mounts. The flag and
162
+ * the origin are cleared BEFORE the sink is published: a {@link #request}
163
+ * that reads the new sink must never see the previous runtime's leftover
164
+ * state.
165
+ */
166
+ void attach(@NonNull final Sink newSink, @NonNull final OriginSource newOrigin) {
167
+ viewTreeEnabled = false;
168
+ origin = newOrigin;
169
+ sink.set(newSink);
170
+ }
171
+
172
+ /**
173
+ * Completes every request emitted to {@code stale} with {@code null}:
174
+ * nothing in any other JS runtime knows them, so waiting for their
175
+ * deadlines would only delay the SDK's capture. Clears the sink, the
176
+ * origin and the enabled flag only if {@code stale} is still the attached
177
+ * one -- a fast reload attaches the new module before the old one is
178
+ * invalidated, and an unconditional clear would silence it.
179
+ */
180
+ void detach(@NonNull final Sink stale) {
181
+ if (sink.compareAndSet(stale, null)) {
182
+ origin = null;
183
+ viewTreeEnabled = false;
184
+ }
185
+ for (final Entry entry : entries.values()) {
186
+ if (entry.owner == stale) {
187
+ finish(entry, null, "detach");
188
+ }
189
+ }
190
+ }
191
+
192
+ /**
193
+ * The number of requests currently outstanding (minted, not yet
194
+ * completed). Package-private, for tests: every terminal path must leave
195
+ * this at zero.
196
+ */
197
+ int outstanding() {
198
+ return entries.size();
199
+ }
200
+
201
+ /**
202
+ * Requests data of {@code type}, never throwing. See the class doc for
203
+ * the ordering: an unknown type, no live sink (or a disabled view tree),
204
+ * and no known origin all reply {@code null} synchronously; only then is
205
+ * a request actually minted and emitted.
206
+ */
207
+ void request(@NonNull final String type, @NonNull final Reply reply) {
208
+ // Taken as the first statement: the plan's "ms" is measured from the
209
+ // moment requestData was entered, not from whenever a request happens
210
+ // to be minted.
211
+ final long start = clock.nowMs();
212
+ final String id = "dr-" + counter.incrementAndGet();
213
+ Entry entry = null;
214
+ try {
215
+ if (!VIEW_HIERARCHY.equals(type)) {
216
+ resolveUnminted(id, start, reply, "unknown-type");
217
+ return;
218
+ }
219
+ final Sink target = sink.get();
220
+ if (target == null || !viewTreeEnabled) {
221
+ resolveUnminted(id, start, reply, "no-js");
222
+ return;
223
+ }
224
+ final OriginSource originSource = origin;
225
+ final int[] currentOrigin = originSource == null ? null : originSource.currentOrigin();
226
+ if (currentOrigin == null) {
227
+ resolveUnminted(id, start, reply, "no-origin");
228
+ return;
229
+ }
230
+
231
+ entry = new Entry(id, reply, target, start);
232
+ entries.put(entry.id, entry);
233
+ final Entry armed = entry;
234
+ final Cancellable timer = scheduler.schedule(() -> finish(armed, null, "deadline"), DEADLINE_MS);
235
+ armed.timer = timer;
236
+ if (armed.done.get()) {
237
+ // Finished between put and here; don't leave the timer armed.
238
+ cancelQuietly(timer);
239
+ }
240
+ // The real race: a detach() ran after the sink was read above but
241
+ // before the entry was in the table, so its sweep could not see
242
+ // this one. Whichever side comes second must still catch it --
243
+ // otherwise it emits to a dead runtime and waits out the whole
244
+ // deadline for nothing.
245
+ if (sink.get() != target) {
246
+ finish(armed, null, "detach");
247
+ return;
248
+ }
249
+ outcomes.line("data request " + id + " type=" + type
250
+ + " origin=" + currentOrigin[0] + "," + currentOrigin[1]);
251
+ try {
252
+ target.onDataRequest(id, type, currentOrigin[0], currentOrigin[1]);
253
+ } catch (final Throwable e) {
254
+ // A dead bridge throws from the emit, on the SDK's thread. JS
255
+ // will never answer, so answer for it now.
256
+ Log.w(TAG, "data request " + id + " could not reach JS: " + e.getClass().getName());
257
+ finish(armed, null, "sink-threw");
258
+ }
259
+ } catch (final Throwable e) {
260
+ // Never throws: this runs on the SDK's own thread mid-capture,
261
+ // where an exception would either crash the host or stall the
262
+ // pass until the SDK's own timeout. If a request was already
263
+ // minted (entries.put succeeded but something after it threw --
264
+ // e.g. the scheduler rejecting the task), it must still be
265
+ // completed through finish(): replying directly here and leaving
266
+ // the entry behind would both leak it and let a later detach()
267
+ // reply to the SDK a second time.
268
+ Log.w(TAG, "data request failed unexpectedly: " + e.getClass().getName());
269
+ if (entry != null) {
270
+ finish(entry, null, "failed");
271
+ } else {
272
+ resolveUnminted(id, start, reply, "failed");
273
+ }
274
+ }
275
+ }
276
+
277
+ /**
278
+ * @return true only for the call that delivered the payload. {@code
279
+ * null} is treated as an unknown id rather than throwing: {@code
280
+ * replyDataRequest} is a void TurboModule method, and JS always echoes
281
+ * the id it was given, so this only guards against misuse.
282
+ */
283
+ boolean complete(@Nullable final String requestId, @Nullable final String payload) {
284
+ if (requestId == null) {
285
+ return false;
286
+ }
287
+ final Entry entry = entries.get(requestId);
288
+ return entry != null && finish(entry, payload, "js");
289
+ }
290
+
291
+ private boolean finish(@NonNull final Entry entry, @Nullable final String payload, @NonNull final String by) {
292
+ if (!entry.done.compareAndSet(false, true)) {
293
+ return false;
294
+ }
295
+ entries.remove(entry.id, entry);
296
+ final Cancellable timer = entry.timer;
297
+ if (timer != null) {
298
+ cancelQuietly(timer);
299
+ }
300
+ runQuietly(entry.reply, payload);
301
+ logCompleted(entry.id, by, payload, entry.startMs);
302
+ return true;
303
+ }
304
+
305
+ /** No request was minted; the line still names the outcome for correlation. */
306
+ private void resolveUnminted(
307
+ @NonNull final String id,
308
+ final long startMs,
309
+ @NonNull final Reply reply,
310
+ @NonNull final String by
311
+ ) {
312
+ runQuietly(reply, null);
313
+ logCompleted(id, by, null, startMs);
314
+ }
315
+
316
+ /**
317
+ * {@code data request <id> completed by=<…> bytes=<n|null> ms=<elapsed>},
318
+ * verbatim from the plan's Phase 6 "Log lines". {@code bytes} is the
319
+ * UTF-8 byte count of the payload, not its UTF-16 character length --
320
+ * iOS's {@code BGSRNDataRequestBridge} (Task 6.6) must use the same
321
+ * definition so the two platforms' bundles read the same way.
322
+ */
323
+ private void logCompleted(
324
+ @NonNull final String id,
325
+ @NonNull final String by,
326
+ @Nullable final String payload,
327
+ final long startMs
328
+ ) {
329
+ outcomes.line("data request " + id + " completed by=" + by
330
+ + " bytes=" + bytesOf(payload) + " ms=" + (clock.nowMs() - startMs));
331
+ }
332
+
333
+ @NonNull
334
+ private static String bytesOf(@Nullable final String payload) {
335
+ return payload == null ? "null" : String.valueOf(payload.getBytes(StandardCharsets.UTF_8).length);
336
+ }
337
+
338
+ /** Whatever JS's reply implementation does, it must not escape onto the SDK's thread. */
339
+ private static void runQuietly(@NonNull final Reply reply, @Nullable final String payload) {
340
+ try {
341
+ reply.onResult(payload);
342
+ } catch (final Throwable e) {
343
+ Log.w(TAG, "data request reply threw: " + e.getClass().getName());
344
+ }
345
+ }
346
+
347
+ private static void cancelQuietly(@NonNull final Cancellable timer) {
348
+ try {
349
+ timer.cancel();
350
+ } catch (final Throwable e) {
351
+ Log.w(TAG, "data request timer cancel threw: " + e.getClass().getName());
352
+ }
353
+ }
354
+
355
+ /** One daemon thread, started on first use, for every request's deadline. */
356
+ private static final class DaemonScheduler implements Scheduler {
357
+ private final ScheduledThreadPoolExecutor executor;
358
+
359
+ DaemonScheduler() {
360
+ executor = new ScheduledThreadPoolExecutor(1, runnable -> {
361
+ final Thread thread = new Thread(runnable, "BugseeRN-DataRequestDeadline");
362
+ thread.setDaemon(true);
363
+ return thread;
364
+ });
365
+ // A request completed by JS should not leave a dead task queued.
366
+ executor.setRemoveOnCancelPolicy(true);
367
+ }
368
+
369
+ @Override
370
+ public Cancellable schedule(final Runnable task, final long delayMs) {
371
+ final ScheduledFuture<?> future = executor.schedule(task, delayMs, TimeUnit.MILLISECONDS);
372
+ return () -> future.cancel(false);
373
+ }
374
+ }
375
+ }
@@ -0,0 +1,88 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import android.util.Log;
7
+
8
+ import java.util.Map;
9
+
10
+ /**
11
+ * Turns a JS exception payload (and optional options JSON) into the SDK's
12
+ * {@code logException} / {@code logUnhandledException} calls. Plain Java so
13
+ * the rules here are unit-tested without React Native or a device.
14
+ *
15
+ * <p>Both send paths never throw: a bad options blob is logged (message only,
16
+ * never the text) and the exception is still sent without a domain; a throwing
17
+ * SDK is swallowed the same way every other void bridge method defends the
18
+ * host.
19
+ */
20
+ final class ExceptionBridge {
21
+
22
+ private static final String TAG = "BugseeRN";
23
+
24
+ /** What the module implements against; the production adapter calls {@code Bugsee.*}. */
25
+ interface Sdk {
26
+ void logException(Throwable t, @Nullable String domain);
27
+
28
+ void logUnhandledException(Throwable t, @Nullable Map<String, Object> options);
29
+ }
30
+
31
+ private ExceptionBridge() {
32
+ }
33
+
34
+ /**
35
+ * The exception domain of the options text; other keys are dropped (labels
36
+ * and {@code includeVideo} are no longer options). {@code null} for null
37
+ * text or no domain.
38
+ *
39
+ * @throws BridgeJson.BadJson when the text is unparseable, or the domain
40
+ * is not a string.
41
+ */
42
+ @Nullable
43
+ static String domain(@Nullable final String optionsJson) throws BridgeJson.BadJson {
44
+ if (optionsJson == null) {
45
+ return null;
46
+ }
47
+ final Map<String, Object> raw = BridgeJson.parseObject(optionsJson);
48
+ if (!raw.containsKey("domain")) {
49
+ return null;
50
+ }
51
+ final Object domain = raw.get("domain");
52
+ if (!(domain instanceof String)) {
53
+ throw new BridgeJson.BadJson("domain must be a string");
54
+ }
55
+ return (String) domain;
56
+ }
57
+
58
+ /**
59
+ * Never throws. Bad options are logged (code only) and the exception is
60
+ * still sent, without options.
61
+ */
62
+ static void logHandled(
63
+ @NonNull final Sdk sdk,
64
+ @NonNull final String payloadJson,
65
+ @Nullable final String optionsJson
66
+ ) {
67
+ String domain = null;
68
+ try {
69
+ domain = domain(optionsJson);
70
+ } catch (final BridgeJson.BadJson e) {
71
+ Log.e(TAG, "exception options rejected: " + e.getMessage());
72
+ }
73
+ try {
74
+ sdk.logException(new ReactNativeWebException(payloadJson), domain);
75
+ } catch (final RuntimeException e) {
76
+ Log.e(TAG, "logException failed: " + e.getClass().getName());
77
+ }
78
+ }
79
+
80
+ /** Never throws. */
81
+ static void logUnhandled(@NonNull final Sdk sdk, @NonNull final String payloadJson) {
82
+ try {
83
+ sdk.logUnhandledException(new ReactNativeWebException(payloadJson), null);
84
+ } catch (final RuntimeException e) {
85
+ Log.e(TAG, "logUnhandledException failed: " + e.getClass().getName());
86
+ }
87
+ }
88
+ }
@@ -0,0 +1,33 @@
1
+ package com.bugsee.reactnative;
2
+
3
+ import java.util.concurrent.Executor;
4
+ import java.util.concurrent.Executors;
5
+
6
+ /**
7
+ * Where {@code Bugsee.logException} and {@code logUnhandledException} run.
8
+ *
9
+ * <p>Android 7.3.0 blocks the caller for the view hierarchy. That caller must
10
+ * not be the React Native modules thread, or the hierarchy request cannot be
11
+ * answered. Handled and unhandled do not share a queue: JS waits at most
12
+ * 1500 ms for an unhandled report, and a handled backlog on one thread would
13
+ * spend that wait before the fatal call starts.
14
+ */
15
+ final class ExceptionExecutors {
16
+
17
+ /** Handled reports. A backlog here must not delay {@link #UNHANDLED}. */
18
+ static final Executor HANDLED = singleThread("BugseeRN-exceptions");
19
+
20
+ /** Fatal reports. Starts even while {@link #HANDLED} is blocked in the SDK. */
21
+ static final Executor UNHANDLED = singleThread("BugseeRN-fatal");
22
+
23
+ private ExceptionExecutors() {
24
+ }
25
+
26
+ private static Executor singleThread(final String name) {
27
+ return Executors.newSingleThreadExecutor(r -> {
28
+ final Thread thread = new Thread(r, name);
29
+ thread.setDaemon(true);
30
+ return thread;
31
+ });
32
+ }
33
+ }