Skip to content

onActivityResult can hang forever if OK but data == null, and pending… - #70

Open
MegaManSec wants to merge 2 commits into
Expensify:mainfrom
MegaManSec:pr/jr-3-a330c1e
Open

MegaManSec wants to merge 2 commits into
Expensify:mainfrom
MegaManSec:pr/jr-3-a330c1e

Conversation

@MegaManSec

Copy link
Copy Markdown
Contributor

… promise is not cleared

… promise is not cleared

(cherry picked from commit a330c1ee2261f192103ac4e7a2fa5d86e2c59b7f)
@JakubKorytko

Copy link
Copy Markdown
Member

@MegaManSec may you resolve conflicts with main please?

@MegaManSec

Copy link
Copy Markdown
Contributor Author

@JakubKorytko done

@JakubKorytko JakubKorytko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on an emulator by calling onActivityResult directly with a fake promise:

  • RESULT_OK + null data: rejects (hangs on main)
  • unknown resultCode: rejects (hangs on main)
  • RESULT_CANCELED: resolves CANCELED, same as main

)
localPromise?.resolve(TokenizationStatus.SUCCESS.code)
if (data == null) {
localPromise?.reject(E_OPERATION_FAILED, "Tokenization returned RESULT_OK but intent data was null")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is RESULT_OK with null data a real failure? Google says OK, so the card might be in the wallet already, just without the token id. Rejecting here would show an error to the user while the card was added. Do you have a repro for this, or is it a safety net?

localPromise?.reject(E_OPERATION_FAILED, "Tokenization returned RESULT_OK but intent data was null")
return
}
val tokenId = data.getStringExtra(TapAndPay.EXTRA_ISSUER_TOKEN_ID).toString()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the extra is missing, .toString() turns null into the string "null" and that goes out as tokenId in the event. Since this line is touched anyway, maybe drop .toString() and pass the nullable value, OnCardActivatedEvent already takes null for the canceled case.

)
localPromise?.resolve(TokenizationStatus.CANCELED.code)
} else {
localPromise?.reject(E_OPERATION_FAILED, "Tokenization failed with resultCode=$resultCode")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have TokenizationStatus.ERROR (-1), and JS maps it to 'error' in getTokenizationStatus, but nothing returns it yet. Would localPromise?.resolve(TokenizationStatus.ERROR.code) fit the API better here? Callers would get 'error' through the normal path instead of a thrown error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants