Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +6 −2 Original line number Diff line number Diff line Loading @@ -110,6 +110,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> mHiSyncId = id; } public boolean isHearingAidDevice() { return mHiSyncId != BluetoothHearingAid.HI_SYNC_ID_INVALID; } /** * Last time a bt profile auto-connect was attempted. * If an ACTION_UUID intent comes in within Loading Loading @@ -144,8 +148,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> void onProfileStateChanged(LocalBluetoothProfile profile, int newProfileState) { if (Utils.D) { Log.d(TAG, "onProfileStateChanged: profile " + profile + " newProfileState " + newProfileState); Log.d(TAG, "onProfileStateChanged: profile " + profile + ", device=" + mDevice + ", newProfileState " + newProfileState); } if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) { Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +8 −8 Original line number Diff line number Diff line Loading @@ -162,14 +162,14 @@ public class CachedBluetoothDeviceManager { */ public synchronized String getHearingAidPairDeviceSummary(CachedBluetoothDevice device) { String pairDeviceSummary = null; if (device.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) { for (CachedBluetoothDevice hearingAidDevice : mHearingAidDevicesNotAddedInCache) { if (hearingAidDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID && hearingAidDevice.getHiSyncId() == device.getHiSyncId()) { pairDeviceSummary = hearingAidDevice.getConnectionSummary(); } } CachedBluetoothDevice otherHearingAidDevice = getHearingAidOtherDevice(device, device.getHiSyncId()); if (otherHearingAidDevice != null) { pairDeviceSummary = otherHearingAidDevice.getConnectionSummary(); } log("getHearingAidPairDeviceSummary: pairDeviceSummary=" + pairDeviceSummary + ", otherHearingAidDevice=" + otherHearingAidDevice); return pairDeviceSummary; } Loading Loading @@ -358,7 +358,7 @@ public class CachedBluetoothDeviceManager { } } private CachedBluetoothDevice getHearingAidOtherDevice(CachedBluetoothDevice thisDevice, public CachedBluetoothDevice getHearingAidOtherDevice(CachedBluetoothDevice thisDevice, long hiSyncId) { if (hiSyncId == BluetoothHearingAid.HI_SYNC_ID_INVALID) { return null; Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java +18 −5 Original line number Diff line number Diff line Loading @@ -378,9 +378,10 @@ public class LocalBluetoothProfileManager { Log.i(TAG, "Failed to connect " + mProfile + " device"); } if (getHearingAidProfile() != null && mProfile instanceof HearingAidProfile && (newState == BluetoothProfile.STATE_CONNECTED)) { boolean isHearingAidProfile = (getHearingAidProfile() != null) && (mProfile instanceof HearingAidProfile); if (isHearingAidProfile && (newState == BluetoothProfile.STATE_CONNECTED)) { // Check if the HiSyncID has being initialized if (cachedDevice.getHiSyncId() == BluetoothHearingAid.HI_SYNC_ID_INVALID) { Loading @@ -393,10 +394,22 @@ public class LocalBluetoothProfileManager { } } mEventManager.dispatchProfileConnectionStateChanged(cachedDevice, newState, mProfile.getProfileId()); cachedDevice.onProfileStateChanged(mProfile, newState); cachedDevice.refresh(); if (isHearingAidProfile) { CachedBluetoothDevice otherDevice = mDeviceManager.getHearingAidOtherDevice(cachedDevice, cachedDevice.getHiSyncId()); if (otherDevice != null) { if (DEBUG) { Log.d(TAG, "Refreshing other hearing aid=" + otherDevice + ", newState=" + newState); } otherDevice.refresh(); } } mEventManager.dispatchProfileConnectionStateChanged(cachedDevice, newState, mProfile.getProfileId()); } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManagerTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -828,4 +828,20 @@ public class CachedBluetoothDeviceManagerTest { assertThat(cachedDevice2.isActiveDevice(BluetoothProfile.HEADSET)).isFalse(); assertThat(cachedDevice2.isActiveDevice(BluetoothProfile.HEARING_AID)).isFalse(); } /** * Test to verify getHearingAidOtherDevice() for hearing aid devices with same HiSyncId. */ @Test public void testGetHearingAidOtherDevice_bothHearingAidsPaired_returnsOtherDevice() { mCachedDevice1.setHiSyncId(HISYNCID1); mCachedDevice2.setHiSyncId(HISYNCID1); mCachedDeviceManager.mCachedDevices.add(mCachedDevice1); mCachedDeviceManager.mHearingAidDevicesNotAddedInCache.add(mCachedDevice2); doAnswer((invocation) -> DEVICE_SUMMARY_1).when(mCachedDevice1).getConnectionSummary(); doAnswer((invocation) -> DEVICE_SUMMARY_2).when(mCachedDevice2).getConnectionSummary(); assertThat(mCachedDeviceManager.getHearingAidOtherDevice(mCachedDevice1, HISYNCID1)) .isEqualTo(mCachedDevice2); } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.robolectric.Shadows.shadowOf; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.media.AudioManager; Loading Loading @@ -572,4 +573,16 @@ public class CachedBluetoothDeviceTest { assertThat(mCachedDevice.isHfpDevice()).isFalse(); } @Test public void testIsHearingAidDevice_isHearingAidDevice() { mCachedDevice.setHiSyncId(0x1234); assertThat(mCachedDevice.isHearingAidDevice()).isTrue(); } @Test public void testIsHearingAidDevice_isNotHearingAidDevice() { mCachedDevice.setHiSyncId(BluetoothHearingAid.HI_SYNC_ID_INVALID); assertThat(mCachedDevice.isHearingAidDevice()).isFalse(); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +6 −2 Original line number Diff line number Diff line Loading @@ -110,6 +110,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> mHiSyncId = id; } public boolean isHearingAidDevice() { return mHiSyncId != BluetoothHearingAid.HI_SYNC_ID_INVALID; } /** * Last time a bt profile auto-connect was attempted. * If an ACTION_UUID intent comes in within Loading Loading @@ -144,8 +148,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> void onProfileStateChanged(LocalBluetoothProfile profile, int newProfileState) { if (Utils.D) { Log.d(TAG, "onProfileStateChanged: profile " + profile + " newProfileState " + newProfileState); Log.d(TAG, "onProfileStateChanged: profile " + profile + ", device=" + mDevice + ", newProfileState " + newProfileState); } if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) { Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +8 −8 Original line number Diff line number Diff line Loading @@ -162,14 +162,14 @@ public class CachedBluetoothDeviceManager { */ public synchronized String getHearingAidPairDeviceSummary(CachedBluetoothDevice device) { String pairDeviceSummary = null; if (device.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) { for (CachedBluetoothDevice hearingAidDevice : mHearingAidDevicesNotAddedInCache) { if (hearingAidDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID && hearingAidDevice.getHiSyncId() == device.getHiSyncId()) { pairDeviceSummary = hearingAidDevice.getConnectionSummary(); } } CachedBluetoothDevice otherHearingAidDevice = getHearingAidOtherDevice(device, device.getHiSyncId()); if (otherHearingAidDevice != null) { pairDeviceSummary = otherHearingAidDevice.getConnectionSummary(); } log("getHearingAidPairDeviceSummary: pairDeviceSummary=" + pairDeviceSummary + ", otherHearingAidDevice=" + otherHearingAidDevice); return pairDeviceSummary; } Loading Loading @@ -358,7 +358,7 @@ public class CachedBluetoothDeviceManager { } } private CachedBluetoothDevice getHearingAidOtherDevice(CachedBluetoothDevice thisDevice, public CachedBluetoothDevice getHearingAidOtherDevice(CachedBluetoothDevice thisDevice, long hiSyncId) { if (hiSyncId == BluetoothHearingAid.HI_SYNC_ID_INVALID) { return null; Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java +18 −5 Original line number Diff line number Diff line Loading @@ -378,9 +378,10 @@ public class LocalBluetoothProfileManager { Log.i(TAG, "Failed to connect " + mProfile + " device"); } if (getHearingAidProfile() != null && mProfile instanceof HearingAidProfile && (newState == BluetoothProfile.STATE_CONNECTED)) { boolean isHearingAidProfile = (getHearingAidProfile() != null) && (mProfile instanceof HearingAidProfile); if (isHearingAidProfile && (newState == BluetoothProfile.STATE_CONNECTED)) { // Check if the HiSyncID has being initialized if (cachedDevice.getHiSyncId() == BluetoothHearingAid.HI_SYNC_ID_INVALID) { Loading @@ -393,10 +394,22 @@ public class LocalBluetoothProfileManager { } } mEventManager.dispatchProfileConnectionStateChanged(cachedDevice, newState, mProfile.getProfileId()); cachedDevice.onProfileStateChanged(mProfile, newState); cachedDevice.refresh(); if (isHearingAidProfile) { CachedBluetoothDevice otherDevice = mDeviceManager.getHearingAidOtherDevice(cachedDevice, cachedDevice.getHiSyncId()); if (otherDevice != null) { if (DEBUG) { Log.d(TAG, "Refreshing other hearing aid=" + otherDevice + ", newState=" + newState); } otherDevice.refresh(); } } mEventManager.dispatchProfileConnectionStateChanged(cachedDevice, newState, mProfile.getProfileId()); } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManagerTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -828,4 +828,20 @@ public class CachedBluetoothDeviceManagerTest { assertThat(cachedDevice2.isActiveDevice(BluetoothProfile.HEADSET)).isFalse(); assertThat(cachedDevice2.isActiveDevice(BluetoothProfile.HEARING_AID)).isFalse(); } /** * Test to verify getHearingAidOtherDevice() for hearing aid devices with same HiSyncId. */ @Test public void testGetHearingAidOtherDevice_bothHearingAidsPaired_returnsOtherDevice() { mCachedDevice1.setHiSyncId(HISYNCID1); mCachedDevice2.setHiSyncId(HISYNCID1); mCachedDeviceManager.mCachedDevices.add(mCachedDevice1); mCachedDeviceManager.mHearingAidDevicesNotAddedInCache.add(mCachedDevice2); doAnswer((invocation) -> DEVICE_SUMMARY_1).when(mCachedDevice1).getConnectionSummary(); doAnswer((invocation) -> DEVICE_SUMMARY_2).when(mCachedDevice2).getConnectionSummary(); assertThat(mCachedDeviceManager.getHearingAidOtherDevice(mCachedDevice1, HISYNCID1)) .isEqualTo(mCachedDevice2); } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.robolectric.Shadows.shadowOf; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.media.AudioManager; Loading Loading @@ -572,4 +573,16 @@ public class CachedBluetoothDeviceTest { assertThat(mCachedDevice.isHfpDevice()).isFalse(); } @Test public void testIsHearingAidDevice_isHearingAidDevice() { mCachedDevice.setHiSyncId(0x1234); assertThat(mCachedDevice.isHearingAidDevice()).isTrue(); } @Test public void testIsHearingAidDevice_isNotHearingAidDevice() { mCachedDevice.setHiSyncId(BluetoothHearingAid.HI_SYNC_ID_INVALID); assertThat(mCachedDevice.isHearingAidDevice()).isFalse(); } }