configure method

  1. @override
Future<void> configure({
  1. DeploymentService? deploymentService,
  2. DeviceDataCollectorFactory? deviceController,
  3. DeviceRegistration? registration,
  4. bool enableNotifications = true,
  5. NotificationController? notificationController,
  6. bool askForPermissions = true,
  7. bool heartbeat = true,
})
override

Configure this SmartPhoneClientManager.

If the deploymentService is not specified, the local SmartphoneDeploymentService will be used. If the deviceController is not specified, the default DeviceController is used. The registration is a unique device registration for this client device. If not specified, a SmartphoneDeviceRegistration is created and used.

If enableNotifications is true (default), notifications is created when an AppTask is triggered. The notificationController specifies what NotificationController to use for notifications. If not specified, the FlutterLocalNotificationController is used.

If askForPermissions is true (default), this client manager will automatically ask for permissions for all sampling packages at once. If you want the app to handle permissions itself, set this to false. You can later use the askForAllPermissions to ask for all permissions.

If heartbeat is true, a Heartbeat data point will be uploaded for all devices (including the phone) in all studies running on this client (every 5 minutes).

Implementation

@override
Future<void> configure({
  DeploymentService? deploymentService,
  DeviceDataCollectorFactory? deviceController,
  DeviceRegistration? registration,
  bool enableNotifications = true,
  NotificationController? notificationController,
  bool askForPermissions = true,
  bool heartbeat = true,
}) async {
  // initialize misc device settings
  await DeviceInfo().init();
  await Settings().init();
  await Persistence().init();

  // create and register the built-in data managers
  DataManagerRegistry().register(ConsoleDataManagerFactory());
  DataManagerRegistry().register(FileDataManagerFactory());
  DataManagerRegistry().register(SQLiteDataManagerFactory());

  // create the device registration using the [DeviceInfo] singleton
  registration ??= DefaultDeviceRegistration(
    deviceId: DeviceInfo().deviceID,
    deviceDisplayName: DeviceInfo().toString(),
  );

  // initialize default services, if not specified
  deploymentService ??= SmartphoneDeploymentService();
  deviceController ??= DeviceController();
  if (enableNotifications) {
    _notificationController =
        notificationController ?? FlutterLocalNotificationController();
  }
  _heartbeat = heartbeat;

  // initialize the app task controller singleton
  await AppTaskController()
      .initialize(enableNotifications: enableNotifications);

  // setting up permissions
  if (askForPermissions) await askForAllPermissions();

  super.configure(
    deploymentService: deploymentService,
    deviceController: deviceController,
    registration: registration,
  );

  // look up and register all connected devices and services on this client
  this.deviceController.registerAllAvailableDevices();

  print('===========================================================');
  print('  CARP Mobile Sensing (CAMS) - $runtimeType');
  print('===========================================================');
  print('             device : ${registration.deviceDisplayName}');
  print(' deployment service : ${this.deploymentService}');
  print('  device controller : ${this.deviceController}');
  print('  available devices : ${this.deviceController.devicesToString()}');
  print(
      '        persistence : ${Persistence().databaseName.split('/').last}');
  print('===========================================================');

  _state = ClientManagerState.configured;
}