cph-cachet / carp.sensing-flutter

CARP Mobile Sensing for Flutter, including mobile sensing framework, data backend support, and the CARP mobile sensing app.
MIT License
80 stars 28 forks source link

Handle permission on a Measure level #407

Closed bardram closed 2 months ago

bardram commented 3 months ago

Right now, permissions are handled on a package level. For example, the connectivity package, asks for access to nearby BLE devices to support the BLUETOOTH measure. Hence, if the connectivity package is included in an app (like the CARP Studies App), the app will ask for this permission. And this happens EVEN THOUGH the BLUETOOTH measure might not be part of a protocol.

An alternative solution would be to assign permission to measures, e.g., as part of a measure's DataTypeMetaData definition. In this manner, CAMS could ask for permissions for only those measures which are actually part of a protocol.

See #306.

bardram commented 2 months ago

After 2 whole days of research and debugging into this issue, it seems like this permission issue is mainly related to Android.

On iOS, permissions are defined/declared in the info.plist file and then the OS automatically asks for permissions when the sensor is used. For example, if step count is collected (using the PedometerProbe) permissions to access "Fitness & Activity Data" is requested, once the probe is started.

On Android, on the contrary, permission needs to be asked explicitly. You cannot access the "Fitness" data (steps count) if the app has not asked for permission. It will throw all sorts of exceptions, some of them in the native OS, and cannot be caught in Flutter. And to make things even worse on Android, you have to ask for all the permissions in one call -- you cannot request multiple permissions by multiple calls (using the permission_handler plugin).

So - the conclusion is:

bardram commented 2 months ago

The health sampling package has its own unique way to ask for health permissions on both Android and iOS. Right now we ask for permission to access all health data types. This should (also) be aligned with the data types specified in the study protocol.