osmandapp / OsmAnd

OsmAnd
https://osmand.net
Other
4.63k stars 1.01k forks source link

Music app crashes in some cases #16578

Open breversa opened 1 year ago

breversa commented 1 year ago

Description

This is a reopening of https://github.com/osmandapp/OsmAnd/issues/3682: Using routing with voice guidance would randomly crash the playing music app (I'm using Auxio : https://github.com/OxygenCobalt/Auxio).

Steps to reproduce

  1. Play music with Auxio
  2. Start routing with OsmAnd with voice guidance

Actual result

Auxio will randomly crash Bug report: https://github.com/OxygenCobalt/Auxio/files/10831236/bugreport-starltexx-QQ3A.200805.001-2023-02-25-12-26-43.zip

Expected result

Auxio will not crash

Your Environment

OsmAnd Version: 4.3.8 Android/iOS version: Android 10 (/e/OS 1.8.1) Device model: Samsung Galaxy S9 (SM-G960F)

Additional info

It doesn't seem to be an Auxio bug, but an OsmAnd one: https://github.com/OxygenCobalt/Auxio/issues/362#issuecomment-1445162872 I think that other music apps crash as well but I'm not certain. Other navigation apps (such as Magic Earth) don't crash Auxio.

sonora commented 1 year ago

The analysis already performed and linked to above indicates that there is no crash, instead your system seems to rather agressively kill background apps.

This is usually done to save battery (if battery saving modes are enabled), or free up memory, or both.

Do you run any dedicated power saving or system optimization app? Have you tried if exempting Auxio from the system battery optimization (a link explaining how to do that is in the prior analysis) or temporarily disabling all power saving settings as far as possible does make any difference?

breversa commented 1 year ago

Hello Hardy!

I'm running /e/OS which is a fork of LineageOS, so I guess there's pretty much no Samsung shenanigan at work to limit the battery use. I can however disable battery optimization for Auxio, but what puzzles me is that only when using OsmAnd does Auxio crash, hence the present bug report ("Your navigator app is really resource-hungry" : is that so?).

sonora commented 1 year ago

Well, undoubtedly reading map data, calculating routing algorithms, and producing screen and voice output are demanding processes to some degree.

But having said that, I have over the years run OsmAnd on many a mid and even low end Samsung devices (always using Stock ROMs, though), and yes, sometimes run music apps like TuneIn or Audible (online radio) or Samsung Music (local MP3s) in parallel. I may ne wrong, but cannot really say I recall that one of these apps was killed ever while playing music...

How long does it actually take on average before this happensfor you, seconds, minutes, hours?

Another thing that strikes me is that I currently know of only two reportings in our Issues list, so not a mainstream problem, it seems. Both reports are from you 😉 , both apparently on different devices and with different music apps (?), but both on custom ROMs, right? I am still fishing for some facts or correlations which could shed some light here...

TheSnoozer commented 1 year ago

Unsure if it's related, but the MediaCodec mentioned in the stacktrace would suggest so:

Cmdline: net.osmand.plus
pid: 7520, tid: 7590, name: NDK MediaCodec_  >>> net.osmand.plus <<<
uid: 10248
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Cause: null pointer dereference
    x0  0000000000000000  x1  0000000000000000  x2  0000000000000000  x3  0000007db67dd000
    x4  0000000000000038  x5  0000000000000073  x6  653d2c66726c2720  x7  7f7f7f7f7f7f7f7f
    x8  0000000000000000  x9  0000000000000000  x10 0000000000000001  x11 0000000000000000
    x12 0000000000000000  x13 0000000063f74513  x14 0027b8ef4d54958b  x15 000022232ec4f50c
    x16 0000007dae4f5228  x17 0000007d98121f60  x18 0000007c7de5a000  x19 0000007c7fdfb930
    x20 b400007c8a2c5300  x21 b400007c8a2c5018  x22 0000007c7ebfe000  x23 0000007dae4f1118
    x24 0000007c7ebfdcb0  x25 0000007c7ebfd8b0  x26 0000007c7ebfe000  x27 00000000000fe000
    x28 00000000000fc000  x29 0000007c7ebfd670
    lr  0000007dae4935c4  sp  0000007c7ebfd640  pc  0000007dae4935d8  pst 0000000060001000

