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

Set device name via advertisement records (on Android) #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

janusw
Copy link
Member

@janusw janusw commented Apr 7, 2023

This should fix #660 and #456. It is based on the idea (and initial implementation) of @BasuHuddar.

We check if the advertisment records, which are available for a specific device, contain a record of type CompleteLocalName. If yes, we use the corresponding data for setting the device name.

While writing this, I wonder whether we should additionally make use of ShortLocalName (in case CompleteLocalName is not available) ...?

@janusw
Copy link
Member Author

janusw commented Apr 7, 2023

@BasuHuddar, could you please check if this behaves the same way as your original implementation (d452eea)? There is a nupkg built by the GHA CI that you can use: https://github.com/dotnet-bluetooth-le/dotnet-bluetooth-le/actions/runs/4637918781#artifacts

What do you think about the ShortLocalName? Would it help to handle this as well?

@BasuHuddar
Copy link

@janusw getting error
GET https://api.nuget.org/v3-flatcontainer/plugin.ble/index.json
OK https://api.nuget.org/v3-flatcontainer/plugin.ble/index.json 1105ms
Unable to find package Plugin.BLE with version (>= 3.0.0-beta.2-9-ge0b2bd8)

  • Found 39 version(s) in nuget.org [ Nearest version: 3.0.0-beta.2 ]
  • Found 0 version(s) in Basappa_Huddar
  • Found 0 version(s) in /usr/local/share/dotnet/library-packs

published nuget package is not availble in https://api.nuget.org/v3-flatcontainer/plugin.ble/index.json

{
"versions": [
"1.0.0-beta",
"1.0.0-beta2",
"1.0.0-beta3",
"1.0.0-beta4",
"1.0.0-beta5",
"1.0.0",
"1.1.0-beta1",
"1.1.0-beta2",
"1.1.0-beta3",
"1.1.0-beta4",
"1.1.0-beta5",
"1.1.0",
"1.2.0-beta1",
"1.2.0-beta2",
"1.2.0-beta3",
"1.2.0-beta4",
"1.2.0",
"1.2.1",
"1.2.2",
"1.2.3",
"1.3.0-alpha1",
"1.3.0-beta1",
"1.3.0-beta2",
"1.3.0-beta3",
"1.3.0",
"2.0.0-pre1",
"2.0.0",
"2.0.1",
"2.1.0-pre1",
"2.1.0",
"2.1.1",
"2.1.2",
"2.1.3",
"2.2.0-pre1",
"2.2.0-pre2",
"2.2.0-pre4",
"2.2.0-pre5",
"3.0.0-beta.1",
"3.0.0-beta.2"
]
}

In the version list published nuget package is not available

@janusw
Copy link
Member Author

janusw commented Apr 7, 2023

@janusw getting error GET https://api.nuget.org/v3-flatcontainer/plugin.ble/index.json OK https://api.nuget.org/v3-flatcontainer/plugin.ble/index.json 1105ms Unable to find package Plugin.BLE with version (>= 3.0.0-beta.2-9-ge0b2bd8)

* Found 39 version(s) in nuget.org [ Nearest version: 3.0.0-beta.2 ]

* Found 0 version(s) in Basappa_Huddar

* Found 0 version(s) in /usr/local/share/dotnet/library-packs

published nuget package is not availble in https://api.nuget.org/v3-flatcontainer/plugin.ble/index.json

The nupkg built from this PR is not available on nuget.org, but you can just download it manually and use a local package source (in your case, copying it to /usr/local/share/dotnet/library-packs should be sufficient, judging from the output above).

@BasuHuddar
Copy link

@janusw It's not working

@janusw
Copy link
Member Author

janusw commented Apr 8, 2023

@janusw It's not working

Huh, any idea why? Could you do some debugging (maybe with the sample app)? (AFAICT my commit should more-or-less do the same as yours, but maybe it differs in some detail.)

