How to enable / disable Bluetooth hardware initialization logging on Android? - android

The short question is: Is there a way to enable / disable logging of the Bluetooth hardware initialization on Android? If so, how?
I'm having two "Samsung Galaxy Tab A 10.5" devices and a BLE app I'm currently working on. The app is working flawlessly on one device. The second device, however, does
not find any Bluetooth devices when scanning.
The issue was discovered about a month ago. Those days a quick look at logcat revealed plenty of HIDL related error messages. Now, a few weeks later, the HIDL messages no longer appear in logcat. However, scanning still doesn't work.
Oddly enough, there's not even a single Bluetooth related message in logcat, which makes debugging this issue a little difficult.
EDIT:
Enabling HCI snoop log just revealed a single error message:
*** command 'lshal debug -E android.hardware.bluetooth#1.0::IBluetoothHci/default' failed: exit code 128
It is obvious that one of the tablets is damaged. Interesting is why the HIDL error messages all out of a sudden stopped showing up, and how to get them back?
The actual problem is that Bluetooth, although initialization finishes without errors, isn't working. The question is, how can an app detect it and warn the user about it?
I thought about detecting malfunctioning Bluetooth by reading the logs: If scanning for Bluetooth devices does not yield any results and if there are some HIDL error messages logged, than the user should be warned that there is something wrong with the device running the app.
Now with the HIDL error messages gone, a different approach is needed. Do you have a better idea how to detect if Bluetooth is functioning?

You can enable bluetooth HCI snoop log in developer options:
device settings -> developer options -> enable bluetooth HCI snoop log.
Detailed instruction - how to enable HCI log.

Related

App logs are sometimes absent from Android bugreport

I'm trying to get logs from a certain Android application (KDE Connect, if this is relevant), whenever a certain issue/error happens.
When I reproduce the issue first, then connect to the phone over USB (USB debugging enabled) and run adb bugreport to capture a bug report -- I cannot see any logs from the application, in the zip's logcat. (I can see other logs from the issue's timeframe though, even from hours earlier, so this doesn't look like a buffer issue)
When I connect to the phone over USB first (USB debugging enabled), reproduce the issue and then run adb bugreport -- I can see the interesting app logs, even a backtrace of the interesting errors, in the zip's logcat.
So it would appear there is a difference in what gets logged when USB debugging is connected/enabled, versus when it is not. I'm no Android developer but I cannot find any info on this behaviour.
Does anyone have an explanation (and sources)?

Gathering logs without using adb

I am trying to troubleshoot a bug on my app, and need to access the logs.
I normally would do this by connecting my device and using adb logcat (either by USB or WiFi).
The problem I have is, the bug I am looking into is not reproduced when the device is connected to the USB or connected to adb via WiFi. So in other words, I need to view logs, but when I connect adb the bug does not happen.
Does Android store a log buffer on memory that can be downloaded after the fact?
ADB stores the log messages in a small RAM based ring buffer. That means the newest message overwrites the oldest message. If you connect a device via USB and execute adb logcat logcat first prints all messages from that buffer and then waits for new messages and prints each of them.
Thus if you connect your phone via USB and execute adb logcat you will get also messages that appeared before you connected your phone via USB.
How many of those "old" messages you can get depends on the number of logcat messages per second and the configured adb logcat buffer size.
The logcat buffer size can be configured in Developer Options as described here.
The number of messages per second can depends on the used device and the number of installed and active apps. Some devices have multiple messages per second (I remember especially Samsung devices having a high frequency of logcat messages). The number of messages can not be configured or directly changed. You can only try to stop/kill or disable apps to reduce the number of messages if you need to.
But usually increasing the logact buffer should be sufficient. So you can reproduce the error, then connect the phone via USB and directly execute adb logcat. Hopefully the error is then included in logcat output.
Option 1.
You can try taking the bug report that is available on the device level, tough it is not the best experience. This is inside "Developer Options" menu.
Option 2. There are many applications available at play store for Logcat. One that I just tried is "Logcat Reader".
Option 3. Requires effort and coding. Switch to a logging library that can write application logs to a file. One famous logging library is Timber, and these are some suggestions how to configure it to log in files: Android: a library to write log on file?

