App logs are sometimes absent from Android bugreport - android

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)?

Related

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?

How to enable / disable Bluetooth hardware initialization logging on 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.

Android ADB not detecting device

There's absolutely heaps of these questions out there, all with a seemingly random assembly of answers that don't really talk about why, and don't offer anything that at least covers ALL of the reasonable approaches.
I'm running ADB on OSX, but I've got other team members using Linux (Ubuntu) and I occasionally use Windows. OS doesn't really seem to matter, so long as the relevant USB driver has been installed on Windows.
I've got a heap of different makes and models of phone that I'm swapping in and out. Sometimes a phone that previously worked stops being recognised by adb devices. So not really specific to a particular phone.
I've got a USB cable that I know works, for several makes/models of phone.
But still, when I get a new phone to try I still have to faff around with it to get it working.
What I'm after is a checklist of sorts, that results in a reasonable chance of success in getting adb devices to work.
So here's what I've found:
Hardware:
Good USB cable - if it works for one phone it will probably
work for others. If it consistently stops working, throw it away and
get another.
Phone/Tablet/Device - Pre-requisites:
Make sure the phone is charged up - at least 30% seems to be a common
minimum.
Get all system updates and app updates done.
Enable Developer Mode. Settings->About phone->Build number - tap 7 times
Computer - the 'turn it off and on again' approach:
This is useful to know, but doesn't generally get things working. It goes like this:
adb kill-server
adb start-server
adb devices
If you don't see your device after adb devices then the above isn't the answer (but it's still good to know).
Phone/Tablet/Device - the 'wipe it and start again' approach:
This is basically clear your current settings and then re-establish them.
In Developer options, under Debugging:
Turn OFF USB debugging (some phones won't let you click this option - thanks LG)
Click/Tap Revoke USB debugging authorizations
Turn ON USB debugging, answer OK to the first dialog
And if you device is already plugged in:
WAIT, for a second prompt asking if you want 'Allow USB debugging' and click 'OK' - not every device will trigger this second prompt straight away, but give it 5 to 10 seconds just in case.
Now, get permission for EVERY use of the USB connection.
Swipe down from the top and tap on the item for USB connection.
Systematically work through every option your device provides and grant permission when asked. Don't do just one option, do ALL of them, including Charge phone.
Having given permission for one of the usages of the USB connection some devices will give permission for everything - but most won't. For the majority you should go through each one and give the permission. Just to add to the confusion some devices will require you to revisit an option a second time before they give you the prompt asking for permission (thanks again LG).
Now try adb devices again. Still nothing? Go back through the USB usage options again from start to finish (I kid you not).
You may still need to reboot the device and/or swap between media transfer and photo transfer to get it showing up on adb devices.
So what if a previously working device stops working? Go through the 'wipe it and start again' approach first. It's likely to be the most effective. but I'd definitely check whether its time to retire the USB cable as well.

Cannot run on production devices

When I run my application, the message below is printed in the error log. I don't understand if the problem is from my application or if the message is printed by my Android device.
E/NEW_BHD: Cannot run on production devices!
I read this answer Unable to run 'adb root' on a rooted Android phone , but my device is not rooted.
Why this error log is printed ?
Try enabling this function: go to Settings -> Security Just activate Unknown sources.
Now that you're ready to install your apk.
The main problem (I believe) that causes this, is your mobile's battery.
When Motorola mobiles have low battery, and they're connected to a computer, the USB option for the mobile will be forced to charging only mode.
To solve this, just swipe down from the top, click the USB for charging, touch for more options and select File Transfer. This will resolve your problem.
Try to active Developer Mode on setting of your device.
Enable Developer Options In Android 6.0 Marshmallow
Pull down on the notifications shade and open the Settings app. You can also achieve the same thing from the app drawer if you so wish.
Scroll all the way down and tap on ‘About phone’.
Now scroll down again and you’ll see an entry labelled ‘Build number’. Keep on tapping till you see a prompt that says ‘You are now a developer!’

Testing an android app for restart functionality

I am trying to develop an Android App that, though having an Activity, needs to run in the background as a service. The app needs to start up automatically after rebooting the phone/device.
My question is HOW to troubleshoot such requirements, since the LogCat gets disconnected when the phone is rebooted, even using "adb shell broadcast -am android.intent.action.BOOT_COMPLETED" on a connected phone. (Though possible on an emulator, I dont feel like it is able to properly replicate real-world scenarios). I would like to be able to see the Logcat messages after device restarts, thus allowing me to troubleshoot ANRs and app crashes during reboot.
Any pointers would be appreciated.
Based on this link, I understand the closest we can get to debugging reboot errors is to use
adb logcat -v time > <localfile>
or
adb bugreport
Both of these options may not be the cleanest ways to pinpoint the issue, but atleast something is better than nothing.

Categories

Resources