dpa99c / cordova-diagnostic-plugin

Cordova/Phonegap plugin to manage device settings
540 stars 361 forks source link

Android 12.0 - API 31 - combineLocationStatuses() #456

Closed spoxies closed 2 years ago

spoxies commented 2 years ago

Bug report

Current behavior:

With Android 12.0, when asking for location permission requestLocationAuthorization(), the user is now presented with a choice to share a 'approximate'/COURSE or a 'precise'/FINE location.

When the user has set the location to be 'Approximate', getLocationAuthorizationStatus() will return DENIED_ALWAYS. As Android 12 in that case returns ACCESS_FINE_LOCATION is DENIED_ALWAYS ACCESS_COARSE_LOCATION is GRANTED. However combineLocationStatuses()expects both statuses to be GRANTED or it returns DENIED_ALWAYS.

Screenshots

Console output

On allow "When in use" (approx location)

Android 12.0 - API 31

V/Diagnostic: Authorisation for ACCESS_FINE_LOCATION is DENIED_ALWAYS
V/Diagnostic: Authorisation for ACCESS_COARSE_LOCATION is GRANTED

Android 11.0 - API 30

V/Diagnostic: Authorisation for ACCESS_FINE_LOCATION is GRANTED
V/Diagnostic: Authorisation for ACCESS_COARSE_LOCATION is GRANTED

Android 10.0 - API 29

V/Diagnostic: Authorisation for  ACCESS_FINE_LOCATION is GRANTED
V/Diagnostic: Authorisation for ACCESS_COARSE_LOCATION is GRANTED

Expected behavior:

I think the function getLocationAuthorizationStatus() should not return DENIED_ALWAYS if ACCESS_COARSE_LOCATION is granted but GRANTED/GRANTED_WHEN_IN_USE.

The specific type/precision (sh/c)ould be accessed by the one of the other fuctions like isGpsLocationAvailable().

Steps to reproduce:

cordova.plugins.diagnostic.requestLocationAuthorization(function(status){
     [...]
 }
}, function(error){
    //err
}, cordova.plugins.diagnostic.locationAuthorizationMode.ALWAYS);

cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
    console.log("Location setting is " + (enabled ? "enabled" : "disabled"));
}, function(error){ });

Related code:

./cordova.plugins.diagnostic/www/android/diagnostic.location.js

    function combineLocationStatuses(statuses){
       [..]
        if(coarseStatus === Diagnostic.permissionStatus.DENIED_ALWAYS || fineStatus === Diagnostic.permissionStatus.DENIED_ALWAYS){
            status = Diagnostic.permissionStatus.DENIED_ALWAYS;
        }
       [..]
        return status;
    }

Environment information

- Cordova CLI version - `10.0.0` - Cordova platform version - ` ios 6.2.0` - `android 10.0.1` - Plugins & versions installed in project (including this plugin) - `cordova-background-geolocation 4.4.1 "BackgroundGeolocation"` - `cordova-plugin-firebasex 13.0.0-cli "Google Firebase Plugin"` - `cordova.plugins.diagnostic 6.1.0 "Diagnostic"` - `...`

Note: There might be a good reason why both statuses need to be granted, and this proposal is not right. But I lack the historic context/experience to make a judgement on that. @dpa99c a big thanks and lots of respect for carrying essential plugins like this and others.