fix: prevent location permission crashes from FusedLocation API calls#2653
fix: prevent location permission crashes from FusedLocation API calls#2653Protactinium234 wants to merge 2 commits into
Conversation
|
Hi @Protactinium234 thanks for submitting this PR, we will get it merged and shipped |
|
@claude review |
There was a problem hiding this comment.
LGTM — mirrors the existing try/catch pattern in requestLocationUpdates within the same file to handle the same SecurityException class.
Extended reasoning...
Overview
This PR adds a defensive try/catch wrapper to FusedLocationApiWrapperImpl.cancelLocationUpdates, mirroring the identical pattern already present on requestLocationUpdates in the same file. The change addresses a real crash (SecurityException: no location permission) observed on grapheneos/gmscompat where the permission check happens server-side in the GMS binder, so the isConnected guard cannot catch it.
Security risks
None. The change only catches and logs a Throwable; it does not weaken any permission/authentication checks. Failure mode is now a logged warning instead of an app crash, which is the intended behavior.
Level of scrutiny
Low. The diff is 8 lines in a single method, follows an established defensive pattern present one method below it in the same file, and has a clear, documented crash to motivate it. The PR author manually verified the fix and a maintainer (nan-li) has already indicated intent to merge.
Other factors
The bug hunter found one pre-existing issue: getLastLocation in the same wrapper lacks equivalent protection and could throw the same SecurityException. That is a reasonable follow-up but is explicitly out of scope for this PR (the diff does not touch those lines), so it does not block approval. The inline comment is posted for the author's awareness.
Mirror the guard on requestLocationUpdates/cancelLocationUpdates so a SecurityException from the GMS binder (e.g. a revoked or server-side denied location permission) is logged instead of crashing. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@claude review |
There was a problem hiding this comment.
LGTM — the added try/catch on getLastLocation matches the prior pattern in requestLocationUpdates and closes the gap I flagged.
Extended reasoning...
Overview
This PR adds defensive try/catch blocks around two methods in FusedLocationApiWrapperImpl.kt: cancelLocationUpdates (the original fix for the reported SecurityException crash on gmscompat) and getLastLocation (added after my prior review pointed out it had the same gap). Both now follow the same pattern already in use by requestLocationUpdates: wrap the isConnected guard + LocationServices.FusedLocationApi call in try/catch and log via Logging.warn on Throwable.
Security risks
None. This is a purely defensive change that broadens existing exception handling. It does not introduce new permissions, IPC surface, data flow, or auth logic — it just prevents an already-crashing path from terminating the host app.
Level of scrutiny
Low. The change is mechanical, ~10 lines, follows an established intra-file pattern (requestLocationUpdates already had the identical guard), and is supported by a real crash report with a clear stack trace in the PR description. The maintainer (nan-li) already engaged with my prior comment, clarified that the follow-up should land here rather than in a separate PR, and re-requested review after the author addressed it.
Other factors
The current diff is exactly the change I recommended in my prior review (matching the catch-Throwable + warn-log convention used elsewhere in the file and in HmsLocationController.getLastLocation). Returning null from the catch path preserves existing call-site semantics — GmsLocationController already treats a null result from getLastLocation as a no-op. No new behavior, no API surface change, no test coverage needed beyond what the wrapper already implies.
Description
One Line Summary
Add try/catch to cancelLocationUpdates
Details
Motivation
App crashes on reopen due to
java.lang.SecurityException: no location permissionManual testing
Now gracefully handles exception
Affected code checklist
Checklist
Overview
Testing
Final pass