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

Commit fdae953a authored by Martin Brabham's avatar Martin Brabham
Browse files

Integers are not a reliable method to determine if value set

Bug: 236738437
Test: system/gd/cert/run --clean --sl4a OobPairingSl4aTest
Test: system/gd/cert/run --clean --sl4a_sl4a OobPairingTest
Tag: #refactor
Ignore-AOSP-First: Need in tm-dev stat and can't put it in AOSP yet
Change-Id: Id782d06ae6c0adaf01e07eacee524049e7ad1db7
parent d49c7291
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -2568,11 +2568,13 @@ void btif_dm_load_local_oob(void) {
}

static bool waiting_on_oob_advertiser_start = false;
static uint8_t oob_advertiser_id = 0;
static std::unique_ptr<uint8_t> oob_advertiser_id_;
static void stop_oob_advertiser() {
  // For chasing an advertising bug b/237023051
  LOG_DEBUG("oob_advertiser_id: %s", oob_advertiser_id_.get());
  auto advertiser = get_ble_advertiser_instance();
  advertiser->Unregister(oob_advertiser_id);
  oob_advertiser_id = 0;
  advertiser->Unregister(*oob_advertiser_id_);
  oob_advertiser_id_ = nullptr;
}

/*******************************************************************************
@@ -2593,7 +2595,9 @@ void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport) {
    // the state machine lifecycle.  Rather, lets create the data, then start
    // advertising then request the address.
    if (!waiting_on_oob_advertiser_start) {
      if (oob_advertiser_id != 0) {
      // For chasing an advertising bug b/237023051
      LOG_DEBUG("oob_advertiser_id: %s", oob_advertiser_id_.get());
      if (oob_advertiser_id_ != nullptr) {
        stop_oob_advertiser();
      }
      waiting_on_oob_advertiser_start = true;
@@ -2622,7 +2626,7 @@ static void start_advertising_callback(uint8_t id, tBT_TRANSPORT transport,
    invoke_oob_data_request_cb(transport, false, c, r, RawAddress{}, 0x00);
    SMP_ClearLocScOobData();
    waiting_on_oob_advertiser_start = false;
    oob_advertiser_id = 0;
    oob_advertiser_id_ = nullptr;
    return;
  }
  LOG_DEBUG("OOB advertiser with id %hhd", id);
@@ -2638,7 +2642,7 @@ static void timeout_cb(uint8_t id, tBTM_STATUS status) {
  advertiser->Unregister(id);
  SMP_ClearLocScOobData();
  waiting_on_oob_advertiser_start = false;
  oob_advertiser_id = 0;
  oob_advertiser_id_ = nullptr;
}

// Step Two: CallBack from Step One, advertise and get address
@@ -2650,11 +2654,12 @@ static void id_status_callback(tBT_TRANSPORT transport, bool is_valid,
    invoke_oob_data_request_cb(transport, false, c, r, RawAddress{}, 0x00);
    SMP_ClearLocScOobData();
    waiting_on_oob_advertiser_start = false;
    oob_advertiser_id = 0;
    oob_advertiser_id_ = nullptr;
    return;
  }

  oob_advertiser_id = id;
  oob_advertiser_id_ = std::make_unique<uint8_t>(id);
  LOG_ERROR("oob_advertiser_id: %s", oob_advertiser_id_.get());

  auto advertiser = get_ble_advertiser_instance();
  AdvertiseParameters parameters;
@@ -2674,7 +2679,7 @@ static void id_status_callback(tBT_TRANSPORT transport, bool is_valid,
  advertiser->StartAdvertising(
      id,
      base::Bind(&start_advertising_callback, id, transport, is_valid, c, r),
      parameters, advertisement, scan_data, 3600 /* timeout_s */,
      parameters, advertisement, scan_data, 120 /* timeout_s */,
      base::Bind(&timeout_cb, id));
}

@@ -2910,6 +2915,7 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
    bond_state_changed(status, bd_addr, BT_BOND_STATE_BONDING);
  }
  bond_state_changed(status, bd_addr, state);
  // TODO(240451061): Calling `stop_oob_advertiser();` gets command disallowed...
}

void btif_dm_load_ble_local_keys(void) {