twilio / audioswitch

An Android audio management library for real-time communication apps.
Apache License 2.0
160 stars 49 forks source link

Fix issue #119 by ensuring the existing runnable is cancelled #123

Closed robholmes closed 2 years ago

robholmes commented 2 years ago

Description

As seen in https://github.com/twilio/audioswitch/issues/119

When switching away from a Bluetooth headset to the speaker (for example), then switching back to the Bluetooth headset, a few seconds later the audio will be switched back to the "earpiece".

After debugging this, I found that this happens because there are multiple EnableBluetoothScoJob runnables running, with one of them timing out, therefore causing the AudioActivationError state to be set and causing the behaviour of the connection having errored, although this isn't the case and audio is still heard through the BT headset.

This fixes the problem by ensuring that when we start a new EnableBluetoothScoJob, we cancel the existing runnable first (if it exists).

Breakdown

Validation

Additional Notes

n/a

Submission Checklist