Merge "Fix hearing aid appears wrong side after device reboot." into tm-qpr-dev am: bf7c555c2f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19903185 Change-Id: Ifee717d914fdd1cc3800c08ea7bafc95482fca9e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -46,16 +46,43 @@ public class HearingAidDeviceManager {
|
|||||||
if (isValidHiSyncId(hiSyncId)) {
|
if (isValidHiSyncId(hiSyncId)) {
|
||||||
// Once hiSyncId is valid, assign hiSyncId
|
// Once hiSyncId is valid, assign hiSyncId
|
||||||
newDevice.setHiSyncId(hiSyncId);
|
newDevice.setHiSyncId(hiSyncId);
|
||||||
|
final int side = getDeviceSide(newDevice.getDevice());
|
||||||
|
final int mode = getDeviceMode(newDevice.getDevice());
|
||||||
|
newDevice.setDeviceSide(side);
|
||||||
|
newDevice.setDeviceMode(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getHiSyncId(BluetoothDevice device) {
|
private long getHiSyncId(BluetoothDevice device) {
|
||||||
LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();
|
final LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();
|
||||||
HearingAidProfile profileProxy = profileManager.getHearingAidProfile();
|
final HearingAidProfile profileProxy = profileManager.getHearingAidProfile();
|
||||||
if (profileProxy != null) {
|
if (profileProxy == null) {
|
||||||
|
return BluetoothHearingAid.HI_SYNC_ID_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
return profileProxy.getHiSyncId(device);
|
return profileProxy.getHiSyncId(device);
|
||||||
}
|
}
|
||||||
return BluetoothHearingAid.HI_SYNC_ID_INVALID;
|
|
||||||
|
private int getDeviceSide(BluetoothDevice device) {
|
||||||
|
final LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();
|
||||||
|
final HearingAidProfile profileProxy = profileManager.getHearingAidProfile();
|
||||||
|
if (profileProxy == null) {
|
||||||
|
Log.w(TAG, "HearingAidProfile is not supported and not ready to fetch device side");
|
||||||
|
return HearingAidProfile.DeviceSide.SIDE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return profileProxy.getDeviceSide(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDeviceMode(BluetoothDevice device) {
|
||||||
|
final LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();
|
||||||
|
final HearingAidProfile profileProxy = profileManager.getHearingAidProfile();
|
||||||
|
if (profileProxy == null) {
|
||||||
|
Log.w(TAG, "HearingAidProfile is not supported and not ready to fetch device mode");
|
||||||
|
return HearingAidProfile.DeviceMode.MODE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return profileProxy.getDeviceMode(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean setSubDeviceIfNeeded(CachedBluetoothDevice newDevice) {
|
boolean setSubDeviceIfNeeded(CachedBluetoothDevice newDevice) {
|
||||||
@@ -98,6 +125,10 @@ public class HearingAidDeviceManager {
|
|||||||
if (isValidHiSyncId(newHiSyncId)) {
|
if (isValidHiSyncId(newHiSyncId)) {
|
||||||
cachedDevice.setHiSyncId(newHiSyncId);
|
cachedDevice.setHiSyncId(newHiSyncId);
|
||||||
newSyncIdSet.add(newHiSyncId);
|
newSyncIdSet.add(newHiSyncId);
|
||||||
|
final int side = getDeviceSide(cachedDevice.getDevice());
|
||||||
|
final int mode = getDeviceMode(cachedDevice.getDevice());
|
||||||
|
cachedDevice.setDeviceSide(side);
|
||||||
|
cachedDevice.setDeviceMode(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,16 +102,25 @@ public class HearingAidDeviceManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test initHearingAidDeviceIfNeeded, a valid HiSyncId will be assigned
|
* Test initHearingAidDeviceIfNeeded, set HearingAid's information, including HiSyncId,
|
||||||
|
* deviceSide, deviceMode.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void initHearingAidDeviceIfNeeded_validHiSyncId_verifyHiSyncId() {
|
public void initHearingAidDeviceIfNeeded_validHiSyncId_setHearingAidInfos() {
|
||||||
when(mHearingAidProfile.getHiSyncId(mDevice1)).thenReturn(HISYNCID1);
|
when(mHearingAidProfile.getHiSyncId(mDevice1)).thenReturn(HISYNCID1);
|
||||||
|
when(mHearingAidProfile.getDeviceMode(mDevice1)).thenReturn(
|
||||||
|
HearingAidProfile.DeviceMode.MODE_BINAURAL);
|
||||||
|
when(mHearingAidProfile.getDeviceSide(mDevice1)).thenReturn(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||||
|
|
||||||
assertThat(mCachedDevice1.getHiSyncId()).isNotEqualTo(HISYNCID1);
|
assertThat(mCachedDevice1.getHiSyncId()).isNotEqualTo(HISYNCID1);
|
||||||
mHearingAidDeviceManager.initHearingAidDeviceIfNeeded(mCachedDevice1);
|
mHearingAidDeviceManager.initHearingAidDeviceIfNeeded(mCachedDevice1);
|
||||||
|
|
||||||
assertThat(mCachedDevice1.getHiSyncId()).isEqualTo(HISYNCID1);
|
assertThat(mCachedDevice1.getHiSyncId()).isEqualTo(HISYNCID1);
|
||||||
|
assertThat(mCachedDevice1.getDeviceMode()).isEqualTo(
|
||||||
|
HearingAidProfile.DeviceMode.MODE_BINAURAL);
|
||||||
|
assertThat(mCachedDevice1.getDeviceSide()).isEqualTo(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,6 +259,29 @@ public class HearingAidDeviceManagerTest {
|
|||||||
verify(mHearingAidDeviceManager, never()).onHiSyncIdChanged(anyLong());
|
verify(mHearingAidDeviceManager, never()).onHiSyncIdChanged(anyLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test updateHearingAidsDevices, set HearingAid's information, including HiSyncId, deviceSide,
|
||||||
|
* deviceMode.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void updateHearingAidsDevices_validHiSyncId_setHearingAidInfos() {
|
||||||
|
when(mHearingAidProfile.getHiSyncId(mDevice1)).thenReturn(HISYNCID1);
|
||||||
|
when(mHearingAidProfile.getDeviceMode(mDevice1)).thenReturn(
|
||||||
|
HearingAidProfile.DeviceMode.MODE_BINAURAL);
|
||||||
|
when(mHearingAidProfile.getDeviceSide(mDevice1)).thenReturn(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||||
|
mCachedDeviceManager.mCachedDevices.add(mCachedDevice1);
|
||||||
|
|
||||||
|
mHearingAidDeviceManager.updateHearingAidsDevices();
|
||||||
|
|
||||||
|
assertThat(mCachedDevice1.getHiSyncId()).isEqualTo(HISYNCID1);
|
||||||
|
assertThat(mCachedDevice1.getDeviceMode()).isEqualTo(
|
||||||
|
HearingAidProfile.DeviceMode.MODE_BINAURAL);
|
||||||
|
assertThat(mCachedDevice1.getDeviceSide()).isEqualTo(
|
||||||
|
HearingAidProfile.DeviceSide.SIDE_RIGHT);
|
||||||
|
verify(mHearingAidDeviceManager).onHiSyncIdChanged(HISYNCID1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test onProfileConnectionStateChangedIfProcessed.
|
* Test onProfileConnectionStateChangedIfProcessed.
|
||||||
* When first hearing aid device is connected, to process it same as other generic devices.
|
* When first hearing aid device is connected, to process it same as other generic devices.
|
||||||
|
|||||||
Reference in New Issue
Block a user