backtrace:
      #00 pc 00000000000515d8  /system/lib64/libsfplugin_ccodec.so (android::CCodecBufferChannel::getOutputBufferArray(android::Vector<android::sp<android::MediaCodecBuffer> >*)+128) (BuildId: 6280bfee5d79c79e77ca8e87bcfbc816)
      #01 pc 0000000000121df0  /system/lib64/libstagefright.so (android::MediaCodec::onMessageReceived(android::sp<android::AMessage> const&)+3496) (BuildId: 58cd657e3d929d2afd5272abeb625c97)
      #02 pc 00000000000188ec  /system/lib64/libstagefright_foundation.so (android::AHandler::deliverMessage(android::sp<android::AMessage> const&)+84) (BuildId: a27e60196e4bf8796af5e81fa8011628)
      #03 pc 000000000001e714  /system/lib64/libstagefright_foundation.so (android::AMessage::deliver()+188) (BuildId: a27e60196e4bf8796af5e81fa8011628)
      #04 pc 0000000000019c48  /system/lib64/libstagefright_foundation.so (android::ALooper::loop()+592) (BuildId: a27e60196e4bf8796af5e81fa8011628)
      #05 pc 0000000000012304  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+460) (BuildId: 0c269320029489b4040b2307f9282499)
      #06 pc 00000000000bb584  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+140) (BuildId: c646cf84c51fc07b4bb81680ce4aed68)
      #07 pc 0000000000011acc  /system/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+404) (BuildId: 0c269320029489b4040b2307f9282499)
      #08 pc 00000000000dc188  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+264) (BuildId: f24f65acf653c409ca4332aced817a71)
      #09 pc 000000000007a438  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: f24f65acf653c409ca4332aced817a71)
breversa commented 1 year ago

After more tests, I can confirm that my music player doesn't crash with other navigation app, but (so far) only with OsmAnd. :(

The "good" news is that it happens so frequently that I should be able to reproduce the crash pretty easily and provide a report if needed. :)

(I'll also test with OsmAnd + another music app)

sonora commented 1 year ago

Do you see a time correlation, e.g. the music crashing always exactly when OsmAnd starts to speak, or something along these lines?

Also: What's your audio output do you use: The built in speakers, or a car radio, or some BT device? And does in OsmAnd selecting another Voice guidance output (Go to your Navigation Profile > Configure Profile > Navigation settings > Voice prompts > Voice guidance output) make any difference?

breversa commented 1 year ago

Sadly not: it seems to be almost totally random: Sometimes the music player would crash with no voice guidance, and sometimes voice guidance would not crash the music app. :-/

However, it seems that the more (frequent) the voice guidance, the more probable the music app will crash.

breversa commented 1 year ago

My audio output is TTS (french, using Ivona then Pico) through media/guidance. I don't have Bluetooth in my car so I use a 3,5mm plugged into my audio in.

sonora commented 1 year ago

Temporarily test OsmAnd with "Notification output". It should essentially sound the same,, through the same speaker, only that OsmAnd will then obey the notification (alarms) volume slider. I am not convinced the issue is related to audio output at all, but maybe we discover something...

Also (1): It also happens without using the 3.5mm earplug, right?

Also (2): Do you have a feeling that when it happens, Auxio truly "crashed", i.e. when you open it again, it "behaves" as if it was a fresh app start (is there a splash screen etc., as opposed to maybe it still being in the background, but somehow is not playing music because it merely did not re-gain access to the sound system after OsmAnd stopped speaking.).

breversa commented 1 year ago
  1. Notification output does not prevent the music app from crashing.
  2. Yes, the music app crashes also without jack plugged in.
  3. Yes, Auxio totally crashes, as there is a music library loading screen when I start it again.

I may have discovered something though: I'm currently sitting in my living room testing your suggestions (thanks for your time!!) and trying to provoke the crash (by tapping the "Next turn" button), but it crashes way less often, as if it was more likely tied to position/route calculation than voice guidance…

(Also, Auxio crashed when the screen went off after timeout. Could it be linked to what OsmAnd displays then?)

sonora commented 1 year ago

It had been my feeling all along that not "OsmAnd crashes Auxio" (I would not even know how to do that in Android architecture), but that maybe the Android system stops Auxio under certain circumstances, like perhaps in need for resources when e.g. a route needs recalculating, or the screen needs refreshing, etc. Your observation may point in that direction.

Does closing most other apps and only keeping these two open make a difference?

If you activate the OsmAnd Development plugin under Menu/Plugins, it has a setting to adjust the memory used for routing, maybe also worth testing.

In any case I see no evidence it has to do with sound output. Have again verified that in our code OsmAnd asks for permission to use the audio channel, talks only after granted, and releases audio focus again immediately afterwards, as is prescribed programming practice. So we can probably put audio issues aside for now.

Regarding resource shortage: Can you find other ways to produce the effect, like maybe open more and more apps, and tabs in a web browser, perhaps to heavy duty sites like youtube, and see if that produces a similar effect than when OsmAnd navigates?

breversa commented 1 year ago

Thanks @sonora for your input. :)

