[TIMOB-28049] Android: Investigate "ACCESS_BACKGROUND_LOCATION" handling on Android 11
GitHub Issue | n/a |
---|---|
Type | Story |
Priority | High |
Status | Closed |
Resolution | Done |
Resolution Date | 2020-09-19T06:09:32.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.3.0 |
Components | Android |
Labels | android, location, permission |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-07-25T01:20:26.000+0000 |
Updated | 2020-11-03T15:22:08.000+0000 |
Description
*Summary:*
Supposedly, Android 11 will no longer show a permission request dialog for the
ACCESS_BACKGROUND_LOCATION
permission. We need to confirm this.
https://developer.android.com/preview/privacy/location#background-location-permission-dialog-changes
If true, then the only way to enable permission is to go to the app's "Location Permissions" activity under system settings. This very well maybe true because according to Google's developer blog below, they will be removing apps using this permission from Google Play unless they provide a valid reason and pass Google's review process.
https://android-developers.googleblog.com/2020/02/safer-location-access.html
*Note 1:*
We might be able to reach the app's "Location Permission" activity under system settings via the following intent action.
ACTION_LOCATION_SOURCE_SETTINGS
*Note 2:*
We may need to expose Android's [shouldShowRequestPermissionRationale ()](https://developer.android.com/reference/android/app/Activity.html#shouldShowRequestPermissionRationale(java.lang.String)) API. Normally, this method would return true
if the end-user tapped on "Disallow" in the permission request dialog. On Android 11, this might always return true
for the ACCESS_BACKGROUND_LOCATION
where you would have to tell the end-user how to enable it under system settings.
Attachments
File | Date | Size |
---|---|---|
Android11-AllLocationPermissions.png | 2020-09-05T03:35:01.000+0000 | 171003 |
Android11-BackgroundLocationPermission.png | 2020-09-05T03:35:01.000+0000 | 166667 |
GeolocationGpsService.js | 2020-09-11T00:32:13.000+0000 | 419 |
GeolocationGpsTest.js | 2020-09-11T00:32:14.000+0000 | 5482 |
tiapp.xml | 2020-09-11T00:32:14.000+0000 | 1083 |
Here are my test results... If you call
requestPermission()
forACCESS_BACKGROUND_LOCATION
and the app has *+NOT+* been grantedACCESS_COARSE_LOCATION
orACCESS_FINE_LOCATION
permission, then a dialog will *+NOT+* appear and the method will report the permission as denied. This behavior exists on Android 10 as well. So, this is not an Android 11 breaking-change. If the app was granted theACCESS_COARSE_LOCATION
orACCESS_FINE_LOCATION
permission first and then you callrequestPermission()
forACCESS_BACKGROUND_LOCATION
, then a dialog will appear as shown below. What's different in Android 11 is the end-user must tap on the "*Allow in setting*" link to enable location access in the background. This is the major Android 11 change, but it doesn't require anyone to change their native or JS code to support this. Google merely added more steps to the UI to enable it on their end. !Android11-BackgroundLocationPermission.png|thumbnail! *Side Note:* A better solution for Android 10 and 11 would be to request for all 3 location permissions at once like the below. If you do, then a dialog will always appear... unless the end-user denied it several times already.!Android11-AllLocationPermissions.png|thumbnail! We should update our "Background Location Service Example" in our docs (link below) to request
ACCESS_BACKGROUND_LOCATION
as shown above. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Service *Final Notes:* We do not need to use aACTION_LOCATION_SOURCE_SETTINGS
intent to enableACCESS_BACKGROUND_LOCATION
. The "Allow in settings" link in the permission request dialog will take the end-user to that screen for us. We don't need to add ashouldShowRequestPermissionRationale()
method. It's actually not helpful in this case.The current plan is to improve the Ti.Geolocation parity between Android and iOS, while also improving our APIs to make it easier to access the GPS in the background on both platform. This will be handled by the epic [TIMOB-28114]. \\ For now, the attached files below is an example of how to access GPS data in the background on both Android and iOS. This correctly works on Android 11 and older OS versions as well as iOS 14 and older iOS versions. * [^tiapp.xml] * [^GeolocationGpsTest.js] * [^GeolocationGpsService.js]
The release version of Android 11 has completely changed behavior. It no longer displays a "Show in settings" link option as shown in the dialog screenshots above. More importantly, you can no longer ask for
"ACCESS_BACKGROUND_LOCATION"
and"ACCESS_FINE_LOCATION"
in the same request anymore or else it will fail if you don't have any location permission at all. This is a breaking-change in the release version of Android 11. You now must request"ACCESS_FINE_LOCATION"
first and then"ACCESS_BACKGROUND_LOCATION"
second. Note that our docs currently suggest devs to do this already. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.ServiceClosing ticket as investigation is complete. If this is a mistake feel free to reopen.