summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHsin-Yu Chao <hychao@chromium.org>2021-03-05 08:39:22 +0000
committerCommit Bot <commit-bot@chromium.org>2021-03-08 11:14:14 +0000
commitc14c7eec51a05f1e0a51dd04845b2545ca0dde14 (patch)
tree4cd32486e080f874e624d8ec09b446bf05917420
parente3deafc9fbf6a900fd5622e7849bc885db3ed757 (diff)
downloadadhd-c14c7eec51a05f1e0a51dd04845b2545ca0dde14.tar.gz
CRAS: bt_device - Log stable id of bt_device
In order to tell different BT devices in dump log, this change moves the stable_id field into bt_device and specifically created CONNECTED, DISCONNECTED events to log stable_id with. BUG=b:181831987 TEST=cras_test_client --dump_bt | grep stable_id can see clearly which device is related to the event we care in BT dump. Change-Id: If628181eda912fe9460e0d0b47824343305cc9c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2739018 Reviewed-by: Hsinyu Chao <hychao@chromium.org> Commit-Queue: Hsinyu Chao <hychao@chromium.org> Tested-by: Hsinyu Chao <hychao@chromium.org>
-rw-r--r--cras/src/Makefile.am8
-rw-r--r--cras/src/common/cras_types.h3
-rw-r--r--cras/src/server/cras_a2dp_iodev.c6
-rw-r--r--cras/src/server/cras_bt_device.c19
-rw-r--r--cras/src/server/cras_bt_device.h4
-rw-r--r--cras/src/server/cras_bt_io.c5
-rw-r--r--cras/src/server/cras_hfp_alsa_iodev.c6
-rw-r--r--cras/src/server/cras_hfp_iodev.c6
-rw-r--r--cras/src/tests/a2dp_iodev_unittest.cc4
-rw-r--r--cras/src/tests/bt_io_unittest.cc4
-rw-r--r--cras/src/tests/hfp_alsa_iodev_unittest.cc4
-rw-r--r--cras/src/tests/hfp_iodev_unittest.cc4
-rw-r--r--cras/src/tools/cras_test_client/cras_test_client.c11
13 files changed, 54 insertions, 30 deletions
diff --git a/cras/src/Makefile.am b/cras/src/Makefile.am
index a7844e2d..1e89f811 100644
--- a/cras/src/Makefile.am
+++ b/cras/src/Makefile.am
@@ -615,7 +615,7 @@ a2dp_info_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/server \
-I$(top_srcdir)/src/common
a2dp_info_unittest_LDADD = -lgtest -lpthread
-a2dp_iodev_unittest_SOURCES = tests/a2dp_iodev_unittest.cc common/sfh.c
+a2dp_iodev_unittest_SOURCES = tests/a2dp_iodev_unittest.cc
a2dp_iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/server \
-I$(top_srcdir)/src/common $(DBUS_CFLAGS)
a2dp_iodev_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS)
@@ -688,7 +688,7 @@ audio_thread_monitor_unittest_LDADD = -lgtest -lpthread -lrt
if HAVE_DBUS
bt_device_unittest_SOURCES = tests/bt_device_unittest.cc \
server/cras_bt_device.c \
- tests/metrics_stub.cc
+ tests/metrics_stub.cc common/sfh.c
bt_device_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/server \
-I$(top_srcdir)/src/common $(DBUS_CFLAGS)
bt_device_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS)
@@ -863,13 +863,13 @@ hfp_info_unittest_LDADD = -lgtest -lpthread
if HAVE_DBUS
hfp_iodev_unittest_SOURCES = tests/hfp_iodev_unittest.cc \
- server/cras_hfp_iodev.c common/sfh.c
+ server/cras_hfp_iodev.c
hfp_iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) -I$(top_srcdir)/src/common \
-I$(top_srcdir)/src/server $(DBUS_CFLAGS)
hfp_iodev_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS)
hfp_alsa_iodev_unittest_SOURCES = tests/hfp_alsa_iodev_unittest.cc \
- server/cras_hfp_alsa_iodev.c common/sfh.c
+ server/cras_hfp_alsa_iodev.c
hfp_alsa_iodev_unittest_CPPFLAGS = $(COMMON_CPPFLAGS) \
-I$(top_srcdir)/src/common -I$(top_srcdir)/src/server $(DBUS_CFLAGS)
hfp_alsa_iodev_unittest_LDADD = -lgtest -lpthread $(DBUS_LIBS)
diff --git a/cras/src/common/cras_types.h b/cras/src/common/cras_types.h
index 7c8a4229..89e3b816 100644
--- a/cras/src/common/cras_types.h
+++ b/cras/src/common/cras_types.h
@@ -368,7 +368,8 @@ enum CRAS_BT_LOG_EVENTS {
BT_A2DP_START,
BT_A2DP_SUSPENDED,
BT_CODEC_SELECTION,
- BT_DEV_CONNECTED_CHANGE,
+ BT_DEV_CONNECTED,
+ BT_DEV_DISCONNECTED,
BT_DEV_CONN_WATCH_CB,
BT_DEV_SUSPEND_CB,
BT_HFP_NEW_CONNECTION,
diff --git a/cras/src/server/cras_a2dp_iodev.c b/cras/src/server/cras_a2dp_iodev.c
index 6c434758..b8a606e4 100644
--- a/cras/src/server/cras_a2dp_iodev.c
+++ b/cras/src/server/cras_a2dp_iodev.c
@@ -24,7 +24,6 @@
#include "cras_bt_device.h"
#include "cras_iodev.h"
#include "cras_util.h"
-#include "sfh.h"
#include "rtp.h"
#include "utlist.h"
@@ -644,10 +643,7 @@ struct cras_iodev *a2dp_iodev_create(struct cras_bt_transport *transport)
snprintf(iodev->info.name, sizeof(iodev->info.name), "%s", name);
iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = '\0';
- iodev->info.stable_id =
- SuperFastHash(cras_bt_device_object_path(device),
- strlen(cras_bt_device_object_path(device)),
- strlen(cras_bt_device_object_path(device)));
+ iodev->info.stable_id = cras_bt_device_get_stable_id(device);
iodev->configure_dev = configure_dev;
iodev->frames_queued = frames_queued;
diff --git a/cras/src/server/cras_bt_device.c b/cras/src/server/cras_bt_device.c
index 70c87479..6b06dd13 100644
--- a/cras/src/server/cras_bt_device.c
+++ b/cras/src/server/cras_bt_device.c
@@ -34,6 +34,7 @@
#include "cras_server_metrics.h"
#include "cras_system_state.h"
#include "cras_tm.h"
+#include "sfh.h"
#include "utlist.h"
/*
@@ -91,6 +92,7 @@ static const unsigned int CRAS_SUPPORTED_PROFILES =
* sco_fd - The file descriptor of the SCO connection.
* sco_ref_count - The reference counts of the SCO connection.
* suspend_reason - The reason code for why suspend is scheduled.
+ * stable_id - The unique and persistent id of this bt_device.
*/
struct cras_bt_device {
DBusConnection *conn;
@@ -115,6 +117,7 @@ struct cras_bt_device {
int sco_fd;
size_t sco_ref_count;
enum cras_bt_device_suspend_reason suspend_reason;
+ unsigned int stable_id;
struct cras_bt_device *prev, *next;
};
@@ -174,6 +177,9 @@ struct cras_bt_device *cras_bt_device_create(DBusConnection *conn,
free(device);
return NULL;
}
+ device->stable_id =
+ SuperFastHash(device->object_path, strlen(device->object_path),
+ strlen(device->object_path));
DL_APPEND(devices, device);
@@ -343,6 +349,11 @@ const char *cras_bt_device_object_path(const struct cras_bt_device *device)
return device->object_path;
}
+int cras_bt_device_get_stable_id(const struct cras_bt_device *device)
+{
+ return device->stable_id;
+}
+
struct cras_bt_adapter *
cras_bt_device_adapter(const struct cras_bt_device *device)
{
@@ -704,10 +715,14 @@ static void bt_device_cancel_suspend(struct cras_bt_device *device);
void cras_bt_device_set_connected(struct cras_bt_device *device, int value)
{
struct cras_tm *tm = cras_system_state_get_tm();
- if (device->connected || value)
- BTLOG(btlog, BT_DEV_CONNECTED_CHANGE, device->profiles, value);
+ if (!device->connected && value) {
+ BTLOG(btlog, BT_DEV_CONNECTED, device->profiles,
+ device->stable_id);
+ }
if (device->connected && !value) {
+ BTLOG(btlog, BT_DEV_DISCONNECTED, device->profiles,
+ device->stable_id);
cras_bt_profile_on_device_disconnected(device);
/* Device is disconnected, resets connected profiles and the
* suspend timer which scheduled earlier. */
diff --git a/cras/src/server/cras_bt_device.h b/cras/src/server/cras_bt_device.h
index 4202bc93..9d3a2b9e 100644
--- a/cras/src/server/cras_bt_device.h
+++ b/cras/src/server/cras_bt_device.h
@@ -50,6 +50,10 @@ void cras_bt_device_reset();
struct cras_bt_device *cras_bt_device_get(const char *object_path);
const char *cras_bt_device_object_path(const struct cras_bt_device *device);
+
+/* Gets the stable id of given cras_bt_device. */
+int cras_bt_device_get_stable_id(const struct cras_bt_device *device);
+
struct cras_bt_adapter *
cras_bt_device_adapter(const struct cras_bt_device *device);
const char *cras_bt_device_address(const struct cras_bt_device *device);
diff --git a/cras/src/server/cras_bt_io.c b/cras/src/server/cras_bt_io.c
index 9f5c2f79..acdca809 100644
--- a/cras/src/server/cras_bt_io.c
+++ b/cras/src/server/cras_bt_io.c
@@ -527,10 +527,7 @@ struct cras_iodev *cras_bt_io_create(struct cras_bt_device *device,
active->base.idx = btio->next_node_id++;
active->base.type = dev->active_node->type;
active->base.volume = 100;
- active->base.stable_id =
- SuperFastHash(cras_bt_device_object_path(device),
- strlen(cras_bt_device_object_path(device)),
- strlen(cras_bt_device_object_path(device)));
+ active->base.stable_id = cras_bt_device_get_stable_id(device);
active->base.ui_gain_scaler = 1.0f;
/*
* If the same headset is connected in wideband mode, we shall assign
diff --git a/cras/src/server/cras_hfp_alsa_iodev.c b/cras/src/server/cras_hfp_alsa_iodev.c
index 6e40776a..c1b60b30 100644
--- a/cras/src/server/cras_hfp_alsa_iodev.c
+++ b/cras/src/server/cras_hfp_alsa_iodev.c
@@ -12,7 +12,6 @@
#include "cras_iodev.h"
#include "cras_system_state.h"
#include "cras_util.h"
-#include "sfh.h"
#include "utlist.h"
#include "cras_bt_device.h"
@@ -261,10 +260,7 @@ struct cras_iodev *hfp_alsa_iodev_create(struct cras_iodev *aio,
name = cras_bt_device_object_path(device);
snprintf(iodev->info.name, sizeof(iodev->info.name), "%s", name);
iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = 0;
- iodev->info.stable_id =
- SuperFastHash(cras_bt_device_object_path(device),
- strlen(cras_bt_device_object_path(device)),
- strlen(cras_bt_device_object_path(device)));
+ iodev->info.stable_id = cras_bt_device_get_stable_id(device);
iodev->open_dev = hfp_alsa_open_dev;
iodev->update_supported_formats = hfp_alsa_update_supported_formats;
diff --git a/cras/src/server/cras_hfp_iodev.c b/cras/src/server/cras_hfp_iodev.c
index 0c184c3a..6a4ced04 100644
--- a/cras/src/server/cras_hfp_iodev.c
+++ b/cras/src/server/cras_hfp_iodev.c
@@ -17,7 +17,6 @@
#include "cras_iodev.h"
#include "cras_system_state.h"
#include "cras_util.h"
-#include "sfh.h"
#include "utlist.h"
/* Implementation of bluetooth hands-free profile iodev.
@@ -309,10 +308,7 @@ struct cras_iodev *hfp_iodev_create(enum CRAS_STREAM_DIRECTION dir,
snprintf(iodev->info.name, sizeof(iodev->info.name), "%s", name);
iodev->info.name[ARRAY_SIZE(iodev->info.name) - 1] = 0;
- iodev->info.stable_id =
- SuperFastHash(cras_bt_device_object_path(device),
- strlen(cras_bt_device_object_path(device)),
- strlen(cras_bt_device_object_path(device)));
+ iodev->info.stable_id = cras_bt_device_get_stable_id(device);
iodev->configure_dev = configure_dev;
iodev->frames_queued = frames_queued;
diff --git a/cras/src/tests/a2dp_iodev_unittest.cc b/cras/src/tests/a2dp_iodev_unittest.cc
index 523a62e4..06c1cd3c 100644
--- a/cras/src/tests/a2dp_iodev_unittest.cc
+++ b/cras/src/tests/a2dp_iodev_unittest.cc
@@ -803,6 +803,10 @@ const char* cras_bt_device_object_path(const struct cras_bt_device* device) {
return "/org/bluez/hci0/dev_1A_2B_3C_4D_5E_6F";
}
+int cras_bt_device_get_stable_id(const struct cras_bt_device* device) {
+ return 123;
+}
+
void cras_bt_device_append_iodev(struct cras_bt_device* device,
struct cras_iodev* iodev,
enum cras_bt_device_profile profile) {
diff --git a/cras/src/tests/bt_io_unittest.cc b/cras/src/tests/bt_io_unittest.cc
index ee013cf3..dd02652f 100644
--- a/cras/src/tests/bt_io_unittest.cc
+++ b/cras/src/tests/bt_io_unittest.cc
@@ -458,6 +458,10 @@ const char* cras_bt_device_object_path(const struct cras_bt_device* device) {
return "/fake/object/path";
}
+int cras_bt_device_get_stable_id(const struct cras_bt_device* device) {
+ return 123;
+}
+
int cras_bt_device_get_use_hardware_volume(struct cras_bt_device* device) {
return 1;
}
diff --git a/cras/src/tests/hfp_alsa_iodev_unittest.cc b/cras/src/tests/hfp_alsa_iodev_unittest.cc
index 2f2825b8..8756c201 100644
--- a/cras/src/tests/hfp_alsa_iodev_unittest.cc
+++ b/cras/src/tests/hfp_alsa_iodev_unittest.cc
@@ -507,6 +507,10 @@ const char* cras_bt_device_object_path(const struct cras_bt_device* device) {
return "/fake/object/path";
}
+int cras_bt_device_get_stable_id(const struct cras_bt_device* device) {
+ return 123;
+}
+
void cras_iodev_free_resources(struct cras_iodev* iodev) {
cras_iodev_free_resources_called++;
}
diff --git a/cras/src/tests/hfp_iodev_unittest.cc b/cras/src/tests/hfp_iodev_unittest.cc
index 18262bf9..1275ef2c 100644
--- a/cras/src/tests/hfp_iodev_unittest.cc
+++ b/cras/src/tests/hfp_iodev_unittest.cc
@@ -285,6 +285,10 @@ const char* cras_bt_device_object_path(const struct cras_bt_device* device) {
return "/fake/object/path";
}
+int cras_bt_device_get_stable_id(const struct cras_bt_device* device) {
+ return 123;
+}
+
// From cras_hfp_info
int hfp_info_add_iodev(struct hfp_info* info,
enum CRAS_STREAM_DIRECTION direction,
diff --git a/cras/src/tools/cras_test_client/cras_test_client.c b/cras/src/tools/cras_test_client/cras_test_client.c
index 5a7b3e06..7a851852 100644
--- a/cras/src/tools/cras_test_client/cras_test_client.c
+++ b/cras/src/tools/cras_test_client/cras_test_client.c
@@ -1017,10 +1017,13 @@ static void show_btlog_tag(const struct cras_bt_event_log *log,
printf("%-30s dir %u codec id %u\n", "CODEC_SELECTION", data1,
data2);
break;
- case BT_DEV_CONNECTED_CHANGE:
- printf("%-30s supported profiles 0x%.2x now %s\n",
- "DEV_CONNECTED_CHANGE", data1,
- data2 ? "connected" : "disconnected");
+ case BT_DEV_CONNECTED:
+ printf("%-30s supported profiles 0x%.2x stable_id 0x%08x\n",
+ "DEV_CONNECTED", data1, data2);
+ break;
+ case BT_DEV_DISCONNECTED:
+ printf("%-30s supported profiles 0x%.2x stable_id 0x%08x\n",
+ "DEV_DISCONNECTED", data1, data2);
break;
case BT_DEV_CONN_WATCH_CB:
printf("%-30s %u retries left, supported profiles 0x%.2x\n",