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

Commit 0f9b45aa authored by Chris Manton's avatar Chris Manton Committed by android-build-merger
Browse files

Redirect osi/config interface based upon gd status

am: f979d618

Change-Id: I99eeea4e6188d0bd2da35cdc530f54e245b818da
parents 6550b99c f979d618
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -64,3 +64,39 @@ bool btif_get_address_type(const RawAddress& bd_addr, int* p_addr_type);
bool btif_get_device_type(const RawAddress& bd_addr, int* p_device_type);

void btif_debug_config_dump(int fd);

typedef struct {
  std::string (*checksum_read)(const char* filename);
  bool (*checksum_save)(const std::string& checksum,
                        const std::string& filename);
  bool (*config_get_bool)(const config_t& config, const std::string& section,
                          const std::string& key, bool def_value);
  int (*config_get_int)(const config_t& config, const std::string& section,
                        const std::string& key, int def_value);
  const std::string* (*config_get_string)(const config_t& config,
                                          const std::string& section,
                                          const std::string& key,
                                          const std::string* def_value);
  uint64_t (*config_get_uint64)(const config_t& config,
                                const std::string& section,
                                const std::string& key, uint64_t def_value);
  bool (*config_has_key)(const config_t& config, const std::string& section,
                         const std::string& key);
  bool (*config_has_section)(const config_t& config,
                             const std::string& section);
  std::unique_ptr<config_t> (*config_new)(const char* filename);
  std::unique_ptr<config_t> (*config_new_clone)(const config_t& src);
  std::unique_ptr<config_t> (*config_new_empty)(void);
  bool (*config_remove_key)(config_t* config, const std::string& section,
                            const std::string& key);
  bool (*config_remove_section)(config_t* config, const std::string& section);
  bool (*config_save)(const config_t& config, const std::string& filename);
  void (*config_set_bool)(config_t* config, const std::string& section,
                          const std::string& key, bool value);
  void (*config_set_int)(config_t* config, const std::string& section,
                         const std::string& key, int value);
  void (*config_set_string)(config_t* config, const std::string& section,
                            const std::string& key, const std::string& value);
  void (*config_set_uint64)(config_t* config, const std::string& section,
                            const std::string& key, uint64_t value);
} storage_config_t;
+68 −26
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@
//#include "btif_keystore.h"
#include "btif_util.h"
#include "common/address_obfuscator.h"
#include "main/shim/config.h"
#include "main/shim/shim.h"
#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
#include "osi/include/compat.h"
@@ -110,6 +112,23 @@ static enum ConfigSource {
static int btif_config_devices_loaded = -1;
static char btif_config_time_created[TIME_STRING_LENGTH];

static const storage_config_t interface = {
    checksum_read,         checksum_save,      config_get_bool,
    config_get_int,        config_get_string,  config_get_uint64,
    config_has_key,        config_has_section, config_new,
    config_new_clone,      config_new_empty,   config_remove_key,
    config_remove_section, config_save,        config_set_bool,
    config_set_int,        config_set_string,  config_set_uint64,
};

static const storage_config_t* storage_config_get_interface() {
  if (bluetooth::shim::is_gd_shim_enabled()) {
    return bluetooth::shim::storage_config_get_interface();
  } else {
    return &interface;
  }
}

// TODO(zachoverflow): Move these two functions out, because they are too
// specific for this file
// {grumpy-cat/no, monty-python/you-make-me-sad}
@@ -214,13 +233,14 @@ static future_t* init(void) {
    LOG_ERROR(LOG_TAG,
              "%s unable to transcode legacy file; creating empty config.",
              __func__);
    config = config_new_empty();
    config = storage_config_get_interface()->config_new_empty();
    btif_config_source = NEW_FILE;
    file_source = "Empty";
  }

  if (!file_source.empty())
    config_set_string(config.get(), INFO_SECTION, FILE_SOURCE, file_source);
    storage_config_get_interface()->config_set_string(
        config.get(), INFO_SECTION, FILE_SOURCE, file_source);

  btif_config_remove_unpaired(config.get());

@@ -229,7 +249,8 @@ static future_t* init(void) {

  // Read or set config file creation timestamp
  const std::string* time_str;
  time_str = config_get_string(*config, INFO_SECTION, FILE_TIMESTAMP, NULL);
  time_str = storage_config_get_interface()->config_get_string(
      *config, INFO_SECTION, FILE_TIMESTAMP, NULL);
  if (time_str != NULL) {
    strlcpy(btif_config_time_created, time_str->c_str(), TIME_STRING_LENGTH);
  } else {
@@ -237,8 +258,8 @@ static future_t* init(void) {
    struct tm* time_created = localtime(&current_time);
    strftime(btif_config_time_created, TIME_STRING_LENGTH, TIME_STRING_FORMAT,
             time_created);
    config_set_string(config.get(), INFO_SECTION, FILE_TIMESTAMP,
                      btif_config_time_created);
    storage_config_get_interface()->config_set_string(
        config.get(), INFO_SECTION, FILE_TIMESTAMP, btif_config_time_created);
  }

  // Read or set metrics 256 bit hashing salt
@@ -284,7 +305,8 @@ static std::unique_ptr<config_t> btif_config_open(const char* filename, const ch
  }
  // END KEY ATTESTATION*/

  std::unique_ptr<config_t> config = config_new(filename);
  std::unique_ptr<config_t> config =
      storage_config_get_interface()->config_new(filename);
  if (!config) return nullptr;

  if (!config_has_section(*config, "Adapter")) {
@@ -322,14 +344,14 @@ bool btif_config_has_section(const char* section) {
  CHECK(section != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  return config_has_section(*config, section);
  return storage_config_get_interface()->config_has_section(*config, section);
}

bool btif_config_exist(const std::string& section, const std::string& key) {
  CHECK(config != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  return config_has_key(*config, section, key);
  return storage_config_get_interface()->config_has_key(*config, section, key);
}

bool btif_config_get_int(const std::string& section, const std::string& key,
@@ -338,8 +360,11 @@ bool btif_config_get_int(const std::string& section, const std::string& key,
  CHECK(value != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  bool ret = config_has_key(*config, section, key);
  if (ret) *value = config_get_int(*config, section, key, *value);
  bool ret =
      storage_config_get_interface()->config_has_key(*config, section, key);
  if (ret)
    *value = storage_config_get_interface()->config_get_int(*config, section,
                                                            key, *value);

  return ret;
}
@@ -349,7 +374,8 @@ bool btif_config_set_int(const std::string& section, const std::string& key,
  CHECK(config != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  config_set_int(config.get(), section, key, value);
  storage_config_get_interface()->config_set_int(config.get(), section, key,
                                                 value);

  return true;
}
@@ -360,8 +386,11 @@ bool btif_config_get_uint64(const std::string& section, const std::string& key,
  CHECK(value != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  bool ret = config_has_key(*config, section, key);
  if (ret) *value = config_get_uint64(*config, section, key, *value);
  bool ret =
      storage_config_get_interface()->config_has_key(*config, section, key);
  if (ret)
    *value = storage_config_get_interface()->config_get_uint64(*config, section,
                                                               key, *value);

  return ret;
}
@@ -371,7 +400,8 @@ bool btif_config_set_uint64(const std::string& section, const std::string& key,
  CHECK(config != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  config_set_uint64(config.get(), section, key, value);
  storage_config_get_interface()->config_set_uint64(config.get(), section, key,
                                                    value);

  return true;
}
@@ -385,7 +415,8 @@ bool btif_config_get_str(const std::string& section, const std::string& key,
  {
    std::unique_lock<std::recursive_mutex> lock(config_lock);
    const std::string* stored_value =
        config_get_string(*config, section, key, NULL);
        storage_config_get_interface()->config_get_string(*config, section, key,
                                                          NULL);
    if (!stored_value) return false;
    strlcpy(value, stored_value->c_str(), *size_bytes);
  }
@@ -399,7 +430,8 @@ bool btif_config_set_str(const std::string& section, const std::string& key,
  CHECK(config != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  config_set_string(config.get(), section, key, value);
  storage_config_get_interface()->config_set_string(config.get(), section, key,
                                                    value);
  return true;
}

@@ -410,7 +442,9 @@ bool btif_config_get_bin(const std::string& section, const std::string& key,
  CHECK(length != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  const std::string* value_str = config_get_string(*config, section, key, NULL);
  const std::string* value_str =
      storage_config_get_interface()->config_get_string(*config, section, key,
                                                        NULL);

  if (!value_str) {
    VLOG(1) << __func__ << ": cannot find string for section " << section
@@ -442,7 +476,9 @@ size_t btif_config_get_bin_length(const std::string& section,
  CHECK(config != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  const std::string* value_str = config_get_string(*config, section, key, NULL);
  const std::string* value_str =
      storage_config_get_interface()->config_get_string(*config, section, key,
                                                        NULL);
  if (!value_str) return 0;

  size_t value_len = value_str->length();
@@ -472,7 +508,8 @@ bool btif_config_set_bin(const std::string& section, const std::string& key,

  {
    std::unique_lock<std::recursive_mutex> lock(config_lock);
    config_set_string(config.get(), section, key, str);
    storage_config_get_interface()->config_set_string(config.get(), section,
                                                      key, str);
  }

  osi_free(str);
@@ -485,7 +522,8 @@ bool btif_config_remove(const std::string& section, const std::string& key) {
  CHECK(config != NULL);

  std::unique_lock<std::recursive_mutex> lock(config_lock);
  return config_remove_key(config.get(), section, key);
  return storage_config_get_interface()->config_remove_key(config.get(),
                                                           section, key);
}

void btif_config_save(void) {
@@ -511,9 +549,10 @@ bool btif_config_clear(void) {

  std::unique_lock<std::recursive_mutex> lock(config_lock);

  config = config_new_empty();
  config = storage_config_get_interface()->config_new_empty();

  bool ret = config_save(*config, CONFIG_FILE_PATH);
  bool ret =
      storage_config_get_interface()->config_save(*config, CONFIG_FILE_PATH);
  btif_config_source = RESET;

  /*// Save encrypted hash
@@ -540,9 +579,10 @@ static void btif_config_write(UNUSED_ATTR uint16_t event,
  std::unique_lock<std::recursive_mutex> lock(config_lock);
  rename(CONFIG_FILE_PATH, CONFIG_BACKUP_PATH);
  rename(CONFIG_FILE_CHECKSUM_PATH, CONFIG_BACKUP_CHECKSUM_PATH);
  std::unique_ptr<config_t> config_paired = config_new_clone(*config);
  std::unique_ptr<config_t> config_paired =
      storage_config_get_interface()->config_new_clone(*config);
  btif_config_remove_unpaired(config_paired.get());
  config_save(*config_paired, CONFIG_FILE_PATH);
  storage_config_get_interface()->config_save(*config_paired, CONFIG_FILE_PATH);
  /*// Save hash
  std::string current_hash = hash_file(CONFIG_FILE_PATH);
  if (!current_hash.empty()) {
@@ -610,7 +650,8 @@ void btif_debug_config_dump(int fd) {
  dprintf(fd, "  Devices loaded: %d\n", btif_config_devices_loaded);
  dprintf(fd, "  File created/tagged: %s\n", btif_config_time_created);
  dprintf(fd, "  File source: %s\n",
          config_get_string(*config, INFO_SECTION, FILE_SOURCE, &original)
          storage_config_get_interface()
              ->config_get_string(*config, INFO_SECTION, FILE_SOURCE, &original)
              ->c_str());
}

@@ -620,7 +661,8 @@ static void btif_config_remove_restricted(config_t* config) {
  for (auto it = config->sections.begin(); it != config->sections.end();) {
    const std::string& section = it->name;
    if (RawAddress::IsValidAddress(section) &&
        config_has_key(*config, section, "Restricted")) {
        storage_config_get_interface()->config_has_key(*config, section,
                                                       "Restricted")) {
      BTIF_TRACE_DEBUG("%s: Removing restricted device %s", __func__,
                       section.c_str());
      it = config->sections.erase(it);
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ filegroup {
        "btm.cc",
        "btm_api.cc",
        "controller.cc",
        "config.cc",
        "entry.cc",
        "hci_layer.cc",
        "l2c_api.cc",
+504 −0

File added.

Preview size limit exceeded, changes collapsed.

+27 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "btif/include/btif_config.h"

namespace bluetooth {
namespace shim {

const storage_config_t* storage_config_get_interface();

}  // namespace shim
}  // namespace bluetooth