From 783d0017bb0f424d78c0ccbe67ed47d3cec0171f Mon Sep 17 00:00:00 2001 From: "Jack Boswell (boswelja)" Date: Wed, 17 Nov 2021 22:28:21 +1300 Subject: [PATCH] Only pass on deserialized message if the path matches the serializer --- .../serialization/MessageReceiver.kt | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/serialization/src/androidMain/kotlin/com/boswelja/watchconnection/serialization/MessageReceiver.kt b/serialization/src/androidMain/kotlin/com/boswelja/watchconnection/serialization/MessageReceiver.kt index 037040fb..f31f8531 100644 --- a/serialization/src/androidMain/kotlin/com/boswelja/watchconnection/serialization/MessageReceiver.kt +++ b/serialization/src/androidMain/kotlin/com/boswelja/watchconnection/serialization/MessageReceiver.kt @@ -36,22 +36,24 @@ public abstract class MessageReceiver( // Get message details val message = MessageReceiverUtils.getReceivedMessageFromIntent(intent) - val pendingResult = goAsync() - coroutineScope.launch { - // Deserialize and pass message on - val deserializedData = serializer.deserialize(message.data) - try { - onMessageReceived( - context, - ReceivedMessage( - message.sourceUid, - message.path, - deserializedData + if (serializer.messagePaths.contains(message.path)) { + val pendingResult = goAsync() + coroutineScope.launch { + // Deserialize and pass message on + val deserializedData = serializer.deserialize(message.data) + try { + onMessageReceived( + context, + ReceivedMessage( + message.sourceUid, + message.path, + deserializedData + ) ) - ) - } finally { - pendingResult.finish() - coroutineScope.cancel() + } finally { + pendingResult.finish() + coroutineScope.cancel() + } } } }