blob: e63eba58a8425e249f636466f0cc94c725d53863 [file] [log] [blame]
Matthew Xie6c91bc02012-02-16 18:47:53 -08001/*
Hemant Guptaaebc7262013-08-19 18:54:29 +05302 * Copyright (c) 2014 The Android Open Source Project
Zhihai Xuede67c22012-10-23 17:01:01 -07003 * Copyright (C) 2012 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Matthew Xie6c91bc02012-02-16 18:47:53 -080016 */
17
18#ifndef COM_ANDROID_BLUETOOTH_H
19#define COM_ANDROID_BLUETOOTH_H
20
21#include "JNIHelp.h"
22#include "jni.h"
23#include "hardware/hardware.h"
24#include "hardware/bluetooth.h"
Marie Janssenfe377102016-10-11 16:09:58 -070025#include "utils/Log.h"
26#include "android_runtime/AndroidRuntime.h"
27#include "android_runtime/Log.h"
Matthew Xie6c91bc02012-02-16 18:47:53 -080028
29namespace android {
30
Marie Janssenfe377102016-10-11 16:09:58 -070031JNIEnv* getCallbackEnv();
32
33class CallbackEnv {
34public:
35 CallbackEnv(const char *methodName) : mName(methodName) {
36 mCallbackEnv = getCallbackEnv();
37 }
38
39 ~CallbackEnv() {
40 if (mCallbackEnv && mCallbackEnv->ExceptionCheck()) {
41 ALOGE("An exception was thrown by callback '%s'.", mName);
42 LOGE_EX(mCallbackEnv);
43 mCallbackEnv->ExceptionClear();
44 }
45 }
46
47 bool valid() const {
48 JNIEnv *env = AndroidRuntime::getJNIEnv();
49 if (!mCallbackEnv || (mCallbackEnv != env)) {
50 ALOGE("%s: Callback env fail: env: %p, callback: %p", mName, env, mCallbackEnv);
51 return false;
52 }
53 return true;
54 }
55
56 JNIEnv *operator-> () const {
57 return mCallbackEnv;
58 }
59
60 JNIEnv *get() const {
61 return mCallbackEnv;
62 }
63
64private:
65 JNIEnv *mCallbackEnv;
66 const char *mName;
67
68 DISALLOW_COPY_AND_ASSIGN(CallbackEnv);
69};
Matthew Xie6c91bc02012-02-16 18:47:53 -080070
71const bt_interface_t* getBluetoothInterface();
72
Matthew Xie6c91bc02012-02-16 18:47:53 -080073int register_com_android_bluetooth_hfp(JNIEnv* env);
74
Hemant Guptaaebc7262013-08-19 18:54:29 +053075int register_com_android_bluetooth_hfpclient(JNIEnv* env);
76
Matthew Xie6c91bc02012-02-16 18:47:53 -080077int register_com_android_bluetooth_a2dp(JNIEnv* env);
78
Mike Lockwoodc030f082014-06-07 14:04:40 -070079int register_com_android_bluetooth_a2dp_sink(JNIEnv* env);
80
Zhihai Xuc1c259c2013-03-14 11:51:06 -070081int register_com_android_bluetooth_avrcp(JNIEnv* env);
82
Mike Lockwood066ad9e12014-06-06 13:04:55 -070083int register_com_android_bluetooth_avrcp_controller(JNIEnv* env);
84
Matthew Xie35207a52012-03-21 23:11:40 -070085int register_com_android_bluetooth_hid(JNIEnv* env);
86
Matthew Xie676cb1b2012-03-22 17:32:29 -070087int register_com_android_bluetooth_hdp(JNIEnv* env);
88
fredc6654f5c2012-04-12 00:18:52 -070089int register_com_android_bluetooth_pan(JNIEnv* env);
90
Ganesh Ganapathi Batta03b83862013-02-05 15:38:27 -080091int register_com_android_bluetooth_gatt (JNIEnv* env);
92
Casper Bondebbb41102015-04-09 09:20:50 +020093int register_com_android_bluetooth_sdp (JNIEnv* env);
94
Matthew Xie6c91bc02012-02-16 18:47:53 -080095}
96
97#endif /* COM_ANDROID_BLUETOOTH_H */