Merge "Fix incorrect API invoke for BT profiles" am: 625c1eeaa9
am: dbc26b576c

Change-Id: Ic6b7a4b7541310b3a635b94a799e3476cf5cc684
diff --git a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
index fdbf610..0bf8786 100644
--- a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
+++ b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
@@ -100,12 +100,9 @@
         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 bf9e37f..5b1c217 100644
--- a/src/com/android/settings/sound/MediaOutputPreferenceController.java
+++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java
@@ -112,12 +112,9 @@
         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 4e67143..1a49652 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 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;
@@ -179,6 +180,7 @@
         mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
 
         verify(mHearingAidProfile).setActiveDevice(mLeftBluetoothHapDevice);
+        verify(mHeadsetProfile, never()).setActiveDevice(mLeftBluetoothHapDevice);
     }
 
     /**
@@ -192,6 +194,7 @@
         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 e1b9301..a6b6291 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 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;
@@ -181,6 +182,7 @@
         mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
 
         verify(mHearingAidProfile).setActiveDevice(mLeftBluetoothHapDevice);
+        verify(mA2dpProfile, never()).setActiveDevice(mLeftBluetoothHapDevice);
     }
 
     /**
@@ -194,6 +196,7 @@
         mController.setActiveBluetoothDevice(mBluetoothDevice);
 
         verify(mA2dpProfile).setActiveDevice(mBluetoothDevice);
+        verify(mHearingAidProfile, never()).setActiveDevice(mBluetoothDevice);
     }
 
     /**