ChipReadCoordinator
The platform-neutral part of one chip read through a platform entry point: the states, the one ending, the attempts, the decision to start again after a lost link, and the progress. The Android and iOS entry points feed it platform events and run each attempt on their transport; everything they report to the app goes through it, so both platforms behave the same.
Guarantees:
Exactly one ending, through one atomic gate: the first cause wins and later ones do nothing (each ending method returns
falsethen).No update after the ending; observer calls never overlap and keep their order, whichever thread calls in. An exception the observer throws is ignored.
A new attempt only after a loss of the link itself (NfcTagLost or NfcTimeout from the transport), within LinkLossPolicy.maxRestarts, and only when the platform allows it; never after an answered refusal, a secure-messaging error, a malformed file, or a person, app or system ending.
At most one more try of access per read, inside read on the same link, after the first refusal of the key when no earlier try reached the command that uses the key and the key has no try counter and looks right (the rule is in ChipReadEnding.KeyNotAccepted). It uses no restart and no new attempt number; the second try starts with ChipCommandTimeLimit.BEFORE_ACCESS again.
A loss of the link before the attempt sent the first command that uses the key (BAC's EXTERNAL AUTHENTICATE, PACE's first GENERAL AUTHENTICATE; the chip was asked nothing about the key) uses no restart and is no new attempt: the read reports ChipReadState.NoAnswerYet and the platform tries the same attempt again (ChipReadAttemptOutcome.NO_ANSWER_YET), within its own time bound.
A read that ends while no try of it reached the first command that uses the key, because the last try was lost before it and no other try may follow, ends with ChipReadEnding.Failed and NfcNoAnswer, on every platform alike.
Each command gets the time limit of its kind (ChipCommandTimeLimit), and the platform is asked to change the limit only when the kind changes from one command to the next.
The calls, in order, for a platform entry point:
start; when it returns
falsethe read has ended (the key was refused), so release nothing and stop. Then check NFC: notStarted when it cannot be used.waiting when the reader is on, and again every few seconds with the time waited.
documentFound when a tag is found; after the settle time, connecting; when the link cannot be set up, connectionFailed and wait for the next tag.
read on the connected transport. ChipReadAttemptOutcome.ENDED: release the link, done. ChipReadAttemptOutcome.LINK_LOST: release the link, wait for the document (restart polling), then go to step 3; when the platform gives up waiting, documentNotReturned. ChipReadAttemptOutcome.NO_ANSWER_YET: the same, but try again soon, since the document is likely still there; when the platform's time bound for unanswered tries passes, documentNotReturned. ChipReadAttemptOutcome.HANDED_OVER: the platform stopped the attempt on purpose to get a fresh connection to the same document (its
handedOverhook); release the link, ask the platform for the document again, then go to step 3; when it does not come back within the platform's short wait, handoverFailed.At any time: cancel with ChipReadEnding.Cancelled.By.APP (then release the link in the background) or ChipReadEnding.Cancelled.By.PERSON; endedBySystem; fail for a platform problem with no better ending.
Experimental: see ExperimentalTesseraChipApi. Internal: see InternalTesseraChipApi.
Since
1.0.0
Parameters
The read options; the key is checked in start.
What to do after a lost link.
Where the updates and the ending go.
The reader that runs each attempt (its telemetry sink receives the step events).
Whether the coordinator takes over the access key in options: with true, it clears the key at the ending, whatever the ending is, and not before, so every attempt of the read (a restart or a resume after a lost link) can still use it. The platform entry points pass true; a caller that owns its key passes false.
How long a lost link may still lead to a restart, counted from the first link to the document, not from the start of waiting; past it, the loss ends the read. Before the first link it does nothing. NO_TIME_LIMIT for no limit.
The clock for totalTimeLimitMillis, in milliseconds, never going back.
Types
Properties
The attempts the read can make when every restart is used: 1 plus LinkLossPolicy.maxRestarts. Under LinkLossPolicy.Resume a restart after an attempt that kept more bytes uses no restart (see takeRestart), so the attempt number can pass this; the updates then carry the attempt number as the most.
Functions
The person or the app cancelled. For the app, ChipReadState.Stopping comes first; release the link in the background after this call.
The link to the chip is being set up: ChipReadState.Connecting. While the read shows ChipReadState.NoAnswerYet, or hands over, it does nothing.
The link could not be set up, before any command: back to waiting, with no restart used (ChipReadState.WaitingForDocument, ChipReadState.LinkLost again after a lost link, or ChipReadState.NoAnswerYet again after unanswered tries).
The link to a found document could not be set up MAX_CONNECT_ATTEMPTS times in a row, each time with a loss of the link itself (last): the read ends. When no try of the read got past the first commands, the chip never answered, and the error is NfcNoAnswer, the same on every platform; otherwise it is last. ChipReadEnding.Partial when an attempt was granted access, else ChipReadEnding.Failed.
A document is found and nothing was sent yet: ChipReadState.DocumentFound. While the read shows ChipReadState.NoAnswerYet, or hands over (ChipReadAttemptOutcome.HANDED_OVER), it does nothing: the state before stays.
The document did not come back after a lost link within the platform's wait, or its chip did not answer within the platform's time bound for unanswered tries: the read ends with ChipReadEnding.Partial when any attempt was granted access, ChipReadEnding.Failed otherwise, stopped by the last loss. When the read shows ChipReadState.NoAnswerYet and no try of it reached the first command that uses the key, the error is NfcNoAnswer instead of the loss.
The system ended the read: ChipReadEnding.EndedBySystem.
A platform problem with no better ending (for example a tag that is not an ISO 14443-4 chip): ChipReadEnding.Partial when an attempt was granted access, else ChipReadEnding.Failed.
The document did not come back within the platform's short wait after a planned handover (ChipReadAttemptOutcome.HANDED_OVER), or its new link could not be set up: from here the lost-link rules apply, as after any loss. When a restart is left, the read uses it, publishes ChipReadState.LinkLost and waits for the document; the next read is a new attempt that continues from what was read. Otherwise the read ends as documentNotReturned does.
The read could not start: ChipReadEnding.NotStarted.
Runs one attempt on transport, already connected, and decides what follows. Call it from the context that may block on the transport (never the main thread).
The platform closes its reader session and opens a new one while no document was reported: ChipReadState.RenewingSession. No attempt or restart is used; call waiting when the new session is on.
Starts the read: ChipReadState.Starting, then the key check, before any radio activity or system sheet. The read ends with ChipReadEnding.KeyRejected when the key was already used (cleared, for example by an earlier read: ChipAccessDenied with ChipAccessDenied.Reason.KEY_CLEARED), or when an MRZ key's check digits do not match, unless ChipReadOptions.allowCheckDigitMismatch allows that.
The reader is on and waits for a document: ChipReadState.WaitingForDocument with waitedMillis. Call it when polling starts and again every few seconds. While the read waits after a lost link it does nothing: ChipReadState.LinkLost stays until the document is found again.
The update waiting would publish now for waitedMillis, without publishing it: for a platform that shows its text before the reader is on.