Closed AeliusSaionji closed 5 years ago
I don't think it's possible: the app needs to receive bluetooth events and BLE beacons. I haven't noticed any difference in battery life though.
I might be able to make the BLE scanner smarter, but manual activation of the scanner is out of the question, it would make the application pretty useless.
I discovered this while investigating battery drain issues :/ My "screen off" idle drain is 2-4%/hour with OpenPods, and 0.5%/hour with OpenPods disabled.
The culprit as revealed by BetterBatteryStats was Bluetooth repeatedly doing a "gatt" scan, which also kept the CPU in higher clock speeds. Thus my phone is never truly sleeping.
Try this APK: app-debug.zip
This only starts the scanner when it detects the connection event. I don't think it's reliable though, especially because I noticed that sometimes the ACL_CONNECTED and ACL_DISCONNECTED events are not sent in the correct order.
Thanks, I'll let you know the results in a day or two!
Yep, before connecting to the airpods, there was no bluetooth activity. After connecting then disconnecting a few times, OpenPods was right back to scanning when the airpods were disconnected. Furthermore, I observed that while airpods are connected and the screen is off, OpenPods is still hitting bluetooth.
Here's a thought: can you pause any and all app functions while the screen is off?
It's exactly what I expected, shit and unreliable, like most android APIs. Yea I could try pausing the scanner when the screen is off, I'll see if that works
I tried repeating what you did but it seems that on my phone the bluetooth scanner does NOT run when the screen is off.
What phone and OS are you running?
Android Pie, basically aosp
Do you have BetterBatteryStats?
Looking at the Alarms view is the fastest way for me to see if OpenPods is running. There are 0 bt alarms otherwise.
I'm using LineageOS 16 which should be pretty close to AOSP. The BLE scanner stops working after a few minutes with the screen turned off.
By the way the Android documentation says that the BLE scanner is supposed to stop scanning with the screen off, as I observed. I'm not sure why it's not doing it on your phone. I will try to investigate it though.
I have the razer phone 2, could be razer messed that up ¯_(ツ)_/¯
The rom is pretty close to aosp, though.
Here's another test APK for you: app-debug.zip
This one tries to turn off the scanner when the screen is turned off. The screen on/off events work, but the stopScan method of the BLE scanner doesn't seem to do jack shit on my phone (android still decides to stop scanning after a few minutes of screen off).
Let me know if it's better for you.
By the way, do you have 1st gen or 2nd gen AirPods?
1st gen.
Thanks, installed, will get back to you later!
Preliminary impression: what black magic did you use to create this? It's more responsive than it ever was about showing the notification, and it's not using the bluetooth radio at all as far as BBS can see. What's the catch? 😆
I didn't do anything, I just added that screen on/off listener. Funny enough, this version does NOT stop scanning on my phone when I turn off the screen, only when android decides to.
Just as a sanity test, I reinstalled the Alpha 9 version currently on F-Droid and kept bluetooth turned on for the last 11 hours. I asked my friend to do the same (he has a samsung stock ROM), and we both got around 2% battery usage from bluetooth, confirming what the android documentation says, no scanning is performed when the screen is off. I can only conclude that your problem must be a bug with razer's ROM.
I could add a switch in the settings to toggle this mode, I have to think about it.
Well, I can confirm OpenPods is working as expected and my phone is down to an idle drain of -0.7%/hr
. Whatever the case, this is the version that is working for me!
I decided to push these changes to master and see if anyone complains; if it happens, I'll go back to Alpha 9.
You can get the updated APK from here: https://downloads.fdossena.com/geth.php?r=openpods-apk
I pulled Alpha 10, sorry :laughing:
I want to add a settings menu where you can toggle this, because Alpha 9 worked better on my phone, and I suspect that it works better for most people too. I'll re-release Alpha 10 tomorrow.
How does it work better for you? Notification pops up faster?
With Alpha 10 sometimes it takes like 30 seconds before it notices that airpods have been connected/disconnected
Alpha 10 is up again at the previous link. You can enable the battery saving in the settings. Let me know if it works for you.
Nope, the power saving setting is not power saving for me!
That's weird, it's the same code as yesterday. Are you sure it isn't working?
I did not actually install the first alpha10 at that url, I only used the app-debug from 2 days ago. With that one, there were zero bluetooth "alarms" in betterbatterystats.
The alpha10, even with that setting checked, is back at it.
Maybe it needs to be restarted to release those wakelocks? I'm really running out of ideas here
Yeah a restart of the app seems to have fixed it, thanks.
Did you restart the app by swiping it from task manager or by force stopping it?
I force stopped it from android
This issue is really bad on Android 11 - both on my Pixel 5 and Pixel 2 xl.
On a 10 seconds logcat dumb (19:40:37.370 -19:40:47.369 to be exact) I have 1571 "BtGatt.ScanManager: awakened up at time XXXXXX" - That's over 100 times/second.
And that causes my phone to never go to deep sleep, thus causing it drain at ~10% battery/hour.
Oddly enough the problem is pressent even after uninstalling the app, and only goes away after a reboot.
Damn, that's really bad. I don't have android 11 yet to test it though.
I definitely don't scan that much, I just start one scanner and restart it if it dies. Can you put a log print here? https://github.com/adolfintel/OpenPods/blob/ae5a1ab119ac1e88ed2710a50b7cc51657bd322f/OpenPods/app/src/main/java/com/dosse/airpods/PodsService.java#L119
It should only be called once or twice.
While I've never done android development I got it up and running and did a log there is only printed once, but after a adding a few more logs, it seems to be the onBatchScanResults method that's called VERY frequently:
Does it change anything if you enable battery saver in the app settings?
That stops it stops the onBatchScanResults and BtGatt spam.
but also causes there to be no notification when my airpods connect.
Actually it's supposed to start/stop the scanner when the screen is turned on/off. Can you see that event in the logcat?
I see those log events, also seems to log when I connect my Airpods, just no notification.
It still detects connections even with screen off.
It doesn't receive anything, otherwise you'd see the data coming from the airpods. So basically both modes of BLE scanning are broken: regular scanning rapes the battery, slow scanning doesn't work at all. Brilliant
I'll create an issue about Android 11 compatibility, maybe others can provide insights
Using regular scanning I do get some data on connection:
Cool - Let me know if I can provide anything else.
Your device has a qualcomm soc, right?
Correct - for a bit more info I'm seeing it on both a Pixel 5 (765G) and Pixel 2 xl (835)
It still does this on a Pixel 2 XL and Pixel 4 XL.
I thought something was wrong with Bluetooth on the 2 XL for months and then I got the 4 XL and experienced the same exact issue, I had to leave Bluetooth off all the time to prevent the insane battery drain. Finally I figured out it was openpods causing the issue and uninstalled it.
I've been using materialpods and it doesn't drain the battery at all, not sure how it works differently but it certainly does.
Hello!
I've recently become aware that this app is preventing my phone from entering deep sleep. It's issuing a wakelock anywhere from 15 to 40 times a minute, all the time. I was probably the one who requested the feature that forced you to do that :smile:
Is there any way you can stop the scanning unless it's a) connected or b) manually requested?
Thanks!