Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 1 | /* |
Zhihai Xu | ede67c2 | 2012-10-23 17:01:01 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 15 | */ |
Zhihai Xu | ede67c2 | 2012-10-23 17:01:01 -0700 | [diff] [blame] | 16 | |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 17 | #define LOG_TAG "BluetoothA2dpServiceJni" |
| 18 | |
| 19 | #define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include "com_android_bluetooth.h" |
| 22 | #include "hardware/bt_av.h" |
| 23 | #include "utils/Log.h" |
| 24 | #include "android_runtime/AndroidRuntime.h" |
| 25 | |
| 26 | #include <string.h> |
| 27 | |
| 28 | namespace android { |
| 29 | static jmethodID method_onConnectionStateChanged; |
Kausik Sinnaswamy | ac234ef | 2012-04-20 00:24:28 +0530 | [diff] [blame] | 30 | static jmethodID method_onAudioStateChanged; |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 31 | static jmethodID method_onCheckConnectionPriority; |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 32 | static jmethodID method_onAudioFocusRequest; |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 33 | |
| 34 | static const btav_interface_t *sBluetoothA2dpInterface = NULL; |
| 35 | static jobject mCallbacksObj = NULL; |
| 36 | static JNIEnv *sCallbackEnv = NULL; |
| 37 | |
| 38 | static bool checkCallbackThread() { |
Kausik Sinnaswamy | 93f548f | 2012-03-21 15:14:32 +0530 | [diff] [blame] | 39 | // Always fetch the latest callbackEnv from AdapterService. |
| 40 | // Caching this could cause this sCallbackEnv to go out-of-sync |
| 41 | // with the AdapterService's ENV if an ASSOCIATE/DISASSOCIATE event |
| 42 | // is received |
| 43 | //if (sCallbackEnv == NULL) { |
| 44 | sCallbackEnv = getCallbackEnv(); |
| 45 | //} |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 46 | |
| 47 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 48 | if (sCallbackEnv != env || sCallbackEnv == NULL) return false; |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_bdaddr_t* bd_addr) { |
| 53 | jbyteArray addr; |
| 54 | |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 55 | ALOGI("%s", __FUNCTION__); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 56 | |
| 57 | if (!checkCallbackThread()) { \ |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 58 | ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 59 | return; \ |
| 60 | } |
| 61 | addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); |
| 62 | if (!addr) { |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 63 | ALOGE("Fail to new jbyteArray bd addr for connection state"); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 64 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*) bd_addr); |
| 69 | sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, (jint) state, |
| 70 | addr); |
| 71 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 72 | sCallbackEnv->DeleteLocalRef(addr); |
| 73 | } |
| 74 | |
Kausik Sinnaswamy | ac234ef | 2012-04-20 00:24:28 +0530 | [diff] [blame] | 75 | static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* bd_addr) { |
| 76 | jbyteArray addr; |
| 77 | |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 78 | ALOGI("%s", __FUNCTION__); |
Kausik Sinnaswamy | ac234ef | 2012-04-20 00:24:28 +0530 | [diff] [blame] | 79 | |
| 80 | if (!checkCallbackThread()) { \ |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 81 | ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ |
Kausik Sinnaswamy | ac234ef | 2012-04-20 00:24:28 +0530 | [diff] [blame] | 82 | return; \ |
| 83 | } |
| 84 | addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); |
| 85 | if (!addr) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 86 | ALOGE("Fail to new jbyteArray bd addr for connection state"); |
Kausik Sinnaswamy | ac234ef | 2012-04-20 00:24:28 +0530 | [diff] [blame] | 87 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*) bd_addr); |
| 92 | sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, (jint) state, |
| 93 | addr); |
| 94 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 95 | sCallbackEnv->DeleteLocalRef(addr); |
| 96 | } |
| 97 | |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 98 | static void bta2dp_connection_priority_callback(bt_bdaddr_t* bd_addr) { |
| 99 | jbyteArray addr; |
| 100 | |
| 101 | ALOGI("%s", __FUNCTION__); |
| 102 | |
| 103 | if (!checkCallbackThread()) { \ |
| 104 | ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ |
| 105 | return; \ |
| 106 | } |
| 107 | addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); |
| 108 | if (!addr) { |
| 109 | ALOGE("Fail to new jbyteArray bd addr for connection state"); |
| 110 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*) bd_addr); |
| 115 | sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCheckConnectionPriority, addr); |
| 116 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 117 | sCallbackEnv->DeleteLocalRef(addr); |
| 118 | } |
| 119 | |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 120 | static void bta2dp_audio_focus_request_callback(int enable, bt_bdaddr_t* bd_addr) { |
| 121 | jbyteArray addr; |
| 122 | |
| 123 | ALOGI("%s", __FUNCTION__); |
| 124 | |
| 125 | if (!checkCallbackThread()) { \ |
| 126 | ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ |
| 127 | return; \ |
| 128 | } |
| 129 | addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); |
| 130 | if (!addr) { |
| 131 | ALOGE("Fail to new jbyteArray bd addr for connection state"); |
| 132 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*) bd_addr); |
| 137 | sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioFocusRequest, (jint) enable, addr); |
| 138 | checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); |
| 139 | sCallbackEnv->DeleteLocalRef(addr); |
| 140 | } |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 141 | static btav_callbacks_t sBluetoothA2dpCallbacks = { |
| 142 | sizeof(sBluetoothA2dpCallbacks), |
| 143 | bta2dp_connection_state_callback, |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 144 | bta2dp_audio_state_callback, |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 145 | bta2dp_connection_priority_callback, |
| 146 | bta2dp_audio_focus_request_callback |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | static void classInitNative(JNIEnv* env, jclass clazz) { |
| 150 | int err; |
| 151 | const bt_interface_t* btInf; |
| 152 | bt_status_t status; |
| 153 | |
| 154 | method_onConnectionStateChanged = |
| 155 | env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V"); |
| 156 | |
Kausik Sinnaswamy | ac234ef | 2012-04-20 00:24:28 +0530 | [diff] [blame] | 157 | method_onAudioStateChanged = |
| 158 | env->GetMethodID(clazz, "onAudioStateChanged", "(I[B)V"); |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 159 | |
| 160 | method_onCheckConnectionPriority = |
| 161 | env->GetMethodID(clazz, "onCheckConnectionPriority", "([B)V"); |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 162 | |
| 163 | method_onAudioFocusRequest = |
| 164 | env->GetMethodID(clazz, "onAudioFocusRequest", "(I[B)V"); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 165 | /* |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 166 | if ( (btInf = getBluetoothInterface()) == NULL) { |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 167 | ALOGE("Bluetooth module is not loaded"); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 168 | return; |
| 169 | } |
| 170 | |
| 171 | if ( (sBluetoothA2dpInterface = (btav_interface_t *) |
| 172 | btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID)) == NULL) { |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 173 | ALOGE("Failed to get Bluetooth A2DP Interface"); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 174 | return; |
| 175 | } |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 176 | */ |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 177 | |
| 178 | // TODO(BT) do this only once or |
| 179 | // Do we need to do this every time the BT reenables? |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 180 | /* |
| 181 | if ( (status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks)) != BT_STATUS_SUCCESS) { |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 182 | ALOGE("Failed to initialize Bluetooth A2DP, status: %d", status); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 183 | sBluetoothA2dpInterface = NULL; |
| 184 | return; |
| 185 | }*/ |
| 186 | |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 187 | ALOGI("%s: succeeds", __FUNCTION__); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void initNative(JNIEnv *env, jobject object) { |
| 191 | const bt_interface_t* btInf; |
| 192 | bt_status_t status; |
| 193 | |
| 194 | if ( (btInf = getBluetoothInterface()) == NULL) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 195 | ALOGE("Bluetooth module is not loaded"); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 196 | return; |
| 197 | } |
| 198 | |
| 199 | if (sBluetoothA2dpInterface !=NULL) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 200 | ALOGW("Cleaning up A2DP Interface before initializing..."); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 201 | sBluetoothA2dpInterface->cleanup(); |
| 202 | sBluetoothA2dpInterface = NULL; |
| 203 | } |
| 204 | |
| 205 | if (mCallbacksObj != NULL) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 206 | ALOGW("Cleaning up A2DP callback object"); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 207 | env->DeleteGlobalRef(mCallbacksObj); |
| 208 | mCallbacksObj = NULL; |
| 209 | } |
| 210 | |
| 211 | if ( (sBluetoothA2dpInterface = (btav_interface_t *) |
| 212 | btInf->get_profile_interface(BT_PROFILE_ADVANCED_AUDIO_ID)) == NULL) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 213 | ALOGE("Failed to get Bluetooth A2DP Interface"); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 214 | return; |
| 215 | } |
| 216 | |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 217 | if ( (status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks)) != BT_STATUS_SUCCESS) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 218 | ALOGE("Failed to initialize Bluetooth A2DP, status: %d", status); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 219 | sBluetoothA2dpInterface = NULL; |
| 220 | return; |
| 221 | } |
| 222 | |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 223 | mCallbacksObj = env->NewGlobalRef(object); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 224 | } |
| 225 | |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 226 | static void cleanupNative(JNIEnv *env, jobject object) { |
| 227 | const bt_interface_t* btInf; |
| 228 | bt_status_t status; |
| 229 | |
| 230 | if ( (btInf = getBluetoothInterface()) == NULL) { |
Matthew Xie | e469f16 | 2012-06-05 23:57:59 -0700 | [diff] [blame] | 231 | ALOGE("Bluetooth module is not loaded"); |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 232 | return; |
| 233 | } |
| 234 | |
| 235 | if (sBluetoothA2dpInterface !=NULL) { |
| 236 | sBluetoothA2dpInterface->cleanup(); |
| 237 | sBluetoothA2dpInterface = NULL; |
| 238 | } |
| 239 | |
| 240 | if (mCallbacksObj != NULL) { |
| 241 | env->DeleteGlobalRef(mCallbacksObj); |
| 242 | mCallbacksObj = NULL; |
| 243 | } |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static jboolean connectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) { |
| 247 | jbyte *addr; |
| 248 | bt_bdaddr_t * btAddr; |
| 249 | bt_status_t status; |
| 250 | |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 251 | ALOGI("%s: sBluetoothA2dpInterface: %p", __FUNCTION__, sBluetoothA2dpInterface); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 252 | if (!sBluetoothA2dpInterface) return JNI_FALSE; |
| 253 | |
| 254 | addr = env->GetByteArrayElements(address, NULL); |
| 255 | btAddr = (bt_bdaddr_t *) addr; |
| 256 | if (!addr) { |
| 257 | jniThrowIOException(env, EINVAL); |
| 258 | return JNI_FALSE; |
| 259 | } |
| 260 | |
| 261 | if ((status = sBluetoothA2dpInterface->connect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { |
Matthew Xie | c55a983 | 2012-04-07 03:44:13 -0700 | [diff] [blame] | 262 | ALOGE("Failed HF connection, status: %d", status); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 263 | } |
| 264 | env->ReleaseByteArrayElements(address, addr, 0); |
| 265 | return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; |
| 266 | } |
| 267 | |
| 268 | static jboolean disconnectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) { |
| 269 | jbyte *addr; |
| 270 | bt_status_t status; |
| 271 | |
| 272 | if (!sBluetoothA2dpInterface) return JNI_FALSE; |
| 273 | |
| 274 | addr = env->GetByteArrayElements(address, NULL); |
| 275 | if (!addr) { |
| 276 | jniThrowIOException(env, EINVAL); |
| 277 | return JNI_FALSE; |
| 278 | } |
| 279 | |
| 280 | if ( (status = sBluetoothA2dpInterface->disconnect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 281 | ALOGE("Failed A2DP disconnection, status: %d", status); |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 282 | } |
| 283 | env->ReleaseByteArrayElements(address, addr, 0); |
| 284 | return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; |
| 285 | } |
| 286 | |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 287 | static void allowConnectionNative(JNIEnv *env, jobject object, int is_valid) { |
| 288 | |
| 289 | if (!sBluetoothA2dpInterface) { |
| 290 | ALOGE("sBluetoothA2dpInterface is NULL "); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | sBluetoothA2dpInterface->allow_connection(is_valid); |
| 295 | |
| 296 | } |
| 297 | |
Gubbala Venugopal Rao | 819d65f | 2014-01-02 16:35:12 +0530 | [diff] [blame] | 298 | static void informAudioFocusStateNative(JNIEnv *env, jobject object, int state) { |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 299 | |
| 300 | if (!sBluetoothA2dpInterface) { |
| 301 | ALOGE("sBluetoothA2dpInterface is NULL "); |
| 302 | return; |
| 303 | } |
Gubbala Venugopal Rao | 819d65f | 2014-01-02 16:35:12 +0530 | [diff] [blame] | 304 | sBluetoothA2dpInterface->audio_focus_status(state); |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 305 | |
| 306 | } |
| 307 | |
Gaurav Asati | 00af3b0 | 2014-02-27 14:39:20 +0530 | [diff] [blame] | 308 | static jint isSrcNative(JNIEnv *env, jobject object, jbyteArray address) { |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 309 | jbyte *addr; |
| 310 | bt_status_t status; |
| 311 | |
AnubhavGupta | 851de92 | 2014-03-15 18:39:01 +0530 | [diff] [blame] | 312 | if (!sBluetoothA2dpInterface) { |
| 313 | ALOGE("sBluetoothA2dpInterface is NULL "); |
| 314 | return JNI_FALSE; |
| 315 | } |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 316 | |
| 317 | addr = env->GetByteArrayElements(address, NULL); |
| 318 | if (!addr) { |
| 319 | jniThrowIOException(env, EINVAL); |
| 320 | return JNI_FALSE; |
| 321 | } |
| 322 | |
AnubhavGupta | 851de92 | 2014-03-15 18:39:01 +0530 | [diff] [blame] | 323 | status = sBluetoothA2dpInterface->is_src((bt_bdaddr_t *)addr); |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 324 | env->ReleaseByteArrayElements(address, addr, 0); |
Gaurav Asati | 00af3b0 | 2014-02-27 14:39:20 +0530 | [diff] [blame] | 325 | return status; |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void suspendA2dpNative(JNIEnv *env, jobject object) { |
| 329 | |
| 330 | if (!sBluetoothA2dpInterface) { |
| 331 | ALOGE("sBluetoothA2dpInterface is NULL "); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | sBluetoothA2dpInterface->suspend_sink(); |
| 336 | } |
| 337 | |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 338 | static void resumeA2dpNative(JNIEnv *env, jobject object) { |
| 339 | |
| 340 | if (!sBluetoothA2dpInterface) { |
| 341 | ALOGE("sBluetoothA2dpInterface is NULL "); |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | sBluetoothA2dpInterface->resume_sink(); |
| 346 | } |
| 347 | |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 348 | |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 349 | static JNINativeMethod sMethods[] = { |
| 350 | {"classInitNative", "()V", (void *) classInitNative}, |
fredc | 6654f5c | 2012-04-12 00:18:52 -0700 | [diff] [blame] | 351 | {"initNative", "()V", (void *) initNative}, |
| 352 | {"cleanupNative", "()V", (void *) cleanupNative}, |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 353 | {"connectA2dpNative", "([B)Z", (void *) connectA2dpNative}, |
| 354 | {"disconnectA2dpNative", "([B)Z", (void *) disconnectA2dpNative}, |
Gaurav Asati | d2584b6 | 2013-10-09 14:07:46 +0530 | [diff] [blame] | 355 | {"allowConnectionNative", "(I)V", (void *) allowConnectionNative}, |
Gaurav Asati | 00af3b0 | 2014-02-27 14:39:20 +0530 | [diff] [blame] | 356 | {"isSrcNative", "([B)I", (void *) isSrcNative}, |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 357 | {"suspendA2dpNative", "()V", (void *) suspendA2dpNative}, |
AnubhavGupta | d4b2838 | 2013-11-28 20:16:20 +0530 | [diff] [blame] | 358 | {"resumeA2dpNative", "()V", (void *) resumeA2dpNative}, |
| 359 | {"informAudioFocusStateNative", "(I)V", (void *) informAudioFocusStateNative}, |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | int register_com_android_bluetooth_a2dp(JNIEnv* env) |
| 363 | { |
Anubhav Gupta | de7eb80 | 2013-11-08 14:18:37 +0530 | [diff] [blame] | 364 | return jniRegisterNativeMethods(env, "com/android/bluetooth/a2dp/A2dpStateMachine", |
Matthew Xie | 6c91bc0 | 2012-02-16 18:47:53 -0800 | [diff] [blame] | 365 | sMethods, NELEM(sMethods)); |
| 366 | } |
| 367 | |
| 368 | } |