Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono.Android] Fix incorrect Bluetooth enumification (#6214)
Fixes: https://developercommunity2.visualstudio.com/t/xamarin-android-bluetooth-the-advertisin/841102 Fixes: #2595 Update enumification of various `Android.Bluetooth.LE.AdvertisingSetParameters.Builder` and `Android.Bluetooth.BluetoothDevice` methods to use the `Android.Bluetooth.BluetoothPhy` enum instead of the `Android.Bluetooth.LE.ScanSettingsPhy` enum, introduced in e33eb53. Backwards compatibility is achieved by creating overloads for the existing methods in `Additions`, and marking them as `[Obsolete]`. The API "breakage" is because the `[Register]` attribute has moved from the incorrect methods to the correct methods. As the signature change is an enum, the marshalled type is still an `int`, so moving the `[Register]` should not cause issues. For example: // Current [Register] public void DoSomething (BadEnum value) { ... } // Fixed [Register] public void DoSomething (GoodEnum value) { ... } [Obsolete ("Use DoSomething(GoodEnum)")] public void DoSomething (BadEnum value) => DoSomething ((GoodEnum)value); Note: this is only generally save to do when `DoSomething()` is a *non-`virtual`* method (i.e. Java `final` method). Fortunately, this is the case with the methods involved here.
- Loading branch information
Showing
5 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Mono.Android/Android.Bluetooth/AdvertisingSetParametersBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#if ANDROID_26 | ||
|
||
namespace Android.Bluetooth.LE | ||
{ | ||
public sealed partial class AdvertisingSetParameters | ||
{ | ||
public sealed partial class Builder | ||
{ | ||
// These methods were obsoleted as a warning in API-31 | ||
[global::System.Obsolete ("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")] | ||
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android26.0")] | ||
public unsafe Android.Bluetooth.LE.AdvertisingSetParameters.Builder? SetPrimaryPhy ([global::Android.Runtime.GeneratedEnum] Android.Bluetooth.LE.ScanSettingsPhy primaryPhy) | ||
=> SetPrimaryPhy ((Android.Bluetooth.BluetoothPhy) primaryPhy); | ||
|
||
[global::System.Obsolete ("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")] | ||
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android26.0")] | ||
public unsafe Android.Bluetooth.LE.AdvertisingSetParameters.Builder? SetSecondaryPhy ([global::Android.Runtime.GeneratedEnum] Android.Bluetooth.LE.ScanSettingsPhy secondaryPhy) | ||
=> SetSecondaryPhy ((Android.Bluetooth.BluetoothPhy) secondaryPhy); | ||
} | ||
} | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#if ANDROID_26 | ||
|
||
namespace Android.Bluetooth | ||
{ | ||
public sealed partial class BluetoothDevice | ||
{ | ||
// These methods were obsoleted as a warning in API-31 | ||
[global::System.Obsolete ("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")] | ||
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android26.0")] | ||
public unsafe Android.Bluetooth.BluetoothGatt? ConnectGatt (Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? @callback, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.BluetoothTransports transport, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.LE.ScanSettingsPhy phy) | ||
=> ConnectGatt (context, autoConnect, @callback, transport, (Android.Bluetooth.BluetoothPhy) phy); | ||
|
||
[global::System.Obsolete ("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")] | ||
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android26.0")] | ||
public unsafe Android.Bluetooth.BluetoothGatt? ConnectGatt (Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? @callback, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.BluetoothTransports transport, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.LE.ScanSettingsPhy phy, Android.OS.Handler? handler) | ||
=> ConnectGatt (context, autoConnect, @callback, transport, (Android.Bluetooth.BluetoothPhy) phy, handler); | ||
} | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Compat issues with assembly Mono.Android: | ||
CannotRemoveAttribute : Attribute 'Android.Runtime.RegisterAttribute' exists on 'Android.Bluetooth.BluetoothDevice.ConnectGatt(Android.Content.Context, System.Boolean, Android.Bluetooth.BluetoothGattCallback, Android.Bluetooth.BluetoothTransports, Android.Bluetooth.LE.ScanSettingsPhy)' in the contract but not the implementation. | ||
CannotRemoveAttribute : Attribute 'Android.Runtime.RegisterAttribute' exists on 'Android.Bluetooth.BluetoothDevice.ConnectGatt(Android.Content.Context, System.Boolean, Android.Bluetooth.BluetoothGattCallback, Android.Bluetooth.BluetoothTransports, Android.Bluetooth.LE.ScanSettingsPhy, Android.OS.Handler)' in the contract but not the implementation. | ||
CannotRemoveAttribute : Attribute 'Android.Runtime.RegisterAttribute' exists on 'Android.Bluetooth.LE.AdvertisingSetParameters.Builder.SetPrimaryPhy(Android.Bluetooth.LE.ScanSettingsPhy)' in the contract but not the implementation. | ||
CannotRemoveAttribute : Attribute 'Android.Runtime.RegisterAttribute' exists on 'Android.Bluetooth.LE.AdvertisingSetParameters.Builder.SetSecondaryPhy(Android.Bluetooth.LE.ScanSettingsPhy)' in the contract but not the implementation. |