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

Commit 2d018b8c authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Add config source to dumpsys output

This logs where the config file was loaded from in the Bluetooth
Manager dumpsys output.

Bug: 27354612
Change-Id: I50d4aaa0be4f4d1d890580b03742713f4345c80f
parent c59c56ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -52,3 +52,4 @@ bool btif_config_clear(void);
bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type);
bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type);


void btif_debug_config_dump(int fd);
+1 −0
Original line number Original line Diff line number Diff line
@@ -343,6 +343,7 @@ static void dump(int fd, const char **arguments)
    btif_debug_conn_dump(fd);
    btif_debug_conn_dump(fd);
    btif_debug_bond_event_dump(fd);
    btif_debug_bond_event_dump(fd);
    btif_debug_a2dp_dump(fd);
    btif_debug_a2dp_dump(fd);
    btif_debug_config_dump(fd);
    wakelock_debug_dump(fd);
    wakelock_debug_dump(fd);
    alarm_debug_dump(fd);
    alarm_debug_dump(fd);
#if defined(BTSNOOP_MEM) && (BTSNOOP_MEM == TRUE)
#if defined(BTSNOOP_MEM) && (BTSNOOP_MEM == TRUE)
+40 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,15 @@ static void timer_config_save_cb(void *data);
static void btif_config_write(UINT16 event, char *p_param);
static void btif_config_write(UINT16 event, char *p_param);
static void btif_config_devcache_cleanup(void);
static void btif_config_devcache_cleanup(void);


static enum ConfigSource {
  NOT_LOADED,
  ORIGINAL,
  BACKUP,
  NEW_FILE,
  RESET
} btif_config_source = NOT_LOADED;


// TODO(zachoverflow): Move these two functions out, because they are too specific for this file
// TODO(zachoverflow): Move these two functions out, because they are too specific for this file
// {grumpy-cat/no, monty-python/you-make-me-sad}
// {grumpy-cat/no, monty-python/you-make-me-sad}
bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
@@ -101,13 +110,16 @@ static alarm_t *config_timer;
static future_t *init(void) {
static future_t *init(void) {
  pthread_mutex_init(&lock, NULL);
  pthread_mutex_init(&lock, NULL);
  config = config_new(CONFIG_FILE_PATH);
  config = config_new(CONFIG_FILE_PATH);
  btif_config_source = ORIGINAL;
  if (!config) {
  if (!config) {
    LOG_WARN(LOG_TAG, "%s unable to load config file: %s; using backup.",
    LOG_WARN(LOG_TAG, "%s unable to load config file: %s; using backup.",
              __func__, CONFIG_FILE_PATH);
              __func__, CONFIG_FILE_PATH);
    config = config_new(CONFIG_BACKUP_PATH);
    config = config_new(CONFIG_BACKUP_PATH);
    btif_config_source = BACKUP;
    if (!config) {
    if (!config) {
      LOG_ERROR(LOG_TAG, "%s unable to load backup; creating empty config.", __func__);
      LOG_ERROR(LOG_TAG, "%s unable to load backup; creating empty config.", __func__);
      config = config_new_empty();
      config = config_new_empty();
      btif_config_source = NEW_FILE;
      if (!config) {
      if (!config) {
        LOG_ERROR(LOG_TAG, "%s unable to allocate a config object.", __func__);
        LOG_ERROR(LOG_TAG, "%s unable to allocate a config object.", __func__);
        goto error;
        goto error;
@@ -385,6 +397,7 @@ bool btif_config_clear(void){
  }
  }


  bool ret = config_save(config, CONFIG_FILE_PATH);
  bool ret = config_save(config, CONFIG_FILE_PATH);
  btif_config_source = RESET;
  pthread_mutex_unlock(&lock);
  pthread_mutex_unlock(&lock);
  return ret;
  return ret;
}
}
@@ -441,3 +454,30 @@ static void btif_config_devcache_cleanup(void) {
  }
  }
  pthread_mutex_unlock(&lock);
  pthread_mutex_unlock(&lock);
}
}

void btif_debug_config_dump(int fd) {
    pthread_mutex_lock(&lock);

    dprintf(fd, "\nBluetooth Config:\n");

    dprintf(fd, "  Config Source: ");
    switch(btif_config_source) {
        case NOT_LOADED:
            dprintf(fd, "Not loaded\n");
            break;
        case ORIGINAL:
            dprintf(fd, "Original file\n");
            break;
        case BACKUP:
            dprintf(fd, "Backup file\n");
            break;
        case NEW_FILE:
            dprintf(fd, "New file\n");
            break;
        case RESET:
            dprintf(fd, "Reset file\n");
            break;
    }

    pthread_mutex_unlock(&lock);
}