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

Commit 60e7ee15 authored by Jack He's avatar Jack He
Browse files

GD: Read LE supported features and states before sending cmds

* Check if BLE privacy is supported before trying to read
  resolving list size
* Check if BLE packet extension is supported before
  reading max data length and suggested default data length
* Check if BLE extended advertising is supported before reading
  maximum advertising data length and number of supported
  advertising sets
* Check if BLE periodic advertising is supported before reading periodic
  advertising list size

Bug: 189123400
Test: DeviceBootTest
Tag: #gd-refactor
Change-Id: I6f1b2d036926205dedbd6b866302378053d422a2
parent b6d2c5d2
Loading
Loading
Loading
Loading
+28 −12
Original line number Diff line number Diff line
@@ -57,6 +57,14 @@ struct Controller::impl {
    hci_->EnqueueCommand(ReadLocalSupportedCommandsBuilder::Create(),
                         handler->BindOnceOn(this, &Controller::impl::read_local_supported_commands_complete_handler));

    hci_->EnqueueCommand(
        LeReadLocalSupportedFeaturesBuilder::Create(),
        handler->BindOnceOn(this, &Controller::impl::le_read_local_supported_features_handler));

    hci_->EnqueueCommand(
        LeReadSupportedStatesBuilder::Create(),
        handler->BindOnceOn(this, &Controller::impl::le_read_supported_states_handler));

    // Wait for all extended features read
    std::promise<void> features_promise;
    auto features_future = features_promise.get_future();
@@ -78,17 +86,11 @@ struct Controller::impl {
          handler->BindOnceOn(this, &Controller::impl::le_read_buffer_size_handler));
    }

    hci_->EnqueueCommand(LeReadLocalSupportedFeaturesBuilder::Create(),
                         handler->BindOnceOn(this, &Controller::impl::le_read_local_supported_features_handler));

    hci_->EnqueueCommand(LeReadSupportedStatesBuilder::Create(),
                         handler->BindOnceOn(this, &Controller::impl::le_read_supported_states_handler));

    hci_->EnqueueCommand(
        LeReadConnectListSizeBuilder::Create(),
        handler->BindOnceOn(this, &Controller::impl::le_read_connect_list_size_handler));

    if (is_supported(OpCode::LE_READ_RESOLVING_LIST_SIZE)) {
    if (is_supported(OpCode::LE_READ_RESOLVING_LIST_SIZE) && module_.SupportsBlePrivacy()) {
      hci_->EnqueueCommand(
          LeReadResolvingListSizeBuilder::Create(),
          handler->BindOnceOn(this, &Controller::impl::le_read_resolving_list_size_handler));
@@ -97,38 +99,52 @@ struct Controller::impl {
      le_resolving_list_size_ = 0;
    }

    if (is_supported(OpCode::LE_READ_MAXIMUM_DATA_LENGTH)) {
    if (is_supported(OpCode::LE_READ_MAXIMUM_DATA_LENGTH) && module_.SupportsBlePacketExtension()) {
      hci_->EnqueueCommand(LeReadMaximumDataLengthBuilder::Create(),
                           handler->BindOnceOn(this, &Controller::impl::le_read_maximum_data_length_handler));
    } else {
      LOG_INFO("LE_READ_MAXIMUM_DATA_LENGTH not supported, defaulting to 0");
      le_maximum_data_length_.supported_max_rx_octets_ = 0;
      le_maximum_data_length_.supported_max_rx_time_ = 0;
      le_maximum_data_length_.supported_max_tx_octets_ = 0;
      le_maximum_data_length_.supported_max_tx_time_ = 0;
    }
    if (is_supported(OpCode::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH)) {

    if (is_supported(OpCode::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH) && module_.SupportsBlePacketExtension()) {
      hci_->EnqueueCommand(
          LeReadSuggestedDefaultDataLengthBuilder::Create(),
          handler->BindOnceOn(this, &Controller::impl::le_read_suggested_default_data_length_handler));
    } else {
      LOG_INFO("LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH not supported, defaulting to 27 (0x1B)");
      le_suggested_default_data_length_ = 27;
    }
    if (is_supported(OpCode::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH)) {

    if (is_supported(OpCode::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH) && module_.SupportsBleExtendedAdvertising()) {
      hci_->EnqueueCommand(
          LeReadMaximumAdvertisingDataLengthBuilder::Create(),
          handler->BindOnceOn(this, &Controller::impl::le_read_maximum_advertising_data_length_handler));
    } else {
      LOG_INFO("LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH not supported, defaulting to 31 (0x1F)");
      le_maximum_advertising_data_length_ = 31;
    }
    if (is_supported(OpCode::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS)) {

    if (is_supported(OpCode::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS) &&
        module_.SupportsBleExtendedAdvertising()) {
      hci_->EnqueueCommand(
          LeReadNumberOfSupportedAdvertisingSetsBuilder::Create(),
          handler->BindOnceOn(this, &Controller::impl::le_read_number_of_supported_advertising_sets_handler));
    } else {
      LOG_INFO("LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS not supported, defaulting to 1");
      le_number_supported_advertising_sets_ = 1;
    }
    if (is_supported(OpCode::LE_READ_PERIODIC_ADVERTISING_LIST_SIZE)) {

    if (is_supported(OpCode::LE_READ_PERIODIC_ADVERTISING_LIST_SIZE) && module_.SupportsBlePeriodicAdvertising()) {
      hci_->EnqueueCommand(
          LeReadPeriodicAdvertiserListSizeBuilder::Create(),
          handler->BindOnceOn(this, &Controller::impl::le_read_periodic_advertiser_list_size_handler));
    } else {
      LOG_INFO("LE_READ_PERIODIC_ADVERTISING_LIST_SIZE not supported, defaulting to 0");
      le_periodic_advertiser_list_size_ = 0;
    }

    hci_->EnqueueCommand(LeGetVendorCapabilitiesBuilder::Create(),
+10 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "module.h"
#include "os/handler.h"
#include "os/log.h"
#include "os/system_properties.h"

namespace bluetooth {
namespace hci {
@@ -116,11 +117,17 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
      advertising_api_type_ = AdvertisingApiType::ANDROID_HCI;
    } else {
      advertising_api_type_ = AdvertisingApiType::LEGACY;
      int vendor_version = os::GetAndroidVendorReleaseVersion();
      if (vendor_version != 0 && vendor_version <= 11 && os::IsRootCanalEnabled()) {
        LOG_INFO("LeReadAdvertisingPhysicalChannelTxPower is not supported on Android R RootCanal, default to 0");
        le_physical_channel_tx_power_ = 0;
      } else {
        hci_layer_->EnqueueCommand(
            LeReadAdvertisingPhysicalChannelTxPowerBuilder::Create(),
            handler->BindOnceOn(this, &impl::on_read_advertising_physical_channel_tx_power));
      }
    }
  }

  size_t GetNumberOfAdvertisingInstances() const {
    return num_instances_;
+53 −0
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@
#include <cutils/properties.h>

#include <array>
#include <cctype>

#include "common/strings.h"
#include "os/log.h"

namespace bluetooth {
@@ -47,5 +49,56 @@ bool SetSystemProperty(const std::string& property, const std::string& value) {
  return true;
}

bool IsRootCanalEnabled() {
  auto value = GetSystemProperty("ro.vendor.build.fingerprint");
  if (value.has_value()) {
    LOG_INFO("ro.vendor.build.fingerprint='%s', length=%zu", value->c_str(), value->length());
  } else {
    LOG_INFO("ro.vendor.build.fingerprint is not found");
  }
  // aosp_cf_x86_64_phone is just one platform that currently runs root canal
  // When other platforms appears, or there is a better signal, add them here
  if (value->find("generic/aosp_cf_x86_64_phone") == std::string::npos) {
    LOG_INFO("Not on generic/aosp_cf_x86_64_phone and hence not root canal");
    return false;
  }
  return true;
}

int GetAndroidVendorReleaseVersion() {
  auto value = GetSystemProperty("ro.vendor.build.version.release_or_codename");
  if (!value) {
    LOG_INFO("ro.vendor.build.version.release_or_codename does not exist");
    return 0;
  }
  LOG_INFO("ro.vendor.build.version.release_or_codename='%s', length=%zu", value->c_str(), value->length());
  auto int_value = common::Int64FromString(*value);
  if (int_value) {
    return static_cast<int>(*int_value);
  }
  LOG_INFO("value '%s' cannot be parsed to int", value->c_str());
  if (value->empty()) {
    LOG_INFO("value '%s' is empty", value->c_str());
    return 0;
  }
  if (value->length() > 1) {
    LOG_INFO("value '%s' length is %zu, which is > 1", value->c_str(), value->length());
  }
  char release_code = toupper(value->at(0));
  switch (release_code) {
    case 'S':
      return 11;
    case 'R':
      return 10;
    case 'P':
      return 9;
    case 'O':
      return 8;
    default:
      // Treble not enabled before Android O
      return 0;
  }
}

}  // namespace os
}  // namespace bluetooth
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -48,5 +48,13 @@ void ClearSystemPropertiesForHost() {
  properties.clear();
}

bool IsRootCanalEnabled() {
  return false;
}

int GetAndroidVendorReleaseVersion() {
  return 0;
}

}  // namespace os
}  // namespace bluetooth
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -48,5 +48,13 @@ void ClearSystemPropertiesForHost() {
  properties.clear();
}

bool IsRootCanalEnabled() {
  return false;
}

int GetAndroidVendorReleaseVersion() {
  return 0;
}

}  // namespace os
}  // namespace bluetooth
 No newline at end of file
Loading