I tried the branch myself (with a Samsung Galaxy S21+ running Android 13), and I found some devices that advertise themselves with a CompleteLocalName or a ShortLocalName, but in both cases the device name was already set to that name (i.e. I cannot really reproduce the problem you're having, so that I cannot actually test the fix).

@BasuHuddar
Copy link

@janusw Yes i added the committed code into the sample code base, but in the advertising flag, i dint find out the CompleteLocalName or a ShortLocalName in Android 13(Samsung M33 5G), but in Android 11(Samsung M40) able to find the CompleteLocalName or a ShortLocalName
Android13

Android11

PFA

@janusw
Copy link
Member Author

janusw commented Apr 10, 2023

@janusw Yes i added the committed code into the sample code base

Actually it should not be necessary to add any code manually (and it should be avoided for the sake of reproducibility). Instead you can simply build the sample client on my branch.

but in the advertising flag, i dint find out the CompleteLocalName or a ShortLocalName in Android 13(Samsung M33 5G), but in Android 11(Samsung M40) able to find the CompleteLocalName or a ShortLocalName

Hm, so either the difference is due to the different device and Android version, or there is a problem when parsing the advertisement records?

As noted above, I see both *LocalName records on Android 13.

It's still unclear to me why your branch works for you, but mine doesn't?!?

@BasuHuddar
Copy link

@janusw For me im getting error in your branch(master), unable to build the solution for me.

I am able to build 2.1.3 tag version, but not getting the completelocal name.

Yeah, may be parsing is differing from one android mobile to another mobile.

And i tested it by using the published nuget package (Plugin.BLE.3.0.0-beta.2-9-ge0b2bd8.nupkg), this is also not working.

But this commit is working on my SamsungM33.

d452eea

@janusw
Copy link
Member Author

janusw commented Apr 16, 2023

@janusw For me im getting error in your branch(master), unable to build the solution for me.

I am able to build 2.1.3 tag version, but not getting the completelocal name.

Yeah, may be parsing is differing from one android mobile to another mobile.

And i tested it by using the published nuget package (Plugin.BLE.3.0.0-beta.2-9-ge0b2bd8.nupkg), this is also not working.

But this commit is working on my SamsungM33.

d452eea

So, if your commit above is working, but my PR here is not (and you don't even see a CompleteLocalName record), then it sounds like there may be a problem with parsing the raw advertisement data into AdvertisementRecord structures (which is done in Plugin.BLE.Android.Device.ParseScanRecord).

Since I have no way of reproducing the problem, I'm afraid you'll have to debug this on your own (or you tell me how to reproduce it). I guess the best setup for you to debug this is with the sample client on v2.1.3 (which should probably behave the same way as master in this respect). Try to step through ParseScanRecord to see what it does, if it behaves as expected and check if there are any errors or exceptions.

Good luck (and please report any findings here)!

@samirgcofficial
Copy link

Hi @janusw I created the new maui app and added the above local nuget package to test just the android names are visible or not then found Names are not visible can you help me what i'am missing ?
http://xamaringuyshow.com/wp-content/uploads/2023/07/BLEMAUIApp.zip

@janusw
Copy link
Member Author

janusw commented Jul 5, 2023

Hi Samir,

Hi @janusw I created the new maui app and added the above local nuget package to test just the android names are visible or not then found Names are not visible can you help me what i'am missing ?

you may not be missing anything. This PR was an attempt to fix the missing device names on Android, but @BasuHuddar already reported that it does not seem to help.

It would be great if you could help to debug the problem. Under which conditions does it occur? Are you missing device names only for particular devices, or for all of them? Does it make a difference on which Android version it runs? Are you using a scan filter?

@samirgcofficial
Copy link

Hi @janusw I tested in all the real android devices using my code it does not work. My Android Devices are VivoV15 pro, SamsungA51 which are on Android 10 and Android 12 running.
Are you using a scan filter? - > Tried it but failed.

@janusw
Copy link
Member Author

janusw commented Jul 6, 2023

Are you using a scan filter? - > Tried it but failed.

Hm, what kind of filter did you try?

The reason I was asking is because using a scan filter was the only condition under which I could reproduce the missing device names, see #660 (comment)

@vitalii-vov
Copy link
Contributor

Please try that #660 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BLE devices are retuning device name NULL during scanning process on android 13
4 participants