Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39d02130 authored by Bhakthavatsala Raghavendra's avatar Bhakthavatsala Raghavendra
Browse files

Do not push disconnect error code when socket is connected state

App error codes are mainly to send exceptions to applications when socket connection fails. Stack don't need to push these error codes when socket is already connected and l2cap connection is removed from remote.

Test: mmm packages/modules/Bluetooth
Test: Tested manually to ensure no unexpected data on socket read after disconnect
Flag: com.android.bluetooth.flags.donot_push_error_code_to_app_when_connected
Bug: 359992434
Bug: 365844219

Change-Id: I5a026fd01a998df74eea8b1700ed79bad45a9f29
parent 3f1c9a78
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <com_android_bluetooth_flags.h>

#include <cstdint>
#include <cstring>
@@ -646,10 +647,19 @@ static void on_l2cap_close(tBTA_JV_L2CAP_CLOSE* p_close, uint32_t id) {
                              SOCKET_CONNECTION_STATE_DISCONNECTING,
                              sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION,
                              sock->app_uid, sock->channel, 0, 0, sock->name);

  if (com::android::bluetooth::flags::donot_push_error_code_to_app_when_connected()) {
    if (!sock->connected) {
      if (!send_app_err_code(sock, p_close->reason)) {
        log::error("Unable to send l2cap socket to application socket_id:{}", sock->id);
      }
    } else {
      log::info("Don't push error for already connected socket:{}", sock->id);
    }
  } else {
    if (!send_app_err_code(sock, p_close->reason)) {
      log::error("Unable to send l2cap socket to application socket_id:{}", sock->id);
    }
  }
  // TODO: This does not seem to be called...
  // I'm not sure if this will be called for non-server sockets?
  if (sock->server) {