diff options
author | Myles Watson <mylesgw@google.com> | 2018-01-08 16:49:13 -0800 |
---|---|---|
committer | Myles Watson <mylesgw@google.com> | 2018-01-09 23:54:05 +0000 |
commit | 0d63f8af7c87597f103718751d3cb84a8fb35792 (patch) | |
tree | 1c4c208d1942ef78fd8869b892266ad0b8330dc3 /bluetooth | |
parent | 424ffd0da56d818510000acd56b23824c960d7d7 (diff) | |
download | platform_hardware_interfaces-0d63f8af7c87597f103718751d3cb84a8fb35792.tar.gz platform_hardware_interfaces-0d63f8af7c87597f103718751d3cb84a8fb35792.tar.bz2 platform_hardware_interfaces-0d63f8af7c87597f103718751d3cb84a8fb35792.zip |
Bluetooth: Sleep instead of dying on EOF
When a device is restarted, the UART may go away before the
packetizer. Print an error and sleep in case it isn't really
a restart.
Bug: 70855323
Test: Repeated restarts, check for Bluetooth tombstones
Change-Id: I2b4e677451e826d40dcc9d063d80dc0e17fc9aca
Diffstat (limited to 'bluetooth')
-rw-r--r-- | bluetooth/1.0/default/h4_protocol.cc | 6 | ||||
-rw-r--r-- | bluetooth/1.0/default/hci_packetizer.cc | 21 |
2 files changed, 18 insertions, 9 deletions
diff --git a/bluetooth/1.0/default/h4_protocol.cc b/bluetooth/1.0/default/h4_protocol.cc index 163cc333c4..df4050771f 100644 --- a/bluetooth/1.0/default/h4_protocol.cc +++ b/bluetooth/1.0/default/h4_protocol.cc @@ -71,8 +71,10 @@ void H4Protocol::OnDataReady(int fd) { ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, 1)); if (bytes_read != 1) { if (bytes_read == 0) { - LOG_ALWAYS_FATAL("%s: Unexpected EOF reading the packet type!", - __func__); + // This is only expected if the UART got closed when shutting down. + ALOGE("%s: Unexpected EOF reading the packet type!", __func__); + sleep(5); // Expect to be shut down within 5 seconds. + return; } else if (bytes_read < 0) { LOG_ALWAYS_FATAL("%s: Read packet type error: %s", __func__, strerror(errno)); diff --git a/bluetooth/1.0/default/hci_packetizer.cc b/bluetooth/1.0/default/hci_packetizer.cc index fde08ac1cb..71f43284b1 100644 --- a/bluetooth/1.0/default/hci_packetizer.cc +++ b/bluetooth/1.0/default/hci_packetizer.cc @@ -56,9 +56,13 @@ void HciPacketizer::OnDataReady(int fd, HciPacketType packet_type) { ssize_t bytes_read = TEMP_FAILURE_RETRY( read(fd, preamble_ + bytes_read_, preamble_size_for_type[packet_type] - bytes_read_)); - if (bytes_read <= 0) { - LOG_ALWAYS_FATAL_IF((bytes_read == 0), - "%s: Unexpected EOF reading the header!", __func__); + if (bytes_read == 0) { + // This is only expected if the UART got closed when shutting down. + ALOGE("%s: Unexpected EOF reading the header!", __func__); + sleep(5); // Expect to be shut down within 5 seconds. + return; + } + if (bytes_read < 0) { LOG_ALWAYS_FATAL("%s: Read header error: %s", __func__, strerror(errno)); } @@ -80,10 +84,13 @@ void HciPacketizer::OnDataReady(int fd, HciPacketType packet_type) { fd, packet_.data() + preamble_size_for_type[packet_type] + bytes_read_, bytes_remaining_)); - if (bytes_read <= 0) { - LOG_ALWAYS_FATAL_IF((bytes_read == 0), - "%s: Unexpected EOF reading the payload!", - __func__); + if (bytes_read == 0) { + // This is only expected if the UART got closed when shutting down. + ALOGE("%s: Unexpected EOF reading the payload!", __func__); + sleep(5); // Expect to be shut down within 5 seconds. + return; + } + if (bytes_read < 0) { LOG_ALWAYS_FATAL("%s: Read payload error: %s", __func__, strerror(errno)); } |