diff options
author | Ayan Ghosh <abghosh@codeaurora.org> | 2015-12-04 18:48:27 +0530 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2016-12-30 06:30:59 +0200 |
commit | 86f300eabc71ba2aeef13d2fd1482cc0be4bc32f (patch) | |
tree | 623cf1cecce2b47b20ab3b69c4d05f2ad292338c | |
parent | 66fde3337a450e6c8a2b7b6b96bcd3bc8c5a1f55 (diff) | |
download | android_packages_apps_Bluetooth-86f300eabc71ba2aeef13d2fd1482cc0be4bc32f.tar.gz android_packages_apps_Bluetooth-86f300eabc71ba2aeef13d2fd1482cc0be4bc32f.tar.bz2 android_packages_apps_Bluetooth-86f300eabc71ba2aeef13d2fd1482cc0be4bc32f.zip |
Fix to avoid JNI crashes
For quick BT turn on/off cases there may be instances
where callback from btif is triggered even before
callback object is created or cleanup path may clear
callback object just before stray btif callback call
tries to access the same. These checks will help
prevent those unwanted crashes.
Change-Id: I9b793ed1d703ac616ed357694a365986707ee376
-rw-r--r-- | jni/com_android_bluetooth_a2dp.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp index 48649d23e..7d13f3a01 100644 --- a/jni/com_android_bluetooth_a2dp.cpp +++ b/jni/com_android_bluetooth_a2dp.cpp @@ -58,10 +58,15 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_b ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ } + addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); if (!addr) { ALOGE("Fail to new jbyteArray bd addr for connection state"); @@ -81,6 +86,10 @@ static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* b ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ @@ -104,6 +113,10 @@ static void bta2dp_connection_priority_callback(bt_bdaddr_t* bd_addr) { ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ @@ -125,6 +138,10 @@ static void bta2dp_multicast_enabled_callback(int state) { ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ @@ -224,6 +241,11 @@ static void initNative(JNIEnv *env, jobject object, jint maxA2dpConnections, offload_capabilities)) != BT_STATUS_SUCCESS) { ALOGE("Failed to initialize Bluetooth A2DP, status: %d", status); sBluetoothA2dpInterface = NULL; + if (mCallbacksObj != NULL) { + ALOGW("Clean up A2DP callback object"); + env->DeleteGlobalRef(mCallbacksObj); + mCallbacksObj = NULL; + } return; } } |