Change-Id: Id959c99a0aa7823d36a0437d0b59972052f3edb9
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
+
+ sCallbackEnv = getCallbackEnv();
JNIEnv* env = AndroidRuntime::getJNIEnv();
if (sCallbackEnv != env || sCallbackEnv == NULL) return false;