Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import cloud.mindbox.mobile_sdk.services.BackgroundWorkManager
import cloud.mindbox.mobile_sdk.utils.Constants
import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
import cloud.mindbox.mobile_sdk.utils.MigrationManager
import cloud.mindbox.mobile_sdk.utils.loggingRunCatching
import com.jakewharton.threetenabp.AndroidThreeTen
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Default
Expand Down Expand Up @@ -309,23 +310,23 @@ object Mindbox : MindboxLog {
* @param pushService - the instance of [MindboxPushService], which handles push notifications.
*/
fun updatePushToken(context: Context, token: String, pushService: MindboxPushService) =
MindboxLoggerImpl.runCatching {
loggingRunCatching {
initComponents(context)
mindboxLogI("updatePushToken token: $token with provider $pushService")

if (token.trim().isEmpty()) {
mindboxLogW("Token is empty! Skipping update token.")
return@runCatching
return@loggingRunCatching
}

if (MindboxPreferences.isFirstInitialize) {
mindboxLogW("Mindbox init was never called. Skipping update token.")
return@runCatching
return@loggingRunCatching
}

if (pushService.tag != pushServiceHandler?.notificationProvider) {
mindboxLogW("Token provider ${pushService.tag} not matching with selected provider ${pushServiceHandler?.notificationProvider}. Skipping update token.")
return@runCatching
return@loggingRunCatching
}

mindboxScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ internal object LoggingExceptionHandler: ExceptionHandler() {
}
}

}
}

internal fun <T> loggingRunCatching(block: () -> T) = LoggingExceptionHandler.runCatching(block)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cloud.mindbox.mobile_sdk.utils

import android.content.Context
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mobile_sdk.logger.MindboxLoggerImpl
import cloud.mindbox.mobile_sdk.logger.mindboxLogI
import cloud.mindbox.mobile_sdk.managers.SharedPreferencesManager
import cloud.mindbox.mobile_sdk.repository.MindboxPreferences
Expand All @@ -15,7 +14,7 @@ internal class MigrationManager(val context: Context) {
version282()
).filter { it.isNeeded }
.onEach { migration ->
MindboxLoggerImpl.runCatching {
loggingRunCatching {
mindboxLogI("Run migration '${migration.description}'")
migration.run()
}
Expand Down