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

Commit 8745112c authored by Sal Savage's avatar Sal Savage
Browse files

Properly update config when the MAC Address changes

The existing code has two issues:
- We pass a 0 size value for the buffer we intend to contain the value
we're getting. This causes btif_config_get_str to always return
positively but never write a value because its usage of srtlcpy doesn't
think it has space to write.
- We check to see if the address in the config is the same as the one
received from the controller using (strcmp(...) == 0). However, strcmp
returns 0 if they are the same. It will be a non-zero value if they are
different.

Following this change, the bt_config.conf file should have the correct
value for the MAC Address in the case the controller interface starts
reporting something new.

Bug: 169686820
Test: setprop persist.vendor.service.bdroid.bdaddr <something new>; cat
/data/misc/bluedroid/bt_config.conf | grep Address;

Change-Id: I6cdb70776fef689426baf58be0ccaf4abe9c9023
parent 4407ac75
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -451,6 +451,25 @@ bool btif_config_set_uint64(const std::string& section, const std::string& key,
  return true;
}

/*******************************************************************************
 *
 * Function         btif_config_get_str
 *
 * Description      Get the string value associated with a particular section
 *                  and key.
 *
 *                  section : The section name (i.e "Adapter")
 *                  key : The key name (i.e "Address")
 *                  value : A pointer to a buffer where we will store the value
 *                  size_bytes : The size of the buffer we have available to
 *                               write the value into. Will be updated upon
 *                               returning to contain the number of bytes
 *                               written.
 *
 * Returns          True if a value was found, False otherwise.
 *
 ******************************************************************************/

bool btif_config_get_str(const std::string& section, const std::string& key,
                         char* value, int* size_bytes) {
  if (bluetooth::shim::is_any_gd_enabled()) {
+6 −4
Original line number Diff line number Diff line
@@ -260,10 +260,12 @@ void btif_enable_bluetooth_evt() {
  std::string bdstr = local_bd_addr.ToString();

  char val[PROPERTY_VALUE_MAX] = "";
  int val_size = 0;
  if ((btif_config_get_str("Adapter", "Address", val, &val_size) == 0) ||
      strcmp(bdstr.c_str(), val) == 0) {
    LOG_DEBUG("Storing the adapter address into the config file");
  int val_size = PROPERTY_VALUE_MAX;
  if (!btif_config_get_str("Adapter", "Address", val, &val_size) ||
      strcmp(bdstr.c_str(), val) != 0) {
    // We failed to get an address or the one in the config file does not match
    // the address given by the controller interface. Update the config cache
    LOG_DEBUG("%s: Storing '%s' into the config file", __func__, bdstr.c_str());
    btif_config_set_str("Adapter", "Address", bdstr.c_str());
    btif_config_save();