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

Commit d4426200 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Bump GATT cache file version marker

In commit 2238a88f, the type used for UUID in the GATT cache was changed
from tBT_UUID to bluetooth:Uuid. This changed the binary representation of
this field. 18 bytes were used previously, now only 16 bytes are used.
This change made GATT cache file format incompatible between Android
versions, and requires an increment of cache file format version.

Fixes: 70297056
Test: added GattCacheTest
Change-Id: I4bceada300dbe3aab10d14df2aa853e4573c536e
parent c9a06de6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ cc_test {
    defaults: ["fluoride_bta_defaults"],
    srcs: [
        "test/bta_hf_client_test.cc",
        "test/gatt_cache_file_test.cc",
    ],
    shared_libs: [
        "liblog",
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(
#define BTA_GATT_SDP_DB_SIZE 4096

#define GATT_CACHE_PREFIX "/data/misc/bluetooth/gatt_cache_"
#define GATT_CACHE_VERSION 2
#define GATT_CACHE_VERSION 3

static void bta_gattc_generate_cache_file_name(char* buffer, size_t buffer_len,
                                               const RawAddress& bda) {
+49 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2018 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.
 *
 ******************************************************************************/

#include <gtest/gtest.h>

#include <base/logging.h>
#include <base/strings/string_number_conversions.h>
#include "bta/include/bta_gatt_api.h"

using bluetooth::Uuid;

/* This test makes sure that v3 cache element is properly encoded into file*/
TEST(GattCacheTest, nv_attr_to_binary_test) {
  tBTA_GATTC_NV_ATTR attr{
      .uuid = Uuid::FromString("1800"),
      .s_handle = 0x0001,
      .e_handle = 0xFFFF,
      .attr_type = 0x01,
      .id = 0x02,
      .prop = 0x03,
      .is_primary = false,
      .incl_srvc_handle = 0x4543,
  };

  constexpr size_t len = sizeof(tBTA_GATTC_NV_ATTR);
  uint8_t binary_form[len] = {0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x10,
                              0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B,
                              0x34, 0xFB, 0x01, 0x00, 0xFF, 0xFF, 0x01,
                              0x02, 0x03, 0x00, 0x43, 0x45};

  // USEFUL for debugging:
  // LOG(ERROR) << " " << base::HexEncode(binary_form, len);
  EXPECT_EQ(memcmp(binary_form, &attr, len), 0);
}