Sublimis / UrbanBiker

Urban Biker issue tracker and Knowledge Base
https://urban-bike-computer.com/
18 stars 4 forks source link

Won't run with screen off on Android 12/OnePlus 9/ColorOS #178

Closed zim2dive closed 1 year ago

zim2dive commented 1 year ago

I used to be able to start a ride/recording and then turn off the screen (to save battery) and UB would continue to run, and take the place of my lock screen if I tapped the phone.

With ColorOS12, I am not able to get this to work. If I turn off the screen for more than a timeout period, when I tap the screen, UB is NOT there as the lock screen.. I then have to unlock, and I see that UB seemingly went to sleep (did not continue to count distance/time/etc).

I have disabled every battery setting I can find, and am stumped as to what to try next. Currently I can only record a full ride by keeping the screen ON the entire time.

thanks for any ideas.

Sublimis commented 1 year ago

Hi!

Does the app have it's notification and notification icon displayed while tracking is active in that case? Having its notification displayed is essential for the app to continue running after the screen is turned off.

Since the app doesn't show on the lock screen, presumably the notification wasn't created upon tracking start. If this is true, it means that the system didn't allow the app to create its notification.

Can you please click the "Report an issue" from within the app itself (main menu) and send us your log files. Alternatively, you can open up log files yourself and see if there's any mention of the following (or similar):

android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.sublimis.urbanbiker/.ServiceMain

This would be the easiest explanation. It means that battery optimizations are still active for the app, otherwise the app would be able to display its notification icon.

The app usually checks whether battery optimizations are still active before tracking starts, and shows a dialog, however if you ignored that dialog or clicked "Later", the app won't ask for another 3 days. We now lowered this interval to 1 hour for the next version release.

If the above is correct, possible workaround could be to enable the option "Persistent notification" in Settings > Advanced within the app.

Please let us know how this goes. Thanks for the feedback!

zim2dive commented 1 year ago

I enabled "Persistent notification" and that worked on my ride this morning... so many thanks for that suggestion!

if that tells you what you need to know we can stop here, but I am happy to try to provide more debug info if it would help

a) I started to "Report an issue" within the app, but it didn't appear that it was going to attach any logs automatically? b) I am not scared to follow instructions, but don't normally keep adb installed, etc. I was able to install a logcat program, and with Android 12 I had to use adb to disable permission checking... but I'm not familiar enough with this debug to know if there is just one main syslog (which we'd grep for relevant UB messages) vs. log files for each app.

So again.. happy to provide more debug info, but will need some basic instructions.

zim2dive commented 1 year ago

One other data point... I have attempted to find every place in settings where I could enable unlimited battery for UB... but I still get the reminder screen when I launch it (every 3 days).. but what is curious is that if I click thru from the dialog box, it takes me to a battery setting page on which UB is NOT listed as an option to adjust.

Again, this is OnePlus, ColrOS(?) Android 12... as a long time OnePlus user, I think their OS switch has been, ehem, not a success, and their settings are so fragmented across many menu sub-hierarchies.. but again, for whatever reason, Urban Biker is not listed on the battery page it takes me to from within UB. FWIW, I have signed up for the beta, which I'm assuming will have the more frequent battery reminder (not that I'm sure it will have any more success, but it will offer more frequent testing)

Sublimis commented 1 year ago

Sorry for not being clear, the mentioned log files are located in the folder /Android/data/com.sublimis.urbanbiker/files/Documents/UrbanBiker and named debug1.log and debug2.log, no need to access the logcat. If there are no debug files attached in the email after the "Report an issue" is used, chances are that no debug files were created so far (and this is perfectly okay, as it means the app had nothing to report).

About the ColorOS and battery optimization settings. Does your Battery optimization screen look similar to the screenshots below (created on stock Android 12)? Important thing to note is that you must select "All apps" from the drop down list, only then will the Urban Biker appear in the main list.

Thanks for the feedback!

Screenshot_1 Screenshot_2

zim2dive commented 1 year ago

I see the dialog inside UB, which then takes me to the 2nd Screenshot where I do not see UB, nor do I see any option for expanding the list of available apps to pick from (already seems like 90%+ which seems odd).. also checked and there were no debug log files. Screenshot_2022-10-18-10-33-50-36_fc704e6b13c4fb26bf5e411f75da84f2 Screenshot_2022-10-18-10-33-38-63_8bea59df4efca3ebec46d4deccdfa44c

Sublimis commented 1 year ago

This is very strange, it could be a bug in the system. Just to be clear, Urban Biker is not listed under the "Work" tab either? Maybe some information from this link could help?

zim2dive commented 1 year ago

Correct.. I checked under "Work" and also looked at the com. section (just in case).. UB isn't there.. Now understand the above screenshot is what I see when UB attempts to take me to the battery optimizations ... but if I try to navigate to the same/equivalent place, I end up here.. which is not exactly the same.. and* you'll note according to this page I HAVE enabled "don't optimize".. yet the behavior from UB would suggest that UB doesn't agree (based on whatever status bits it checks.. and the real world behavior also tends to suggest UB is correct in its interpretation.. else I wouldn't need to enable the persistent notifications)... so I'd be leaning towards "bug in the system".. altho again I find it curious that UB takes me to a different battery optimization page vs. what I find if I navigate thru the settings menus....

Screenshot_2022-10-19-12-33-47-29_0ba066473b79d6e213a1f6f52505e2ee

Sublimis commented 1 year ago

There's only so much an app can do to manage its battery optimization status: Call a function called isIgnoringBatteryOptimizations which returns a simple TRUE or FALSE answer, and based on that decide whether to lead the user to the setting screen by using the intent action. If a former function call returns bogus answers, the app is helpless, it has no other option but to trust. So yes, this is almost certainly a bug in the system which will hopefully be resolved by some future system update.

On stock Android 12 the situation with settings screens is the same as you describe. By navigating manually there is no such battery optimizations screen like the one you get when you let the application open it for you. Very strange.

However, since you were able to fix the app's behavior by using persistent notification, it seems that the system correctly recognizes that the app is not optimized once it shows the notification. So we focused on this, and made some slight changes to the way the app requests notification, so hopefully there will be no more problems at least with this part (starting from the next beta release).

Thanks for the feedback!

zim2dive commented 1 year ago

One follow-up request... IF/when the user has selected "Persistent notification" in Settings > Advanced , could you disable the check for Battery optimization? ie. The work-around is working just fine for me.. but I am always asked if I want to fix the battery setting (which I can't). It would be nice not to have to dismiss this "Later" every time I start a ride.

Minor, but would be nice.

thanks! Mike