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

Commit 7eedeab0 authored by Alain Vongsouvanh's avatar Alain Vongsouvanh Committed by Andre Eisenbach
Browse files

Bring back support for legacy bt_config.xml

If a device migrates directly from L or earlier to a version using this
new implementation, all bt_config will be lost, requiring to repair to
the devices.

Change-Id: Ifdca0d8cad8efaa9f503ca40ac0725547a06f15c
parent 17043071
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ cd third_party
git clone https://github.com/google/googletest.git
git clone https://android.googlesource.com/platform/external/libchrome
git clone https://android.googlesource.com/platform/external/modp_b64
git clone https://android.googlesource.com/platform/external/tinyxml2
```

And third party dependencies of third party dependencies:
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ btifCommonSrc += \
  src/btif_av.c \
  src/btif_avrcp_audio_track.cpp \
  src/btif_config.c \
  src/btif_config_transcode.cpp \
  src/btif_core.c \
  src/btif_debug.c \
  src/btif_debug_btsnoop.c \
@@ -105,6 +106,7 @@ btifCommonIncludes := \
  $(LOCAL_PATH)/../audio_a2dp_hw \
  $(LOCAL_PATH)/../utils/include \
  $(bluetooth_C_INCLUDES) \
  external/tinyxml2 \
  external/zlib

# libbtif static library for target
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ static_library("btif") {
    "//stack/a2dp",
    "//stack/btm",
    "//stack/include",
    "//third_party/tinyxml2",
    "//include",
    "//udrv/include",
    "//utils/include",
+23 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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

typedef struct config_t config_t;

config_t *btif_config_transcode(const char *xml_filename);
+23 −10
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "btcore/include/module.h"
#include "btif_common.h"
#include "btif_config.h"
#include "btif_config_transcode.h"
#include "btif_util.h"
#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
@@ -53,9 +54,11 @@
#if defined(OS_GENERIC)
static const char *CONFIG_FILE_PATH = "bt_config.conf";
static const char *CONFIG_BACKUP_PATH = "bt_config.bak";
static const char *CONFIG_LEGACY_FILE_PATH = "bt_config.xml";
#else  // !defined(OS_GENERIC)
static const char *CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf";
static const char *CONFIG_BACKUP_PATH = "/data/misc/bluedroid/bt_config.bak";
static const char *CONFIG_LEGACY_FILE_PATH = "/data/misc/bluedroid/bt_config.xml";
#endif  // defined(OS_GENERIC)
static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000;

@@ -69,6 +72,7 @@ static enum ConfigSource {
  NOT_LOADED,
  ORIGINAL,
  BACKUP,
  LEGACY,
  NEW_FILE,
  RESET
} btif_config_source = NOT_LOADED;
@@ -127,20 +131,25 @@ static future_t *init(void) {
  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.",
    LOG_WARN("%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_WARN("%s unable to load backup; attempting to transcode legacy file.", __func__);
    config = btif_config_transcode(CONFIG_LEGACY_FILE_PATH);
    btif_config_source = LEGACY;
  }
  if (!config) {
      LOG_ERROR(LOG_TAG, "%s unable to load backup; creating empty config.", __func__);
    LOG_ERROR("%s unable to transcode legacy file; 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__);
    LOG_ERROR("%s unable to allocate a config object.", __func__);
    goto error;
  }
    }
  }

  btif_config_devcache_cleanup();

@@ -161,6 +170,7 @@ error:
  pthread_mutex_destroy(&lock);
  config_timer = NULL;
  config = NULL;
  btif_config_source = NOT_LOADED;
  return future_new_immediate(FUTURE_FAIL);
}

@@ -487,6 +497,9 @@ void btif_debug_config_dump(int fd) {
        case BACKUP:
            dprintf(fd, "Backup file\n");
            break;
        case LEGACY:
            dprintf(fd, "Legacy file\n");
            break;
        case NEW_FILE:
            dprintf(fd, "New file\n");
            break;
Loading