Skip to content
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

[sign_in_with_apple] Handle cancellation of chrome custom tab #88

Merged

Conversation

HenriBeck
Copy link
Member

No description provided.

@HenriBeck HenriBeck requested a review from tp as a code owner June 1, 2020 14:42
@HenriBeck HenriBeck changed the title Feature/sign in with apple/handle cancellation of chrome custom tab [sign-in-with-apple] Handle cancellation of chrome custom tab Jun 1, 2020
@HenriBeck HenriBeck changed the title [sign-in-with-apple] Handle cancellation of chrome custom tab [sign_in_with_apple] Handle cancellation of chrome custom tab Jun 1, 2020
if (requestCode == CUSTOM_TABS_REQUEST_CODE) {
val _lastAuthorizationRequestResult = lastAuthorizationRequestResult

if (_lastAuthorizationRequestResult != null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

While this works from my testing on the simulator, I'm a bit worried about introducing a race condition here.

But maybe this activity result callback is only triggered after the deeplink is handled, e.g. triggering the main activity to hide the Custom Tab

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, true, we don't want this to be triggered on "automatic" closes.

Have you looked into the resultCode value? Is that any help?
Else I would hope there is some overall API docs on this that explains the order of method invocation.

I don't think SignInWithAppleCallback.onCreate leaves any room for races here, as we explicitly first send the data to Flutter and null the authorization result, and only then call triggerMainActivityToHideChromeCustomTab, which causes the tab to close.

I checked the resultCode and it was 0 (https://developer.android.com/reference/android/app/Activity#RESULT_CANCELED) both when manually closing as well as when it's triggered by this plugin.

@HenriBeck HenriBeck marked this pull request as draft June 2, 2020 03:41
@tp tp mentioned this pull request Jun 2, 2020
…h-apple/handle-cancellation-of-chrome-custom-tab
@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2020

Codecov Report

Merging #88 into master will decrease coverage by 0.30%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
- Coverage   62.34%   62.04%   -0.31%     
==========================================
  Files          13       13              
  Lines         409      411       +2     
==========================================
  Hits          255      255              
- Misses        154      156       +2     
Flag Coverage Δ
#pending_operations 88.23% <ø> (ø)
#sign_in_with_apple 56.52% <0.00%> (-0.36%) ⬇️
#state_queue 84.37% <ø> (ø)
#with_bloc 77.50% <ø> (ø)
Impacted Files Coverage Δ
...sign_in_with_apple/lib/src/sign_in_with_apple.dart 26.98% <0.00%> (-0.89%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6663d6...89aae02. Read the comment docs.

val notificationIntent = _activity.getPackageManager().getLaunchIntentForPackage(_activity.getPackageName());
lastAuthorizationRequestResult = result
triggerMainActivityToHideChromeCustomTab = {
val notificationIntent = _activity.packageManager.getLaunchIntentForPackage(_activity.packageName);
notificationIntent.setPackage(null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
notificationIntent.setPackage(null)
notificationIntent.package = null

Is this also an option then?

if (requestCode == CUSTOM_TABS_REQUEST_CODE) {
val _lastAuthorizationRequestResult = lastAuthorizationRequestResult

if (_lastAuthorizationRequestResult != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, true, we don't want this to be triggered on "automatic" closes.

Have you looked into the resultCode value? Is that any help?
Else I would hope there is some overall API docs on this that explains the order of method invocation.

I don't think SignInWithAppleCallback.onCreate leaves any room for races here, as we explicitly first send the data to Flutter and null the authorization result, and only then call triggerMainActivityToHideChromeCustomTab, which causes the tab to close.

I checked the resultCode and it was 0 (https://developer.android.com/reference/android/app/Activity#RESULT_CANCELED) both when manually closing as well as when it's triggered by this plugin.

@tp tp marked this pull request as ready for review June 2, 2020 07:13
@tp tp merged commit a2fc0f8 into master Jun 2, 2020
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.

3 participants