From: Ajay Panicker Date: Mon, 21 Mar 2016 18:23:09 +0000 (-0700) Subject: Add config source to dumpsys output X-Git-Tag: android-x86-7.1-r1~296 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=63ddbe8813aac242071dffc0bd413ba60e6dd7bf;p=android-x86%2Fsystem-bt.git 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 --- diff --git a/btif/include/btif_config.h b/btif/include/btif_config.h index 15b747962..495e9386e 100644 --- a/btif/include/btif_config.h +++ b/btif/include/btif_config.h @@ -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_device_type(const BD_ADDR bd_addr, int *p_device_type); +void btif_debug_config_dump(int fd); diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 72046610d..f2eea9c07 100644 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -343,6 +343,7 @@ static void dump(int fd, const char **arguments) btif_debug_conn_dump(fd); btif_debug_bond_event_dump(fd); btif_debug_a2dp_dump(fd); + btif_debug_config_dump(fd); wakelock_debug_dump(fd); alarm_debug_dump(fd); #if defined(BTSNOOP_MEM) && (BTSNOOP_MEM == TRUE) diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c index 3949a2085..a9b781d45 100644 --- a/btif/src/btif_config.c +++ b/btif/src/btif_config.c @@ -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_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 // {grumpy-cat/no, monty-python/you-make-me-sad} 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) { pthread_mutex_init(&lock, NULL); config = config_new(CONFIG_FILE_PATH); + btif_config_source = ORIGINAL; if (!config) { LOG_WARN(LOG_TAG, "%s unable to load config file: %s; using backup.", __func__, CONFIG_FILE_PATH); config = config_new(CONFIG_BACKUP_PATH); + btif_config_source = BACKUP; if (!config) { LOG_ERROR(LOG_TAG, "%s unable to load backup; creating empty config.", __func__); config = config_new_empty(); + btif_config_source = NEW_FILE; if (!config) { LOG_ERROR(LOG_TAG, "%s unable to allocate a config object.", __func__); goto error; @@ -385,6 +397,7 @@ bool btif_config_clear(void){ } bool ret = config_save(config, CONFIG_FILE_PATH); + btif_config_source = RESET; pthread_mutex_unlock(&lock); return ret; } @@ -441,3 +454,30 @@ static void btif_config_devcache_cleanup(void) { } 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); +}