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

Commit a4658dbd authored by Md Shahriar Hossain Sajib's avatar Md Shahriar Hossain Sajib Committed by Gerrit Code Review
Browse files

Merge changes from topic "api"

* changes:
  ble advertisement: permission check and pass own_address_type to native stack
  ble advertisement address type parameter
parents 1e56d510 fb57449e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1973,6 +1973,8 @@ static AdvertiseParameters parseParams(JNIEnv* env, jobject i) {
  uint32_t interval = env->CallIntMethod(i, methodId);
  methodId = env->GetMethodID(clazz, "getTxPowerLevel", "()I");
  int8_t txPowerLevel = env->CallIntMethod(i, methodId);
  methodId = env->GetMethodID(clazz, "getOwnAddressType", "()I");
  int8_t ownAddressType = env->CallIntMethod(i, methodId);

  uint16_t props = 0;
  if (isConnectable) props |= 0x01;
@@ -1993,6 +1995,7 @@ static AdvertiseParameters parseParams(JNIEnv* env, jobject i) {
  p.primary_advertising_phy = primaryPhy;
  p.secondary_advertising_phy = secondaryPhy;
  p.scan_request_notification_enable = false;
  p.own_address_type = ownAddressType;
  return p;
}

+3 −0
Original line number Diff line number Diff line
@@ -2583,6 +2583,9 @@ public class GattService extends ProfileService {
                this, attributionSource, "GattService startAdvertisingSet")) {
            return;
        }
        if (parameters.getOwnAddressType() != AdvertisingSetParameters.ADDRESS_TYPE_DEFAULT) {
            Utils.enforceBluetoothPrivilegedPermission(this);
        }
        mAdvertiseManager.startAdvertisingSet(parameters, advertiseData, scanResponse,
                periodicParameters, periodicData, duration, maxExtAdvEvents, callback);
    }
+1 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ void parseParams(tBTM_BLE_ADV_PARAMS* p_params,
  p_params->secondary_advertising_phy = params.secondary_advertising_phy;
  p_params->scan_request_notification_enable =
      params.scan_request_notification_enable;
  p_params->own_address_type = params.own_address_type;
}

void parsePeriodicParams(tBLE_PERIODIC_ADV_PARAMS* p_periodic_params,
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ struct AdvertiseParameters {
  uint8_t primary_advertising_phy;
  uint8_t secondary_advertising_phy;
  uint8_t scan_request_notification_enable;
  int8_t own_address_type;
};

struct PeriodicAdvertisingParameters {
+18 −4
Original line number Diff line number Diff line
@@ -241,15 +241,23 @@ class BleAdvertisingManagerImpl
  void RegisterAdvertiser(
      base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)> cb)
      override {
    int own_address_type =
        BTM_BleLocalPrivacyEnabled() ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC;
    RegisterAdvertiserImpl(own_address_type, cb);
  }

  void RegisterAdvertiserImpl(
      int own_address_type,
      base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)> cb) {
    AdvertisingInstance* p_inst = &adv_inst[0];
    for (uint8_t i = 0; i < inst_count; i++, p_inst++) {
      if (p_inst->in_use) continue;

      p_inst->in_use = true;
      p_inst->own_address_type = own_address_type;

      // set up periodic timer to update address.
      if (BTM_BleLocalPrivacyEnabled()) {
        p_inst->own_address_type = BLE_ADDR_RANDOM;
      if (own_address_type != BLE_ADDR_PUBLIC) {
        GenerateRpa(Bind(
            [](AdvertisingInstance* p_inst,
               base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)>
@@ -264,7 +272,6 @@ class BleAdvertisingManagerImpl
            },
            p_inst, cb));
      } else {
        p_inst->own_address_type = BLE_ADDR_PUBLIC;
        p_inst->own_address = *controller_get_interface()->get_address();

        cb.Run(p_inst->inst_id, BTM_BLE_MULTI_ADV_SUCCESS);
@@ -395,10 +402,16 @@ class BleAdvertisingManagerImpl
    c->maxExtAdvEvents = maxExtAdvEvents;
    c->timeout_cb = std::move(timeout_cb);

    int own_address_type =
        BTM_BleLocalPrivacyEnabled() ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC;
    if (params->own_address_type != BLE_ADDR_ANONYMOUS) {
      own_address_type = params->own_address_type;
    }

    // this code is intentionally left formatted this way to highlight the
    // asynchronous flow
    // clang-format off
    c->self->RegisterAdvertiser(Bind(
    c->self->RegisterAdvertiserImpl(own_address_type, Bind(
      [](c_type c, uint8_t advertiser_id, uint8_t status) {
        if (!c->self) {
          LOG(INFO) << "Stack was shut down";
@@ -1048,6 +1061,7 @@ void btm_ble_adv_init() {

  if (BleAdvertiserHciInterface::Get()->QuirkAdvertiserZeroHandle()) {
    // If handle 0 can't be used, register advertiser for it, but never use it.
    // TODO: avoid generating/rotating RPA for it
    BleAdvertisingManager::Get().get()->RegisterAdvertiser(base::DoNothing());
  }
}
Loading