Shows LE audio hearing aid device in a11y settings page (3/3)

Shows connected hearing aid in a11y settings page whether it's ASHA hearing aid or LE audio hearing aid. Makes sure preference summary is updated as expected when BluetoothHapClient profile connects or disconnects.

LE audio hearing aid will be a CSIP set. According to the CSIP spec, we will show the device is active without side information if there is only one device in the CSIP set and show the device is active left and right if both side of hearing aids are in the CSIP set.

Bug: 249235823
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityHearingAidPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=HearingAidPairingDialogFragmentTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=HearingAidUtilsTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableMediaBluetoothDeviceUpdaterTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsPairOtherControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsRelatedToolsControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=ConnectedBluetoothDeviceUpdaterTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableMediaDeviceGroupControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDevicesSliceTest
Change-Id: Ifd66cbd81481a1eb94613d89dfd8df16b8c43ae8
This commit is contained in:
Angela Wang
2022-10-06 10:34:46 +00:00
parent 00b549f75a
commit e7a4b1f13d
15 changed files with 215 additions and 124 deletions

View File

@@ -19,7 +19,9 @@ package com.android.settings.accessibility;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -41,6 +43,7 @@ import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
@@ -48,9 +51,12 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.core.lifecycle.events.OnStop;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import java.util.stream.Collectors;
/** /**
* Controller that shows and updates the bluetooth device name * Controller that shows and updates the bluetooth device name
@@ -64,23 +70,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
private final BroadcastReceiver mHearingAidChangedReceiver = new BroadcastReceiver() { private final BroadcastReceiver mHearingAidChangedReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
final int state = intent.getIntExtra(BluetoothHearingAid.EXTRA_STATE,
BluetoothHearingAid.STATE_DISCONNECTED);
if (state == BluetoothHearingAid.STATE_CONNECTED) {
updateState(mHearingAidPreference); updateState(mHearingAidPreference);
} else {
mHearingAidPreference
.setSummary(R.string.accessibility_hearingaid_not_connected_summary);
}
} else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothAdapter.ERROR);
if (state != BluetoothAdapter.STATE_ON) {
mHearingAidPreference
.setSummary(R.string.accessibility_hearingaid_not_connected_summary);
}
}
} }
}; };
@@ -107,18 +97,25 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return isHearingAidProfileSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }
@Override @Override
public void onStart() { public void onStart() {
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
mContext.registerReceiver(mHearingAidChangedReceiver, filter); mContext.registerReceiver(mHearingAidChangedReceiver, filter);
mLocalBluetoothManager.getEventManager().registerCallback(this); mLocalBluetoothManager.getEventManager().registerCallback(this);
// Can't get connected hearing aids when hearing aids related profiles are not ready. The
// profiles will be ready after the services are connected. Needs to add listener and
// updates the information when all hearing aids related services are connected.
if (isAnyHearingAidRelatedProfilesNotReady()) {
mProfileManager.addServiceListener(this); mProfileManager.addServiceListener(this);
} }
}
@Override @Override
public void onStop() { public void onStop() {
@@ -143,6 +140,9 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override @Override
public CharSequence getSummary() { public CharSequence getSummary() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
}
final CachedBluetoothDevice device = getConnectedHearingAidDevice(); final CachedBluetoothDevice device = getConnectedHearingAidDevice();
if (device == null) { if (device == null) {
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary); return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
@@ -150,25 +150,38 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
final int connectedNum = getConnectedHearingAidDeviceNum(); final int connectedNum = getConnectedHearingAidDeviceNum();
final CharSequence name = device.getName(); final CharSequence name = device.getName();
final int side = device.getDeviceSide();
final CachedBluetoothDevice subDevice = device.getSubDevice();
if (connectedNum > 1) { if (connectedNum > 1) {
return mContext.getString(R.string.accessibility_hearingaid_more_device_summary, name); return mContext.getString(R.string.accessibility_hearingaid_more_device_summary, name);
} }
// Check if another side of LE audio hearing aid is connected as a pair
final Set<CachedBluetoothDevice> memberDevices = device.getMemberDevice();
if (memberDevices.stream().anyMatch(m -> m.isConnected())) {
return mContext.getString(
R.string.accessibility_hearingaid_left_and_right_side_device_summary,
name);
}
// Check if another side of ASHA hearing aid is connected as a pair
final CachedBluetoothDevice subDevice = device.getSubDevice();
if (subDevice != null && subDevice.isConnected()) { if (subDevice != null && subDevice.isConnected()) {
return mContext.getString( return mContext.getString(
R.string.accessibility_hearingaid_left_and_right_side_device_summary, name); R.string.accessibility_hearingaid_left_and_right_side_device_summary, name);
} }
if (side == HearingAidProfile.DeviceSide.SIDE_INVALID) {
final int side = device.getDeviceSide();
if (side == HearingAidProfile.DeviceSide.SIDE_LEFT) {
return mContext.getString(
R.string.accessibility_hearingaid_left_side_device_summary, name);
} else if (side == HearingAidProfile.DeviceSide.SIDE_RIGHT) {
return mContext.getString(
R.string.accessibility_hearingaid_right_side_device_summary, name);
}
// Invalid side
return mContext.getString( return mContext.getString(
R.string.accessibility_hearingaid_active_device_summary, name); R.string.accessibility_hearingaid_active_device_summary, name);
} }
return (side == HearingAidProfile.DeviceSide.SIDE_LEFT)
? mContext.getString(
R.string.accessibility_hearingaid_left_side_device_summary, name)
: mContext.getString(
R.string.accessibility_hearingaid_right_side_device_summary, name);
}
@Override @Override
public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) { public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
@@ -183,10 +196,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override @Override
public void onServiceConnected() { public void onServiceConnected() {
// Every registered ProfileService will callback. So we need to use isProfileReady() to if (!isAnyHearingAidRelatedProfilesNotReady()) {
// check is the HearingAidService callback here, not other service.
// When hearing aids service connected, updating the UI.
if (mProfileManager.getHearingAidProfile().isProfileReady()) {
updateState(mHearingAidPreference); updateState(mHearingAidPreference);
mProfileManager.removeServiceListener(this); mProfileManager.removeServiceListener(this);
} }
@@ -203,38 +213,51 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@VisibleForTesting @VisibleForTesting
CachedBluetoothDevice getConnectedHearingAidDevice() { CachedBluetoothDevice getConnectedHearingAidDevice() {
if (!isHearingAidProfileSupported()) { final List<BluetoothDevice> deviceList = getConnectedHearingAidDeviceList();
return null; return deviceList.isEmpty() ? null : mCachedDeviceManager.findDevice(deviceList.get(0));
}
final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
final List<BluetoothDevice> deviceList = hearingAidProfile.getConnectedDevices();
for (BluetoothDevice obj : deviceList) {
if (!mCachedDeviceManager.isSubDevice(obj)) {
return mCachedDeviceManager.findDevice(obj);
}
}
return null;
} }
private int getConnectedHearingAidDeviceNum() { private int getConnectedHearingAidDeviceNum() {
if (!isHearingAidProfileSupported()) { return getConnectedHearingAidDeviceList().size();
return 0;
} }
private List<BluetoothDevice> getConnectedHearingAidDeviceList() {
if (!isHearingAidSupported()) {
return new ArrayList<>();
}
final List<BluetoothDevice> deviceList = new ArrayList<>();
final HapClientProfile hapClientProfile = mProfileManager.getHapClientProfile();
if (hapClientProfile != null) {
deviceList.addAll(hapClientProfile.getConnectedDevices());
}
final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile(); final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
final List<BluetoothDevice> deviceList = hearingAidProfile.getConnectedDevices(); if (hearingAidProfile != null) {
return (int) deviceList.stream() deviceList.addAll(hearingAidProfile.getConnectedDevices());
.filter(device -> !mCachedDeviceManager.isSubDevice(device)) }
.count(); return deviceList.stream()
.distinct()
.filter(d -> !mCachedDeviceManager.isSubDevice(d)).collect(Collectors.toList());
} }
private boolean isHearingAidProfileSupported() { private boolean isHearingAidSupported() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return false; return false;
} }
final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles(); final List<Integer> supportedList = mBluetoothAdapter.getSupportedProfiles();
return supportedList.contains(BluetoothProfile.HEARING_AID); return supportedList.contains(BluetoothProfile.HEARING_AID)
|| supportedList.contains(BluetoothProfile.HAP_CLIENT);
}
private boolean isAnyHearingAidRelatedProfilesNotReady() {
HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
if (hearingAidProfile != null && !hearingAidProfile.isProfileReady()) {
return true;
}
HapClientProfile hapClientProfile = mProfileManager.getHapClientProfile();
if (hapClientProfile != null && !hapClientProfile.isProfileReady()) {
return true;
}
return false;
} }
private LocalBluetoothManager getLocalBluetoothManager() { private LocalBluetoothManager getLocalBluetoothManager() {

View File

@@ -40,7 +40,7 @@ public final class HearingAidUtils {
*/ */
public static void launchHearingAidPairingDialog(FragmentManager fragmentManager, public static void launchHearingAidPairingDialog(FragmentManager fragmentManager,
@NonNull CachedBluetoothDevice device) { @NonNull CachedBluetoothDevice device) {
if (device.isConnectedHearingAidDevice() if (device.isConnectedAshaHearingAidDevice()
&& device.getDeviceMode() == HearingAidProfile.DeviceMode.MODE_BINAURAL && device.getDeviceMode() == HearingAidProfile.DeviceMode.MODE_BINAURAL
&& device.getSubDevice() == null) { && device.getSubDevice() == null) {
launchHearingAidPairingDialogInternal(fragmentManager, device); launchHearingAidPairingDialogInternal(fragmentManager, device);

View File

@@ -72,7 +72,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
} }
// If device is Hearing Aid or LE Audio, it is compatible with HFP and A2DP. // If device is Hearing Aid or LE Audio, it is compatible with HFP and A2DP.
// It would show in Available Devices group. // It would show in Available Devices group.
if (cachedDevice.isConnectedHearingAidDevice() if (cachedDevice.isConnectedAshaHearingAidDevice()
|| cachedDevice.isConnectedLeAudioDevice()) { || cachedDevice.isConnectedLeAudioDevice()) {
Log.d(TAG, "isFilterMatched() device : " + Log.d(TAG, "isFilterMatched() device : " +
cachedDevice.getName() + ", the profile is connected."); cachedDevice.getName() + ", the profile is connected.");

View File

@@ -107,12 +107,12 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
} }
private boolean isOnlyOneSideConnected(CachedBluetoothDevice cachedDevice) { private boolean isOnlyOneSideConnected(CachedBluetoothDevice cachedDevice) {
if (!cachedDevice.isConnectedHearingAidDevice()) { if (!cachedDevice.isConnectedAshaHearingAidDevice()) {
return false; return false;
} }
final CachedBluetoothDevice subDevice = cachedDevice.getSubDevice(); final CachedBluetoothDevice subDevice = cachedDevice.getSubDevice();
if (subDevice != null && subDevice.isConnectedHearingAidDevice()) { if (subDevice != null && subDevice.isConnectedAshaHearingAidDevice()) {
return false; return false;
} }

View File

@@ -72,7 +72,7 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
} }
// If device is Hearing Aid or LE Audio, it is compatible with HFP and A2DP. // If device is Hearing Aid or LE Audio, it is compatible with HFP and A2DP.
// It would not show in Connected Devices group. // It would not show in Connected Devices group.
if (cachedDevice.isConnectedHearingAidDevice() if (cachedDevice.isConnectedAshaHearingAidDevice()
|| cachedDevice.isConnectedLeAudioDevice()) { || cachedDevice.isConnectedLeAudioDevice()) {
return false; return false;
} }

View File

@@ -120,7 +120,7 @@ public class HearingAidPairingDialogFragment extends InstrumentedDialogFragment
@Override @Override
public void onDeviceAttributesChanged() { public void onDeviceAttributesChanged() {
final CachedBluetoothDevice subDevice = mDevice.getSubDevice(); final CachedBluetoothDevice subDevice = mDevice.getSubDevice();
if (subDevice != null && subDevice.isConnectedHearingAidDevice()) { if (subDevice != null && subDevice.isConnectedAshaHearingAidDevice()) {
this.dismiss(); this.dismiss();
} }
} }

View File

@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.app.Activity; import android.app.Activity;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -44,6 +45,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothEventManager; import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
@@ -61,13 +63,16 @@ import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** Tests for {@link AccessibilityHearingAidPreferenceController}. */ /** Tests for {@link AccessibilityHearingAidPreferenceController}. */
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class}) @Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
public class AccessibilityHearingAidPreferenceControllerTest { public class AccessibilityHearingAidPreferenceControllerTest {
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1"; private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
private static final String TEST_DEVICE_ADDRESS_2 = "00:A2:A2:A2:A2:A2";
private static final String TEST_DEVICE_NAME = "TEST_HEARING_AID_BT_DEVICE_NAME"; private static final String TEST_DEVICE_NAME = "TEST_HEARING_AID_BT_DEVICE_NAME";
private static final String HEARING_AID_PREFERENCE = "hearing_aid_preference"; private static final String HEARING_AID_PREFERENCE = "hearing_aid_preference";
@@ -93,6 +98,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
private LocalBluetoothProfileManager mLocalBluetoothProfileManager; private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
@Mock @Mock
private HearingAidProfile mHearingAidProfile; private HearingAidProfile mHearingAidProfile;
@Mock
private HapClientProfile mHapClientProfile;
@Before @Before
public void setUp() { public void setUp() {
@@ -115,10 +122,11 @@ public class AccessibilityHearingAidPreferenceControllerTest {
} }
@Test @Test
public void getSummary_connectedHearingAidRightSide_connectedRightSideSummary() { public void getSummary_connectedAshaHearingAidRightSide_connectedRightSideSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_RIGHT); HearingAidProfile.DeviceSide.SIDE_RIGHT);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList()); when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart(); mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED); intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
@@ -129,12 +137,13 @@ public class AccessibilityHearingAidPreferenceControllerTest {
} }
@Test @Test
public void getSummary_connectedHearingAidBothSide_connectedBothSideSummary() { public void getSummary_connectedAshaHearingAidBothSide_connectedBothSideSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_LEFT); HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true); when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice); when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList()); when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart(); mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED); intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
@@ -145,13 +154,43 @@ public class AccessibilityHearingAidPreferenceControllerTest {
} }
@Test @Test
public void getSummary_connectedMultipleHearingAids_connectedBothSideSummary() { public void getSummary_connectedLeAudioHearingAidOneSide_connectedOneSideSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_INVALID);
when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(new HashSet<>());
when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHapClient.STATE_CONNECTED);
sendIntent(intent);
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
"TEST_HEARING_AID_BT_DEVICE_NAME active")).isTrue();
}
@Test
public void getSummary_connectedLeAudioHearingAidBothSide_connectedBothSideSummary() {
when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(generateMemberDevices());
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHapClient.STATE_CONNECTED);
sendIntent(intent);
assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo(
"TEST_HEARING_AID_BT_DEVICE_NAME, left and right");
}
@Test
public void getSummary_connectedMultipleHearingAids_connectedMultipleDevicesSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_LEFT); HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
when(mHearingAidProfile.getConnectedDevices()).thenReturn( when(mHearingAidProfile.getConnectedDevices()).thenReturn(
generateMultipleHearingAidDeviceList()); generateMultipleHearingAidDeviceList());
mPreferenceController.onStart(); mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED); intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
@@ -161,17 +200,6 @@ public class AccessibilityHearingAidPreferenceControllerTest {
"TEST_HEARING_AID_BT_DEVICE_NAME +1 more")).isTrue(); "TEST_HEARING_AID_BT_DEVICE_NAME +1 more")).isTrue();
} }
@Test
public void getSummary_disconnectedHearingAid_disconnectedSummary() {
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_DISCONNECTED);
sendIntent(intent);
assertThat(mHearingAidPreference.getSummary()).isEqualTo(
mContext.getText(R.string.accessibility_hearingaid_not_connected_summary));
}
@Test @Test
public void getSummary_bluetoothOff_disconnectedSummary() { public void getSummary_bluetoothOff_disconnectedSummary() {
mPreferenceController.onStart(); mPreferenceController.onStart();
@@ -208,8 +236,29 @@ public class AccessibilityHearingAidPreferenceControllerTest {
} }
@Test @Test
public void onNotSupportHearingAidProfile_isNotAvailable() { public void onSupportHearingAidProfile_isAvailable() {
//clear bluetooth supported profile mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE);
mPreferenceController.setPreference(mHearingAidPreference);
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void onSupportHapClientProfile_isAvailable() {
mShadowBluetoothAdapter.clearSupportedProfiles();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT);
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE);
mPreferenceController.setPreference(mHearingAidPreference);
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void onNotSupportAnyHearingAidRelatedProfile_isNotAvailable() {
mShadowBluetoothAdapter.clearSupportedProfiles(); mShadowBluetoothAdapter.clearSupportedProfiles();
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext, mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE); HEARING_AID_PREFERENCE);
@@ -231,7 +280,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = ShadowAlertDialogCompat.class)
public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() { public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() {
final FragmentActivity mActivity = Robolectric.setupActivity(FragmentActivity.class); final FragmentActivity mActivity = Robolectric.setupActivity(FragmentActivity.class);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL); HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
@@ -246,27 +295,38 @@ public class AccessibilityHearingAidPreferenceControllerTest {
} }
@Test @Test
public void onServiceConnected_updateSummary() { public void onServiceConnected_onHearingAidProfileConnected_updateSummary() {
mPreferenceController.onStart();
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_LEFT); HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList()); when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
mPreferenceController.onServiceConnected(); mPreferenceController.onServiceConnected();
assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo( assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo(
"TEST_HEARING_AID_BT_DEVICE_NAME, left only"); "TEST_HEARING_AID_BT_DEVICE_NAME, left only");
} }
@Test
public void onServiceConnected_onHapClientProfileConnected_updateSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_INVALID);
when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
mPreferenceController.onServiceConnected();
assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo(
"TEST_HEARING_AID_BT_DEVICE_NAME active");
}
private void setupEnvironment() { private void setupEnvironment() {
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager; ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
mLocalBluetoothManager = Utils.getLocalBtManager(mContext); mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter); mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS); mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
mBluetoothAdapter.enable(); mBluetoothAdapter.enable();
@@ -274,10 +334,12 @@ public class AccessibilityHearingAidPreferenceControllerTest {
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager); when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
when(mLocalBluetoothProfileManager.getHapClientProfile()).thenReturn(mHapClientProfile);
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
when(mHapClientProfile.isProfileReady()).thenReturn(true);
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME); when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
} }
private void sendIntent(Intent intent) { private void sendIntent(Intent intent) {
@@ -293,9 +355,16 @@ public class AccessibilityHearingAidPreferenceControllerTest {
} }
private List<BluetoothDevice> generateMultipleHearingAidDeviceList() { private List<BluetoothDevice> generateMultipleHearingAidDeviceList() {
// Generates different Bluetooth devices for testing multiple devices
final List<BluetoothDevice> deviceList = new ArrayList<>(2); final List<BluetoothDevice> deviceList = new ArrayList<>(2);
deviceList.add(mBluetoothDevice); deviceList.add(mBluetoothDevice);
deviceList.add(mBluetoothDevice); deviceList.add(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
return deviceList; return deviceList;
} }
private Set<CachedBluetoothDevice> generateMemberDevices() {
final Set<CachedBluetoothDevice> memberDevices = new HashSet<>();
memberDevices.add(mCachedSubBluetoothDevice);
return memberDevices;
}
} }

