Clean up BTM_SetBleDataLength

Test: cert/run
Tag: #gd-refactor
Bug: 141555841
Change-Id: I217fd560afbda434e8bab7effc3716cfcd18a7c2
diff --git a/system/stack/btm/btm_ble.cc b/system/stack/btm/btm_ble.cc
index 07e6b97..4be41ed 100644
--- a/system/stack/btm/btm_ble.cc
+++ b/system/stack/btm/btm_ble.cc
@@ -649,37 +649,39 @@
 
 tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr,
                                  uint16_t tx_pdu_length) {
-  if (bluetooth::shim::is_gd_shim_enabled()) {
-    return bluetooth::shim::BTM_SetBleDataLength(bd_addr, tx_pdu_length);
-  }
-  uint16_t tx_time = BTM_BLE_DATA_TX_TIME_MAX_LEGACY;
-
-  if (!BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
-    LOG_INFO(
-        "Unable to set data length because no le acl link connected to device");
-    return BTM_WRONG_MODE;
-  }
-
   if (!controller_get_interface()->supports_ble_packet_extension()) {
     LOG_INFO("Local controller unable to support le packet extension");
     return BTM_ILLEGAL_VALUE;
   }
 
-  uint16_t hci_handle = acl_get_hci_handle_for_hcif(bd_addr, BT_TRANSPORT_LE);
-
-  if (!acl_peer_supports_ble_packet_extension(hci_handle)) {
-    LOG_INFO("Remote device unable to support le packet extension");
-    return BTM_ILLEGAL_VALUE;
-  }
-
   if (tx_pdu_length > BTM_BLE_DATA_SIZE_MAX)
     tx_pdu_length = BTM_BLE_DATA_SIZE_MAX;
   else if (tx_pdu_length < BTM_BLE_DATA_SIZE_MIN)
     tx_pdu_length = BTM_BLE_DATA_SIZE_MIN;
 
-  if (controller_get_interface()->get_bt_version()->hci_version >= HCI_PROTO_VERSION_5_0)
+  uint16_t tx_time = BTM_BLE_DATA_TX_TIME_MAX_LEGACY;
+
+  if (controller_get_interface()->get_bt_version()->hci_version >=
+      HCI_PROTO_VERSION_5_0)
     tx_time = BTM_BLE_DATA_TX_TIME_MAX;
 
+  if (bluetooth::shim::is_gd_shim_enabled()) {
+    return bluetooth::shim::BTM_SetBleDataLength(bd_addr, tx_pdu_length);
+  }
+
+  if (!BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
+    LOG_INFO(
+        "Unable to set data length because no le acl link connected to device");
+    return BTM_WRONG_MODE;
+  }
+
+  uint16_t hci_handle = acl_get_hci_handle_for_hcif(bd_addr, BT_TRANSPORT_LE);
+
+  if (!acl_peer_supports_ble_packet_extension(hci_handle)) {
+    LOG_INFO("Remote device unable to support le packet extension");
+    return BTM_ILLEGAL_VALUE;
+  }
+
   btsnd_hcic_ble_set_data_length(hci_handle, tx_pdu_length, tx_time);
 
   return BTM_SUCCESS;