dpa99c / cordova-diagnostic-plugin

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

Introduce ACTIVITY_RECOGNITION runtime permission #430

Closed JackMcKew closed 3 years ago

JackMcKew commented 3 years ago

PR Type

What kind of change does this PR introduce?

PR Checklist

For bug fixes / features, please check if your PR fulfills the following requirements:

What is the purpose of this PR?

Add ability to request ACTIVITY_RECOGNITION run time permission: https://developer.android.com/about/versions/10/privacy/changes#physical-activity-recognition

Does this PR introduce a breaking change?

What testing has been done on the changes in the PR?

I have installed this branch of PR in my app and works as expected with the cordova.plugins.diagnostic.requestRuntimePermission function.

What testing has been done on existing functionality?

Other information

fgarcia5 commented 3 years ago

I have tested this PR and it works correctly in all Android version, except Android 11 (API 30). For this platform, when running:

cordova.plugins.diagnostic.requestRuntimePermissions(function(statuses){
      console.log(statuses);
}, function(error){
        console.error("The following error occurred: " + error);
},[
      cordova.plugins.diagnostic.permission.ACCESS_FINE_LOCATION,
      cordova.plugins.diagnostic.permission.ACCESS_COARSE_LOCATION,
      cordova.plugins.diagnostic.permission.ACCESS_BACKGROUND_LOCATION,
      cordova.plugins.diagnostic.permission.ACTIVITY_RECOGNITION
]);

Returns the following statuses without requesting the permissions:

{
      ACCESS_BACKGROUND_LOCATION: "DENIED_ONCE"
      ACCESS_COARSE_LOCATION: "DENIED_ONCE"
      ACCESS_FINE_LOCATION: "DENIED_ONCE"
      ACTIVITY_RECOGNITION: "DENIED_ONCE"
}

In all other versions of OS it works correctly. Could you tell me if I'm making a mistake?

JackMcKew commented 3 years ago

Could this potentially be due to the Physical Activity permission only having the possible state of 'Allow' or 'Deny', as opposed to the Location permission having 4 states: 'Allow all the time', 'Allow only while using the app', 'Ask every time' and 'Deny'?

fgarcia5 commented 3 years ago

Could be. What test should I take to find out if it is?

fgarcia5 commented 3 years ago

If I request all the permissions together in an array (ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_BACKGROUND_LOCATION and ACTIVITY_RECOGNITION) the error occurs. I mean, the permissions are not required and the status "DENIED_ONCE" is returned for each of them.. If I do it one at a time it works correctly. For my use case I need request all the permissions at the same time. Any ideas to fix this error that appears only in API 30?

JackMcKew commented 3 years ago

Seems like it might be an error more underlying to how this plugin makes requests for multiple permissions at this point

Unfortunately don't have the time to spend on this at the moment as it works for the use case when calling individually, maybe we put a caveat on it and say it only works when being called on it's own?

A workaround for your use case would be to request all the others together and the physical activity permission on it's own?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.