public void StartScanning(Context context, TracingInformation tracingInformation) { if (!Initialized) { _logger.LogError("Scanner - Starting failed - not initialized."); return; } try { _tracingInformation = tracingInformation; _logger.LogDebug($"Scanner - Starting for service {_tracingInformation.ServiceId}."); if (_scanCallback == null) { _scanCallback = new BtScanCallback(context, _manager, tracingInformation); } System.Threading.Tasks.Task.Run(() => { _leScanner.StartScan(BuildScanFilters(_tracingInformation), BuildScanSettings(), _scanCallback); }).FireAndForget(); Covi.Features.BluetoothTracing.TracingState.Instance.SetScanningState(true); } catch (Exception ex) { _logger.LogError(ex, "Scanner - Starting failed."); } }
public BtScanCallback(Context context, IDeviceManager deviceManager, TracingInformation tracingInformation) { this._context = context; _deviceManager = deviceManager; _tracingInformation = tracingInformation; _logger = Covi.Logs.Logger.Get(this); }
public BtGattConnectCallback(BtDevice btDevice, DeviceDescriptor descriptor, IDeviceManager deviceManager, TracingInformation tracingInformation) { _btDevice = btDevice; _descriptor = descriptor; _deviceManager = deviceManager; _tracingInformation = tracingInformation; }
public void Start(TracingInformation tracingInformation) { if (tracingInformation == null || _enabled) { return; } _tracingInformation = tracingInformation; _peripheralManager.RemoveAllServices(); CBUUID uuidService = CBUUID.FromString(tracingInformation.ServiceId); CBUUID uuidCharacteristic = CBUUID.FromString(tracingInformation.CharacteristicId); var data = NSData.FromArray(PayloadFormatter.GetBytesToSend(new PackageData(tracingInformation.DeviceId))); var characteristic = new CBMutableCharacteristic(uuidCharacteristic, CBCharacteristicProperties.Read, data, CBAttributePermissions.Readable); var service = new CBMutableService(uuidService, true); service.Characteristics = new CBCharacteristic[] { characteristic }; _peripheralManager.AddService(service); StartAdvertisingOptions advData = new StartAdvertisingOptions { ServicesUUID = new CBUUID[] { uuidService } }; _peripheralManager.StartAdvertising(advData); TracingState.Instance.SetAdvertisingState(true); _enabled = true; _logger.LogDebug("Advertising starting. DeviceId: " + _tracingInformation.DeviceId); }
public PeripheralDelegate(CBCentralManager centralManager, IDeviceManager deviceManager, TracingInformation tracingInformation) { _centralManager = centralManager; _deviceManager = deviceManager; _tracingInformation = tracingInformation; _logger = Covi.Logs.Logger.Get(this); }
public override void StartAdvertising(TracingInformation tracingInformation) { if (!Initialized) { _logger.LogError("Advertiser - Starting failed - not initialized."); return; } TracingInformation = tracingInformation; try { _logger.LogDebug($"Advertiser - Starting. ServiceId: {tracingInformation.ServiceId}."); AdvertisingSetParameters parameters = AdvertisingParameters(); AdvertiseData data = BuildAdvertiseData(tracingInformation); _callback = new BtAdvertisingSetCallback(); System.Threading.Tasks.Task.Run(() => { Advertiser.StartAdvertisingSet(parameters, data, null, null, null, _callback); }); Covi.Features.BluetoothTracing.TracingState.Instance.SetAdvertisingState(true); } catch (Exception ex) { _logger.LogError(ex, "Advertiser - Starting failed."); } }
public void Start(Context context, TracingInformation tracingInformation) { if (!Initialized) { _logger.LogError("Advertiser - Starting failed - not initialized."); return; } _tracingInformation = tracingInformation; try { _logger.LogDebug("Advertiser - starting."); var serviceUuid = ParcelUuid.FromString(_tracingInformation.ServiceId); var characteristicUuid = ParcelUuid.FromString(_tracingInformation.CharacteristicId); _logger.LogDebug($"Advertiser - initializing. ServiceId: {_tracingInformation.ServiceId}. CharacteristicId: {_tracingInformation.CharacteristicId}"); BtGattServerCallback bluetoothGattServerCallback = new BtGattServerCallback(_tracingInformation); _gattServer = _bluetoothManager.OpenGattServer(context, bluetoothGattServerCallback); bluetoothGattServerCallback._gattServer = _gattServer; BluetoothGattService service = new BluetoothGattService(serviceUuid.Uuid, GattServiceType.Primary); BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(characteristicUuid.Uuid, GattProperty.Read, GattPermission.Read); service.AddCharacteristic(characteristic); _gattServer.AddService(service); _logger.LogDebug("Advertiser - started."); } catch (Exception ex) { _logger.LogError(ex, "Advertiser - failed advertising initialization."); } }
public PeripheralManager(CBCentralManager centralManager, TracingInformation tracingInformation) { _centralManager = centralManager; _tracingInformation = tracingInformation; _logger = Covi.Logs.Logger.Get(this); _manager = DeviceManagerProvider.GetInstance(); }
public async Task SetAsync(TracingInformation tracingInformation) { var serialized = await Services.Serialization.Serializer.Instance.SerializeAsync(tracingInformation).ConfigureAwait(false); await Xamarin.Essentials.SecureStorage.SetAsync(TracingInformationStorageKey, serialized).ConfigureAwait(false); _changesSubject.OnNext(tracingInformation); }
protected AdvertiseData BuildAdvertiseData(TracingInformation tracingInformation) { AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder(); var uuid = ParcelUuid.FromString(tracingInformation.ServiceId); dataBuilder.AddServiceUuid(uuid); return(dataBuilder.Build()); }
private IList <ScanFilter> BuildScanFilters(TracingInformation tracingInformation) { var scanFilters = new List <ScanFilter>(); var builder = new ScanFilter.Builder(); var serviceUuid = ParcelUuid.FromString(tracingInformation.ServiceId); builder.SetServiceUuid(serviceUuid); scanFilters.Add(builder.Build()); return(scanFilters); }
private async Task RestartBluetoothAsync() { try { var deviceId = await SecretsProvider.Instance.GetDeviceIdentifierAsync(); var tracingInformation = new TracingInformation(true, deviceId, Configuration.Constants.BluetoothConstants.ServiceUUID, Configuration.Constants.BluetoothConstants.CharacteristicUUID, Configuration.Constants.BluetoothConstants.DataExpirationTime); await TracingInformationContainer.Instance.SetAsync(tracingInformation); await _tracingEngine.RestartAsync(); } catch (Exception) { // ignore } }
public async Task <TracingInformation> GetAsync() { TracingInformation result = null; try { var data = await Xamarin.Essentials.SecureStorage.GetAsync(TracingInformationStorageKey).ConfigureAwait(false); if (!string.IsNullOrEmpty(data)) { result = await Services.Serialization.Serializer.Instance.DeserializeAsync <TracingInformation>(data); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Failed to deserialize tracing information. " + ex.ToString()); } return(result ?? TracingInformation.Default); }
public void Start(TracingInformation config) { if (config == null || _enabled == true) { return; } _tracingInformation = config; CBUUID uuidService = CBUUID.FromString(_tracingInformation.ServiceId); CBUUID uuidCharacteristic = CBUUID.FromString(_tracingInformation.CharacteristicId); // TODO: options prevent android from being discovered on IOS, investigation required var options = new PeripheralScanningOptions() { AllowDuplicatesKey = true }; _centralManager.ScanForPeripherals(new CBUUID[] { uuidService }, options); _enabled = true; Covi.Features.BluetoothTracing.TracingState.Instance.SetScanningState(true); _logger.LogDebug($"Scanning started for service {_tracingInformation.ServiceId}."); }
public abstract void StartAdvertising(TracingInformation tracingInformation);
public BtGattServerCallback(TracingInformation tracingInformation) { _tracingInformation = tracingInformation; _logger = Logs.Logger.Get(this); }