From 7fc064fc659aa98fe10fa741f28df33e6ea24df1 Mon Sep 17 00:00:00 2001 From: Roger Olsson Date: Thu, 30 Mar 2023 12:29:51 +0200 Subject: Fix sub title for connected Bluetooth device Added callback in BluetoothDevicesService to trigger refresh in ConnectedDevicesSliceProvider when receiving BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED. Needed to ensure that the subtitle for a connected or disconnected Bluetooth menu item is correct. Bug: 298653577 Test: Go to Settings > Remotes & Accessories > Pair accessory. Connect a BT device, e.g. a headset. Expected: Device connected. New device menu item added with sub title "Connected". Has preview with menu item "Disconnect". Disconnect BT device. Expected: Device disconnected. Device menu item sub title changed to "Disconnected". Preview has menu item "Connect". Connect BT device. Expected: Device connected. Device menu item sub title changed to "Connected". Preview has menu item "Disconnect". Repeat the two previous steps a few times. Change-Id: I99368b1f5918c783ade0572a8acea604579f47bf --- .../tv/settings/accessories/BluetoothDevicesService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Settings/src/com/android/tv/settings/accessories/BluetoothDevicesService.java b/Settings/src/com/android/tv/settings/accessories/BluetoothDevicesService.java index 6f80a601c..f89896ab9 100644 --- a/Settings/src/com/android/tv/settings/accessories/BluetoothDevicesService.java +++ b/Settings/src/com/android/tv/settings/accessories/BluetoothDevicesService.java @@ -139,8 +139,14 @@ public class BluetoothDevicesService extends Service { } break; case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED: - int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1); - mHandler.post(() -> onA2dpConnectionStateChanged(device.getName(), state)); + final int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1); + mHandler.post(() -> { + onA2dpConnectionStateChanged(device.getName(), state); + if (state == BluetoothProfile.STATE_CONNECTED + || state == BluetoothProfile.STATE_DISCONNECTED) { + onDeviceUpdated(device); + } + }); break; case BluetoothDevice.ACTION_ACL_CONNECTED: Log.i(TAG, "acl connected " + device); -- cgit v1.2.3