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

Commit 33a3081a authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Android Build Coastguard Worker
Browse files

Send preferred MTU from GattService to native GATT module

Adding infrastructure to allow GattService to send application preferred ATT MTU to the native GATT module.

Bug: 369329192
Test: mmm packages/modules/Bluetooth
Flag: EXEMPT manual refactor
(cherry picked from https://android-review.googlesource.com/q/commit:7613d0c38945dac318def1372ecf2dc725513d8d)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9f43bf6dbfab222474e1d467f0866b55309f9dd6)
Merged-In: Icdb3eecca5adb18bbac12d2883b37ea4432e32b3
Change-Id: Icdb3eecca5adb18bbac12d2883b37ea4432e32b3
parent 6c3e7860
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1384,13 +1384,14 @@ static void gattClientScanNative(JNIEnv* /* env */, jobject /* object */, jboole

static void gattClientConnectNative(JNIEnv* env, jobject /* object */, jint clientif,
                                    jstring address, jint addressType, jboolean isDirect,
                                    jint transport, jboolean opportunistic, jint initiating_phys) {
                                    jint transport, jboolean opportunistic, jint initiating_phys,
                                    jint preferred_mtu) {
  if (!sGattIf) {
    return;
  }

  sGattIf->client->connect(clientif, str2addr(env, address), addressType, isDirect, transport,
                           opportunistic, initiating_phys);
                           opportunistic, initiating_phys, preferred_mtu);
}

static void gattClientDisconnectNative(JNIEnv* env, jobject /* object */, jint clientIf,
@@ -2839,7 +2840,7 @@ static int register_com_android_bluetooth_gatt_(JNIEnv* env) {
           (void*)gattClientGetDeviceTypeNative},
          {"gattClientRegisterAppNative", "(JJZ)V", (void*)gattClientRegisterAppNative},
          {"gattClientUnregisterAppNative", "(I)V", (void*)gattClientUnregisterAppNative},
          {"gattClientConnectNative", "(ILjava/lang/String;IZIZI)V",
          {"gattClientConnectNative", "(ILjava/lang/String;IZIZII)V",
           (void*)gattClientConnectNative},
          {"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
           (void*)gattClientDisconnectNative},
+12 −3
Original line number Diff line number Diff line
@@ -293,7 +293,8 @@ public class GattNativeInterface {
            boolean isDirect,
            int transport,
            boolean opportunistic,
            int initiatingPhys);
            int initiatingPhys,
            int preferredMtu);

    private native void gattClientDisconnectNative(int clientIf, String address, int connId);

@@ -447,9 +448,17 @@ public class GattNativeInterface {
            boolean isDirect,
            int transport,
            boolean opportunistic,
            int initiatingPhys) {
            int initiatingPhys,
            int preferredMtu) {
        gattClientConnectNative(
                clientIf, address, addressType, isDirect, transport, opportunistic, initiatingPhys);
                clientIf,
                address,
                addressType,
                isDirect,
                transport,
                opportunistic,
                initiatingPhys,
                preferredMtu);
    }

    /** Disconnect from the remote Gatt server */
+3 −1
Original line number Diff line number Diff line
@@ -2139,8 +2139,10 @@ public class GattService extends ProfileService {
                clientIf,
                BluetoothProtoEnums.CONNECTION_STATE_CONNECTING,
                -1);

        int preferredMtu = 0;
        mNativeInterface.gattClientConnect(
                clientIf, address, addressType, isDirect, transport, opportunistic, phy);
                clientIf, address, addressType, isDirect, transport, opportunistic, phy, preferredMtu);
    }

    @RequiresPermission(BLUETOOTH_CONNECT)
+1 −1
Original line number Diff line number Diff line
@@ -265,7 +265,7 @@ public class GattServiceTest {

        verify(mNativeInterface)
                .gattClientConnect(
                        clientIf, address, addressType, isDirect, transport, opportunistic, phy);
                        clientIf, address, addressType, isDirect, transport, opportunistic, phy, 0);
    }

    @Test
+7 −5
Original line number Diff line number Diff line
@@ -108,7 +108,8 @@ struct gatt_interface_t {
  void (*BTA_GATTC_Close)(tCONN_ID conn_id);
  void (*BTA_GATTC_ServiceSearchRequest)(tCONN_ID conn_id, const bluetooth::Uuid* p_srvc_uuid);
  void (*BTA_GATTC_Open)(tGATT_IF client_if, const RawAddress& remote_bda,
                         tBTM_BLE_CONN_TYPE connection_type, bool opportunistic);
                         tBTM_BLE_CONN_TYPE connection_type, bool opportunistic,
                         uint16_t preferred_mtu);
} default_gatt_interface = {
        .BTA_GATTC_CancelOpen =
                [](tGATT_IF client_if, const RawAddress& remote_bda, bool is_direct) {
@@ -135,8 +136,9 @@ struct gatt_interface_t {
                },
        .BTA_GATTC_Open =
                [](tGATT_IF client_if, const RawAddress& remote_bda,
                   tBTM_BLE_CONN_TYPE connection_type, bool opportunistic) {
                  BTA_GATTC_Open(client_if, remote_bda, connection_type, opportunistic);
                   tBTM_BLE_CONN_TYPE connection_type, bool opportunistic, uint16_t preferred_mtu) {
                  BTA_GATTC_Open(client_if, remote_bda, BLE_ADDR_PUBLIC, connection_type,
                                 BT_TRANSPORT_LE, opportunistic, 1, preferred_mtu);
                },
};

@@ -602,14 +604,14 @@ static void btm_dm_start_gatt_discovery(const RawAddress& bd_addr) {
              "transport:{} opportunistic:{:c}",
              bd_addr, bt_transport_text(BT_TRANSPORT_LE), (kUseOpportunistic) ? 'T' : 'F');
      get_gatt_interface().BTA_GATTC_Open(bta_dm_discovery_cb.client_if, bd_addr,
                                          BTM_BLE_DIRECT_CONNECTION, kUseOpportunistic);
                                          BTM_BLE_DIRECT_CONNECTION, kUseOpportunistic, 0);
    } else {
      log::debug(
              "Opening new gatt client connection for discovery peer:{} "
              "transport:{} opportunistic:{:c}",
              bd_addr, bt_transport_text(BT_TRANSPORT_LE), (!kUseOpportunistic) ? 'T' : 'F');
      get_gatt_interface().BTA_GATTC_Open(bta_dm_discovery_cb.client_if, bd_addr,
                                          BTM_BLE_DIRECT_CONNECTION, !kUseOpportunistic);
                                          BTM_BLE_DIRECT_CONNECTION, !kUseOpportunistic, 0);
    }
  }
}
Loading