OSDN Git Service

Make HearingAid code more generic
authortimhypeng <timhypeng@google.com>
Tue, 9 Oct 2018 03:19:23 +0000 (11:19 +0800)
committerHugh Chen <hughchen@google.com>
Thu, 25 Oct 2018 04:06:40 +0000 (04:06 +0000)
-handle UI updating when sub device connection state changes
-add test case

Bug: 112735753
Test: make -j42 RunSettingsRoboTests
Change-Id: Ie2643657c47a0956aac3f8cac4bfdbdea0399ce8

src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java

index fb6cd56..1795c07 100644 (file)
@@ -65,12 +65,10 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
                 .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);
index 71a415d..987dbe4 100644 (file)
@@ -51,6 +51,8 @@ public class BluetoothDetailsMacAddressController extends BluetoothDetailsContro
 
     @Override
     protected void refresh() {
+        mFooterPreference.setTitle(mContext.getString(
+                R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
     }
 
     @Override
index cac4565..a1ce4a6 100644 (file)
@@ -230,9 +230,19 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
      */
     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);
+            }
         }
     }
 
index 3f19ccb..0430e0f 100644 (file)
@@ -72,7 +72,7 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
         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);
index 4ede947..19e3bfb 100644 (file)
@@ -63,8 +63,12 @@ public class BluetoothDeviceUpdaterTest {
     @Mock
     private CachedBluetoothDevice mCachedBluetoothDevice;
     @Mock
+    private CachedBluetoothDevice mSubCachedBluetoothDevice;
+    @Mock
     private BluetoothDevice mBluetoothDevice;
     @Mock
+    private BluetoothDevice mSubBluetoothDevice;
+    @Mock
     private SettingsActivity mSettingsActivity;
     @Mock
     private LocalBluetoothManager mLocalManager;
@@ -86,6 +90,7 @@ public class BluetoothDeviceUpdaterTest {
         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);
 
@@ -147,6 +152,20 @@ public class BluetoothDeviceUpdaterTest {
     }
 
     @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();