@@ -1844,7 +1844,7 @@ private boolean subscribeAction(Operation operation) {
18441844
18451845 addCharacteristic (returnObj , characteristic );
18461846
1847- CallbackContext checkExisting = GetCallback (characteristicUuid , connection , operationSubscribe );
1847+ SequentialCallbackContext checkExisting = GetSequentialCallbackContext (characteristicUuid , connection , operationSubscribe );
18481848 if (checkExisting != null ) {
18491849 addProperty (returnObj , keyError , errorSubscription );
18501850 addProperty (returnObj , keyMessage , logSubscribeAlready );
@@ -1878,7 +1878,7 @@ private boolean subscribeAction(Operation operation) {
18781878 return false ;
18791879 }
18801880
1881- AddCallback (characteristicUuid , connection , operationSubscribe , callbackContext );
1881+ AddSequentialCallbackContext (characteristicUuid , connection , operationSubscribe , callbackContext );
18821882
18831883 //Write the descriptor value
18841884 result = bluetoothGatt .writeDescriptor (descriptor );
@@ -1952,7 +1952,7 @@ private boolean unsubscribeAction(Operation operation) {
19521952
19531953 addCharacteristic (returnObj , characteristic );
19541954
1955- CallbackContext checkExisting = GetCallback (characteristicUuid , connection , operationSubscribe );
1955+ SequentialCallbackContext checkExisting = GetSequentialCallbackContext (characteristicUuid , connection , operationSubscribe );
19561956 if (checkExisting == null ) {
19571957 addProperty (returnObj , keyError , errorSubscription );
19581958 addProperty (returnObj , keyMessage , logUnsubscribeAlready );
@@ -3283,6 +3283,23 @@ private CallbackContext GetCallback(UUID characteristicUuid, HashMap<Object, Obj
32833283 return (CallbackContext ) characteristicCallbacks .get (operationType );
32843284 }
32853285
3286+ private void AddSequentialCallbackContext (UUID characteristicUuid , HashMap <Object , Object > connection , String operationType , CallbackContext callbackContext ) {
3287+ HashMap <Object , Object > characteristicCallbacks = EnsureCallback (characteristicUuid , connection );
3288+
3289+ characteristicCallbacks .put (operationType , new SequentialCallbackContext (callbackContext ));
3290+ }
3291+
3292+ private SequentialCallbackContext GetSequentialCallbackContext (UUID characteristicUuid , HashMap <Object , Object > connection , String operationType ) {
3293+ HashMap <Object , Object > characteristicCallbacks = (HashMap <Object , Object >) connection .get (characteristicUuid );
3294+
3295+ if (characteristicCallbacks == null ) {
3296+ return null ;
3297+ }
3298+
3299+ //This may return null
3300+ return (SequentialCallbackContext ) characteristicCallbacks .get (operationType );
3301+ }
3302+
32863303 private CallbackContext [] GetCallbacks (HashMap <Object , Object > connection ) {
32873304 ArrayList <CallbackContext > callbacks = new ArrayList <CallbackContext >();
32883305
@@ -3324,7 +3341,12 @@ private void GetMoreCallbacks(HashMap<Object, Object> lower, ArrayList<CallbackC
33243341 continue ;
33253342 }
33263343
3327- CallbackContext callback = (CallbackContext ) lower .get (key );
3344+ CallbackContext callback ;
3345+ if (key .equals (operationSubscribe )) {
3346+ callback = ((SequentialCallbackContext ) lower .get (key )).getContext ();
3347+ } else {
3348+ callback = (CallbackContext ) lower .get (key );
3349+ }
33283350
33293351 if (callback == null ) {
33303352 continue ;
@@ -4175,7 +4197,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
41754197
41764198 UUID characteristicUuid = characteristic .getUuid ();
41774199
4178- CallbackContext callbackContext = GetCallback (characteristicUuid , connection , operationSubscribe );
4200+ SequentialCallbackContext callbackContext = GetSequentialCallbackContext (characteristicUuid , connection , operationSubscribe );
41794201
41804202 //If no callback, just return
41814203 if (callbackContext == null ) {
@@ -4192,9 +4214,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
41924214 addPropertyBytes (returnObj , keyValue , characteristic .getValue ());
41934215
41944216 //Return the characteristic value
4195- PluginResult result = new PluginResult (PluginResult .Status .OK , returnObj );
4196- result .setKeepCallback (true );
4197- callbackContext .sendPluginResult (result );
4217+ callbackContext .sendSequentialResult (returnObj );
41984218 }
41994219
42004220 @ Override
@@ -4365,7 +4385,7 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
43654385
43664386 callbackContext .success (returnObj );
43674387 } else {
4368- CallbackContext callbackContext = GetCallback (characteristicUuid , connection , operationSubscribe );
4388+ SequentialCallbackContext callbackContext = GetSequentialCallbackContext (characteristicUuid , connection , operationSubscribe );
43694389
43704390 //If no callback, just return
43714391 if (callbackContext == null ) {
@@ -4376,7 +4396,7 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
43764396
43774397 PluginResult pluginResult = new PluginResult (PluginResult .Status .OK , returnObj );
43784398 pluginResult .setKeepCallback (true );
4379- callbackContext .sendPluginResult (pluginResult );
4399+ callbackContext .getContext (). sendPluginResult (pluginResult );
43804400 }
43814401
43824402 return ;
0 commit comments