Skip to content

Commit

Permalink
fix auto reconnect on droid
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Apr 21, 2018
1 parent d71289f commit 356b3a7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 48 deletions.
9 changes: 0 additions & 9 deletions Plugin.BluetoothLE/GattConnectionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ public class GattConnectionConfig
{
public static GattConnectionConfig DefaultConfiguration { get; } = new GattConnectionConfig();


/// <summary>
/// Set this to false if you want initial connection to be faster (you need to make sure the device is in range).
/// This property is used only by Android & Tizen
/// Leave as true unless you want to control connections yourselfe (defaults to true)
/// </summary>
public bool AndroidAutoConnect { get; set; } = true;


/// <summary>
/// This will cause disconnected devices to try to immediately reconnect. It will cause WillRestoreState to fire on iOS. Defaults to true
/// </summary>
Expand Down
16 changes: 1 addition & 15 deletions Plugin.BluetoothLE/Platforms/Android/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class Device : AbstractDevice
readonly Subject<ConnectionStatus> connSubject;
readonly BluetoothManager manager;
readonly DeviceContext context;
IDisposable autoReconnectSub;


public Device(BluetoothManager manager, BluetoothDevice native)
Expand All @@ -42,26 +41,13 @@ public Device(BluetoothManager manager, BluetoothDevice native)
public override void Connect(GattConnectionConfig config)
{
config = config ?? GattConnectionConfig.DefaultConfiguration;
if (config.IsPersistent)
{
this.autoReconnectSub = this.WhenStatusChanged()
.Where(x => x == ConnectionStatus.Disconnected)
.Skip(1)
.Delay(CrossBleAdapter.PauseBetweenAutoReconnectAttempts)
.Subscribe(_ =>
{
// TODO: watch for GATT 133 for retry
this.context.Connect(config.Priority, true);
});
}
this.connSubject.OnNext(ConnectionStatus.Connecting);
this.context.Connect(config.Priority, config.AndroidAutoConnect);
this.context.Connect(config.Priority, config.IsPersistent);
}


public override void CancelConnection()
{
this.autoReconnectSub?.Dispose();
this.context.Close();
this.connSubject.OnNext(ConnectionStatus.Disconnected);
}
Expand Down
15 changes: 2 additions & 13 deletions Plugin.BluetoothLE/Platforms/Android/Internals/DeviceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Reactive.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using Acr;
using Acr.Logging;
using Acr.Reactive;

Expand All @@ -32,20 +31,10 @@ public DeviceContext(BluetoothDevice device)
public ConcurrentQueue<Func<Task>> Actions { get; }


public void Reconnect(ConnectionPriority priority)
{
if (this.Gatt == null)
throw new ArgumentException("Device is not in a reconnectable state");

this.CleanUpQueue();
this.InvokeOnMainThread(() => this.Gatt.Connect());
}


public void Connect(ConnectionPriority priority, bool androidAutoReconnect) => this.InvokeOnMainThread(() =>
public void Connect(ConnectionPriority priority, bool autoReconnect) => this.InvokeOnMainThread(() =>
{
this.CleanUpQueue();
this.CreateGatt(androidAutoReconnect);
this.CreateGatt(autoReconnect);
if (this.Gatt == null)
throw new BleException("GATT connection could not be established");
Expand Down
11 changes: 0 additions & 11 deletions Plugin.BluetoothLE/Platforms/Uwp/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ public override IObservable<ConnectionStatus> WhenStatusChanged()
}


//public override IObservable<int> WhenRssiUpdated(TimeSpan? frequency) => Observable
// .Interval(frequency ?? TimeSpan.FromMilliseconds(500))
// .Where(x => this.Status == ConnectionStatus.Connected)
// .Select(_ => (int) this.context
// .NativeDevice
// .DeviceInformation
// .Properties["System.Devices.Aep.SignalStrength"]
// );
// TODO: once the gatt connection is established, this guy will stop obviously!


IObservable<IGattService> serviceOb;
public override IObservable<IGattService> DiscoverServices()
{
Expand Down

0 comments on commit 356b3a7

Please sign in to comment.