OSDN Git Service

Fix incorrect API invoke for BT profiles
authorjackqdyulei <jackqdyulei@google.com>
Tue, 18 Sep 2018 22:07:49 +0000 (15:07 -0700)
committerjackqdyulei <jackqdyulei@google.com>
Tue, 18 Sep 2018 22:19:32 +0000 (15:19 -0700)
When hearing aid device has been set active, we shouldn't invoke
1. a2dpProfile.setActiveDevice()
2. hfpProfile.setActiveDevice()

Change-Id: Ie13dea041dd98d0cb9d913e1f28574b300095db9
Fixes: 113625278
Test: RunSettingsRoboTests

src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
src/com/android/settings/sound/MediaOutputPreferenceController.java
tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java

index 0b50f5f..a02c0b2 100644 (file)
@@ -93,12 +93,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);
         }
     }
index 8704243..2ac460c 100644 (file)
@@ -106,12 +106,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);
         }
     }
index e2fc779..58df2d2 100644 (file)
@@ -23,6 +23,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;
@@ -179,6 +180,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
         mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
 
         verify(mHearingAidProfile).setActiveDevice(mLeftBluetoothHapDevice);
+        verify(mHeadsetProfile, never()).setActiveDevice(mLeftBluetoothHapDevice);
     }
 
     /**
@@ -192,6 +194,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
         mController.setActiveBluetoothDevice(mBluetoothDevice);
 
         verify(mHeadsetProfile).setActiveDevice(mBluetoothDevice);
+        verify(mHearingAidProfile, never()).setActiveDevice(mBluetoothDevice);
     }
 
     /**
index d2f5f1a..9e1ac3d 100644 (file)
@@ -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 MediaOutputPreferenceControllerTest {
         mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
 
         verify(mHearingAidProfile).setActiveDevice(mLeftBluetoothHapDevice);
+        verify(mA2dpProfile, never()).setActiveDevice(mLeftBluetoothHapDevice);
     }
 
     /**
@@ -193,6 +195,7 @@ public class MediaOutputPreferenceControllerTest {
         mController.setActiveBluetoothDevice(mBluetoothDevice);
 
         verify(mA2dpProfile).setActiveDevice(mBluetoothDevice);
+        verify(mHearingAidProfile, never()).setActiveDevice(mBluetoothDevice);
     }
 
     /**