Add Bluetooth metadata listenr

If it is updated, we need to refresh UI to display latest information

Fixes: 124455912
Test: RunSettingsRoboTests
Change-Id: I73b03f4931e3c2b0d367bbd2d3b2057b26c84b59
This commit is contained in:
jackqdyulei
2019-02-25 13:58:13 -08:00
parent 5e5dd25b8f
commit 344d761e60
2 changed files with 41 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.Bitmap;
@@ -65,6 +66,8 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
private ImageView mImageView;
@Mock
private CachedBluetoothDevice mCachedDevice;
@Mock
private BluetoothAdapter mBluetoothAdapter;
private AdvancedBluetoothDetailsHeaderController mController;
private LayoutPreference mLayoutPreference;
@@ -78,6 +81,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
mLayoutPreference = new LayoutPreference(mContext,
LayoutInflater.from(mContext).inflate(R.layout.advanced_bt_entity_header, null));
mController.mLayoutPreference = mLayoutPreference;
mController.mBluetoothAdapter = mBluetoothAdapter;
when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
}
@@ -159,6 +163,21 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
verify(mImageView).setImageBitmap(mBitmap);
}
@Test
public void onStart_registerCallback() {
mController.onStart();
verify(mBluetoothAdapter).registerMetadataListener(mBluetoothDevice,
mController.mMetadataListener, mController.mHandler);
}
@Test
public void onStop_unregisterCallback() {
mController.onStop();
verify(mBluetoothAdapter).unregisterMetadataListener(mBluetoothDevice);
}
private void assertBatteryLevel(LinearLayout linearLayout, int batteryLevel) {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
assertThat(textView.getText().toString()).isEqualTo(