Repository navigation
Task 8.2b: Android createReport through a one-slot registry #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cd150e7
feat(android): report JS exceptions as ReactNativeWebException, kept …
krassx 0b7c404
test(e2e): JS exceptions in Android bundles, handled, unhandled and f…
krassx 56deb41
test(e2e): a release fatal is one ReactNativeWebException bundle
krassx 4b75281
test(e2e): register debug IDs before a render throw
krassx 1705c19
feat(ios): report JS exceptions as ReactNativeWebException
krassx 3275093
test(ios): count concurrent settle with an atomic so a double-settle …
krassx 5667fa5
test(e2e): JS exceptions in iOS bundles, on the iPhone
krassx fb9449b
test(e2e): pin iOS unhandled recovery as failing on beta3
krassx c437703
feat(report): upload with severity and labels, and showReportDialog
krassx cd79431
feat(report): createReport, a report the app fills and uploads, bridg…
krassx 6179794
feat(android): createReport through a one-slot registry
krassx 0542501
fix(android): ignore a created-report callback after its reservation …
krassx 0dbeee8
test(report): pin severity bounds and the exact argument errors
krassx 6a9535e
test(ios): keep the settle-once race to the two callers
krassx 4d61e8a
test(report): cover created-report attachment and native rejection paths
krassx edc94cc
test(ios): keep each settle-once window on its own release
krassx 02ddf11
Merge main into this branch
krassx 5eb1935
fix(android): drop the created-report stubs the main merge left besid…
krassx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
packages/react-native/android/src/main/java/com/bugsee/reactnative/CreatedReports.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package com.bugsee.reactnative; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
|
|
||
| import com.bugsee.library.contracts.reporting.Report; | ||
|
|
||
| /** | ||
| * The one created report this process may have outstanding. | ||
| * | ||
| * <p>A slot is taken by {@link #reserve()} or {@link #tryReserve()} and held | ||
| * until {@link #fulfil} stores a report, {@link #fulfil} is given null, | ||
| * {@link #take} removes the report, or {@link #clear} drops whatever is | ||
| * there. A second reserve while the slot is taken returns false. Handles are | ||
| * {@code cr-<n>}, numbered from 1 for the life of the process, and are not | ||
| * reused after a take or a clear. | ||
| * | ||
| * <p>{@link #clear()} does not cancel an SDK listener that is already in | ||
| * flight. Each reservation carries a stamp, and {@link #fulfil} ignores any | ||
| * stamp that is not the current one, so that listener cannot store its report | ||
| * into a reservation opened afterwards or free that reservation. | ||
| */ | ||
| final class CreatedReports { | ||
|
|
||
| private static final CreatedReports SHARED = new CreatedReports(); | ||
|
|
||
| /** True from a successful reserve until that reservation is ended. */ | ||
| private boolean creating; | ||
|
|
||
| /** | ||
| * Stamp of the open reservation. {@code 0} is never a live stamp: it is | ||
| * what {@link #tryReserve()} returns when busy, and what {@link #clear()} | ||
| * and a finished {@link #fulfil} leave behind so every earlier stamp misses. | ||
| */ | ||
| private int currentStamp; | ||
|
|
||
| /** Next stamp to issue. Skips {@code 0}, which means "not admitted". */ | ||
| private int nextStamp = 1; | ||
|
|
||
| @Nullable | ||
| private Report report; | ||
|
|
||
| @Nullable | ||
| private String handle; | ||
|
|
||
| /** Next suffix. Never reset: a handle is fresh for the process. */ | ||
| private int next = 1; | ||
|
|
||
| static CreatedReports shared() { | ||
| return SHARED; | ||
| } | ||
|
|
||
| /** Package-private so a test can build an instance that is not {@link #shared()}. */ | ||
| CreatedReports() { | ||
| } | ||
|
|
||
| /** False while a created report is outstanding or being created. */ | ||
| synchronized boolean reserve() { | ||
| return tryReserve() != 0; | ||
| } | ||
|
|
||
| /** | ||
| * {@code 0} when a report is outstanding or being created. Otherwise the | ||
| * stamp {@link #fulfil} must present to end this reservation. | ||
| */ | ||
| synchronized int tryReserve() { | ||
| if (creating || report != null) { | ||
| return 0; | ||
| } | ||
| creating = true; | ||
| currentStamp = nextStamp; | ||
| nextStamp += 1; | ||
| if (nextStamp == 0) { | ||
| nextStamp = 1; | ||
| } | ||
| return currentStamp; | ||
| } | ||
|
|
||
| /** | ||
| * Ends the reservation {@code stamp} names. A report gets {@code cr-<n>} | ||
| * and holds the slot. Null frees the slot and mints nothing. A stamp that | ||
| * is not the current one, including every stamp issued before | ||
| * {@link #clear()}, changes nothing and returns null. | ||
| */ | ||
| @Nullable | ||
| synchronized String fulfil(final int stamp, @Nullable final Report created) { | ||
| if (!creating || stamp == 0 || stamp != currentStamp) { | ||
| return null; | ||
| } | ||
| creating = false; | ||
| currentStamp = 0; | ||
| if (created == null) { | ||
| return null; | ||
| } | ||
| handle = "cr-" + next; | ||
| next += 1; | ||
| report = created; | ||
| return handle; | ||
| } | ||
|
|
||
| @Nullable | ||
| synchronized Report get(final String handleId) { | ||
| if (report != null && handleId != null && handleId.equals(handle)) { | ||
| return report; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** Removes the report and frees the slot. An unknown handle removes nothing. */ | ||
| @Nullable | ||
| synchronized Report take(final String handleId) { | ||
| final Report created = get(handleId); | ||
| if (created == null) { | ||
| return null; | ||
| } | ||
| report = null; | ||
| handle = null; | ||
| return created; | ||
| } | ||
|
|
||
| /** Drops the slot and makes every stamp issued so far fail {@link #fulfil}. */ | ||
| synchronized void clear() { | ||
| creating = false; | ||
| report = null; | ||
| handle = null; | ||
| currentStamp = 0; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.