summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2020-09-11 14:10:20 -0400
committerJoey Grover <joeygrover@gmail.com>2020-09-11 14:10:20 -0400
commita0e3e4220958f5041b152a5823ef673584289ab0 (patch)
tree652f4a4d61b41a5f11f3ea8d092c6289d38a5548
parentf92e5b6013c5a35488b26964c6468d42502cf18a (diff)
downloadsdl_android-bugfix/out_of_sync_rpcs.tar.gz
Add synchronized lock around handling RPCsbugfix/out_of_sync_rpcs
This will ensure RPCs are handled in a sequential order
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
index c8566dbad..99c650b41 100644
--- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
@@ -810,6 +810,8 @@ abstract class BaseLifecycleManager {
final ISdlSessionListener sdlSessionListener = new ISdlSessionListener() {
+ private final Object HANDLE_RPC_LOCK = new Object();
+
@Override
public void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
BaseLifecycleManager.this.onTransportDisconnected(info, availablePrimary, transportConfig);
@@ -819,32 +821,34 @@ abstract class BaseLifecycleManager {
public void onRPCMessageReceived(RPCMessage rpc) {
//Incoming message
if (rpc != null) {
- String messageType = rpc.getMessageType();
- DebugTool.logInfo(TAG, "RPC received - " + messageType);
+ synchronized (HANDLE_RPC_LOCK) {
+ String messageType = rpc.getMessageType();
+ DebugTool.logInfo(TAG, "RPC received - " + messageType);
- rpc.format(rpcSpecVersion, true);
+ rpc.format(rpcSpecVersion, true);
- BaseLifecycleManager.this.onRPCReceived(rpc);
+ BaseLifecycleManager.this.onRPCReceived(rpc);
- if (RPCMessage.KEY_RESPONSE.equals(messageType)) {
+ if (RPCMessage.KEY_RESPONSE.equals(messageType)) {
- onRPCResponseReceived((RPCResponse) rpc);
+ onRPCResponseReceived((RPCResponse) rpc);
- } else if (RPCMessage.KEY_NOTIFICATION.equals(messageType)) {
- FunctionID functionID = rpc.getFunctionID();
- if (functionID != null && (functionID.equals(FunctionID.ON_BUTTON_PRESS)) || functionID.equals(FunctionID.ON_BUTTON_EVENT)) {
- RPCNotification notificationCompat = handleButtonNotificationFormatting(rpc);
- if (notificationCompat != null) {
- onRPCNotificationReceived((notificationCompat));
+ } else if (RPCMessage.KEY_NOTIFICATION.equals(messageType)) {
+ FunctionID functionID = rpc.getFunctionID();
+ if (functionID != null && (functionID.equals(FunctionID.ON_BUTTON_PRESS)) || functionID.equals(FunctionID.ON_BUTTON_EVENT)) {
+ RPCNotification notificationCompat = handleButtonNotificationFormatting(rpc);
+ if (notificationCompat != null) {
+ onRPCNotificationReceived((notificationCompat));
+ }
}
- }
- onRPCNotificationReceived((RPCNotification) rpc);
+ onRPCNotificationReceived((RPCNotification) rpc);
- } else if (RPCMessage.KEY_REQUEST.equals(messageType)) {
+ } else if (RPCMessage.KEY_REQUEST.equals(messageType)) {
- onRPCRequestReceived((RPCRequest) rpc);
+ onRPCRequestReceived((RPCRequest) rpc);
+ }
}
} else {
DebugTool.logWarning(TAG, "Shouldn't be here");