com_android_bluetooth_hfp.cpp revision 69d4ca45a25e86823fbdb754ca6a3995f8131d59
16c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie/* 2ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * Copyright (C) 2012 The Android Open Source Project 3ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * 4ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * Licensed under the Apache License, Version 2.0 (the "License"); 5ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * you may not use this file except in compliance with the License. 6ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * You may obtain a copy of the License at 7ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * 8ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * http://www.apache.org/licenses/LICENSE-2.0 9ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * 10ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * Unless required by applicable law or agreed to in writing, software 11ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * distributed under the License is distributed on an "AS IS" BASIS, 12ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * See the License for the specific language governing permissions and 14ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * limitations under the License. 156c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie */ 166c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 176c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#define LOG_TAG "BluetoothHeadsetServiceJni" 186c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 196c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#define LOG_NDEBUG 0 206c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 216c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#define CHECK_CALLBACK_ENV \ 226c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!checkCallbackThread()) { \ 23c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);\ 246c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return; \ 256c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 266c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 276c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#include "com_android_bluetooth.h" 286c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#include "hardware/bt_hf.h" 296c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#include "utils/Log.h" 306c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#include "android_runtime/AndroidRuntime.h" 316c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 326c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie#include <string.h> 336c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 346c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xienamespace android { 356c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 366c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onConnectionStateChanged; 376c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAudioStateChanged; 386c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onVrStateChanged; 396c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAnswerCall; 406c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onHangupCall; 416c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onVolumeChanged; 426c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onDialCall; 436c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onSendDtmf; 446c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onNoiceReductionEnable; 456c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAtChld; 466c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAtCnum; 476c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAtCind; 486c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAtCops; 496c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onAtClcc; 506c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onUnknownAt; 516c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jmethodID method_onKeyPressed; 526c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 536c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic const bthf_interface_t *sBluetoothHfpInterface = NULL; 546c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jobject mCallbacksObj = NULL; 556c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic JNIEnv *sCallbackEnv = NULL; 566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic bool checkCallbackThread() { 5893f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy // Always fetch the latest callbackEnv from AdapterService. 5993f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy // Caching this could cause this sCallbackEnv to go out-of-sync 6093f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy // with the AdapterService's ENV if an ASSOCIATE/DISASSOCIATE event 6193f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy // is received 6293f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy //if (sCallbackEnv == NULL) { 6393f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy sCallbackEnv = getCallbackEnv(); 6493f548ff8560bdecdc4bdd2f91f7dacda1e6bbc3Kausik Sinnaswamy //} 656c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie JNIEnv* env = AndroidRuntime::getJNIEnv(); 666c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (sCallbackEnv != env || sCallbackEnv == NULL) return false; 676c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return true; 686c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 696c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 706c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic void connection_state_callback(bthf_connection_state_t state, bt_bdaddr_t* bd_addr) { 716c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jbyteArray addr; 726c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 73c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGI("%s", __FUNCTION__); 746c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 756c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 766c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 776c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!addr) { 78c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Fail to new jbyteArray bd addr for connection state"); 796c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 806c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return; 816c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 826c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 836c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*) bd_addr); 846c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, 856c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie (jint) state, addr); 866c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 876c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->DeleteLocalRef(addr); 886c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 896c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 906c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic void audio_state_callback(bthf_audio_state_t state, bt_bdaddr_t* bd_addr) { 916c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jbyteArray addr; 926c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 936c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 946c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 956c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!addr) { 96c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Fail to new jbyteArray bd addr for audio state"); 976c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 986c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return; 996c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 1006c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 1016c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 1026c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, (jint) state, addr); 1036c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 1046c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->DeleteLocalRef(addr); 1056c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 1066c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 10769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void voice_recognition_callback(bthf_vr_state_t state, bt_bdaddr_t* bd_addr) { 10869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 10969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 1106c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 11169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 11269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 11369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 11469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 11569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 11669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 11769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 11869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 11969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVrStateChanged, (jint) state, addr); 1206c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 12169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 1226c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 1236c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 12469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void answer_call_callback(bt_bdaddr_t* bd_addr) { 12569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 12669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 1276c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 12869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 12969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 13069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 13169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 13269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 13369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 13469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 13569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 13669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAnswerCall, addr); 1376c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 13869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 1396c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 1406c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 14169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void hangup_call_callback(bt_bdaddr_t* bd_addr) { 14269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 14369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 1446c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 14569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 14669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 14769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 14869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 14969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 15069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 15169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 15269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 15369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onHangupCall, addr); 1546c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 15569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 1566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 1576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 15869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void volume_control_callback(bthf_volume_type_t type, int volume, bt_bdaddr_t* bd_addr) { 15969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 16069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 1616c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 16269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 16369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 16469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 16569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 16669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 16769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 16869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 16969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 17069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVolumeChanged, (jint) type, 17169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava (jint) volume, addr); 1726c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 17369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 1746c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 1756c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 17669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void dial_call_callback(char *number, bt_bdaddr_t* bd_addr) { 17769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 17869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 1796c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 18069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 18169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 18269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 18369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 18469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 18569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 18669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 18769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 188976912e5f597f015754aa67f2a74040e27f58eabSyed Ibrahim M jstring js_number = sCallbackEnv->NewStringUTF(number); 1896c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onDialCall, 19069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava js_number, addr); 1916c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 192976912e5f597f015754aa67f2a74040e27f58eabSyed Ibrahim M sCallbackEnv->DeleteLocalRef(js_number); 19369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 1946c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 1956c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 19669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void dtmf_cmd_callback(char dtmf, bt_bdaddr_t* bd_addr) { 19769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 19869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 1996c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 20069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 20169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 20269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 20369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 20469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 20569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 20669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 20769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 2086c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie // TBD dtmf has changed from int to char 20969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onSendDtmf, dtmf, addr); 2106c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 21169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 2126c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 2136c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 21469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void noice_reduction_callback(bthf_nrec_t nrec, bt_bdaddr_t* bd_addr) { 21569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 21669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 2176c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 21869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 21969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 22069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 22169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 22269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 22369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 22469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 2256c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNoiceReductionEnable, 22669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava nrec == BTHF_NREC_START, addr); 2276c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 22869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 2296c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 2306c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 23169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void at_chld_callback(bthf_chld_type_t chld, bt_bdaddr_t* bd_addr) { 23269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 23369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 2346c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 23569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 23669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 23769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 23869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 23969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 24069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 24169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 24269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 24369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtChld, chld, addr); 2446c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 24569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 2466c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 2476c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 24869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void at_cnum_callback(bt_bdaddr_t* bd_addr) { 24969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 25069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 2516c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 25269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 25369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 25469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 25569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 25669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 25769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 25869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 25969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 26069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtCnum, addr); 2616c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 26269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 2636c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 2646c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 26569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void at_cind_callback(bt_bdaddr_t* bd_addr) { 26669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 26769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 2686c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 26969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 27069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 27169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 27269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 27369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 27469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 27569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 27669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 27769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtCind, addr); 2786c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 27969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 2806c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 2816c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 28269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void at_cops_callback(bt_bdaddr_t* bd_addr) { 28369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 28469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 2856c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 28669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 28769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 28869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 28969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 29069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 29169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 29269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 29369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 29469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtCops, addr); 2956c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 29669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 2976c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 2986c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 29969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void at_clcc_callback(bt_bdaddr_t* bd_addr) { 30069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 30169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 3026c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 30369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 30469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 30569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 30669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 30769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 30869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 30969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 31069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 31169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtClcc, addr); 3126c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 31369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 3146c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 3156c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 31669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void unknown_at_callback(char *at_string, bt_bdaddr_t* bd_addr) { 31769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 31869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 3196c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 32069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 32169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 32269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 32369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 32469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 32569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 32669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 32769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 328976912e5f597f015754aa67f2a74040e27f58eabSyed Ibrahim M jstring js_at_string = sCallbackEnv->NewStringUTF(at_string); 3296c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onUnknownAt, 33069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava js_at_string, addr); 3316c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 332976912e5f597f015754aa67f2a74040e27f58eabSyed Ibrahim M sCallbackEnv->DeleteLocalRef(js_at_string); 33369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 3346c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 3356c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 33669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void key_pressed_callback(bt_bdaddr_t* bd_addr) { 33769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray addr; 33869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 3396c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie CHECK_CALLBACK_ENV 34069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); 34169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 34269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGE("Fail to new jbyteArray bd addr for audio state"); 34369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 34469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return; 34569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 34669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 34769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); 34869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onKeyPressed, addr); 3496c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); 35069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava sCallbackEnv->DeleteLocalRef(addr); 3516c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 3526c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 3536c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic bthf_callbacks_t sBluetoothHfpCallbacks = { 3546c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sizeof(sBluetoothHfpCallbacks), 3556c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie connection_state_callback, 3566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie audio_state_callback, 3576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie voice_recognition_callback, 3586c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie answer_call_callback, 3596c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie hangup_call_callback, 3606c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie volume_control_callback, 3616c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie dial_call_callback, 3626c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie dtmf_cmd_callback, 3636c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie noice_reduction_callback, 3646c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie at_chld_callback, 3656c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie at_cnum_callback, 3666c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie at_cind_callback, 3676c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie at_cops_callback, 3686c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie at_clcc_callback, 3696c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie unknown_at_callback, 3706c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie key_pressed_callback 3716c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie}; 3726c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 3736c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic void classInitNative(JNIEnv* env, jclass clazz) { 3746c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie int err; 3756654f5c903de510a70f9e72cd5ad7837b615d93ffredc /* 3766c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie const bt_interface_t* btInf; 3776c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 3786654f5c903de510a70f9e72cd5ad7837b615d93ffredc */ 3796c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 3806c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie method_onConnectionStateChanged = 3816c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V"); 3826c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie method_onAudioStateChanged = env->GetMethodID(clazz, "onAudioStateChanged", "(I[B)V"); 38369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onVrStateChanged = env->GetMethodID(clazz, "onVrStateChanged", "(I[B)V"); 38469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onAnswerCall = env->GetMethodID(clazz, "onAnswerCall", "([B)V"); 38569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onHangupCall = env->GetMethodID(clazz, "onHangupCall", "([B)V"); 38669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onVolumeChanged = env->GetMethodID(clazz, "onVolumeChanged", "(II[B)V"); 38769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onDialCall = env->GetMethodID(clazz, "onDialCall", "(Ljava/lang/String;[B)V"); 38869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onSendDtmf = env->GetMethodID(clazz, "onSendDtmf", "(I[B)V"); 38969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onNoiceReductionEnable = env->GetMethodID(clazz, "onNoiceReductionEnable", "(Z[B)V"); 39069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onAtChld = env->GetMethodID(clazz, "onAtChld", "(I[B)V"); 39169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onAtCnum = env->GetMethodID(clazz, "onAtCnum", "([B)V"); 39269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onAtCind = env->GetMethodID(clazz, "onAtCind", "([B)V"); 39369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onAtCops = env->GetMethodID(clazz, "onAtCops", "([B)V"); 39469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onAtClcc = env->GetMethodID(clazz, "onAtClcc", "([B)V"); 39569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onUnknownAt = env->GetMethodID(clazz, "onUnknownAt", "(Ljava/lang/String;[B)V"); 39669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava method_onKeyPressed = env->GetMethodID(clazz, "onKeyPressed", "([B)V"); 3976c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 3986654f5c903de510a70f9e72cd5ad7837b615d93ffredc /* 3996c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (btInf = getBluetoothInterface()) == NULL) { 400c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Bluetooth module is not loaded"); 4016c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return; 4026c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 4036c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 4046c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (sBluetoothHfpInterface = (bthf_interface_t *) 4056c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie btInf->get_profile_interface(BT_PROFILE_HANDSFREE_ID)) == NULL) { 406c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed to get Bluetooth Handsfree Interface"); 4076c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return; 4086c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 4096c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 4106c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie // TODO(BT) do this only once or 4116c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie // Do we need to do this every time the BT reenables? 4126c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->init(&sBluetoothHfpCallbacks)) != BT_STATUS_SUCCESS) { 413c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed to initialize Bluetooth HFP, status: %d", status); 4146c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sBluetoothHfpInterface = NULL; 4156c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return; 4166c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 4176654f5c903de510a70f9e72cd5ad7837b615d93ffredc */ 4186c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 419c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGI("%s: succeeds", __FUNCTION__); 4206c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 4216c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 42269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic void initializeNative(JNIEnv *env, jobject object, jint max_hf_clients) { 4236654f5c903de510a70f9e72cd5ad7837b615d93ffredc const bt_interface_t* btInf; 4246654f5c903de510a70f9e72cd5ad7837b615d93ffredc bt_status_t status; 4256654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4266654f5c903de510a70f9e72cd5ad7837b615d93ffredc if ( (btInf = getBluetoothInterface()) == NULL) { 427e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGE("Bluetooth module is not loaded"); 4286654f5c903de510a70f9e72cd5ad7837b615d93ffredc return; 4296654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4306654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4316654f5c903de510a70f9e72cd5ad7837b615d93ffredc if (sBluetoothHfpInterface !=NULL) { 432e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGW("Cleaning up Bluetooth Handsfree Interface before initializing..."); 4336654f5c903de510a70f9e72cd5ad7837b615d93ffredc sBluetoothHfpInterface->cleanup(); 4346654f5c903de510a70f9e72cd5ad7837b615d93ffredc sBluetoothHfpInterface = NULL; 4356654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4366654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4376654f5c903de510a70f9e72cd5ad7837b615d93ffredc if (mCallbacksObj != NULL) { 438e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGW("Cleaning up Bluetooth Handsfree callback object"); 4396654f5c903de510a70f9e72cd5ad7837b615d93ffredc env->DeleteGlobalRef(mCallbacksObj); 4406654f5c903de510a70f9e72cd5ad7837b615d93ffredc mCallbacksObj = NULL; 4416654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4426654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4436654f5c903de510a70f9e72cd5ad7837b615d93ffredc if ( (sBluetoothHfpInterface = (bthf_interface_t *) 4446654f5c903de510a70f9e72cd5ad7837b615d93ffredc btInf->get_profile_interface(BT_PROFILE_HANDSFREE_ID)) == NULL) { 445e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGE("Failed to get Bluetooth Handsfree Interface"); 4466654f5c903de510a70f9e72cd5ad7837b615d93ffredc return; 4476654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4486654f5c903de510a70f9e72cd5ad7837b615d93ffredc 44969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if ( (status = sBluetoothHfpInterface->init(&sBluetoothHfpCallbacks, 45069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava max_hf_clients)) != BT_STATUS_SUCCESS) { 451e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGE("Failed to initialize Bluetooth HFP, status: %d", status); 4526654f5c903de510a70f9e72cd5ad7837b615d93ffredc sBluetoothHfpInterface = NULL; 4536654f5c903de510a70f9e72cd5ad7837b615d93ffredc return; 4546654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4556654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie mCallbacksObj = env->NewGlobalRef(object); 4576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 4586c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 4596654f5c903de510a70f9e72cd5ad7837b615d93ffredcstatic void cleanupNative(JNIEnv *env, jobject object) { 4606654f5c903de510a70f9e72cd5ad7837b615d93ffredc const bt_interface_t* btInf; 4616654f5c903de510a70f9e72cd5ad7837b615d93ffredc bt_status_t status; 4626654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4636654f5c903de510a70f9e72cd5ad7837b615d93ffredc if ( (btInf = getBluetoothInterface()) == NULL) { 464e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGE("Bluetooth module is not loaded"); 4656654f5c903de510a70f9e72cd5ad7837b615d93ffredc return; 4666654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4676654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4686654f5c903de510a70f9e72cd5ad7837b615d93ffredc if (sBluetoothHfpInterface !=NULL) { 469e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGW("Cleaning up Bluetooth Handsfree Interface..."); 4706654f5c903de510a70f9e72cd5ad7837b615d93ffredc sBluetoothHfpInterface->cleanup(); 4716654f5c903de510a70f9e72cd5ad7837b615d93ffredc sBluetoothHfpInterface = NULL; 4726654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4736654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4746654f5c903de510a70f9e72cd5ad7837b615d93ffredc if (mCallbacksObj != NULL) { 475e469f16e5a7d99471d7db1b216d422e8d12cc4cfMatthew Xie ALOGW("Cleaning up Bluetooth Handsfree callback object"); 4766654f5c903de510a70f9e72cd5ad7837b615d93ffredc env->DeleteGlobalRef(mCallbacksObj); 4776654f5c903de510a70f9e72cd5ad7837b615d93ffredc mCallbacksObj = NULL; 4786654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 4796654f5c903de510a70f9e72cd5ad7837b615d93ffredc} 4806654f5c903de510a70f9e72cd5ad7837b615d93ffredc 4816c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean connectHfpNative(JNIEnv *env, jobject object, jbyteArray address) { 4826c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jbyte *addr; 4836c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 4846c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 485c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGI("%s: sBluetoothHfpInterface: %p", __FUNCTION__, sBluetoothHfpInterface); 4866c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 4876c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 4886c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie addr = env->GetByteArrayElements(address, NULL); 4896c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!addr) { 4906c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jniThrowIOException(env, EINVAL); 4916c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return JNI_FALSE; 4926c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 4936c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 4946c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ((status = sBluetoothHfpInterface->connect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { 495c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed HF connection, status: %d", status); 4966c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 4976c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseByteArrayElements(address, addr, 0); 4986c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 4996c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 5006c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5016c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean disconnectHfpNative(JNIEnv *env, jobject object, jbyteArray address) { 5026c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jbyte *addr; 5036c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 5046c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5056c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 5066c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5076c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie addr = env->GetByteArrayElements(address, NULL); 5086c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!addr) { 5096c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jniThrowIOException(env, EINVAL); 5106c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return JNI_FALSE; 5116c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 5126c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5136c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->disconnect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { 514c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed HF disconnection, status: %d", status); 5156c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 5166c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseByteArrayElements(address, addr, 0); 5176c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 5186c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 5196c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5206c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean connectAudioNative(JNIEnv *env, jobject object, jbyteArray address) { 5216c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jbyte *addr; 5226c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 5236c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5246c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 5256c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5266c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie addr = env->GetByteArrayElements(address, NULL); 5276c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!addr) { 5286c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jniThrowIOException(env, EINVAL); 5296c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return JNI_FALSE; 5306c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 5316c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5326c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->connect_audio((bt_bdaddr_t *)addr)) != 5336c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie BT_STATUS_SUCCESS) { 534c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed HF audio connection, status: %d", status); 5356c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 5366c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseByteArrayElements(address, addr, 0); 5376c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 5386c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 5396c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5406c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean disconnectAudioNative(JNIEnv *env, jobject object, jbyteArray address) { 5416c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jbyte *addr; 5426c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 5436c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5446c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 5456c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5466c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie addr = env->GetByteArrayElements(address, NULL); 5476c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!addr) { 5486c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jniThrowIOException(env, EINVAL); 5496c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return JNI_FALSE; 5506c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 5516c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 5526c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->disconnect_audio((bt_bdaddr_t *) addr)) != 5536c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie BT_STATUS_SUCCESS) { 554c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed HF audio disconnection, status: %d", status); 5556c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 5566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseByteArrayElements(address, addr, 0); 5576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 5586c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 5596c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 56069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic jboolean startVoiceRecognitionNative(JNIEnv *env, jobject object, jbyteArray address) { 56169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 5626c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 5636c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 5646c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 56569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 56669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 56769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 56869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 56969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 57069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 57169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if ( (status = sBluetoothHfpInterface->start_voice_recognition((bt_bdaddr_t *) addr)) 57269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava != BT_STATUS_SUCCESS) { 573c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed to start voice recognition, status: %d", status); 5746c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 57569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 5766c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 5776c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 5786c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 57969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic jboolean stopVoiceRecognitionNative(JNIEnv *env, jobject object, jbyteArray address) { 58069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 5816c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 5826c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 5836c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 58469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 58569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 58669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 58769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 58869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 58969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 59069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if ( (status = sBluetoothHfpInterface->stop_voice_recognition((bt_bdaddr_t *) addr)) 59169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava != BT_STATUS_SUCCESS) { 592c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed to stop voice recognition, status: %d", status); 5936c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 59469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 5956c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 5966c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 5976c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 59869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic jboolean setVolumeNative(JNIEnv *env, jobject object, jint volume_type, 59969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jint volume, jbyteArray address) { 60069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 6016c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 6026c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 6036c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 60469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 60569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 60669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 60769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 60869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 60969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 6106c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->volume_control((bthf_volume_type_t) volume_type, 61169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava volume, (bt_bdaddr_t *) addr)) != BT_STATUS_SUCCESS) { 612c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("FAILED to control volume, status: %d", status); 6136c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 61469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 6156c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 6166c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 6176c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 6186c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean notifyDeviceStatusNative(JNIEnv *env, jobject object, 6196c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jint network_state, jint service_type, jint signal, 6206c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jint battery_charge) { 6216c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 6226c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 6236c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 6246c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->device_status_notification 6256c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie ((bthf_network_state_t) network_state, (bthf_service_type_t) service_type, 6266c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie signal, battery_charge)) != BT_STATUS_SUCCESS) { 627c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("FAILED to notify device status, status: %d", status); 6286c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 6296c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 6306c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 6316c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 63269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic jboolean copsResponseNative(JNIEnv *env, jobject object, jstring operator_str, 63369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray address) { 63469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 6356c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 6366c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie const char *operator_name; 6376c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 6386c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 63969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 64069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 64169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 64269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 64369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 64469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 6456c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie operator_name = env->GetStringUTFChars(operator_str, NULL); 6466c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 64769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if ( (status = sBluetoothHfpInterface->cops_response(operator_name,(bt_bdaddr_t *) addr)) 64869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava != BT_STATUS_SUCCESS) { 649c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed sending cops response, status: %d", status); 6506c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 65169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 6526c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseStringUTFChars(operator_str, operator_name); 6536c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 6546c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 6556c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 6566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean cindResponseNative(JNIEnv *env, jobject object, 6576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jint service, jint num_active, jint num_held, jint call_state, 65869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jint signal, jint roam, jint battery_charge, jbyteArray address) { 65969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 6606c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 66169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 66269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava ALOGI("%s: sBluetoothHfpInterface: %p", __FUNCTION__, sBluetoothHfpInterface); 6636c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 6646c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 66569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 66669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 66769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 66869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 66969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 67069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 6716c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->cind_response(service, num_active, num_held, 6726c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie (bthf_call_state_t) call_state, 67369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava signal, roam, battery_charge, (bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { 674c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed cind_response, status: %d", status); 6756c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 67669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 6776c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 6786c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 6796c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 6806c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 68169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic jboolean atResponseStringNative(JNIEnv *env, jobject object, jstring response_str, 68269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyteArray address) { 68369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 6846c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 6856c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie const char *response; 6866c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 6876c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 68869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 68969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 69069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 69169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 69269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 69369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 6946c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie response = env->GetStringUTFChars(response_str, NULL); 6956c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 69669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if ( (status = sBluetoothHfpInterface->formatted_at_response(response, 69769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava (bt_bdaddr_t *)addr))!= BT_STATUS_SUCCESS) { 698c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed formatted AT response, status: %d", status); 6996c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 70069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 7016c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseStringUTFChars(response_str, response); 7026c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 7036c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 7046c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 70569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastavastatic jboolean atResponseCodeNative(JNIEnv *env, jobject object, jint response_code, 70669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jint cmee_code, jbyteArray address) { 70769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 7086c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 7096c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 7106c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 71169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 71269d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 71369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 71469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 71569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 71669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 71769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if ( (status = sBluetoothHfpInterface->at_response((bthf_at_response_t) response_code, 71869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava cmee_code, (bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { 719c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed AT response, status: %d", status); 7206c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 72169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 7226c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 7236c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 7246c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7256c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean clccResponseNative(JNIEnv *env, jobject object, jint index, jint dir, 7266c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jint callStatus, jint mode, jboolean mpty, jstring number_str, 72769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jint type, jbyteArray address) { 72869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jbyte *addr; 7296c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 730bbbfba6398ac613896a4456fae1c9bf909c28bf2Ravi Nagarajan const char *number = NULL; 7316c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 7326c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 73369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava addr = env->GetByteArrayElements(address, NULL); 73469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava if (!addr) { 73569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava jniThrowIOException(env, EINVAL); 73669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava return JNI_FALSE; 73769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava } 73869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava 739bbbfba6398ac613896a4456fae1c9bf909c28bf2Ravi Nagarajan if (number_str) 740bbbfba6398ac613896a4456fae1c9bf909c28bf2Ravi Nagarajan number = env->GetStringUTFChars(number_str, NULL); 7416c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7426c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->clcc_response(index, (bthf_call_direction_t) dir, 74369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava (bthf_call_state_t) callStatus, (bthf_call_mode_t) mode, 74469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava mpty ? BTHF_CALL_MPTY_TYPE_MULTI : BTHF_CALL_MPTY_TYPE_SINGLE, 74569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava number, (bthf_call_addrtype_t) type, (bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) { 746c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed sending CLCC response, status: %d", status); 7476c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 74869d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava env->ReleaseByteArrayElements(address, addr, 0); 749bbbfba6398ac613896a4456fae1c9bf909c28bf2Ravi Nagarajan if (number) 750bbbfba6398ac613896a4456fae1c9bf909c28bf2Ravi Nagarajan env->ReleaseStringUTFChars(number_str, number); 7516c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 7526c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 7536c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7546c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic jboolean phoneStateChangeNative(JNIEnv *env, jobject object, jint num_active, jint num_held, 7556c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie jint call_state, jstring number_str, jint type) { 7566c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie bt_status_t status; 7576c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie const char *number; 7586c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if (!sBluetoothHfpInterface) return JNI_FALSE; 7596c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7606c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie number = env->GetStringUTFChars(number_str, NULL); 7616c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7626c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie if ( (status = sBluetoothHfpInterface->phone_state_change(num_active, num_held, 7636c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie (bthf_call_state_t) call_state, number, 7646c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie (bthf_call_addrtype_t) type)) != BT_STATUS_SUCCESS) { 765c55a9837c004044051b71bb47182ace156691283Matthew Xie ALOGE("Failed report phone state change, status: %d", status); 7666c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie } 7676c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie env->ReleaseStringUTFChars(number_str, number); 7686c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; 7696c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 7706c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7716c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xiestatic JNINativeMethod sMethods[] = { 7726c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"classInitNative", "()V", (void *) classInitNative}, 77369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"initializeNative", "(I)V", (void *) initializeNative}, 7746654f5c903de510a70f9e72cd5ad7837b615d93ffredc {"cleanupNative", "()V", (void *) cleanupNative}, 7756c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"connectHfpNative", "([B)Z", (void *) connectHfpNative}, 7766c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"disconnectHfpNative", "([B)Z", (void *) disconnectHfpNative}, 7776c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"connectAudioNative", "([B)Z", (void *) connectAudioNative}, 7786c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"disconnectAudioNative", "([B)Z", (void *) disconnectAudioNative}, 77969d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"startVoiceRecognitionNative", "([B)Z", (void *) startVoiceRecognitionNative}, 78069d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"stopVoiceRecognitionNative", "([B)Z", (void *) stopVoiceRecognitionNative}, 78169d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"setVolumeNative", "(II[B)Z", (void *) setVolumeNative}, 7826c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"notifyDeviceStatusNative", "(IIII)Z", (void *) notifyDeviceStatusNative}, 78369d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"copsResponseNative", "(Ljava/lang/String;[B)Z", (void *) copsResponseNative}, 78469d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"cindResponseNative", "(IIIIIII[B)Z", (void *) cindResponseNative}, 78569d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"atResponseStringNative", "(Ljava/lang/String;[B)Z", (void *) atResponseStringNative}, 78669d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"atResponseCodeNative", "(II[B)Z", (void *)atResponseCodeNative}, 78769d4ca45a25e86823fbdb754ca6a3995f8131d59Nitin Srivastava {"clccResponseNative", "(IIIIZLjava/lang/String;I[B)Z", (void *) clccResponseNative}, 7886c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie {"phoneStateChangeNative", "(IIILjava/lang/String;I)Z", (void *) phoneStateChangeNative}, 7896c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie}; 7906c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7916c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xieint register_com_android_bluetooth_hfp(JNIEnv* env) 7926c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie{ 7936c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie return jniRegisterNativeMethods(env, "com/android/bluetooth/hfp/HeadsetStateMachine", 7946c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie sMethods, NELEM(sMethods)); 7956c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} 7966c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie 7976c91bc0a163cc7600c40d7fb979777fd911d1ef1Matthew Xie} /* namespace android */ 798