From c7a83b2552580e96b083ee9583b41d0874502121 Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Tue, 18 Sep 2018 15:07:49 -0700 Subject: [PATCH] Fix incorrect API invoke for BT profiles When hearing aid device has been set active, we shouldn't invoke 1. a2dpProfile.setActiveDevice() 2. hfpProfile.setActiveDevice() Change-Id: Ie13dea041dd98d0cb9d913e1f28574b300095db9 Merged-In: Ie13dea041dd98d0cb9d913e1f28574b300095db9 Fixes: 113625278 Test: RunSettingsRoboTests --- .../sound/HandsFreeProfileOutputPreferenceController.java | 7 ++----- .../settings/sound/MediaOutputPreferenceController.java | 7 ++----- .../HandsFreeProfileOutputPreferenceControllerTest.java | 3 +++ .../sound/MediaOutputPreferenceControllerTest.java | 3 +++ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java index b18130a6863..f8cd0a7a457 100644 --- a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java +++ b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java @@ -100,12 +100,9 @@ public class HandsFreeProfileOutputPreferenceController extends if (hapProfile != null && hfpProfile != null && device == null) { hfpProfile.setActiveDevice(null); hapProfile.setActiveDevice(null); - return; - } - if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) { + } else if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) { hapProfile.setActiveDevice(device); - } - if (hfpProfile != null) { + } else if (hfpProfile != null) { hfpProfile.setActiveDevice(device); } } diff --git a/src/com/android/settings/sound/MediaOutputPreferenceController.java b/src/com/android/settings/sound/MediaOutputPreferenceController.java index 8989de3c65b..44130c7f07e 100644 --- a/src/com/android/settings/sound/MediaOutputPreferenceController.java +++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java @@ -112,12 +112,9 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro if (hapProfile != null && a2dpProfile != null && device == null) { hapProfile.setActiveDevice(null); a2dpProfile.setActiveDevice(null); - return; - } - if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) { + } else if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) { hapProfile.setActiveDevice(device); - } - if (a2dpProfile != null) { + } else if (a2dpProfile != null) { a2dpProfile.setActiveDevice(device); } } diff --git a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java index a90f39de064..c89c0683686 100644 --- a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java @@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -180,6 +181,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest { mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice); verify(mHearingAidProfile).setActiveDevice(mLeftBluetoothHapDevice); + verify(mHeadsetProfile, never()).setActiveDevice(mLeftBluetoothHapDevice); } /** @@ -193,6 +195,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest { mController.setActiveBluetoothDevice(mBluetoothDevice); verify(mHeadsetProfile).setActiveDevice(mBluetoothDevice); + verify(mHearingAidProfile, never()).setActiveDevice(mBluetoothDevice); } /** diff --git a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java index 732affa171e..7ebc7bbcdb4 100644 --- a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java @@ -26,6 +26,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -182,6 +183,7 @@ public class MediaOutputPreferenceControllerTest { mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice); verify(mHearingAidProfile).setActiveDevice(mLeftBluetoothHapDevice); + verify(mA2dpProfile, never()).setActiveDevice(mLeftBluetoothHapDevice); } /** @@ -195,6 +197,7 @@ public class MediaOutputPreferenceControllerTest { mController.setActiveBluetoothDevice(mBluetoothDevice); verify(mA2dpProfile).setActiveDevice(mBluetoothDevice); + verify(mHearingAidProfile, never()).setActiveDevice(mBluetoothDevice); } /**