Fix logging format and add test cases
For logging purpose, CachedBluetoothDevice#toString is more clear then BluetoothDevice#toString, so change to use CachedBluetoothDevice#toString Bug: 307890347 Test: atest HearingDevicePairingFragmentTest Change-Id: Ia0af65565ca7067fa6c4d5db286c3739fb65c1d2
This commit is contained in:
@@ -192,7 +192,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
|
||||
public void onDeviceBondStateChanged(@NonNull CachedBluetoothDevice cachedDevice,
|
||||
int bondState) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onDeviceBondStateChanged: " + cachedDevice.getDevice() + ", state = "
|
||||
Log.d(TAG, "onDeviceBondStateChanged: " + cachedDevice + ", state = "
|
||||
+ bondState);
|
||||
}
|
||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
@@ -276,13 +276,13 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
|
||||
}
|
||||
mDevicePreferenceMap.put(cachedDevice, preference);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Add device. device: " + cachedDevice.getDevice());
|
||||
Log.d(TAG, "Add device. device: " + cachedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
void removeDevice(CachedBluetoothDevice cachedDevice) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "removeDevice: " + cachedDevice.getDevice());
|
||||
Log.d(TAG, "removeDevice: " + cachedDevice);
|
||||
}
|
||||
BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
|
||||
if (mAvailableHearingDeviceGroup != null && preference != null) {
|
||||
@@ -331,13 +331,13 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
|
||||
cachedDevice = mCachedDeviceManager.addDevice(device);
|
||||
} else if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Skip this device, already bonded: " + cachedDevice.getDevice());
|
||||
Log.d(TAG, "Skip this device, already bonded: " + cachedDevice);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cachedDevice.getHearingAidInfo() == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Set hearing aid info on device: " + cachedDevice.getDevice());
|
||||
Log.d(TAG, "Set hearing aid info on device: " + cachedDevice);
|
||||
}
|
||||
cachedDevice.setHearingAidInfo(new HearingAidInfo.Builder().build());
|
||||
}
|
||||
@@ -455,7 +455,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
|
||||
|
||||
void discoverServices(CachedBluetoothDevice cachedDevice) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "connectGattToCheckCompatibility, device: " + cachedDevice.getDevice());
|
||||
Log.d(TAG, "connectGattToCheckCompatibility, device: " + cachedDevice);
|
||||
}
|
||||
BluetoothGatt gatt = cachedDevice.getDevice().connectGatt(getContext(), false,
|
||||
new BluetoothGattCallback() {
|
||||
@@ -465,7 +465,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
|
||||
super.onConnectionStateChange(gatt, status, newState);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onConnectionStateChange, status: " + status + ", newState: "
|
||||
+ newState + ", device: " + cachedDevice.getDevice());
|
||||
+ newState + ", device: " + cachedDevice);
|
||||
}
|
||||
if (status == GATT_SUCCESS
|
||||
&& newState == BluetoothProfile.STATE_CONNECTED) {
|
||||
@@ -481,14 +481,14 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
|
||||
super.onServicesDiscovered(gatt, status);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onServicesDiscovered, status: " + status + ", device: "
|
||||
+ cachedDevice.getDevice());
|
||||
+ cachedDevice);
|
||||
}
|
||||
if (status == GATT_SUCCESS) {
|
||||
if (gatt.getService(BluetoothUuid.HEARING_AID.getUuid()) != null
|
||||
|| gatt.getService(BluetoothUuid.HAS.getUuid()) != null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "compatible with Android, device: "
|
||||
+ cachedDevice.getDevice());
|
||||
+ cachedDevice);
|
||||
}
|
||||
addDevice(cachedDevice);
|
||||
}
|
||||
|
@@ -178,7 +178,7 @@ public class HearingDevicePairingFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleLeScanResult_isNotAndroidCompatible_() {
|
||||
public void handleLeScanResult_isNotAndroidCompatible_discoverServices() {
|
||||
ScanResult scanResult = mock(ScanResult.class);
|
||||
doReturn(mDevice).when(scanResult).getDevice();
|
||||
doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
|
||||
@@ -189,6 +189,19 @@ public class HearingDevicePairingFragmentTest {
|
||||
verify(mFragment).discoverServices(mCachedDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleLeScanResult_alreadyBonded_doNothing() {
|
||||
ScanResult scanResult = mock(ScanResult.class);
|
||||
doReturn(mDevice).when(scanResult).getDevice();
|
||||
doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mCachedDevice).getBondState();
|
||||
|
||||
mFragment.handleLeScanResult(scanResult);
|
||||
|
||||
verify(mFragment, never()).addDevice(mCachedDevice);
|
||||
verify(mFragment, never()).discoverServices(mCachedDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceConnected_inSelectedList_finish() {
|
||||
doReturn(true).when(mCachedDevice).isConnected();
|
||||
|
Reference in New Issue
Block a user