configure method
Future<DeviceRegistration>
configure({
- DeploymentService? deploymentService,
- DeviceDataCollectorFactory? deviceController,
- String? deviceId,
- NotificationController? notificationController,
- bool enableNotifications = true,
- bool askForPermissions = true,
override
Configure this SmartPhoneClientManager by specifying:
deploymentService
- where to get study deployments. If not specified, the SmartphoneDeploymentService will be used.deviceController
that handles devices connected to this client. If not specified, the default DeviceController is used.deviceId
- this device's id in study deployments. If not specified, the OS's device id is used.notificationController
- what NotificationController to use for notifications. Two alternatives exists: FlutterLocalNotificationController or AwesomeNotificationController. If not specified, the AwesomeNotificationController is used.enableNotifications
- should notification be enabled and send to the user when an app task is triggered?askForPermissions
- automatically ask for permissions for all sampling packages at once. Default totrue
. If you want the app to handle permissions, set this tofalse
.
Implementation
@override
Future<DeviceRegistration> configure({
DeploymentService? deploymentService,
DeviceDataCollectorFactory? deviceController,
String? deviceId,
NotificationController? notificationController,
bool enableNotifications = true,
bool askForPermissions = true,
}) async {
// initialize device settings
await DeviceInfo().init();
await Settings().init();
// create and register the built-in data managers
DataManagerRegistry().register(ConsoleDataManagerFactory());
DataManagerRegistry().register(FileDataManagerFactory());
DataManagerRegistry().register(SQLiteDataManagerFactory());
// set default values, if not specified
deviceId ??= DeviceInfo().deviceID;
// _notificationController =
// notificationController ?? FlutterLocalNotificationController();
_notificationController =
notificationController ?? AwesomeNotificationController();
this.deploymentService = deploymentService ?? SmartphoneDeploymentService();
this.deviceController = deviceController ?? DeviceController();
// initialize the app task controller singleton
await AppTaskController()
.initialize(enableNotifications: enableNotifications);
// setting up permissions
if (askForPermissions) await askForAllPermissions();
this.deviceController.registerAllAvailableDevices();
print('===========================================================');
print(' CARP Mobile Sensing (CAMS) - $runtimeType');
print('===========================================================');
print(' device ID : $deviceId');
print(' deployment service : ${this.deploymentService}');
print(' device controller : ${this.deviceController}');
print(' available devices : ${this.deviceController.devicesToString()}');
print('===========================================================');
return super.configure(
deploymentService: this.deploymentService!,
deviceController: this.deviceController,
deviceId: deviceId,
);
}