Repository navigation
permission_handler_watchos: locationAlways reads denied until it is asked for - #44
Conversation
permission_handler_apple 9.6.4 answers Permission.locationAlways.status with denied, not permanentlyDenied, while "when in use" is granted and "always" has not been asked for, so an app can still ask for it. The watch strategy, ported from 9.6.2, still gave the old answer. Its status check now reads the flag the "always" request already sets, compiled in with PERMISSION_LOCATION only, as the flag is. The example's integration test gets a case for it, meaningful with location allowed "while using" beforehand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MAUstaoglu
left a comment
There was a problem hiding this comment.
Thanks @iamoguzhanarslantas, this is a clean port of permission_handler_apple 9.6.4. I checked it against upstream's #1577. The status table now matches iOS in every state: with "when in use" granted, locationAlways reads denied until asked and permanentlyDenied after. The new read stays under PERMISSION_LOCATION, so the #19 opt-in holds, and the flag is read and written on the main queue only. The CHANGELOG line under the unpublished 0.0.1 is right.
One thing I would like in this PR before it merges, because this change is what makes it reachable:
- Now that apps will request "always" after reading
denied, a request can wait forever if watchOS does not show the prompt.requestAlwaysis answered only by the delegate or by the app resigning active and coming back, andobserveActiveignores a become-active that had no resign before it. That could happen when something else in the app already asked for "always", or on the Simulator after a reinstall, where location is kept butNSUserDefaultsis not. Before this change the status readpermanentlyDeniedthere, so apps did not ask. I have read this in the code, not seen it on a watch. CouldrequestAlwaysanswer with the current status if the app has not resigned active within a second or two? That is the same pattern as the existing delayed re-read, with the same_answersguard.
Two smaller things, here or in a later PR, as you prefer:
- The two location cases in the integration test return early and report a pass when their precondition is missing. Could they use
markTestSkippedwith thesimctlhint, as the network_info start test does? - In PORTING_REPORT, could the Source line note that the port was compared through 9.6.5, and drop the local
.pub-cachehome path (that line predates this PR)?
…prompt watchOS shows the "always" prompt once. When it was shown before without the askedAlways flag knowing, by other code in the app or before a reinstall that kept location but not NSUserDefaults, a request gets nothing back: no delegate call and no return to active, so it waited forever. Now that locationAlways reads denied until it is asked for, apps reach that request. If the app has not resigned active two seconds after it, the status then is the answer, under the _answers guard the delayed re-read uses. The example's two location cases skip with a simctl hint instead of passing when their precondition is missing, and the PORTING_REPORT's Source line says the port was compared through 9.6.5, without the local path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. All three are in b030bd6.
The CHANGELOG line and the PORTING_REPORT's design notes describe the new answer, and the PR description is updated to match. A local replay of CI is clean: analyze and the 15 host tests, every |
MAUstaoglu
left a comment
There was a problem hiding this comment.
Thanks @iamoguzhanarslantas, all three are in, and the trace holds up.
The hang is closed: every path into requestAlways either answers at once or arms the 2 s check. The check stands down on any answer (_answers) or a resign, so nothing answers twice or answers a later request. It runs on the main queue only, holds the strategy weakly, and the Dart _requesting guard is released on that path too. The answer it gives, permanentlyDenied, is what permission_handler_apple reports for "always" kept at "while using", and what the status reads afterwards. The new code sits under PERMISSION_LOCATION, so the #19 opt-in holds. The skipped cases and the Source line are as asked, and the CHANGELOG and PORTING_REPORT sentences match the code.
Nothing blocks. I'll merge this, and then look at one timing case myself on the Simulator before 0.1.0, so there's nothing to change here. Consider [Permission.locationWhenInUse, Permission.locationAlways].request() from a reset location. If the delegate answers the first request before the app becomes active again, and watchOS shows the second prompt without the app going active in between, no resign arrives. The check would then answer while the "always" prompt is still up. If that shows up, I'll make the check answer only while the app is active, and look again later otherwise. A slow watch that takes more than 2 s to show the prompt is the same case, and needs a physical watch to measure.
Summary
permission_handler_apple 9.6.4 fixed
Permission.locationAlways.statusansweringpermanentlyDeniedwhile "When In Use" is granted and "Always" has not been requested yet: it now answersdenied, so the app can still request it.permission_handler_watchoswas ported from 9.6.2 and still gave the old answer. This mirrors the fix.Since apps now reach that request, it also answers an "always" request that watchOS shows no prompt for (from the review). watchOS shows the "always" prompt once. If other code in the app asked for "always" before, or the prompt was shown before a reinstall that kept location but not this package's flag, the request got no delegate call and no return to active, and waited forever. Now, if the app has not resigned active two seconds after the request, the status then is the answer.
The weekly upstream job compares
permission_handler, still 13.0.2, so a newpermission_handler_appledoes not show up there. This came from comparing the port's source, 9.6.2, with 9.6.5 on pub.dev.What permission_handler_apple 9.6.3 to 9.6.5 change for this package:
locationAlwaysstatus: ported here. The status check reads theNSUserDefaultsflag that the "always" request already sets, so once "always" was asked for and kept at "while using" it still answerspermanentlyDenied, as upstream does. The check sits underPERMISSION_LOCATION, like the flag: an app withNSLocationWhenInUseUsageDescriptionalone still has noNSUserDefaultsreference and no "always" request.getNotificationSettingsWithCompletionHandler:asynchronously.Permission.phoneservice status answered twice: nothing to port.phoneanswers as a permission watchOS does not have.PERMISSION_HANDLER_INFO_PLISTin the SwiftPM manifest: nothing to port; flutter-watchos appliesdefinesinstead.lib/is unchanged since 9.6.3. 9.6.5 adds an iOS XCTest for the notification change only.Changes:
phw_location.m: the status check. InrequestAlways, a check two seconds after the request answers with the status if the app has not resigned active and nothing has answered, under the_answersguard of the delayed re-read.example/integration_test/permission_handler_test.dart: a new case,"always" can still be asked for after "when in use". It and the case for "always" before "when in use" each need location in a given state, and skip with thesimctlcommand otherwise. The file header and the example README say to set location before a run, since the Simulator keeps the answer across installs.Verified
On the watchOS 27.0 Simulator (Apple Watch Series 12, 46 mm), with flutter-watchos 0.1.2:
main'sphw_location.mput back, the new case fails (Expected: PermissionStatus.denied,Actual: PermissionStatus.permanentlyDenied).reset location, the "always" prompt came up. Left up for 32 s and answered "Keep Only While Using":permanentlyDenied, the status thenpermanentlyDenied, and a second requestpermanentlyDeniedwithout a prompt. Left up for 17 s and answered "Change to Always Allow":granted.permanentlyDeniedafter 2.1 s, and the status then readpermanentlyDenied.On the host:
phw_location.mcompiled for the watchOS Simulator with the marker andPERMISSION_LOCATION_WHENINUSEalone has noNSUserDefaultsorrequestAlwaysAuthorizationreference (nm -u) and noaskedAlwayskey. WithPERMISSION_LOCATION, or with no-D, it has them. None of these builds warns with-Wall -Wextra.flutter analyze lib testand the 15 host tests,flutter analyzeof the example'sintegration_test/, everytool/check,dart formatas CI runs it,pub publish --dry-run, andtool/check_native_sources.shwith Xcode 27.2 (phw_location.mwith no-D, with the marker and every macro, with the marker alone, and with the marker and each macro alone, for a watch and the Simulator): clean.Not verified
nativejob covers it.🤖 Generated with Claude Code