I haven't yet tried using resource-heavy apps nor played with the memory in OsmAnd, however I can confirm that other music apps crash while using OsmAnd.

Please find attached two bugreports after such crashes (the app is org.lineageos.eleven)

bugreport-starltexx-QQ3A.200805.001-2023-03-07-16-50-51.zip bugreport-starltexx-QQ3A.200805.001-2023-03-07-16-51-57.zip

sonora commented 1 year ago

I am not very skilled in reading these dump files, but an equivalent of the following lines exists in all 3 files you have submitted and could be related:

03-07 16:51:21.425  1041  4136  4136 E audio_debugfs: dump_audio_debugfs: /sys/kernel/debug/audio/abox_qos open error: No such file or directory
03-07 16:51:21.425  1041  4136  4136 V audio_hw_primary: device-adev_dump: exit with file descriptor(22)
03-07 16:51:21.436  1041  4166 23809 E APM::AudioPolicyEngine/ProductStrategy: dump: failed to convert device 10

Perhaps someone knows what this /sys/kernel/debug/audio/abox_qos open error relates to, or finds the time to research.

secretmango commented 1 year ago

I dont think this issue belongs here. Its obviously the system killing the app. Osmand uses media playback (configurable though) for audio output.

If it was OSMAnd it would just crash itself.

breversa commented 1 year ago

Would anyone know how I can troubleshoot further?

OsmAnd and Auxio are among my favorite apps and not being able to use them together is a real shame. :(

The issue persists with OsmAnd 4.5.10, athough I can now pretty much 100% confirm that it’s not voice guidance itself that provokes Auxio’s crash, but rather heavy calculation such as map 3D rendering, routing, etc. (OsmAnd is very demanding compared to other apps, such as Magic Earth (which is /e/OS’ system navigation app).)

scaidermern commented 1 year ago

You somehow need to raise the priority of your music app so that the system won't kill it when running out of memory. I'm not sure if this can be done on a standard Android.

breversa commented 1 year ago

Thank you all for your help. My phone is rooted so I could look into increasing the priority. Thanks for the lead!

Also, a quick search yielded this: https://stackoverflow.com/questions/12303460/android-mediaplayer-crashing-app but that’s old, so I guess it doesn’t apply to OsmAnd (anymore?), but here goes nothing…

breversa commented 3 months ago

My music app keeps crashing in that context: https://github.com/osmandapp/OsmAnd/issues/19927