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

Commit 3c971a37 authored by Miao Chou's avatar Miao Chou Committed by Miao-chen Chou
Browse files

build: Eliminate cutils/str_parms dependency from system/bt

Eliminate cutils/str_parmss dependency from system/bt by adding osi_str_parms:
 - Added hash_map_utils which implements partial functions of cutils/str_parms
   and uses osi/hash_map instead of cutils/hashmap.
 - Updated osi/Android.mk, osi/BUILD.gn and the includes in audio_a2dp to use
   osi_str_parms.
 - Added unittest for hash_map_utils.

Bug: 21957864
Change-Id: I8458d9e45df6cab2b71840d24d17b9d75de9842c
parent 71191324
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ LOCAL_CFLAGS += -std=c99 $(bdroid_CFLAGS)
LOCAL_MODULE := audio.a2dp.default
LOCAL_MODULE_RELATIVE_PATH := hw

LOCAL_SHARED_LIBRARIES := libcutils liblog
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_STATIC_LIBRARIES := libosi

LOCAL_MODULE_TAGS := optional
+29 −37
Original line number Diff line number Diff line
@@ -39,13 +39,14 @@
#include <sys/un.h>
#include <unistd.h>

#include <cutils/str_parms.h>
#include <hardware/audio.h>
#include <hardware/hardware.h>
#include <system/audio.h>

#include "audio_a2dp_hw.h"
#include "bt_utils.h"
#include "osi/include/hash_map.h"
#include "osi/include/hash_map_utils.h"
#include "osi/include/log.h"
#include "osi/include/socket_utils/sockets.h"

@@ -679,36 +680,31 @@ static int out_dump(const struct audio_stream *stream, int fd)
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
    struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
    struct str_parms *parms;
    char keyval[16];
    int retval;
    int status = 0;

    INFO("state %d", out->common.state);

    pthread_mutex_lock(&out->common.lock);

    parms = str_parms_create_str(kvpairs);
    hash_map_t *params = hash_map_utils_new_from_string_params(kvpairs);

    int status = 0;
    if (!params)
      return status;

    /* dump params */
    str_parms_dump(parms);
    hash_map_utils_dump_string_keys_string_values(params);

    retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval));
    char *keyval = (char *)hash_map_get(params, "closing");

    if (retval >= 0)
    {
        if (strcmp(keyval, "true") == 0)
    if (keyval && strcmp(keyval, "true") == 0)
    {
        DEBUG("stream closing, disallow any writes");
        out->common.state = AUDIO_A2DP_STATE_STOPPING;
    }
    }

    retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval));
    keyval = (char *)hash_map_get(params, "A2dpSuspended");

    if (retval >= 0)
    {
        if (strcmp(keyval, "true") == 0)
    if (keyval && strcmp(keyval, "true") == 0)
    {
        if (out->common.state == AUDIO_A2DP_STATE_STARTED)
            status = suspend_audio_datapath(&out->common, false);
@@ -722,10 +718,9 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
            out->common.state = AUDIO_A2DP_STATE_STANDBY;
        /* Irrespective of the state, return 0 */
    }
    }

    pthread_mutex_unlock(&out->common.lock);
    str_parms_destroy(parms);
    hash_map_free(params);

    return status;
}
@@ -1108,16 +1103,13 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
static char * adev_get_parameters(const struct audio_hw_device *dev,
                                  const char *keys)
{
    struct str_parms *parms;
    UNUSED(dev);

    FNLOG();

    parms = str_parms_create_str(keys);

    str_parms_dump(parms);

    str_parms_destroy(parms);
    hash_map_t *params = hash_map_utils_new_from_string_params(keys);
    hash_map_utils_dump_string_keys_string_values(params);
    hash_map_free(params);

    return strdup("");
}
+5 −1
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ LOCAL_CLANG := false

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/..
    $(LOCAL_PATH)/.. \
    $(LOCAL_PATH)/../utils/include

# TODO(mcchou): Remove socket_utils sources after platform specific
# dependencies are abstracted.
@@ -42,6 +43,7 @@ LOCAL_SRC_FILES := \
    ./src/future.c \
    ./src/hash_functions.c \
    ./src/hash_map.c \
    ./src/hash_map_utils.c \
    ./src/list.c \
    ./src/non_repeating_timer.c \
    ./src/reactor.c \
@@ -78,6 +80,7 @@ LOCAL_SRC_FILES := \
    ./test/AllocationTestHarness.cpp \
    ./test/alarm_test.cpp \
    ./test/allocation_tracker_test.cpp \
    ./test/allocator_test.cpp \
    ./test/array_test.cpp \
    ./test/atomic_test.cpp \
    ./test/config_test.cpp \
@@ -85,6 +88,7 @@ LOCAL_SRC_FILES := \
    ./test/eager_reader_test.cpp \
    ./test/future_test.cpp \
    ./test/hash_map_test.cpp \
    ./test/hash_map_utils_test.cpp \
    ./test/list_test.cpp \
    ./test/reactor_test.cpp \
    ./test/ringbuffer_test.cpp \
+5 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ static_library("osi") {
    "src/future.c",
    "src/hash_functions.c",
    "src/hash_map.c",
    "src/hash_map_utils.c",
    "src/list.c",
    "src/non_repeating_timer.c",
    "src/reactor.c",
@@ -46,7 +47,8 @@ static_library("osi") {

  include_dirs = [
    "include",
    "//"
    "//",
    "//utils/include",
  ]
}

@@ -57,6 +59,7 @@ executable("net_test_osi") {
    "test/AllocationTestHarness.cpp",
    "test/alarm_test.cpp",
    "test/allocation_tracker_test.cpp",
    "test/allocator_test.cpp",
    "test/array_test.cpp",
    "test/atomic_test.cpp",
    "test/config_test.cpp",
@@ -64,6 +67,7 @@ executable("net_test_osi") {
    "test/eager_reader_test.cpp",
    "test/future_test.cpp",
    "test/hash_map_test.cpp",
    "test/hash_map_utils_test.cpp",
    "test/list_test.cpp",
    "test/reactor_test.cpp",
    "test/ringbuffer_test.cpp",
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ extern const allocator_t allocator_malloc;
extern const allocator_t allocator_calloc;

char *osi_strdup(const char *str);
char *osi_strndup(const char *str, size_t len);

void *osi_malloc(size_t size);
void *osi_calloc(size_t size);
Loading