elastic-rock / KeepScreenOn

An Android screen timeout quick settings tile
GNU General Public License v3.0
131 stars 4 forks source link

Keep Screen On keeps crashing (exception and logcat provided) #18

Closed aureq closed 6 months ago

aureq commented 9 months ago

I'm running on the latest version of GrapheneOS and the latest version of KeepScreenOn (via f-droid). When I unlock my phone, KeepScreenOn keeps crashing and below is the exception that's generated. I've also attached the logcat in hope this might help Keep Screen On log 53aeee890cf9.txt.

Let me know if you need further information or tests on my end.

type: crash
osVersion: google/bluejay/bluejay:14/UQ1A.240105.002/2024011600:user/release-keys
package: com.elasticrock.keepscreenon:22
process: com.elasticrock.keepscreenon
processUptime: 539002 + 341 ms
installer: com.android.packageinstaller

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.service.quicksettings.Tile.setLabel(java.lang.CharSequence)' on a null object reference
    at com.elasticrock.keepscreenon.QSTileService.onStartListening(SourceFile:71)
    at android.service.quicksettings.TileService$H.handleMessage(TileService.java:488)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8279)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ExecInit.main(ExecInit.java:49)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
elastic-rock commented 9 months ago

From the logcat you provided, it seems that the problem is in the background start of the service responsible for restoring the timeout when battery is low and/or screen is turned off. Prior to version 1.16.1, it was possible to use the feature without exempting the app from battery optimization, but it is now mandatory, as the the service sometimes started and sometimes not when the exemption was not granted. The user is, however, confronted with the requirement only when enabling/disabling the functions, so existing users are able to use the function without battery optimizations ignored, unless they make changes in the app itself. Therefore, exempt the app from battery optimizations and tell me if this fixes the issue.

P.S. Thanks for the logcat 🙂

aureq commented 9 months ago

Thanks a lot for the explanation @elastic-rock

I've manually set the setting as your recommended and so far no reboot. I will keep you posted over the next few days whether or not I see another crash.

aureq commented 9 months ago

Ok, so after giving it a few days, the app is still randomly crashing.

The KeepScreenOn app shows the tile is correctly installed and all the permissions have been granted correctly.

The 1st occurrence below occurred when I switch back to my main Android user, the second, about an hour later occurred after browsing for a while.

  1. crash report = Error in Keep Screen On 212e6c3f3e6e.txt, logcat = Keep Screen On log 9c33df6c3f5f.txt
  2. crash report = Error in Keep Screen On 2e9642feb9ab.txt, logcat = Keep Screen On log cf71e7d98e8b.txt
elastic-rock commented 9 months ago

It seems the app crashes because it calls setLabel() without knowing the Tile object for which it should do so. However, I have no idea why this is the case, because it should take the Tile object from the TileService() class. Additionally, this is not a problem on my Pixel running the stock os. It might be a GrapheneOS thing, idk. If you haven't tried reinstalling the app, try so, but I fear that won't help anything. 🙁

aureq commented 9 months ago

Ah! Interesting. I'm running multiple Androind profiles on my phone (as a way to separate some apps). The app tends to crash more often when coming back to the profile where the app is installed.

I've deployed the latest f-droid update this morning. Would you like me to keep updating this issue if I see new crashes?

elastic-rock commented 9 months ago

I think you do not need to post new logcats if you encounter crashes. I will try to get Graphene OS up and running in the emulator to hopefully reproduce the crashes.

elastic-rock commented 6 months ago

I've tested it on grapheneos but no crashes occur to me

aureq commented 6 months ago

@elastic-rock The issue occurs only when switching user profiles. If you only use a single profile, then everything works as expected.