askForAllPermissions method
Asking for permissions for all the measures included in this study.
Since we only ask for permission relevant to the deployment, this method should be called after deployment has taken place but before this controller is resumed.
Permissions are asked for one at a time, through SmartPhoneClientManager.requestPermissions, on both Android and iOS.
Implementation
Future<void> askForAllPermissions() async {
if (deployment == null) {
warning(
'$runtimeType - No deployment available. Skipping requesting permissions.',
);
return;
}
Set<Permission> permissions = {};
for (var measure in deployment?.measures ?? <Measure>[]) {
var schema = SamplingPackageRegistry().samplingSchemes[measure.type];
if (schema != null && schema.dataType is CamsDataTypeMetaData) {
permissions.addAll(
(schema.dataType as CamsDataTypeMetaData).permissions,
);
}
}
debug(
'$runtimeType - Required permissions for this deployment: $permissions',
);
if (permissions.isNotEmpty) {
info(
'$runtimeType - Asking for permissions for all measures in this deployment...',
);
await SmartPhoneClientManager().requestPermissions(permissions.toList());
_permissions = {
for (final permission in permissions) permission: await permission.status,
};
debug('$runtimeType - Permissions: $_permissions');
}
}