Skip to content

Commit

Permalink
Merge pull request #679 from janusw/ble5_caps
Browse files Browse the repository at this point in the history
Querying adapter capabilities: extended advertisements & coded phy
  • Loading branch information
janusw authored Apr 27, 2023
2 parents c2d45ef + 94768bf commit fe93658
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Source/Plugin.BLE/Android/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,39 @@ public override IReadOnlyList<IDevice> GetKnownDevicesByIds(Guid[] ids)
return devices.Where(item => ids.Contains(item.Id)).ToList();
}

public override bool supportsExtendedAdvertising()
{
#if NET6_0_OR_GREATER
if (OperatingSystem.IsAndroidVersionAtLeast(26))
#else
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
#endif
{
return _bluetoothAdapter.IsLeExtendedAdvertisingSupported;
}
else
{
return false;
}
}

public override bool supportsCodedPHY()
{
#if NET6_0_OR_GREATER
if (OperatingSystem.IsAndroidVersionAtLeast(26))
#else
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
#endif
{
return _bluetoothAdapter.IsLeCodedPhySupported;
}
else
{
return false;
}
}


private class DeviceComparer : IEqualityComparer<BluetoothDevice>
{
public bool Equals(BluetoothDevice x, BluetoothDevice y)
Expand Down
18 changes: 18 additions & 0 deletions Source/Plugin.BLE/Apple/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,5 +422,23 @@ public static List<AdvertisementRecord> ParseAdvertismentData(NSDictionary adver

return records;
}

#if NET6_0_OR_GREATER || __IOS__
public override bool supportsExtendedAdvertising()
{
#if NET6_0_OR_GREATER
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
#elif __IOS__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
#endif
{
return CBCentralManager.SupportsFeatures(CBCentralManagerFeature.ExtendedScanAndConnect);
}
else
{
return false;
}
}
#endif
}
}
10 changes: 10 additions & 0 deletions Source/Plugin.BLE/Shared/AdapterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,5 +356,15 @@ public void HandleConnectionFail(IDevice device, string errorMessage)
/// Returns a list of paired BLE devices for the given UUIDs.
/// </summary>
public abstract IReadOnlyList<IDevice> GetKnownDevicesByIds(Guid[] ids);

/// <summary>
/// Indicates whether extended advertising (BLE5) is supported.
/// </summary>
public virtual bool supportsExtendedAdvertising() => false;

/// <summary>
/// Indicates whether the Coded PHY feature (BLE5) is supported.
/// </summary>
public virtual bool supportsCodedPHY() => false;
}
}
12 changes: 12 additions & 0 deletions Source/Plugin.BLE/Shared/Contracts/IAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,17 @@ public interface IAdapter
/// <param name="ids">The list of UUIDs</param>
/// <returns>The known device. Empty list if no device known.</returns>
IReadOnlyList<IDevice> GetKnownDevicesByIds(Guid[] ids);

/// <summary>
/// Indicates whether extended advertising (BLE5) is supported.
/// </summary>
/// <returns><c>true</c> if extended advertising is supported, otherwise <c>false</c>.</returns>
bool supportsExtendedAdvertising();

/// <summary>
/// Indicates whether the Coded PHY feature (BLE5) is supported.
/// </summary>
/// <returns><c>true</c> if extended advertising is supported, otherwise <c>false</c>.</returns>
bool supportsCodedPHY();
}
}

0 comments on commit fe93658

Please sign in to comment.