Communication Timeout Disconnect status 8 after Notifications Enabled (Android 7.1.2)

I'm developing a Android Application to control a small device over BLE. The app is more or less finished, but during testing we noticed some weird behaviour. On most phones there are no issues, but on Android 7.1.2 the app keeps disconnecting after notifications are enabled.
The App works perfectly on most phones we tested on, but on Android 7.1.2 the phones disconnect with status 8 (connection timeout) once notifications are enabled.
We are using the RN4870 michrochip module, which might have some issues with it, seeing as when we wrote a simulated peripheral app to run on another phone, the problem phone connected and remained connected after notifications were enabled.
From further reading, the primary issue seems to be with the connection parameters being set to 20 seconds for supervision timeout on the problem phones, which appeared to cause issues for other developers and has appeared in various bug reports for google.
-- edit --
A link to the hci snoop file,
https://drive.google.com/open?id=1XzzwfhVGoZ__sP7R4BkMwnU-ahOgR8-a
Thanks for advance for any help, and if anyone requires anything to be edited feel free to let me know (my first forum post).
Bluetooth error code 0x08 (Connection Timeout) simply means that the two Bluetooth chips lost each other. It has nothing to do with the Android software since Android runs on the main CPU (in another chip). Having notifications enabled or not should also not make any difference, other than the fact that some data is being sent over the link to set that up.
The timeout of 20 seconds has been reduced to 5 seconds in newer Android versions since as you noticed 20 seconds are too much for most cases. It is however not a bug, just a feature.
If you get a BLE sniffer you should be able to figure out which device you should blame.

Is it possible to monitor discovering process when using Google Nearby Connections 2.0?

I have been playing around with Google Nearby Connections 2.0 sample program: walkietalkie. I ran the APP on several android phones and tablets. I usually put one device on advertising mode and other devices in discovering mode very close by. The devices sometimes discover successfully but also fail to discover frequently.
Is there a way to monitor the Bluetooth discovering process to get more information? I suspect Bluetooth pairing issue.
You can filter for the log tags 'NearbyConnections' and 'NearbyMediums'
adb logcat NearbyConnections:* NearbyMediums:* *:S
That will print out any warnings and/or errors that occur. If you find a device that's particularly troublesome, give me the model number and I'll add it to our test suite. [Disclaimer: I work on Nearby Connections]

Android, Bluetooth, BTLE, GATT reading characteristic fails?

I have an android app i am developing. It's a BTLE app, i have some BTLE tags i need to talk to.
I do all by the book, discover device, GATT connect (subsequent bonding), write/read characteristics... it works.
Now the weird is that it will stop working if i close and open the application two times.
Let's say i have already one tag correctly connected, bonded and working properly.
phone reboot.
Open app the first time -> everything works.
close app, open again -> everything works.
close app again, open -> unable to receive any readCharacteristic from the GATT callbacks.
In the logs, there is NOTHING DIFFERENT from each attempt. I log each call and print return statuses: no difference. Just the readChar callback is never called.
Android is 4.3, same issue on different phones (S3, S4, Note3)
(note: on app shutdown i properly disconnect all the GATT stuff)
Do you have any ideas on what to check? Or is this a known android bug? I have searched, but could not find anything....
The bluetooth stack on Android 4.3(at least) specially for BTLE definitely has quite some issues. I don't know if it's a specific vendor implementation, driver issues, or what else, but it's honestly a nightmare for developers.
This is what i found out does help to improve things:
- disable Wifi
- forcefully enable/disable bluetooth by code (BluetoothAdapter methods enable() and disable())
In fact, cyclying bluetooth on and off when things start getting "unstable" do fix it. This requires the BLUETOOTH_ADMIN capability and might clearly not be desired, since it will briefly shut down ALL you bluetooth conencted gadgets AND will popup some dialogs to the user where he/she can disable the ongoing restart.
Now i am getting more stable results.
Still, shame on Google (or whoever i don't know) for letting such poor software out in the wild.

Categories

Resources