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

Fix racey dialog dismissal in PlacePickerActivity #13461

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fynngodau
Copy link
Contributor

First time contributor checklist

Contributor checklist

  • OnePlus Nord / avicii, Android 12
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

The first commit avoids a race condition with closing the location picker map for location sharing where the following exception would occur:

IllegalArgumentException: View[…] not attached to window manager

This was because dismiss, together with its delay, could be executed after the activity that contained the dialog, PlacePickerActivity, had already been destroyed. This faulty behavior can be reproduced more easily when artificially increasing the minimum time that the dialog should be shown. Instead of potentially scheduling a dismissal for the future using dismiss, dismissNow is now called during onDestroy.

The second commit avoids similar problems in the future, because it ensures that the delayed dismiss callback is always cancelled when dismissNow is called (which it should be whenever the activity containing the progress bar is closed for some reason, which may be in between a dismiss call and the dismiss-scheduled delayed dismissal.

The second commit could be left out as the first one already fixes the crash I mentioned above, but I would recommend to add it nonetheless.

Avoids a race condition when dismiss is delayed because the progress bar
hadn't been shown for long enough, while avoiding the flickering that
would be caused when immediately dismissing the dialog earlier.
In case `dismiss` (with delay) is called during an activity and the
activity is consequently destroyed, and calls `dismissNow` in the
process of its cleanup (i.e. in `onDestroy`), the delayed `dismiss`
callback could still try to dismiss the dialog, causing an
`IllegalArgumentException: View[…] not attached to window manager`.

To avoid this faulty behavior, the delayed callbacks are removed
whenever `dismissNow` is called.
@fynngodau
Copy link
Contributor Author

@alex-signal I added another commit with your requested changes.

Copy link

stale bot commented May 11, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants