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

Commit 75d086e5 authored by Doug Kwan's avatar Doug Kwan
Browse files

Add C code to use BDADDR_ANY macro properly. The macro expands into code

that is not valid C++.  So we need to use a C helper.

Change-Id: I5e7a46dd2af404972c1b4b97d21398d77c339cac
parent 176ee3d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ LOCAL_SRC_FILES:= \
	android_bluetooth_common.cpp \
	android_bluetooth_BluetoothAudioGateway.cpp \
	android_bluetooth_BluetoothSocket.cpp \
	android_bluetooth_c.c \
	android_server_BluetoothService.cpp \
	android_server_BluetoothEventLoop.cpp \
	android_server_BluetoothA2dpService.cpp \
+3 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_TAG "BluetoothAudioGateway.cpp"

#include "android_bluetooth_common.h"
#include "android_bluetooth_c.h"
#include "android_runtime/AndroidRuntime.h"
#include "JNIHelp.h"
#include "jni.h"
@@ -491,7 +492,8 @@ static int setup_listening_socket(int dev, int channel) {
    }

    laddr.rc_family = AF_BLUETOOTH;
    memcpy(&laddr.rc_bdaddr, BDADDR_ANY, sizeof(bdaddr_t));
    bdaddr_t any = android_bluetooth_bdaddr_any();
    memcpy(&laddr.rc_bdaddr, &any, sizeof(bdaddr_t));
    laddr.rc_channel = channel;

    if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_TAG "BluetoothSocket.cpp"

#include "android_bluetooth_common.h"
#include "android_bluetooth_c.h"
#include "android_runtime/AndroidRuntime.h"
#include "JNIHelp.h"
#include "utils/Log.h"
@@ -245,7 +246,7 @@ static int bindListenNative(JNIEnv *env, jobject obj) {
    jint type;
    socklen_t addr_sz;
    struct sockaddr *addr;
    bdaddr_t bdaddr = *BDADDR_ANY;
    bdaddr_t bdaddr = android_bluetooth_bdaddr_any();
    struct asocket *s = get_socketData(env, obj);

    if (!s)
+31 −0
Original line number Diff line number Diff line
/*
** Copyright 2011, 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.
*/

#ifdef HAVE_BLUETOOTH

#include "android_bluetooth_c.h"

/*
 * A C helper for creating a bdaddr_t object with the value BDADDR_ANY.
 * We have to do this in C because the macro BDADDR_ANY in bluetooth.h
 * is not valid C++ code.
 */
bdaddr_t android_bluetooth_bdaddr_any(void)
{
  bdaddr_t any = *BDADDR_ANY;
  return any;
}
#endif
+39 −0
Original line number Diff line number Diff line
/*
** Copyright 2010, 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.
*/

#ifndef ANDROID_BLUETOOTH_C_H
#define ANDROID_BLUETOOTH_C_H
#ifdef HAVE_BLUETOOTH

#include <bluetooth/bluetooth.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * A C helper for creating a bdaddr_t object with the value BDADDR_ANY.
 * We have to do this in C because the macro BDADDR_ANY in bluetooth.h
 * is not valid C++ code.
 */
bdaddr_t android_bluetooth_bdaddr_any(void);

#ifdef __cplusplus
}
#endif

#endif /*HAVE_BLUETOOTH*/
#endif /*ANDROID_BLUETOOTH_C_H*/