OpenTracksApp / OpenTracks

OpenTracks is a sport tracking application that completely respects your privacy.
https://OpenTracksApp.com
Apache License 2.0
1.07k stars 190 forks source link

Unexpected crash after unlock phone #1824

Closed duhow closed 8 months ago

duhow commented 10 months ago

App information

Device information

Firmware

Cause of error

Exception in thread "main": android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{842e215 u0 de.dennisguse.opentracks/.services.TrackRecordingService}
    at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2315)
    at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2286)
    at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2611)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8893)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here
    at android.app.ContextImpl.startServiceCommon(ContextImpl.java:2023)
    at android.app.ContextImpl.startForegroundService(ContextImpl.java:1967)
    at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
    at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
    at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:1189)
    at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:752)
    at de.dennisguse.opentracks.services.TrackRecordingServiceConnection.execute(TrackRecordingServiceConnection.java:164)
    at de.dennisguse.opentracks.publicapi.AbstractAPIActivity.onCreate(AbstractAPIActivity.java:40)
    at android.app.Activity.performCreate(Activity.java:8944)
    at android.app.Activity.performCreate(Activity.java:8913)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4146)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4322)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
    ... 7 more
dennisguse commented 10 months ago

Is this reproducible and if so: how?

duhow commented 10 months ago

It's the first time I have seen a crash from the app. Unlocked the phone and found it. I suspect that Gadgetbridge may have triggered it?

dennisguse commented 10 months ago

Was any data recorded aka did OpenTracks crash immediately after triggering record? And you triggered it via Gadgetbridge. This implies the screen was off when you started the recording?

duhow commented 10 months ago

I did not open OpenTracks app for weeks. Just did some exercise with my Mi Band, get my phone 10 minutes later, unlock it, and find this crash report.

dennisguse commented 10 months ago

OK. Could you try if this is always crashing or only sometimes? I don't have this setup at hand.

bentolor commented 9 months ago

Thank you very much, Dennis, for your valueable tool. This helps me to increase the value of my otherwise rather dumb Mi Band 5. I've got the same/similar error: I see a full-screen error screen with an OpenTracks error.

I assume this happens whenever I move and my paired Mi Band 5 autodetect walking as activity: This causes a request to Gadgetbridge to start a recording. Of course the phone is locked at this moment.

This reproducible: @dennisguse

  1. Lock phone screen.
  2. Initiate a GPS-based activity on the Mi Band (i.e. Cycling).
  3. Stop it directly before actually starting the activity.
  4. After phone screen unlock, crash screen is displayed.

App information

Device information

Firmware

Cause of error

Exception in thread "main": android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{c7c0eb u0 de.dennisguse.opentracks/.services.TrackRecordingService}
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2005)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7664)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Nota bene: I've been using this combination since quite a long time. So this error only has become visible since some update in the past month. Never seen this error before. Not sure if update from GB or OpenTracks.

dennisguse commented 9 months ago

@bentolor Can you check that this PR fixes the issue? https://github.com/OpenTracksApp/OpenTracks/pull/1855

I don't have a device at hand that I can use for testing :/

bentolor commented 9 months ago

Thanks @dennisguse for your quick reaction!

I just installed the nightly APK attached to the merge request, installed it on my phone, changed the package name in GB to *.nightly and then successfully executed the testcase above without any errors.

Buuuuut: Then I revert my changes above and tried to reproduce and… was not able to reproduce.

Since our last conversation my F-Droid upgraded OT from v4.11.0 to v4.11.1: Could this patch already have fixed the issue? Otherwise it seems my reproduce is only stable under some circumstances and I'm unable to actually confirm or deny the fix is working.

Not sure how to proceed from here on: Is it safe to merge the change anyway?

dennisguse commented 9 months ago

v4.11.1 is broken and v4.11.2 reverts the initial fix. The recording was just stopped when the screen is turned as the recording service was started incorrectly.

This PR contains a (hopefully) correct fix. Can you try it for a real recording (outdoor, screen off, more than 10min; started and stopped via watch)?

bentolor commented 9 months ago

Let me check I'm able to reproduce. Might take some time until I get the opportunity. Thank you for your support!

bentolor commented 8 months ago

Sorry for my lack of feedback @dennisguse , but I struggled to actually replicate the issue stably, even though I was able to reproduce it stably when I wrote my comment above.

So it seems some additional state comes into play. I've successfully run nightly and yet not observed the issue, but I cannot confirm it really addresses it. So hope this works.

Thanks for your support and finger-crossed this solves the issue.

dennisguse commented 8 months ago

@bentolor Thanks. Hope it is solved; if it occurs again, just re-open the issue :D