Skip to content

Devices and permissions

Every device in the protocol has a DeviceManager at runtime. The DeviceController singleton owns them all, including the phone itself, and is what SamplingPackageRegistry registers device managers with.

A device manager reports a DeviceStatus: unknown, configured, paired, connecting, connected, reconnected, disconnecting, disconnected. It also checks (hasPermissions) and requests (requestPermissions) the permissions its device needs.

Base class For
SmartphoneDeviceManager The phone. Default for packages that use only onboard sensors
HardwareDeviceManager External hardware with a battery
BLEDeviceManager Bluetooth LE devices
ServiceManager Online and on-board services, like weather or location
File What is in it
runtime/device_manager/device_manager.dart DeviceManager and DeviceStatus
runtime/device_manager/device_managers.dart The base classes above
runtime/device_manager/device_controller.dart DeviceController
runtime/permissions.dart PermissionRequester, requestPermissionsInOrder

CAMS asks for permissions when a probe or device needs them, through a PermissionRequester. The default, requestPermissionsInOrder, shows the system dialogs one at a time. Android silently denies a request made while another dialog is up, and some permissions (e.g. background location) only work after another one is granted.

To show your own rationale before each dialog, pass your own requester:

await SmartPhoneClientManager().configure(
permissionRequester: (permissions) async {
// show your explanation, then ask
await requestPermissionsInOrder(permissions);
},
);

A requester runs inside the permission queue. Call permission_handler (or requestPermissionsInOrder) directly, never SmartPhoneClientManager.requestPermissions, which would wait on itself.

Platform setup for the permissions is on Run in production.

See Add a device manager.