resolve merge conflicts of b0e99e147253df35932c8c7c15911d091a07dda1 to stage-aosp-master

Bug: None
Test: I solemnly swear I tested this conflict resolution.
Change-Id: Ife619e714d451b6cb77bfaf50e3f45c969d37cb4
Merged-In: I0b1a170967ddcce7f388603fd521f6ed1eeba30b
Merged-In: I169cda4a1658b0a67cc7c7367b38d57a021e6953
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
index dca7e20..aff314b 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.graphics.drawable.Drawable;
+import android.util.Log;
 import androidx.preference.PreferenceFragment;
 import androidx.preference.PreferenceScreen;
 import android.util.Pair;
@@ -36,6 +37,7 @@
  */
 public class BluetoothDetailsHeaderController extends BluetoothDetailsController {
     private static final String KEY_DEVICE_HEADER = "bluetooth_device_header";
+    private static final String TAG = "BluetoothDetailsHeaderController";
 
     private EntityHeaderController mHeaderController;
     private LocalBluetoothManager mLocalManager;
@@ -63,12 +65,16 @@
                 .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) {
+
+        if (mCachedDevice.isHearingAidDevice()) {
+            // For Hearing Aid device, display the other battery status.
+            final String pairDeviceSummary = mDeviceManager
+                .getHearingAidPairDeviceSummary(mCachedDevice);
+            Log.d(TAG, "setHeaderProperties: HearingAid: summaryText=" + summaryText
+                  + ", pairDeviceSummary=" + pairDeviceSummary);
             mHeaderController.setSecondSummary(pairDeviceSummary);
         }
+
         mHeaderController.setLabel(mCachedDevice.getName());
         mHeaderController.setIcon(pair.first);
         mHeaderController.setIconContentDescription(pair.second);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
index 2567f53..e3f26b2 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
@@ -19,6 +19,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -96,7 +97,7 @@
         verify(mHeaderController).setIcon(any(Drawable.class));
         verify(mHeaderController).setIconContentDescription(any(String.class));
         verify(mHeaderController).setSummary(any(String.class));
-        verify(mHeaderController).setSecondSummary(any(String.class));
+        verify(mHeaderController, never()).setSecondSummary(any(String.class));
         verify(mHeaderController).done(mActivity, true);
     }
 
@@ -119,4 +120,12 @@
         inOrder.verify(mHeaderController)
             .setSummary(mContext.getString(R.string.bluetooth_connecting));
     }
+
+    @Test
+    public void testSecondSummary_isHearingAidDevice_showSecondSummary() {
+        when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
+        showScreen(mController);
+
+        verify(mHeaderController).setSecondSummary(any(String.class));
+    }
 }