cph-cachet/carp.sensing-flutter

Handle permission on a Measure level

Closed this issue · 2 comments

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.

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:

  • permission handling on runtime is only relevant on Android
  • permissions should be asked once and for all for all permissions needed
  • this should be aligned with the study protocol - only ask for permissions needed in the study

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.