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

This commit is contained in:
Angela Wang
2022-11-28 07:16:25 +00:00
committed by Android (Google) Code Review
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.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
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.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
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.OnStop;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.stream.Collectors;
/**
* Controller that shows and updates the bluetooth device name
@@ -64,23 +70,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
private final BroadcastReceiver mHearingAidChangedReceiver = new BroadcastReceiver() {
@Override
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);
} 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);
}
}
updateState(mHearingAidPreference);
}
};
@@ -107,17 +97,24 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public int getAvailabilityStatus() {
return isHearingAidProfileSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public void onStart() {
IntentFilter filter = new IntentFilter();
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);
mContext.registerReceiver(mHearingAidChangedReceiver, filter);
mLocalBluetoothManager.getEventManager().registerCallback(this);
mProfileManager.addServiceListener(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);
}
}
@Override
@@ -143,6 +140,9 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public CharSequence getSummary() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
}
final CachedBluetoothDevice device = getConnectedHearingAidDevice();
if (device == null) {
return mContext.getText(R.string.accessibility_hearingaid_not_connected_summary);
@@ -150,24 +150,37 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
final int connectedNum = getConnectedHearingAidDeviceNum();
final CharSequence name = device.getName();
final int side = device.getDeviceSide();
final CachedBluetoothDevice subDevice = device.getSubDevice();
if (connectedNum > 1) {
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()) {
return mContext.getString(
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_active_device_summary, name);
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);
}
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);
// Invalid side
return mContext.getString(
R.string.accessibility_hearingaid_active_device_summary, name);
}
@Override
@@ -183,10 +196,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@Override
public void onServiceConnected() {
// Every registered ProfileService will callback. So we need to use isProfileReady() to
// check is the HearingAidService callback here, not other service.
// When hearing aids service connected, updating the UI.
if (mProfileManager.getHearingAidProfile().isProfileReady()) {
if (!isAnyHearingAidRelatedProfilesNotReady()) {
updateState(mHearingAidPreference);
mProfileManager.removeServiceListener(this);
}
@@ -203,38 +213,51 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
@VisibleForTesting
CachedBluetoothDevice getConnectedHearingAidDevice() {
if (!isHearingAidProfileSupported()) {
return null;
}
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;
final List<BluetoothDevice> deviceList = getConnectedHearingAidDeviceList();
return deviceList.isEmpty() ? null : mCachedDeviceManager.findDevice(deviceList.get(0));
}
private int getConnectedHearingAidDeviceNum() {
if (!isHearingAidProfileSupported()) {
return 0;
}
final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
final List<BluetoothDevice> deviceList = hearingAidProfile.getConnectedDevices();
return (int) deviceList.stream()
.filter(device -> !mCachedDeviceManager.isSubDevice(device))
.count();
return getConnectedHearingAidDeviceList().size();
}
private boolean isHearingAidProfileSupported() {
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();
if (hearingAidProfile != null) {
deviceList.addAll(hearingAidProfile.getConnectedDevices());
}
return deviceList.stream()
.distinct()
.filter(d -> !mCachedDeviceManager.isSubDevice(d)).collect(Collectors.toList());
}
private boolean isHearingAidSupported() {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
return false;
}
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() {

View File

@@ -40,7 +40,7 @@ public final class HearingAidUtils {
*/
public static void launchHearingAidPairingDialog(FragmentManager fragmentManager,
@NonNull CachedBluetoothDevice device) {
if (device.isConnectedHearingAidDevice()
if (device.isConnectedAshaHearingAidDevice()
&& device.getDeviceMode() == HearingAidProfile.DeviceMode.MODE_BINAURAL
&& device.getSubDevice() == null) {
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.
// It would show in Available Devices group.
if (cachedDevice.isConnectedHearingAidDevice()
if (cachedDevice.isConnectedAshaHearingAidDevice()
|| cachedDevice.isConnectedLeAudioDevice()) {
Log.d(TAG, "isFilterMatched() device : " +
cachedDevice.getName() + ", the profile is connected.");

View File

@@ -107,12 +107,12 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
}
private boolean isOnlyOneSideConnected(CachedBluetoothDevice cachedDevice) {
if (!cachedDevice.isConnectedHearingAidDevice()) {
if (!cachedDevice.isConnectedAshaHearingAidDevice()) {
return false;
}
final CachedBluetoothDevice subDevice = cachedDevice.getSubDevice();
if (subDevice != null && subDevice.isConnectedHearingAidDevice()) {
if (subDevice != null && subDevice.isConnectedAshaHearingAidDevice()) {
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.
// It would not show in Connected Devices group.
if (cachedDevice.isConnectedHearingAidDevice()
if (cachedDevice.isConnectedAshaHearingAidDevice()
|| cachedDevice.isConnectedLeAudioDevice()) {
return false;
}

View File

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

View File

@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
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.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
@@ -61,13 +63,16 @@ import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** Tests for {@link AccessibilityHearingAidPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
public class AccessibilityHearingAidPreferenceControllerTest {
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 HEARING_AID_PREFERENCE = "hearing_aid_preference";
@@ -93,6 +98,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
private HapClientProfile mHapClientProfile;
@Before
public void setUp() {
@@ -115,10 +122,11 @@ public class AccessibilityHearingAidPreferenceControllerTest {
}
@Test
public void getSummary_connectedHearingAidRightSide_connectedRightSideSummary() {
public void getSummary_connectedAshaHearingAidRightSide_connectedRightSideSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_RIGHT);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
@@ -129,12 +137,13 @@ public class AccessibilityHearingAidPreferenceControllerTest {
}
@Test
public void getSummary_connectedHearingAidBothSide_connectedBothSideSummary() {
public void getSummary_connectedAshaHearingAidBothSide_connectedBothSideSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHearingAid.STATE_CONNECTED);
@@ -145,13 +154,43 @@ public class AccessibilityHearingAidPreferenceControllerTest {
}
@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(
HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(
generateMultipleHearingAidDeviceList());
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
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
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
public void getSummary_bluetoothOff_disconnectedSummary() {
mPreferenceController.onStart();
@@ -208,8 +236,29 @@ public class AccessibilityHearingAidPreferenceControllerTest {
}
@Test
public void onNotSupportHearingAidProfile_isNotAvailable() {
//clear bluetooth supported profile
public void onSupportHearingAidProfile_isAvailable() {
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();
mPreferenceController = new AccessibilityHearingAidPreferenceController(mContext,
HEARING_AID_PREFERENCE);
@@ -231,7 +280,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Config(shadows = ShadowAlertDialogCompat.class)
public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() {
final FragmentActivity mActivity = Robolectric.setupActivity(FragmentActivity.class);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
@@ -246,27 +295,38 @@ public class AccessibilityHearingAidPreferenceControllerTest {
}
@Test
public void onServiceConnected_updateSummary() {
mPreferenceController.onStart();
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL);
public void onServiceConnected_onHearingAidProfileConnected_updateSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
mPreferenceController.onServiceConnected();
assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo(
"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() {
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
mBluetoothAdapter.enable();
@@ -274,10 +334,12 @@ public class AccessibilityHearingAidPreferenceControllerTest {
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
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(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
}
private void sendIntent(Intent intent) {
@@ -293,9 +355,16 @@ public class AccessibilityHearingAidPreferenceControllerTest {
}
private List<BluetoothDevice> generateMultipleHearingAidDeviceList() {
// Generates different Bluetooth devices for testing multiple devices
final List<BluetoothDevice> deviceList = new ArrayList<>(2);
deviceList.add(mBluetoothDevice);
deviceList.add(mBluetoothDevice);
deviceList.add(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
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
public void onDeviceAttributesChanged_subHearingAidDeviceConnected_dialogDismiss() {
when(mCachedSubBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
public void onDeviceAttributesChanged_subAshaHearingAidDeviceConnected_dialogDismiss() {
when(mCachedSubBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
mFragment.onDeviceAttributesChanged();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -191,7 +191,7 @@ public class BluetoothDevicesSliceTest {
public void getSlice_hasAvailableMediaDevice_shouldBuildPrimaryBluetoothAction() {
mockBluetoothDeviceList(1);
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();
mBluetoothDevicesSlice.getSlice();