.getBtClassDrawableWithDescription(mContext, mCachedDevice,
mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1, 1));
String summaryText = mCachedDevice.getConnectionSummary();
- // If both the hearing aids are connected, two battery status should be shown.
- final String pairDeviceSummary = mDeviceManager
- .getHearingAidPairDeviceSummary(mCachedDevice);
- if (pairDeviceSummary != null) {
- mHeaderController.setSecondSummary(pairDeviceSummary);
- }
+ // If both the hearing aids are connected, two device status should be shown.
+ // If Second Summary is unavailable, to set it to null.
+ mHeaderController.setSecondSummary(
+ mDeviceManager.getSubDeviceSummary(mCachedDevice));
mHeaderController.setLabel(mCachedDevice.getName());
mHeaderController.setIcon(pair.first);
mHeaderController.setIconContentDescription(pair.second);
@Override
protected void refresh() {
+ mFooterPreference.setTitle(mContext.getString(
+ R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
}
@Override
*/
protected void removePreference(CachedBluetoothDevice cachedDevice) {
final BluetoothDevice device = cachedDevice.getDevice();
+ final CachedBluetoothDevice subCachedDevice = cachedDevice.getSubDevice();
if (mPreferenceMap.containsKey(device)) {
mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(device));
mPreferenceMap.remove(device);
+ } else if (subCachedDevice != null) {
+ // When doing remove, to check if preference maps to sub device.
+ // This would happen when connection state is changed in detail page that there is no
+ // callback from SettingsLib.
+ final BluetoothDevice subDevice = subCachedDevice.getDevice();
+ if (mPreferenceMap.containsKey(subDevice)) {
+ mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(subDevice));
+ mPreferenceMap.remove(subDevice);
+ }
}
}
FakeFeatureFactory.setupForTest();
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
- when(mCachedDeviceManager.getHearingAidPairDeviceSummary(mCachedDevice)).thenReturn("abc");
+ when(mCachedDeviceManager.getSubDeviceSummary(mCachedDevice)).thenReturn("abc");
mController =
new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice, mLifecycle,
mBluetoothManager);
@Mock
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
+ private CachedBluetoothDevice mSubCachedBluetoothDevice;
+ @Mock
private BluetoothDevice mBluetoothDevice;
@Mock
+ private BluetoothDevice mSubBluetoothDevice;
+ @Mock
private SettingsActivity mSettingsActivity;
@Mock
private LocalBluetoothManager mLocalManager;
mCachedDevices.add(mCachedBluetoothDevice);
doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mSubCachedBluetoothDevice.getDevice()).thenReturn(mSubBluetoothDevice);
when(mLocalManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
}
@Test
+ public void testRemovePreference_subDeviceExist_removePreference() {
+ when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
+ mBluetoothDeviceUpdater.mPreferenceMap.put(mSubBluetoothDevice, mPreference);
+
+ assertThat(mBluetoothDeviceUpdater.mPreferenceMap.
+ containsKey(mSubBluetoothDevice)).isTrue();
+ mBluetoothDeviceUpdater.removePreference(mCachedBluetoothDevice);
+
+ verify(mDevicePreferenceCallback).onDeviceRemoved(mPreference);
+ assertThat(mBluetoothDeviceUpdater.mPreferenceMap.
+ containsKey(mSubBluetoothDevice)).isFalse();
+ }
+
+ @Test
public void testDeviceProfilesListener_click_startBluetoothDeviceDetailPage() {
doReturn(mSettingsActivity).when(mDashboardFragment).getContext();