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?
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!