@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.
- package/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +557 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +962 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.bugsee.library.contracts.options.FrameRate;
|
|
7
|
+
import com.bugsee.library.contracts.options.IssueSeverity;
|
|
8
|
+
import com.bugsee.library.contracts.options.LogLevel;
|
|
9
|
+
import com.bugsee.library.contracts.options.VideoMode;
|
|
10
|
+
import com.bugsee.library.contracts.options.VideoQuality;
|
|
11
|
+
|
|
12
|
+
import java.io.Serializable;
|
|
13
|
+
import java.util.Collections;
|
|
14
|
+
import java.util.HashMap;
|
|
15
|
+
import java.util.Map;
|
|
16
|
+
import java.util.Set;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Turns the numbers JS sends into the enum instances the Android SDK expects.
|
|
20
|
+
*
|
|
21
|
+
* <p>iOS consumes these numbers directly; Android's Map path does not coerce,
|
|
22
|
+
* so an enum-typed option arriving as a number is ignored unless converted
|
|
23
|
+
* here.
|
|
24
|
+
*
|
|
25
|
+
* <p><strong>The number is the enum's internal value, never its ordinal.</strong>
|
|
26
|
+
* The two diverge on four of the five option enums — {@code LogLevel.Error} is
|
|
27
|
+
* value 1 at ordinal 0, {@code VideoMode.Fullscreen} is value 20 at ordinal 3,
|
|
28
|
+
* and {@code FrameRate} and {@code IssueSeverity} are likewise offset by one.
|
|
29
|
+
* Only {@code VideoQuality} coincides. So conversion goes through each enum's
|
|
30
|
+
* own {@code fromIntValue} / {@code fromRawValue} and never {@code values()[n]}:
|
|
31
|
+
* an ordinal lookup returns a valid but DIFFERENT constant, which the SDK then
|
|
32
|
+
* honours, and nothing reports it.
|
|
33
|
+
*
|
|
34
|
+
* <p>The internal values are also what iOS uses, so one number is correct on
|
|
35
|
+
* both platforms — which is the whole reason the wrapper sends numbers.
|
|
36
|
+
*/
|
|
37
|
+
final class BugseeOptionEnums {
|
|
38
|
+
|
|
39
|
+
/** Converts one number, or returns null when no constant carries it. */
|
|
40
|
+
private interface Coercion {
|
|
41
|
+
@Nullable
|
|
42
|
+
Serializable apply(int value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private static final Map<String, Coercion> BY_KEY = new HashMap<>();
|
|
46
|
+
|
|
47
|
+
static {
|
|
48
|
+
BY_KEY.put("com.bugsee.option.capture.logs.level",
|
|
49
|
+
value -> LogLevel.fromRawValue((byte) value));
|
|
50
|
+
BY_KEY.put("com.bugsee.option.capture.video.mode",
|
|
51
|
+
VideoMode::fromIntValue);
|
|
52
|
+
BY_KEY.put("com.bugsee.option.capture.video.quality",
|
|
53
|
+
VideoQuality::fromIntValue);
|
|
54
|
+
BY_KEY.put("com.bugsee.option.capture.video.frame-rate",
|
|
55
|
+
FrameRate::fromIntValue);
|
|
56
|
+
// The one-argument fromIntValue falls back to VeryLow for ANY unknown
|
|
57
|
+
// number, so 0 or 6 would be honoured as "very low" and wireValue
|
|
58
|
+
// would answer 0 for VeryLow. The two-argument form with a null
|
|
59
|
+
// default returns null for what no constant carries.
|
|
60
|
+
BY_KEY.put("com.bugsee.option.reporting.defaults.crash-priority",
|
|
61
|
+
value -> IssueSeverity.fromIntValue(value, null));
|
|
62
|
+
BY_KEY.put("com.bugsee.option.reporting.defaults.error-priority",
|
|
63
|
+
value -> IssueSeverity.fromIntValue(value, null));
|
|
64
|
+
BY_KEY.put("com.bugsee.option.reporting.defaults.bug-priority",
|
|
65
|
+
value -> IssueSeverity.fromIntValue(value, null));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private BugseeOptionEnums() {
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The enum constant for {@code value} under {@code key}, or null when the
|
|
73
|
+
* key is not enum-typed or no constant carries that value.
|
|
74
|
+
*
|
|
75
|
+
* <p>Null for an unknown value is deliberate: the option is then absent
|
|
76
|
+
* and the SDK applies its own default, which is the honest outcome for a
|
|
77
|
+
* number the wrapper cannot interpret. Snapping to a nearby constant would
|
|
78
|
+
* look like the option was honoured.
|
|
79
|
+
*/
|
|
80
|
+
@Nullable
|
|
81
|
+
static Serializable coerce(@NonNull final String key, final int value) {
|
|
82
|
+
final Coercion coercion = BY_KEY.get(key);
|
|
83
|
+
return coercion == null ? null : coercion.apply(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* What to store for a numeric option, or null to drop it.
|
|
88
|
+
*
|
|
89
|
+
* <p>JS has one number type, so every number arrives as a double. An
|
|
90
|
+
* enum-typed key needs an exact integer: 20.5 names no constant, and
|
|
91
|
+
* truncating it would silently pick one.
|
|
92
|
+
*/
|
|
93
|
+
@Nullable
|
|
94
|
+
static Serializable numberFor(@NonNull final String key, final double raw) {
|
|
95
|
+
if (!isEnumKey(key)) {
|
|
96
|
+
return raw;
|
|
97
|
+
}
|
|
98
|
+
if (Double.isNaN(raw) || Double.isInfinite(raw) || raw != Math.rint(raw)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return coerce(key, (int) raw);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Whether this key carries an enum rather than a scalar. */
|
|
105
|
+
static boolean isEnumKey(@NonNull final String key) {
|
|
106
|
+
return BY_KEY.containsKey(key);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The number an enum constant travels back as.
|
|
111
|
+
*
|
|
112
|
+
* Its INTERNAL VALUE, found by asking the enum's own converter which value
|
|
113
|
+
* maps to it -- never {@code ordinal()}, for the same reason the inbound
|
|
114
|
+
* direction never uses {@code values()[n]}. Round-tripping through the
|
|
115
|
+
* ordinal would hand JS a different constant than the one in effect.
|
|
116
|
+
*/
|
|
117
|
+
static double wireValue(@NonNull final Object constant) {
|
|
118
|
+
for (final Coercion coercion : BY_KEY.values()) {
|
|
119
|
+
for (int value = 0; value <= MAX_ENUM_VALUE; value++) {
|
|
120
|
+
if (constant.equals(coercion.apply(value))) {
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return -1;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** DirectBuffers, at 21, is the largest value any option enum carries. */
|
|
129
|
+
private static final int MAX_ENUM_VALUE = 64;
|
|
130
|
+
|
|
131
|
+
/** Every enum-typed key, so a test can assert the table is complete. */
|
|
132
|
+
@NonNull
|
|
133
|
+
static Set<String> enumKeys() {
|
|
134
|
+
return Collections.unmodifiableSet(BY_KEY.keySet());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.BaseReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
10
|
+
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What autolinking finds. The app never names it; `autolinkLibrariesFromCommand`
|
|
16
|
+
* discovers this class and writes it into the generated PackageList.
|
|
17
|
+
*/
|
|
18
|
+
public class BugseePackage extends BaseReactPackage {
|
|
19
|
+
|
|
20
|
+
@Nullable
|
|
21
|
+
@Override
|
|
22
|
+
public NativeModule getModule(final String name, final ReactApplicationContext context) {
|
|
23
|
+
return BugseeModule.NAME.equals(name) ? new BugseeModule(context) : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
28
|
+
return () -> {
|
|
29
|
+
final Map<String, ReactModuleInfo> modules = new HashMap<>();
|
|
30
|
+
modules.put(
|
|
31
|
+
BugseeModule.NAME,
|
|
32
|
+
new ReactModuleInfo(
|
|
33
|
+
BugseeModule.NAME,
|
|
34
|
+
BugseeModule.NAME,
|
|
35
|
+
/* canOverrideExistingModule */ false,
|
|
36
|
+
/* needsEagerInit */ false,
|
|
37
|
+
/* isCxxModule */ false,
|
|
38
|
+
/* isTurboModule */ true));
|
|
39
|
+
return modules;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.bugsee.library.contracts.common.DataRequestResultCallback;
|
|
7
|
+
import com.bugsee.library.contracts.internal.BugseeWrapper;
|
|
8
|
+
import com.bugsee.library.contracts.internal.BugseeWrapperChannel;
|
|
9
|
+
import com.bugsee.library.contracts.reporting.Report;
|
|
10
|
+
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.HashMap;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What the SDK asks a wrapper to say about itself.
|
|
17
|
+
*
|
|
18
|
+
* The values are gathered in JS and handed down, because that is where they
|
|
19
|
+
* are knowable: the React Native version comes from
|
|
20
|
+
* {@code Platform.constants}, the engine from whether Hermes installed its
|
|
21
|
+
* global, and the build configuration from {@code __DEV__}. Nothing here
|
|
22
|
+
* infers them natively, which would produce a second, disagreeing answer.
|
|
23
|
+
*
|
|
24
|
+
* <p>Lifecycle events, secure rectangles, report handling and the wrapper
|
|
25
|
+
* channel are the other halves of this contract; each is forwarded to a
|
|
26
|
+
* process-wide object that outlives this instance.
|
|
27
|
+
*/
|
|
28
|
+
final class BugseeReactNativeWrapper implements BugseeWrapper {
|
|
29
|
+
|
|
30
|
+
private final String type;
|
|
31
|
+
private final String version;
|
|
32
|
+
@Nullable
|
|
33
|
+
private final String build;
|
|
34
|
+
private final Map<String, String> context;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The backend's identifier for this wrapper. Duplicated from
|
|
38
|
+
* {@code WRAPPER_TYPE} in {@code src/wrapper/identity.ts} because the
|
|
39
|
+
* provider registers before any JS exists to supply it; a test compares
|
|
40
|
+
* the two so they cannot drift into two different wrappers.
|
|
41
|
+
*/
|
|
42
|
+
static final String WRAPPER_TYPE = "react_native";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The identity the SDK gets before React Native has a JS runtime.
|
|
46
|
+
*
|
|
47
|
+
* <p>Type and version only. Everything else in the full identity — the
|
|
48
|
+
* React Native version, the engine, the build configuration — is a JS-side
|
|
49
|
+
* fact, and inferring it natively would produce a second, disagreeing
|
|
50
|
+
* answer. {@code setWrapperInfo} replaces this with the complete identity
|
|
51
|
+
* as soon as the bridge is up.
|
|
52
|
+
*/
|
|
53
|
+
@NonNull
|
|
54
|
+
static BugseeReactNativeWrapper withoutJsRuntime() {
|
|
55
|
+
return new BugseeReactNativeWrapper(
|
|
56
|
+
WRAPPER_TYPE,
|
|
57
|
+
BuildConfig.WRAPPER_VERSION,
|
|
58
|
+
null,
|
|
59
|
+
Collections.<String, String>emptyMap()
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
BugseeReactNativeWrapper(
|
|
64
|
+
@NonNull final String type,
|
|
65
|
+
@NonNull final String version,
|
|
66
|
+
@Nullable final String build,
|
|
67
|
+
@NonNull final Map<String, String> context
|
|
68
|
+
) {
|
|
69
|
+
this.type = type;
|
|
70
|
+
this.version = version;
|
|
71
|
+
this.build = build;
|
|
72
|
+
this.context = Collections.unmodifiableMap(new HashMap<>(context));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public String getWrapperType() {
|
|
77
|
+
return type;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Override
|
|
81
|
+
public String getWrapperVersion() {
|
|
82
|
+
return version;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
@Nullable
|
|
87
|
+
public String getWrapperBuild() {
|
|
88
|
+
return build;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Override
|
|
92
|
+
public Map<String, String> getContext() {
|
|
93
|
+
return context;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Override
|
|
97
|
+
public void onLifecycleEvent(@NonNull final String eventType, @Nullable final Object data) {
|
|
98
|
+
// Through the bus rather than straight to the bridge: this wrapper is
|
|
99
|
+
// registered before React Native exists and is replaced once it does,
|
|
100
|
+
// while the bridge itself appears late and can be torn down by a
|
|
101
|
+
// reload. The two lifetimes do not line up, so neither side holds the
|
|
102
|
+
// other. See WrapperEventBus.
|
|
103
|
+
WrapperEventBus.shared().emitLifecycle(eventType, reportIdFrom(data));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The report id an event carries, when it carries one.
|
|
108
|
+
*
|
|
109
|
+
* <p>The SDK types the payload as {@code Object} because most events carry
|
|
110
|
+
* nothing; the ones that do carry the id as a string. Anything else is
|
|
111
|
+
* ignored rather than stringified -- a JS caller reading `reportId` should
|
|
112
|
+
* get the id or nothing, never a toString of some future payload shape.
|
|
113
|
+
*/
|
|
114
|
+
@Nullable
|
|
115
|
+
private static String reportIdFrom(@Nullable final Object data) {
|
|
116
|
+
return data instanceof String ? (String) data : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Stores the channel in the process-wide holder, and does nothing else.
|
|
121
|
+
*
|
|
122
|
+
* <p>Runs inside {@code Bugsee.setWrapper}, under the SDK's registration
|
|
123
|
+
* lock, so it must not block or take a lock. Storing is the first
|
|
124
|
+
* statement for a harder reason: if anything threw before it, registering
|
|
125
|
+
* this same instance again is a no-op and would deliver no replacement.
|
|
126
|
+
* Held outside this instance because {@code setWrapperInfo} replaces it.
|
|
127
|
+
*/
|
|
128
|
+
@Override
|
|
129
|
+
public void onWrapperChannelAvailable(@NonNull final BugseeWrapperChannel channel) {
|
|
130
|
+
WrapperChannelHolder.shared().set(channel);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The packed buffer the SDK expects: {@code [version, count, l,t,r,b, ...]}.
|
|
135
|
+
*
|
|
136
|
+
* <p>Read from the process-wide store rather than from this instance: the
|
|
137
|
+
* SDK pulls 2-3 times a second on a background thread, and the wrapper it
|
|
138
|
+
* pulls through is replaced when setWrapperInfo runs. See
|
|
139
|
+
* {@link SecureRectangleStore} for the version contract, which is what
|
|
140
|
+
* makes the SDK notice a change at all.
|
|
141
|
+
*
|
|
142
|
+
* <p>Through {@link SecureRectanglePulls}, which also uses the pull to keep
|
|
143
|
+
* the React root's display origin fresh when the window moves without a
|
|
144
|
+
* relayout.
|
|
145
|
+
*/
|
|
146
|
+
@Override
|
|
147
|
+
public int[] getSecureRectangles(final int display) {
|
|
148
|
+
return SecureRectanglePulls.shared().pull(display);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Hands the report to JS through the process-wide bridge, which owns
|
|
153
|
+
* running {@code completionCallback} exactly once on every path -- the
|
|
154
|
+
* pipeline waits on it, so failing to call it stalls the report rather
|
|
155
|
+
* than merely skipping our contribution. Through the bridge rather than
|
|
156
|
+
* held here for the same reason as the lifecycle events: this wrapper
|
|
157
|
+
* instance is replaced mid-session.
|
|
158
|
+
*/
|
|
159
|
+
@Override
|
|
160
|
+
public void onBeforeReportCreated(
|
|
161
|
+
@NonNull final Report report,
|
|
162
|
+
final boolean isTerminating,
|
|
163
|
+
@NonNull final Runnable completionCallback
|
|
164
|
+
) {
|
|
165
|
+
ReportHandlerBridge.shared().dispatch(
|
|
166
|
+
ReportHandlerBridge.Phase.BEFORE, report, isTerminating, completionCallback);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@Override
|
|
170
|
+
public void onAfterReportCreated(
|
|
171
|
+
@NonNull final Report report,
|
|
172
|
+
final boolean isTerminating,
|
|
173
|
+
@NonNull final Runnable completionCallback
|
|
174
|
+
) {
|
|
175
|
+
ReportHandlerBridge.shared().dispatch(
|
|
176
|
+
ReportHandlerBridge.Phase.AFTER, report, isTerminating, completionCallback);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The SDK asks a wrapper for data it cannot see itself — today only
|
|
181
|
+
* {@code "vh"}, the JS view hierarchy, which the capture builder requests
|
|
182
|
+
* while composing a frame.
|
|
183
|
+
*
|
|
184
|
+
* <p>Through the process-wide {@link DataRequestBridge} rather than held
|
|
185
|
+
* here, for the same reason as the lifecycle events and the report
|
|
186
|
+
* handler: this wrapper instance is replaced mid-session, while the
|
|
187
|
+
* bridge and the module it emits to have their own, different lifetimes.
|
|
188
|
+
* The bridge owns answering the callback exactly once — an unsupported
|
|
189
|
+
* type, a JS side with nothing to contribute, or a request that JS never
|
|
190
|
+
* gets to all answer with {@code null} — because a provider that never
|
|
191
|
+
* calls back leaves the SDK waiting mid-capture.
|
|
192
|
+
*/
|
|
193
|
+
@Override
|
|
194
|
+
public void requestData(
|
|
195
|
+
@NonNull final String dataType,
|
|
196
|
+
@NonNull final DataRequestResultCallback callback
|
|
197
|
+
) {
|
|
198
|
+
DataRequestBridge.shared().request(dataType, callback::onResult);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.bugsee.library.contracts.lifecycle.BugseeStatus;
|
|
6
|
+
|
|
7
|
+
import java.util.Collections;
|
|
8
|
+
import java.util.EnumMap;
|
|
9
|
+
import java.util.Map;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Translates the SDK's lifecycle status into the numbers the JS layer uses.
|
|
13
|
+
*
|
|
14
|
+
* <p>The wire numbers are part of the JS API (`Status` in index.ts) and are
|
|
15
|
+
* shared with the iOS bridge, so they are fixed here rather than derived from
|
|
16
|
+
* the enum's ordinal — an SDK reordering its constants must not silently
|
|
17
|
+
* change what JS sees.
|
|
18
|
+
*
|
|
19
|
+
* <p>One table drives both {@link #toWire} and {@link #isMapped}. An earlier
|
|
20
|
+
* version duplicated the mapping as two switch statements, which meant they
|
|
21
|
+
* could disagree, and meant {@code isMapped} could be stubbed out without any
|
|
22
|
+
* test noticing.
|
|
23
|
+
*/
|
|
24
|
+
public final class BugseeStatusMapper {
|
|
25
|
+
|
|
26
|
+
public static final int STOPPED = 0;
|
|
27
|
+
public static final int LAUNCHING = 1;
|
|
28
|
+
public static final int LAUNCHED = 2;
|
|
29
|
+
public static final int STOPPING = 3;
|
|
30
|
+
|
|
31
|
+
private static final Map<BugseeStatus, Integer> WIRE;
|
|
32
|
+
|
|
33
|
+
static {
|
|
34
|
+
final EnumMap<BugseeStatus, Integer> wire = new EnumMap<>(BugseeStatus.class);
|
|
35
|
+
wire.put(BugseeStatus.Stopped, STOPPED);
|
|
36
|
+
wire.put(BugseeStatus.Launching, LAUNCHING);
|
|
37
|
+
wire.put(BugseeStatus.Launched, LAUNCHED);
|
|
38
|
+
wire.put(BugseeStatus.Stopping, STOPPING);
|
|
39
|
+
WIRE = Collections.unmodifiableMap(wire);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private BugseeStatusMapper() {}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param status the SDK's status, or {@code null} if it could not be read
|
|
46
|
+
* @return the wire number; {@link #STOPPED} when unknown, because "we
|
|
47
|
+
* cannot tell" is far closer to stopped than to launched, and a
|
|
48
|
+
* caller waiting to start should keep waiting rather than proceed
|
|
49
|
+
*/
|
|
50
|
+
public static int toWire(@Nullable final BugseeStatus status) {
|
|
51
|
+
if (status == null) {
|
|
52
|
+
return STOPPED;
|
|
53
|
+
}
|
|
54
|
+
final Integer mapped = WIRE.get(status);
|
|
55
|
+
return mapped != null ? mapped : STOPPED;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether this mapper explicitly handles {@code status}. A test sweeps
|
|
60
|
+
* {@link BugseeStatus#values()} through this so that an SDK adding a state
|
|
61
|
+
* fails the build, rather than quietly surfacing in JS as {@code Stopped}.
|
|
62
|
+
*/
|
|
63
|
+
public static boolean isMapped(@Nullable final BugseeStatus status) {
|
|
64
|
+
return status != null && WIRE.containsKey(status);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* App-token validation, shared by every bridge entry point that takes one.
|
|
7
|
+
*
|
|
8
|
+
* <p>Deliberately permissive about shape: the token's format is the server's
|
|
9
|
+
* business, and a wrapper that rejected an otherwise-valid token because the
|
|
10
|
+
* format changed would be worse than one that forwarded it. Only genuinely
|
|
11
|
+
* unusable input — absent or whitespace — is refused, and refused early, so
|
|
12
|
+
* the failure names the real problem instead of surfacing as a confusing
|
|
13
|
+
* launch failure later.
|
|
14
|
+
*/
|
|
15
|
+
public final class BugseeTokens {
|
|
16
|
+
|
|
17
|
+
private BugseeTokens() {}
|
|
18
|
+
|
|
19
|
+
public static boolean isUsable(@Nullable final String token) {
|
|
20
|
+
return token != null && !token.trim().isEmpty();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.bugsee.library.contracts.internal.LogSource;
|
|
7
|
+
|
|
8
|
+
import java.util.ArrayDeque;
|
|
9
|
+
import java.util.ArrayList;
|
|
10
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Drops the logcat echo of a console line the JS patch already sent through
|
|
14
|
+
* the wrapper channel, before the user's log filter is asked.
|
|
15
|
+
*
|
|
16
|
+
* <p>React Native's console polyfill writes the same call to logcat under
|
|
17
|
+
* the tag {@code ReactNativeJS}. The SDK's logcat reader then runs the log
|
|
18
|
+
* filter on it, and the JS patch runs that filter again via the wrapper
|
|
19
|
+
* channel. The channel line is the one that is kept: release builds do not
|
|
20
|
+
* route {@code console.*} through {@code RCTLog}, so dropping the channel
|
|
21
|
+
* line would drop the log. RN-internal lines use other tags and are kept;
|
|
22
|
+
* on Android those already arrive through logcat, one filter pass, which is
|
|
23
|
+
* why this class does not open a second capture of them.
|
|
24
|
+
*
|
|
25
|
+
* <p>Credits for one message live in the map under that message. A note and
|
|
26
|
+
* a drop of the same message both update that entry with {@code compute}, so
|
|
27
|
+
* a credit is never appended to a deque the map has already dropped. The map
|
|
28
|
+
* holds at most {@link #MAX_MESSAGES} messages, and one message at most
|
|
29
|
+
* {@link #MAX_MESSAGES} credits, so at most 32 x 32 credits in all. That is
|
|
30
|
+
* looser than iOS, where {@code BGSRNEchoNoteCap} caps all notes at 32. Every
|
|
31
|
+
* cap fails toward a second filter call, never a lost line: a burst of more
|
|
32
|
+
* than 32 identical lines, or 32 newer distinct ones, before the logcat reader
|
|
33
|
+
* drains them lets the oldest echoes through.
|
|
34
|
+
*/
|
|
35
|
+
final class ConsoleEchoDedup {
|
|
36
|
+
|
|
37
|
+
/** An echo that arrives later than this is a different line. */
|
|
38
|
+
static final long WINDOW_MS = 2_000L;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Distinct messages remembered at once. A further distinct message drops
|
|
42
|
+
* the oldest key. It is also the most
|
|
43
|
+
* credits one message holds: a further note of it drops its oldest credit.
|
|
44
|
+
*/
|
|
45
|
+
static final int MAX_MESSAGES = 32;
|
|
46
|
+
|
|
47
|
+
/** {@code reactAndroidLoggingHook} writes JS console lines under this tag. */
|
|
48
|
+
static final String JS_CONSOLE_TAG = "ReactNativeJS";
|
|
49
|
+
|
|
50
|
+
interface Clock {
|
|
51
|
+
long now();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private final Clock clock;
|
|
55
|
+
private final ConcurrentHashMap<String, ArrayDeque<Long>> credits = new ConcurrentHashMap<>();
|
|
56
|
+
/**
|
|
57
|
+
* One entry per live key, oldest first. Guarded by itself. A key leaves
|
|
58
|
+
* this deque when its last credit is consumed or expires, so a later
|
|
59
|
+
* {@link #note} cannot append a second copy, and {@link #trimToCap}
|
|
60
|
+
* cannot treat that copy as a reason to delete a live credit.
|
|
61
|
+
*/
|
|
62
|
+
private final ArrayDeque<String> notedOrder = new ArrayDeque<>();
|
|
63
|
+
|
|
64
|
+
ConsoleEchoDedup(@NonNull final Clock clock) {
|
|
65
|
+
this.clock = clock;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A wrapper-channel line is about to be filtered. Its logcat echo may follow. */
|
|
69
|
+
void note(@Nullable final String message) {
|
|
70
|
+
if (message == null) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
final long now = clock.now();
|
|
74
|
+
final long expiry = now + WINDOW_MS;
|
|
75
|
+
credits.compute(message, (key, queue) -> {
|
|
76
|
+
final ArrayDeque<Long> next = queue == null ? new ArrayDeque<>() : queue;
|
|
77
|
+
discardExpired(next, now);
|
|
78
|
+
next.addLast(expiry);
|
|
79
|
+
while (next.size() > MAX_MESSAGES) {
|
|
80
|
+
next.removeFirst();
|
|
81
|
+
}
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
syncOrder(message);
|
|
85
|
+
sweep(now);
|
|
86
|
+
trimToCap();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* True when this logcat line is an echo with a live credit. The credit
|
|
91
|
+
* is consumed. Any other source or tag is kept, including a native
|
|
92
|
+
* {@code ReactNative} logcat line.
|
|
93
|
+
*/
|
|
94
|
+
boolean dropEcho(
|
|
95
|
+
@NonNull final LogSource source,
|
|
96
|
+
@Nullable final String tag,
|
|
97
|
+
@Nullable final String message
|
|
98
|
+
) {
|
|
99
|
+
if (source != LogSource.LogCat || !JS_CONSOLE_TAG.equals(tag) || message == null) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
final boolean[] dropped = {false};
|
|
103
|
+
credits.compute(message, (key, queue) -> {
|
|
104
|
+
if (queue == null) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
discardExpired(queue, clock.now());
|
|
108
|
+
if (queue.isEmpty()) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
queue.removeFirst();
|
|
112
|
+
dropped[0] = true;
|
|
113
|
+
return queue.isEmpty() ? null : queue;
|
|
114
|
+
});
|
|
115
|
+
syncOrder(message);
|
|
116
|
+
return dropped[0];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** How many distinct messages still hold a credit. Tests assert the cap. */
|
|
120
|
+
int size() {
|
|
121
|
+
return credits.size();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** How many order entries exist. One per live key; tests reject a stale copy. */
|
|
125
|
+
int orderSize() {
|
|
126
|
+
synchronized (notedOrder) {
|
|
127
|
+
return notedOrder.size();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private void sweep(final long now) {
|
|
132
|
+
for (final String key : new ArrayList<>(credits.keySet())) {
|
|
133
|
+
credits.compute(key, (ignored, queue) -> {
|
|
134
|
+
if (queue == null) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
discardExpired(queue, now);
|
|
138
|
+
return queue.isEmpty() ? null : queue;
|
|
139
|
+
});
|
|
140
|
+
syncOrder(key);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Drops the oldest live keys until the map is within {@link #MAX_MESSAGES}.
|
|
146
|
+
* A polled entry that is a second listing of a key still in the deque is
|
|
147
|
+
* stale: it is discarded and the live credit stays. Eviction runs inside
|
|
148
|
+
* {@code compute}, so it cannot delete a credit a concurrent {@link #note}
|
|
149
|
+
* has just attached to a different deque.
|
|
150
|
+
*/
|
|
151
|
+
private void trimToCap() {
|
|
152
|
+
synchronized (notedOrder) {
|
|
153
|
+
while (credits.size() > MAX_MESSAGES) {
|
|
154
|
+
final String oldest = notedOrder.pollFirst();
|
|
155
|
+
if (oldest == null) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (notedOrder.contains(oldest) || !credits.containsKey(oldest)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
credits.compute(oldest, (key, queue) -> null);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* One listing while {@code message} is in the map, and none once its last
|
|
168
|
+
* credit is gone. Extra copies are dropped. A missing live key is appended.
|
|
169
|
+
*/
|
|
170
|
+
private void syncOrder(@NonNull final String message) {
|
|
171
|
+
synchronized (notedOrder) {
|
|
172
|
+
final boolean live = credits.containsKey(message);
|
|
173
|
+
boolean seen = false;
|
|
174
|
+
final ArrayDeque<String> next = new ArrayDeque<>();
|
|
175
|
+
for (final String key : notedOrder) {
|
|
176
|
+
if (!message.equals(key)) {
|
|
177
|
+
next.addLast(key);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (live && !seen) {
|
|
181
|
+
next.addLast(key);
|
|
182
|
+
seen = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (live && !seen) {
|
|
186
|
+
next.addLast(message);
|
|
187
|
+
}
|
|
188
|
+
notedOrder.clear();
|
|
189
|
+
notedOrder.addAll(next);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private static void discardExpired(@NonNull final ArrayDeque<Long> queue, final long now) {
|
|
194
|
+
while (!queue.isEmpty()) {
|
|
195
|
+
final Long expiry = queue.peekFirst();
|
|
196
|
+
if (expiry != null && expiry > now) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
queue.removeFirst();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|