2

I've implemented VoIP calling in a native Android application, and we've discovered a bug that I'm stuck on. I'm using Twilio for our VoIP calls if that helps at all.

If I place an outgoing VoIP call from our app, after the call ends if I put the app in the background and receive a notification, the volume of the notification is about half what it was before I placed the call. It's also not just notifications from my app, but other apps are affected as well. If I swipe my app away from the app history so it is no longer running in the background, then notifications go back to to playing at their correct volume.

This does not happen when I receive an incoming call, even though I've verified that the same code tears down the call Connection whether it's incoming or outgoing.

I've verified that when the notification is coming in, the device's notification volume is still turned all the way up using AudioManager's getStreamVolume(AudioManager.STREAM_NOTIFICATION) API.

Since all apps appear to be affected, not just my own I'm thinking I can safely assume it's not the code that's playing the notification sound that's the problem. I was thinking maybe something related to the VoIP call wasn't being released properly, and the OS itself is playing the tones at a lower volume because it still thinks we're in a call, but I can't find any evidence of that.

I've confirmed that my Connection object for the call is calling onDisconnect(), and destroy(). My ConnectionService is also being destroyed. The call state at the time of the notification is not CALL_STATE_OFFHOOK according to the TelephonyManager.

Is there anything else you can think of that would cause notifications to play at a reduced volume?

Kyle Borth
  • 21
  • 2
  • I am also seeing this issue. Have you found any resolution. My suspicion is that it is playing out of the earpiece rather than the speaker, hence it being substantially quieter. Something is wrong with the speakerphone status after the call (or at least that is my suspicion) – kjanderson2 Jun 28 '21 at 22:07
  • Here's my SO post looking for answers as well: https://stackoverflow.com/questions/68168193/android-calling-app-not-resetting-audio-stream – kjanderson2 Jun 28 '21 at 22:07
  • I have not been able to resolve it yet – Kyle Borth Jun 30 '21 at 14:33

1 Answers1

1

We also experienced this same issue in our VOIP application, although in our case we're using webrtc directly and not Twilio Video -- so I don't know if this exactly applies to your case but maybe can help you find some clues.

In our case, we discovered we were not calling close() on all of the WebRTCPeer objects. That meant after the call ended, an AudioTrack was still active which affected the audio routing... resulting in the very quiet ring/notification sounds.

I would guess the equivalent with the Twilio Video SDK is to make sure that you unpublish and release all audio tracks (and video and data tracks) and then disconnect the Room object.

https://twilio.github.io/twilio-video-android/docs/latest/com/twilio/video/LocalParticipant.html#unpublishTrack-

https://twilio.github.io/twilio-video-android/docs/latest/com/twilio/video/LocalAudioTrack.html#release--

https://twilio.github.io/twilio-video-android/docs/latest/com/twilio/video/Room.html#disconnect--

We found some good clues examining the output of adb shell dumpsys audio -- in the bad state, we could see in the "Stream Volumes" section that the device for the ring/alarm/notification streams was stuck on "earpiece" rather than "speaker", and that there was an extra AudioTrack in the "Players" section.

Maybe this gives you some ideas to try... good luck!

dfinn
  • 968
  • 1
  • 10
  • 16
  • Thanks for the suggestion dfinn, unfortunately I don't think it's going to help in my case. The 3 links you provided are all for classes that stem from Twilio's Video library, which we're not using. We're just using Audio. I am calling `AudioSwitch.stop()` which if I drill down calls methods such as `audioManager.abandonAudioFocus()` At this point I assume you're right about it being stuck on "speaker", but I think the problem has got to be with the Twilio library. – Kyle Borth Jul 07 '21 at 19:42