Move set speakerphone out of async task executor.
This turned out to cause a regression related to switching to hearing
aids. There are other set/clearcommunicationDevice operations elsewhere
in Telecom which are not part of the async task executor so we were seeing
race conditions where the clear hear doesn't happen before the set
in the Telecom BluetoothDeviceManager code.
For now we'll move this back out of the task executor since that was
only done to try and satisfy issues with Cuttlefish tests.
Test: Run CTS/Unit test suite.
Bug: 283198536
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3221828a158e60b96dcde3b85b8face15ce8dc1b)
Merged-In: I9cc11eb11b59eb04b706a4bd6f61c1b7240a50c2
Change-Id: I9cc11eb11b59eb04b706a4bd6f61c1b7240a50c2
diff --git a/src/com/android/server/telecom/CallAudioRouteStateMachine.java b/src/com/android/server/telecom/CallAudioRouteStateMachine.java
index c5423c2..4a03726 100644
--- a/src/com/android/server/telecom/CallAudioRouteStateMachine.java
+++ b/src/com/android/server/telecom/CallAudioRouteStateMachine.java
@@ -1741,28 +1741,30 @@
final boolean hasAnyCalls = mCallsManager.hasAnyCalls();
// These APIs are all via two-way binder calls so can potentially block Telecom. Since none
// of this has to happen in the Telecom lock we'll offload it to the async executor.
+
+ AudioDeviceInfo speakerDevice = null;
+ for (AudioDeviceInfo info : mAudioManager.getAvailableCommunicationDevices()) {
+ if (info.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
+ speakerDevice = info;
+ break;
+ }
+ }
+ boolean speakerOn = false;
+ if (speakerDevice != null && on) {
+ boolean result = mAudioManager.setCommunicationDevice(speakerDevice);
+ if (result) {
+ speakerOn = true;
+ }
+ } else {
+ AudioDeviceInfo curDevice = mAudioManager.getCommunicationDevice();
+ if (curDevice != null
+ && curDevice.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
+ mAudioManager.clearCommunicationDevice();
+ }
+ }
+ final boolean isSpeakerOn = speakerOn;
mAsyncTaskExecutor.execute(() -> {
- AudioDeviceInfo speakerDevice = null;
- for (AudioDeviceInfo info : mAudioManager.getAvailableCommunicationDevices()) {
- if (info.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
- speakerDevice = info;
- break;
- }
- }
- boolean speakerOn = false;
- if (speakerDevice != null && on) {
- boolean result = mAudioManager.setCommunicationDevice(speakerDevice);
- if (result) {
- speakerOn = true;
- }
- } else {
- AudioDeviceInfo curDevice = mAudioManager.getCommunicationDevice();
- if (curDevice != null
- && curDevice.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
- mAudioManager.clearCommunicationDevice();
- }
- }
- mStatusBarNotifier.notifySpeakerphone(hasAnyCalls && speakerOn);
+ mStatusBarNotifier.notifySpeakerphone(hasAnyCalls && isSpeakerOn);
});
}