Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 1 | /* |
Hemant Gupta | aebc726 | 2013-08-19 18:54:29 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014 The Android Open Source Project |
Zhihai Xu | ede67c2 | 2012-10-23 17:01:01 -0700 | [diff] [blame] | 3 | * 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 Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 16 | */ |
| 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 Janssen | fe37710 | 2016-10-11 16:09:58 -0700 | [diff] [blame^] | 25 | #include "utils/Log.h" |
| 26 | #include "android_runtime/AndroidRuntime.h" |
| 27 | #include "android_runtime/Log.h" |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
Marie Janssen | fe37710 | 2016-10-11 16:09:58 -0700 | [diff] [blame^] | 31 | JNIEnv* getCallbackEnv(); |
| 32 | |
| 33 | class CallbackEnv { |
| 34 | public: |
| 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 | |
| 64 | private: |
| 65 | JNIEnv *mCallbackEnv; |
| 66 | const char *mName; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(CallbackEnv); |
| 69 | }; |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 70 | |
| 71 | const bt_interface_t* getBluetoothInterface(); |
| 72 | |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 73 | int register_com_android_bluetooth_hfp(JNIEnv* env); |
| 74 | |
Hemant Gupta | aebc726 | 2013-08-19 18:54:29 +0530 | [diff] [blame] | 75 | int register_com_android_bluetooth_hfpclient(JNIEnv* env); |
| 76 | |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 77 | int register_com_android_bluetooth_a2dp(JNIEnv* env); |
| 78 | |
Mike Lockwood | c030f08 | 2014-06-07 14:04:40 -0700 | [diff] [blame] | 79 | int register_com_android_bluetooth_a2dp_sink(JNIEnv* env); |
| 80 | |
Zhihai Xu | c1c259c | 2013-03-14 11:51:06 -0700 | [diff] [blame] | 81 | int register_com_android_bluetooth_avrcp(JNIEnv* env); |
| 82 | |
Mike Lockwood | 066ad9e1 | 2014-06-06 13:04:55 -0700 | [diff] [blame] | 83 | int register_com_android_bluetooth_avrcp_controller(JNIEnv* env); |
| 84 | |
Matthew Xie | 35207a5 | 2012-03-21 23:11:40 -0700 | [diff] [blame] | 85 | int register_com_android_bluetooth_hid(JNIEnv* env); |
| 86 | |
Matthew Xie | 676cb1b | 2012-03-22 17:32:29 -0700 | [diff] [blame] | 87 | int register_com_android_bluetooth_hdp(JNIEnv* env); |
| 88 | |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 89 | int register_com_android_bluetooth_pan(JNIEnv* env); |
| 90 | |
Ganesh Ganapathi Batta | 03b8386 | 2013-02-05 15:38:27 -0800 | [diff] [blame] | 91 | int register_com_android_bluetooth_gatt (JNIEnv* env); |
| 92 | |
Casper Bonde | bbb4110 | 2015-04-09 09:20:50 +0200 | [diff] [blame] | 93 | int register_com_android_bluetooth_sdp (JNIEnv* env); |
| 94 | |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | #endif /* COM_ANDROID_BLUETOOTH_H */ |