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

Android.Bluetooth.BluetoothDevice.ConnectGatt has invalid signature #2595

Closed
inwotep opened this issue Jan 9, 2019 · 0 comments · Fixed by #6214
Closed

Android.Bluetooth.BluetoothDevice.ConnectGatt has invalid signature #2595

inwotep opened this issue Jan 9, 2019 · 0 comments · Fixed by #6214

Comments

@inwotep
Copy link

inwotep commented Jan 9, 2019

In the Android.Bluetooth.BluetoothDevice class, the following methods have an incorrect signature:

    public BluetoothGatt ConnectGatt(Context context, bool autoConnect, BluetoothGattCallback callback, [GeneratedEnum] BluetoothTransports transport, [GeneratedEnum] ScanSettingsPhy phy);
    public BluetoothGatt ConnectGatt(Context context, bool autoConnect, BluetoothGattCallback callback, [GeneratedEnum] BluetoothTransports transport, [GeneratedEnum] ScanSettingsPhy phy, Handler handler);

The phy parameter should be Android.Bluetooth.LE.BluetoothPhy, not Android.Bluetooth.LE.ScanSettingsPhy. Additionally, the Android.Bluetooth.LE.BluetoothPhy class is missing mappings to the following values:

PHY_LE_1M
PHY_LE_1M_MASK
PHY_LE_2M
PHY_LE_2M_MASK
PHY_LE_CODED
PHY_LE_CODED_MASK

Using the API as defined causes the Bluetooth stack to crash on Google Pixel 2 running Android 9.0:

Device.ConnectGatt(context, true, this, BluetoothTransports.Le, Android.Bluetooth.LE.ScanSettingsPhy.AllSupported, handler);

The only option is to do something like this:

GattClient = Device.ConnectGatt(context, true, this, BluetoothTransports.Le, (Android.Bluetooth.LE.ScanSettingsPhy)1 /*  PHY_LE_1M_MASK */, handler);

Version Information

Microsoft Visual Studio Professional 2017
Version 15.9.3
VisualStudio.15.Release/15.9.3+28307.145
Microsoft .NET Framework
Version 4.7.03190

Installed Version: Professional

Visual C++ 2017 00369-60000-00001-AA091
Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.14.11009.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.9.04012.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60913.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.9.03024.0
Azure App Service Tools v3.0.0

C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service 2.0
JavaScript Language Service

JavaScript Project System 2.0
JavaScript Project System

JavaScript UWP Project System 2.0
JavaScript UWP Project System

Microsoft Continuous Delivery Tools for Visual Studio 0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

MLGen Package Extension 1.0
MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.13.11-pre (400cfb1)
Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.4.21001.1 Commit Hash:8dd15923800d931b153ab9e4de74e42a74eba5e6
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61810.11040
Microsoft SQL Server Data Tools

TypeScript Tools 15.9.20918.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android) 15.0.28107.00
Visual C++ for Cross Platform Mobile Development (Android)

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers 1.0
Visual Studio Tools for Containers

Visual Studio Tools for Universal Windows Apps 15.0.28301.59
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Xamarin 4.12.3.73 (d15-9@20b35b881)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.16.5 (6b9f32067)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.127 (e975299)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.1.0.38 (HEAD/61d16aa23)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.2.1.11 (5ef73d3)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

XamlFormatter 1.0
Formats Xaml the way I want it formatted. Focusing entirely on spacing and leaving the decision of what belongs on what line up to you.

Log File

N/A

@inwotep inwotep changed the title BluetoothDevice.ConnectGatt has invalid signature Android.Bluetooth.BluetoothDevice.ConnectGatt has invalid signature Jan 9, 2019
jonpryor pushed a commit that referenced this issue Aug 25, 2021
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.
jonathanpeppers pushed a commit that referenced this issue Aug 25, 2021
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.
jonpryor pushed a commit to jonpryor/xamarin-android that referenced this issue Aug 25, 2021
Fixes: https://developercommunity2.visualstudio.com/t/xamarin-android-bluetooth-the-advertisin/841102
Fixes: dotnet#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.
jonpryor pushed a commit that referenced this issue Aug 26, 2021
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.
@ghost ghost locked as resolved and limited conversation to collaborators Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant