diff options
author | Bilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com> | 2019-03-19 09:40:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 09:40:22 -0400 |
commit | ffa6fd9d1466886f604194f32533ea82a411c082 (patch) | |
tree | 770a9e90027cacb446fea8e7e9203f3397f6b308 | |
parent | 283815ed2170197db4be06de766614c8803720bb (diff) | |
parent | 7582cb865d8773c12e23e7f19d3ff8eeebb08afd (diff) | |
download | sdl_android-feature/sdl_java_base.tar.gz |
Merge pull request #1012 from smartdevicelink/feature/queue_notificationsfeature/sdl_java_base
Queue notifications before sdlManager ready
-rw-r--r-- | javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java index 851894d10..628a5038c 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -42,6 +42,7 @@ import com.smartdevicelink.managers.screen.ScreenManager; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.protocol.enums.SessionType; import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCRequest; import com.smartdevicelink.proxy.SystemCapabilityManager; import com.smartdevicelink.proxy.interfaces.ISdl; @@ -59,6 +60,7 @@ import com.smartdevicelink.util.DebugTool; import com.smartdevicelink.util.Version; import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; /** @@ -100,6 +102,8 @@ public class SdlManager extends BaseSdlManager{ private FileManager fileManager; private ScreenManager screenManager; + private Queue<RPCNotification> queuedNotifications = null; + private OnRPCNotificationListener queuedNotificationListener = null; // INTERNAL INTERFACE /** @@ -164,6 +168,7 @@ public class SdlManager extends BaseSdlManager{ if (permissionManager.getState() == BaseSubManager.READY && fileManager.getState() == BaseSubManager.READY && screenManager.getState() == BaseSubManager.READY){ DebugTool.logInfo("Starting sdl manager, all sub managers are in ready state"); transitionToState(BaseSubManager.READY); + handleQueuedNotifications(); notifyDevListener(null); onReady(); } else if (permissionManager.getState() == BaseSubManager.ERROR && fileManager.getState() == BaseSubManager.ERROR && screenManager.getState() == BaseSubManager.ERROR){ @@ -178,6 +183,7 @@ public class SdlManager extends BaseSdlManager{ } else { Log.w(TAG, "LIMITED starting sdl manager, some sub managers are in error or limited state and the others finished setting up"); transitionToState(BaseSubManager.LIMITED); + handleQueuedNotifications(); notifyDevListener(null); onReady(); } @@ -200,6 +206,36 @@ public class SdlManager extends BaseSdlManager{ } } + private void handleQueuedNotifications(){ + //Handle queued notifications and add the listeners + if (onRPCNotificationListeners != null) { + Set<FunctionID> functionIDSet = onRPCNotificationListeners.keySet(); + if (queuedNotifications != null && queuedNotifications.size() > 0) { + for (RPCNotification notification : queuedNotifications) { + try { + onRPCNotificationListeners.get(notification.getFunctionID()).onNotified(notification); + } catch (Exception e) { + DebugTool.logError("Error going through queued notifications", e); + } + } + } + + //Swap queued listener for developer's listeners + if (functionIDSet != null && !functionIDSet.isEmpty()) { + for (FunctionID functionID : functionIDSet) { + //Remove the old queue listener + _internalInterface.removeOnRPCNotificationListener(functionID, queuedNotificationListener); + //Add the developer listener + _internalInterface.addOnRPCNotificationListener(functionID, onRPCNotificationListeners.get(functionID)); + } + } + //Set variables to null that are no longer needed + queuedNotifications = null; + queuedNotificationListener = null; + onRPCNotificationListeners = null; + } + } + private void onReady(){ // Set the app icon if (SdlManager.this.appIcon != null && SdlManager.this.appIcon.getName() != null) { @@ -514,11 +550,20 @@ public class SdlManager extends BaseSdlManager{ if (sdlSecList != null && !sdlSecList.isEmpty()) { lifecycleManager.setSdlSecurityClassList(sdlSecList); } + + //Setup the notification queue if (onRPCNotificationListeners != null) { Set<FunctionID> functionIDSet = onRPCNotificationListeners.keySet(); if (functionIDSet != null && !functionIDSet.isEmpty()) { + queuedNotifications = new ConcurrentLinkedQueue<RPCNotification>(); + queuedNotificationListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + queuedNotifications.add(notification); + } + }; for (FunctionID functionID : functionIDSet) { - _internalInterface.addOnRPCNotificationListener(functionID, onRPCNotificationListeners.get(functionID)); + _internalInterface.addOnRPCNotificationListener(functionID, queuedNotificationListener); } } } |