configure method
Future<void>
configure({
- DataEndPoint? dataEndPoint,
- String privacySchemaName = NameSpace.CARP,
- DatumTransformer? transformer,
Configure this SmartphoneDeploymentController.
Must be called after a deployment is ready using tryDeployment and before start is called.
Can request permissions for all SamplingPackages' permissions.
A number of optional parameters can be specified:
dataEndPoint
- A specificDataEndPoint
specifying where to save or upload data. If not specified, theMasterDeviceDeployment.dataEndPoint
is used. If no data endpoint is found, then no data management is done, but sensing can still be started. This is useful for apps which wants to use the framework for in-app consumption of sensing events without saving the data.privacySchemaName
- the name of a PrivacySchema. Use PrivacySchema.DEFAULT for the default, built-in schema. If not specified, no privacy schema is used and data is saved as sensed.transformer
- a generic DatumTransformer function which transform each collected Datum. If not specified, a 1:1 mapping is done, i.e. no transformation.
Implementation
Future<void> configure({
DataEndPoint? dataEndPoint,
String privacySchemaName = NameSpace.CARP,
DatumTransformer? transformer,
}) async {
assert(deployment != null,
'Cannot configure a StudyDeploymentController without a deployment.');
assert(deployment is SmartphoneDeployment,
'A StudyDeploymentController can only work with a SmartphoneDeployment master device deployment');
info('Configuring $runtimeType');
// initialize all devices from the master deployment, incl. this master device
deviceRegistry.initializeDevices(deployment!);
_executor = StudyDeploymentExecutor();
// initialize optional parameters
_dataEndPoint = dataEndPoint ?? deployment!.dataEndPoint;
_privacySchemaName = privacySchemaName;
_transformer = transformer ?? ((datum) => datum);
if (_dataEndPoint != null) {
_dataManager = DataManagerRegistry().create(_dataEndPoint!.type);
}
if (_dataManager == null) {
warning(
"No data manager for the specified data endpoint found: '${deployment?.dataEndPoint}'.");
}
// if no user is specified for this study, look up the local user id
deployment!.userId ??= await Settings().userId;
// initialize the data manager, device registry, and study executor
await _dataManager?.initialize(
deployment!.dataEndPoint!,
deployment!,
data,
);
// connect to all connectable devices, incl. this phone
await deviceRegistry.connectAllConnectableDevices();
_executor!.initialize(deployment!, deployment!);
// await enablePowerAwareness();
data.listen((dataPoint) => _samplingSize++);
status = StudyStatus.Deployed;
print('===============================================================');
print(' CARP Mobile Sensing (CAMS) - $runtimeType');
print('===============================================================');
print(' controller id : $hashCode');
print(' deployment id : ${deployment!.studyDeploymentId}');
print(' deployed time : ${deployment!.deployed}');
print(' user id : ${deployment!.userId}');
print(' platform : ${DeviceInfo().platform.toString()}');
print(' device ID : ${DeviceInfo().deviceID.toString()}');
print(' data endpoint : $_dataEndPoint');
print(' data manager : $_dataManager');
print(' status : ${status.toString().split('.').last}');
print('===============================================================');
}