Skip to content

Commit

Permalink
Fixes: #462: In com.android.identity.wallet.transfer.Communication se…
Browse files Browse the repository at this point in the history
…ndResponse

If `closeAfterSending` is true, only close the connection after we know the
`deviceResponse` payload have been sent.
  • Loading branch information
Nicklas Warming Jacobsen committed Jan 30, 2024
1 parent 06fe0d3 commit 488360d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ class TransferDocumentFragment : Fragment() {
private fun onTransferDisconnected() {
log("Disconnected")
hideButtons()
TransferManager.getInstance(requireContext()).disconnect()
TransferManager.getInstance(requireContext()).disconnect(true)
}

private fun onTransferError() {
Toast.makeText(requireContext(), "An error occurred.", Toast.LENGTH_SHORT).show()
hideButtons()
TransferManager.getInstance(requireContext()).disconnect()
TransferManager.getInstance(requireContext()).disconnect(true)
}

private fun hideButtons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,16 @@ class Communication private constructor(
if (progress == max) {
log("Completed...")
}
if (progress == max && closeAfterSending) {
deviceRetrievalHelper?.disconnect()
}
}
if (closeAfterSending) {
deviceRetrievalHelper?.sendDeviceResponse(
deviceResponse,
OptionalLong.of(Constants.SESSION_DATA_STATUS_SESSION_TERMINATION),
progressListener,
context.mainExecutor())
deviceRetrievalHelper?.disconnect()
} else {
deviceRetrievalHelper?.sendDeviceResponse(
deviceResponse,
OptionalLong.empty(),
progressListener,
context.mainExecutor())
}

deviceRetrievalHelper?.sendDeviceResponse(
deviceResponse,
OptionalLong.of(Constants.SESSION_DATA_STATUS_SESSION_TERMINATION),
progressListener,
context.mainExecutor())
}

fun stopPresentation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ class TransferManager private constructor(private val context: Context) {
sendSessionTerminationMessage,
useTransportSpecificSessionTermination
)
disconnect()
disconnect(true)
}

fun disconnect() {
communication.disconnect()
fun disconnect(disconnectCommunication: Boolean) {
if (disconnectCommunication) {
communication.disconnect()
}
qrCommunicationSetup?.close()
transferStatusLd = MutableLiveData<TransferStatus>()
destroy()
Expand All @@ -262,9 +264,7 @@ class TransferManager private constructor(private val context: Context) {

fun sendResponse(deviceResponse: ByteArray, closeAfterSending: Boolean) {
communication.sendResponse(deviceResponse, closeAfterSending)
if (closeAfterSending) {
disconnect()
}
disconnect(!closeAfterSending)
}

fun readDocumentEntries(documentName: String): DocumentElements {
Expand Down

0 comments on commit 488360d

Please sign in to comment.