OSDN Git Service

Implement Bluetooth settings factory reset (3/5)
authorAjay Panicker <apanicke@google.com>
Tue, 28 Jul 2015 23:54:53 +0000 (16:54 -0700)
committerAjay Panicker <apanicke@google.com>
Wed, 5 Aug 2015 17:25:22 +0000 (10:25 -0700)
Implemented the factory reset function to be used to reset all bluetooth
settings on device to factory default

Bug: 16161518

btif/include/btif_config.h
btif/src/bluetooth.c
btif/src/btif_config.c

index 30f5f5b..4dc897a 100644 (file)
@@ -46,6 +46,7 @@ const char *btif_config_section_name(const btif_config_section_iter_t *section);
 
 void btif_config_save(void);
 void btif_config_flush(void);
+int btif_config_clear(void);
 
 // TODO(zachoverflow): Eww...we need to move these out. These are peer specific, not config general.
 bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
index f842e5c..3213221 100644 (file)
@@ -54,6 +54,7 @@
 #include "osi/include/allocation_tracker.h"
 #include "osi/include/log.h"
 #include "stack_manager.h"
+#include "btif_config.h"
 
 /************************************************************************************
 **  Constants & Macros
@@ -416,6 +417,11 @@ static int set_os_callouts(bt_os_callouts_t *callouts) {
     return BT_STATUS_SUCCESS;
 }
 
+static int config_clear(void) {
+    LOG_INFO("%s", __func__);
+    return btif_config_clear();
+}
+
 static const bt_interface_t bluetoothInterface = {
     sizeof(bluetoothInterface),
     init,
@@ -449,7 +455,8 @@ static const bt_interface_t bluetoothInterface = {
     config_hci_snoop_log,
     set_os_callouts,
     read_energy_info,
-    dump
+    dump,
+    config_clear
 };
 
 const bt_interface_t* bluetooth__get_bluetooth_interface ()
index 3cbff50..19482ef 100644 (file)
@@ -360,6 +360,26 @@ void btif_config_flush(void) {
   pthread_mutex_unlock(&lock);
 }
 
+int btif_config_clear(void){
+  assert(config != NULL);
+  assert(alarm_timer != NULL);
+
+  alarm_cancel(alarm_timer);
+
+  pthread_mutex_lock(&lock);
+  config_free(config);
+
+  config = config_new_empty();
+  if (config == NULL) {
+    pthread_mutex_unlock(&lock);
+    return false;
+  }
+
+  int ret = config_save(config, CONFIG_FILE_PATH);
+  pthread_mutex_unlock(&lock);
+  return ret;
+}
+
 static void timer_config_save(UNUSED_ATTR void *data) {
   assert(config != NULL);
   assert(alarm_timer != NULL);