Skip to content

Commit 739c475

Browse files
authored
task(SDK-4506) - Moves renderNotification to an executor thread (#304)
* task(SDK-4506) - Moves renderNotification to an executor thread - The core SDK API expected to be called only on a worker thread - This ensures the images are downloaded correctly * task(SDK-4506) - Resolves PR comments * task(SDK-4506) - Adds changelog and bumps versions
1 parent 1955ab6 commit 739c475

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Version 3.3.1 *(18 April 2025)*
88
* Adds `dismissInAppNotification` action to dismiss custom HTML in-Apps
99

1010
**Bug Fixes**
11+
* **[Android Platform]**
12+
* Fixes an issue where images failed to render in push templates when using a custom FCM integration.
13+
1114
* **[iOS Platform]**
1215
* Fixes app freezing issue when using await with `defineVariables()`.
1316
* Fixes custom in-app device orientation check.

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = 'com.clevertap.clevertap_plugin'
2-
version = '3.3.0'
2+
version = '3.3.1'
33

44
buildscript {
55
ext.kotlin_version = "1.8.22"

android/src/main/java/com/clevertap/clevertap_plugin/DartToNativePlatformCommunicator.kt

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
44
import android.content.Context
55
import android.location.Location
66
import android.os.Build
7+
import android.os.Looper
78
import android.util.Log
89
import com.clevertap.android.sdk.CleverTapAPI
910
import com.clevertap.android.sdk.UTMDetail
@@ -24,13 +25,16 @@ import io.flutter.plugin.common.MethodChannel
2425
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
2526
import org.json.JSONException
2627
import org.json.JSONObject
28+
import java.util.concurrent.Executors
2729

2830
@Suppress("DEPRECATION")
2931
class DartToNativePlatformCommunicator(
3032
private val context: Context,
3133
private val cleverTapAPI: CleverTapAPI?
3234
) : MethodCallHandler {
3335

36+
private val notificationExecutor = Executors.newSingleThreadExecutor()
37+
3438
companion object {
3539
const val TAG = "DartToNative"
3640

@@ -990,29 +994,40 @@ class DartToNativePlatformCommunicator(
990994
*/
991995
private fun renderNotification(call: MethodCall, result: MethodChannel.Result) {
992996
val extras = call.argument<String>("extras")
993-
if (cleverTapAPI != null) {
994-
val isSuccess: Boolean
995-
try {
996-
Log.d(TAG, "renderNotification Android")
997-
val messageBundle = Utils.stringToBundle(extras)
998-
isSuccess = PushNotificationHandler.getPushNotificationHandler()
999-
.onMessageReceived(context, messageBundle, PushConstants.FCM.type)
1000-
if (isSuccess) {
1001-
result.success(null)
1002-
} else {
1003-
throw java.lang.Exception("Unable to process notification rendering")
997+
if (cleverTapAPI == null) {
998+
result.error(TAG, ERROR_MSG, null)
999+
}
1000+
try {
1001+
Log.d(TAG, "renderNotification Android")
1002+
// Check if we're on the main thread. Needed since plugins like FCM provide on message received on the main thread
1003+
if (Looper.myLooper() == Looper.getMainLooper()) {
1004+
// We're on the main thread, execute on a background thread
1005+
notificationExecutor.execute {
1006+
processNotification(extras, result)
10041007
}
1005-
} catch (e: JSONException) {
1006-
result.error(
1007-
TAG,
1008-
"Unable to render notification due to JSONException - " + e.localizedMessage,
1009-
null
1010-
)
1011-
} catch (e: java.lang.Exception) {
1012-
result.error(TAG, e.localizedMessage, null)
1008+
} else {
1009+
processNotification(extras, result)
10131010
}
1011+
} catch (e: JSONException) {
1012+
result.error(
1013+
TAG,
1014+
"Unable to render notification due to JSONException - " + e.localizedMessage,
1015+
null
1016+
)
1017+
} catch (e: Exception) {
1018+
result.error(TAG, e.localizedMessage, null)
1019+
}
1020+
}
1021+
1022+
private fun processNotification(extras: String?, result: MethodChannel.Result) {
1023+
val messageBundle = Utils.stringToBundle(extras)
1024+
val isSuccess = PushNotificationHandler.getPushNotificationHandler()
1025+
.onMessageReceived(context, messageBundle, PushConstants.FCM.type)
1026+
1027+
if (isSuccess) {
1028+
result.success(null)
10141029
} else {
1015-
result.error(TAG, ERROR_MSG, null)
1030+
result.error(TAG, "Unable to process notification rendering", null)
10161031
}
10171032
}
10181033

0 commit comments

Comments
 (0)