diff --git a/build.gradle b/build.gradle index a4260fb..1bceef3 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { kotlin_version = '1.8.0' - versionName = '0.0.24' + versionName = '0.0.27' } repositories { diff --git a/lib/src/main/java/com/evdayapps/madassistant/clientlib/connection/ConnectionManagerImpl.kt b/lib/src/main/java/com/evdayapps/madassistant/clientlib/connection/ConnectionManagerImpl.kt index 6f80fec..c70e6c3 100644 --- a/lib/src/main/java/com/evdayapps/madassistant/clientlib/connection/ConnectionManagerImpl.kt +++ b/lib/src/main/java/com/evdayapps/madassistant/clientlib/connection/ConnectionManagerImpl.kt @@ -26,14 +26,14 @@ class ConnectionManagerImpl( ) : ConnectionManager, ServiceConnection, MADAssistantClientAIDL.Stub() { companion object { - const val TAG = "MADAssist:ConnectionManagerImpl" - const val REPO_SERVICE_PACKAGE = "com.evdayapps.madassistant.repository" const val REPO_SERVICE_CLASS = "$REPO_SERVICE_PACKAGE.service.MADAssistantService" const val DEFAULT_REPO_SIGNATURE = "1B:C0:79:26:82:9E:FB:96:5C:6A:51:6C:96:7C:52:88:42:" + "7E:73:8C:05:7D:60:D8:13:9D:C4:3C:18:3B:E3:63" } + private val TAG = "MADAssist:ConnectionManagerImpl" + private var currentState: ConnectionManager.State = ConnectionManager.State.None private var callback: ConnectionManager.Callback? = null @@ -237,12 +237,8 @@ class ConnectionManagerImpl( } when (errorMessage) { - null -> { - setConnectionState(ConnectionManager.State.Connected) - } - else -> { - disconnect(code = 401, message = "AuthToken Failed") - } + null -> setConnectionState(ConnectionManager.State.Connected) + else -> disconnect(code = 401, message = "AuthToken Failed") } } // endregion Handshake diff --git a/lib/src/main/java/com/evdayapps/madassistant/clientlib/transmission/queue/QueueManagerImpl.kt b/lib/src/main/java/com/evdayapps/madassistant/clientlib/transmission/queue/QueueManagerImpl.kt index 39051d3..9b8b43b 100644 --- a/lib/src/main/java/com/evdayapps/madassistant/clientlib/transmission/queue/QueueManagerImpl.kt +++ b/lib/src/main/java/com/evdayapps/madassistant/clientlib/transmission/queue/QueueManagerImpl.kt @@ -33,8 +33,6 @@ class QueueManagerImpl( private var callback: QueueManager.Callback? = null - private val cacheTable: Hashtable = Hashtable() - /** * Add a new message to the queue * @param type The type of the log. One of [MADAssistantTransmissionType] @@ -51,19 +49,18 @@ class QueueManagerImpl( ) { if (connectionManager.isConnectedOrConnecting()) { try { - val data = MessageData( - timestamp = timestamp, - threadName = Thread.currentThread().name, - sessionId = sessionId, - first = first, - second = second, - third = third, - fourth = fourth + queueMessage( + type = type, + data = MessageData( + timestamp = timestamp, + threadName = Thread.currentThread().name, + sessionId = sessionId, + first = first, + second = second, + third = third, + fourth = fourth + ), ) - val key = "$type:$timestamp".hashCode() - cacheTable[key] = data - - queueMessage(type = type, key = key) } catch (ex: Exception) { logger?.e(ex) } @@ -74,17 +71,11 @@ class QueueManagerImpl( * Since the system is not yet ready to send the message (and not disconnecting/disconnected), * Queue the message again so its sent when the system is ready */ - internal fun queueMessage(type: Int, key: Int) { - /*logger?.v( - TAG, - "queueMessage: state: ${connectionManager.currentState} type: $type data: ${ - key.toString().take(256) - }" - )*/ - + internal fun queueMessage(type: Int, data: MessageData) { try { + _clientHandler.sendMessage( - _clientHandler.obtainMessage(type).apply { arg1 = key } + _clientHandler.obtainMessage(type, 0, 0, data) ) } catch (ex: Exception) { logger?.e(ex) @@ -100,23 +91,22 @@ class QueueManagerImpl( * - Drops the message if the state is Disconnected */ override fun handleMessage(message: Message): Boolean { - /*logger?.v( - TAG, - "handleMessage: state: ${connectionManager.currentState} message: $message" - )*/ - - when { - connectionManager.isConnected() || connectionManager.isDisconnecting() -> { - val data = cacheTable[message.arg1] - callback?.processQueuedMessage(type = message.what, data = data as MessageData) - - cacheTable.remove(message.arg1) + try { + when { + connectionManager.isConnected() || connectionManager.isDisconnecting() -> { + callback?.processQueuedMessage( + type = message.what, + data = message.obj as MessageData + ) + } + + connectionManager.isConnecting() -> queueMessage( + type = message.what, + data = message.obj as MessageData + ) } - - connectionManager.isConnecting() -> queueMessage( - type = message.what, - key = message.arg1 - ) + } catch (ex: Exception) { + logger?.e(ex) } return true