View File

@@ -143,8 +143,8 @@ public class HearingAidPairingDialogFragmentTest {
} }
@Test @Test
public void onDeviceAttributesChanged_subHearingAidDeviceConnected_dialogDismiss() { public void onDeviceAttributesChanged_subAshaHearingAidDeviceConnected_dialogDismiss() {
when(mCachedSubBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedSubBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice); when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
mFragment.onDeviceAttributesChanged(); mFragment.onDeviceAttributesChanged();

View File

@@ -86,8 +86,8 @@ public class HearingAidUtilsTest {
} }
@Test @Test
public void launchHearingAidPairingDialog_deviceNotConnectedHearingAid_noDialog() { public void launchHearingAidPairingDialog_deviceIsNotConnectedAshaHearingAid_noDialog() {
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(false); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice); HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
@@ -96,8 +96,8 @@ public class HearingAidUtilsTest {
} }
@Test @Test
public void launchHearingAidPairingDialog_deviceIsModeMonaural_noDialog() { public void launchHearingAidPairingDialog_deviceIsMonauralMode_noDialog() {
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_MONAURAL); HearingAidProfile.DeviceMode.MODE_MONAURAL);
@@ -109,7 +109,7 @@ public class HearingAidUtilsTest {
@Test @Test
public void launchHearingAidPairingDialog_deviceHasSubDevice_noDialog() { public void launchHearingAidPairingDialog_deviceHasSubDevice_noDialog() {
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL); HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice); when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
@@ -122,7 +122,7 @@ public class HearingAidUtilsTest {
@Test @Test
public void launchHearingAidPairingDialog_deviceIsInvalidSide_noDialog() { public void launchHearingAidPairingDialog_deviceIsInvalidSide_noDialog() {
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL); HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
@@ -136,7 +136,7 @@ public class HearingAidUtilsTest {
@Test @Test
public void launchHearingAidPairingDialog_dialogShown() { public void launchHearingAidPairingDialog_dialogShown() {
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL); HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(

View File

@@ -205,12 +205,11 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
} }
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_addPreference() public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_addPreference() {
{
mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID); BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);
@@ -219,11 +218,11 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
} }
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_addPreference() { public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_addPreference() {
mAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID); BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);

View File

@@ -81,8 +81,8 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
} }
@Test @Test
public void init_isNotConnectedHearingAidDevice_notVisiblePreference() { public void init_isNotConnectedAshaHearingAidDevice_notVisiblePreference() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
mController.init(mScreen); mController.init(mScreen);
@@ -91,35 +91,35 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
} }
@Test @Test
public void isAvailable_isNotConnectedHearingAidDevice_notAvailable() { public void isAvailable_isNotConnectedAshaHearingAidDevice_notAvailable() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test @Test
public void isAvailable_notConnectedHearingAidDevice_notAvailable() { public void isAvailable_isConnectedAshaHearingAidDevice_isMonaural_notAvailable() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_MONAURAL); when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_MONAURAL);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test @Test
public void isAvailable_subDeviceIsConnectedHearingAidDevice_notAvailable() { public void isAvailable_subDeviceIsConnectedAshaHearingAidDevice_notAvailable() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL); when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mSubCachedDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mSubCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice); when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test @Test
public void isAvailable_subDeviceNotConnectedHearingAidDevice_available() { public void isAvailable_subDeviceIsNotConnectedAshaHearingAidDevice_available() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL); when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mSubCachedDevice.isConnectedHearingAidDevice()).thenReturn(false); when(mSubCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice); when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice);
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
@@ -127,7 +127,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test @Test
public void isAvailable_subDeviceNotExist_available() { public void isAvailable_subDeviceNotExist_available() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL); when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedDevice.getSubDevice()).thenReturn(null); when(mCachedDevice.getSubDevice()).thenReturn(null);
@@ -146,8 +146,8 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
} }
@Test @Test
public void refresh_isNotConnectedHearingAidDevice_notVisiblePreference() { public void refresh_isNotConnectedAshaHearingAidDevice_notVisiblePreference() {
when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false); when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
mController.init(mScreen); mController.init(mScreen);
mController.refresh(); mController.refresh();

View File

@@ -89,7 +89,7 @@ public class BluetoothDetailsRelatedToolsControllerTest extends BluetoothDetails
} }
@Test @Test
public void isAvailable_notHearingAidDevice_notAvailable() { public void isAvailable_isNotHearingAidDevice_notAvailable() {
when(mCachedDevice.isHearingAidDevice()).thenReturn(false); when(mCachedDevice.isHearingAidDevice()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();

View File

@@ -218,12 +218,12 @@ public class ConnectedBluetoothDeviceUpdaterTest {
} }
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_removePreference() public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_removePreference()
{ {
mAudioManager.setMode(AudioManager.MODE_IN_CALL); mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID); BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);
@@ -232,12 +232,12 @@ public class ConnectedBluetoothDeviceUpdaterTest {
} }
@Test @Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_removePreference public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_removePreference()
() { {
mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater. when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID); BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);

View File

@@ -244,7 +244,7 @@ public class AvailableMediaDeviceGroupControllerTest {
@Test @Test
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = ShadowAlertDialogCompat.class)
public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() { public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() {
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL); HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(

View File

@@ -191,7 +191,7 @@ public class BluetoothDevicesSliceTest {
public void getSlice_hasAvailableMediaDevice_shouldBuildPrimaryBluetoothAction() { public void getSlice_hasAvailableMediaDevice_shouldBuildPrimaryBluetoothAction() {
mockBluetoothDeviceList(1); mockBluetoothDeviceList(1);
when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(true); when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(true);
doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedHearingAidDevice(); doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedAshaHearingAidDevice();
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices(); doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
mBluetoothDevicesSlice.getSlice(); mBluetoothDevicesSlice.getSlice();