Caching callbackEnv in HFP/A2DP JNI results in the ENV going out-of-syn after an disassociate_evt/associate_evt sequence. Removed the caching.
Change-Id: Iebe3d2b3fa632c3332be82291bf32ace62c30ad5
diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp
index 0edf4b4..ebc23a5 100644
--- a/jni/com_android_bluetooth_a2dp.cpp
+++ b/jni/com_android_bluetooth_a2dp.cpp
@@ -20,9 +20,13 @@
static JNIEnv *sCallbackEnv = NULL;
static bool checkCallbackThread() {
- if (sCallbackEnv == NULL) {
- sCallbackEnv = getCallbackEnv();
- }
+ // Always fetch the latest callbackEnv from AdapterService.
+ // Caching this could cause this sCallbackEnv to go out-of-sync
+ // with the AdapterService's ENV if an ASSOCIATE/DISASSOCIATE event
+ // is received
+ //if (sCallbackEnv == NULL) {
+ sCallbackEnv = getCallbackEnv();
+ //}
JNIEnv* env = AndroidRuntime::getJNIEnv();
if (sCallbackEnv != env || sCallbackEnv == NULL) return false;
diff --git a/jni/com_android_bluetooth_hfp.cpp b/jni/com_android_bluetooth_hfp.cpp
index 6b4c61e..f8b0b16 100644
--- a/jni/com_android_bluetooth_hfp.cpp
+++ b/jni/com_android_bluetooth_hfp.cpp
@@ -43,10 +43,13 @@
static JNIEnv *sCallbackEnv = NULL;
static bool checkCallbackThread() {
- if (sCallbackEnv == NULL) {
- sCallbackEnv = getCallbackEnv();
- }
-
+ // Always fetch the latest callbackEnv from AdapterService.
+ // Caching this could cause this sCallbackEnv to go out-of-sync
+ // with the AdapterService's ENV if an ASSOCIATE/DISASSOCIATE event
+ // is received
+ //if (sCallbackEnv == NULL) {
+ sCallbackEnv = getCallbackEnv();
+ //}
JNIEnv* env = AndroidRuntime::getJNIEnv();
if (sCallbackEnv != env || sCallbackEnv == NULL) return false;
return true;