Conversation
pendingResult was assigned on every onMethodCall. requestPermission is the only branch that defers its Result to onActivityResult, so any call landing between the intent launch and the activity result — isOverlayActive, getOverlayPosition, moveOverlay — overwrote it. onActivityResult would then complete that unrelated call with a permission boolean, and the original requestPermission Future would never complete. Assign pendingResult only in the branch that defers, and null-guard onActivityResult so an unpaired activity result (e.g. the activity is recreated while the settings screen is up) no longer throws an NPE. Clear the field after use so it cannot be completed twice. Checking the live permission state rather than resultCode is preserved and now documented: ACTION_MANAGE_OVERLAY_PERMISSION returns RESULT_CANCELED even when the user grants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up #187, which asked for a release containing the
addActivityResultListenerfix already onmain. These are the two smallerpendingResultproblems I mentioned there — both still present onmain, and independent of that release.1.
pendingResultwas claimed by every callrequestPermissionis the only branch that defers itsResult— it starts the settings intent and letsonActivityResultcomplete it later. Every other branch completes its ownResultinline and has no use for the field.So any call arriving while the settings screen is open —
isOverlayActive,getOverlayPosition,moveOverlay— overwritespendingResult. When the user returns,onActivityResultcompletes that call with a permission boolean, and the originalrequestPermissionfuture never completes.This is easy to hit in practice: apps commonly poll
isOverlayActive()from a lifecycle observer, which fires exactly when the user comes back from the settings screen.Fixed by assigning
pendingResultonly in the branch that defers.2.
onActivityResultdereferenced it unguardedAn activity result can arrive with nothing pending — most plausibly when the activity is recreated while the settings screen is up, so the plugin re-attaches with a fresh
pendingResultofnull. Added a null check, and cleared the field after use so the sameResultcannot be completed twice.I kept the existing behaviour of reporting
checkOverlayPermission()rather thanresultCode, and added a comment for why —ACTION_MANAGE_OVERLAY_PERMISSIONreturnsRESULT_CANCELEDeven when the user grants, soresultCodewould be wrong here.Notes
One file, two hunks, no API or behaviour change for correct callers — a
requestPermission()that already worked still resolves the same way.Not fixed here, to keep the diff focused, but noticed nearby in
onMethodCall:closeOverlayreturns without completing itsResultwhenOverlayService.isRunningis false, so that call hangs.isOverlayActivebranch is duplicated — the second is unreachable.Happy to send either as a separate PR if you'd like.
Tested against a real app on Android 16 (API 36), Pixel 9 Pro: revoke the overlay permission, request it, grant, return — the future resolves and the overlay starts without an app restart.