Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logging #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Source/Plugin.BLE.Android/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
using Plugin.BLE.Extensions;
using Object = Java.Lang.Object;
using Trace = Plugin.BLE.Abstractions.Trace;
using Android.App;
using BC.Mobile.Logging;
using Plugin.BLE.Abstractions.EventArgs;

namespace Plugin.BLE.Android
{
public class Adapter : AdapterBase
{
private readonly ILogger _logger = LoggerFactory.CreateLogger(nameof(Adapter));

private readonly BluetoothManager _bluetoothManager;
private readonly BluetoothAdapter _bluetoothAdapter;
private readonly Api18BleScanCallback _api18ScanCallback;
Expand Down Expand Up @@ -65,6 +69,7 @@ public Adapter(BluetoothManager bluetoothManager)

protected override Task StartScanningForDevicesNativeAsync(Guid[] serviceUuids, bool allowDuplicatesKey, CancellationToken scanCancellationToken)
{
_logger.Debug(() => "BLE: Start scanning for devices");
// clear out the list
DiscoveredDevices.Clear();

Expand Down Expand Up @@ -131,6 +136,8 @@ private void StartScanningNew(Guid[] serviceUuids)

protected override void StopScanNative()
{
_logger.Debug(() => "BLE: Stop scanning for devices");

if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
{
Trace.Message("Adapter < 21: Stopping the scan for devices.");
Expand All @@ -148,18 +155,23 @@ protected override void StopScanNative()
protected override Task ConnectToDeviceNativeAsync(IDevice device, ConnectParameters connectParameters,
CancellationToken cancellationToken)
{
_logger.Debug(() => "BLE: Connecting to " + device.Name + "/" + device.Id);
((Device)device).Connect(connectParameters);
return Task.CompletedTask;
return Task.FromResult(true);
}

protected override void DisconnectDeviceNative(IDevice device)
{
_logger.Debug(() => "BLE: Disconnecting from " + device.Name + "/" + device.Id);

//make sure everything is disconnected
((Device)device).Disconnect();
}

public override async Task<IDevice> ConnectToKnownDeviceAsync(Guid deviceGuid, ConnectParameters connectParameters = default(ConnectParameters), CancellationToken cancellationToken = default(CancellationToken))
{
_logger.Debug(() => "BLE: Connecting to known device " + deviceGuid);

var macBytes = deviceGuid.ToByteArray().Skip(10).Take(6).ToArray();
var nativeDevice = _bluetoothAdapter.GetRemoteDevice(macBytes);

Expand Down