Merge "Show ambient volume contrl only for hearing devices" into main
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java
index 4b0b5d4..defa7e9 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java
@@ -129,7 +129,7 @@
 
     @Override
     public boolean isAvailable() {
-        return mCachedDevice.getProfiles().stream().anyMatch(
+        return mCachedDevice.isHearingDevice() && mCachedDevice.getProfiles().stream().anyMatch(
                 profile -> profile instanceof VolumeControlProfile);
     }
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java
index fb10d09..4c20a88 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java
@@ -21,15 +21,11 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import android.os.Handler;
-
 import androidx.preference.PreferenceCategory;
 
 import com.android.settings.testutils.shadow.ShadowThreadUtils;
@@ -70,8 +66,6 @@
     @Mock
     private VolumeControlProfile mVolumeControlProfile;
     @Mock
-    private Handler mTestHandler;
-    @Mock
     private AmbientVolumeUiController mUiController;
 
     private BluetoothDetailsAmbientVolumePreferenceController mController;
@@ -91,13 +85,6 @@
         PreferenceCategory deviceControls = new PreferenceCategory(mContext);
         deviceControls.setKey(KEY_HEARING_DEVICE_GROUP);
         mScreen.addPreference(deviceControls);
-
-        when(mContext.getMainThreadHandler()).thenReturn(mTestHandler);
-        when(mTestHandler.postDelayed(any(Runnable.class), anyLong())).thenAnswer(
-                invocationOnMock -> {
-                    invocationOnMock.getArgument(0, Runnable.class).run();
-                    return null;
-                });
     }
 
     @Test
@@ -109,7 +96,31 @@
     }
 
     @Test
-    public void refresh_deviceNotSupportVcp_verifyUiControllerNoRefresh() {
+    public void isAvailable_notHearingDevice_returnFalse() {
+        when(mCachedDevice.isHearingDevice()).thenReturn(false);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void isAvailable_isHearingDeviceAndNotSupportVcp_returnFalse() {
+        when(mCachedDevice.isHearingDevice()).thenReturn(true);
+        when(mCachedDevice.getProfiles()).thenReturn(List.of());
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void isAvailable_isHearingDeviceAndSupportVcp_returnTrue() {
+        when(mCachedDevice.isHearingDevice()).thenReturn(true);
+        when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile));
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void refresh_isHearingDeviceAndNotSupportVcp_verifyUiControllerNoRefresh() {
+        when(mCachedDevice.isHearingDevice()).thenReturn(true);
         when(mCachedDevice.getProfiles()).thenReturn(List.of());
 
         mController.refresh();
@@ -118,7 +129,8 @@
     }
 
     @Test
-    public void refresh_deviceSupportVcp_verifyUiControllerRefresh() {
+    public void refresh_isHearingDeviceAndSupportVcp_verifyUiControllerRefresh() {
+        when(mCachedDevice.isHearingDevice()).thenReturn(true);
         when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile));
 
         mController.refresh();