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
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jdk:
- openjdk11
- openjdk17
27 changes: 22 additions & 5 deletions sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ object Mindbox : MindboxLog {
private val getDeviceIdMutex = Mutex()
private val inAppMutex = Mutex()
private val mutexUpdateAppInfo: Mutex = Mutex()
private val pushServiceMutex = Mutex()

private var firstInitCall: Boolean = true
private var isPushServiceInitialized = false

private val migrationManager: MigrationManager by mindboxInject { migrationManager }

Expand Down Expand Up @@ -569,10 +569,10 @@ object Mindbox : MindboxLog {

initScope.launch {
InitializeLock.await(InitializeLock.State.MIGRATION)
DbManager.saveConfigurations(Configuration(configuration))
setPushServiceHandler(context, pushServices)
val checkResult = checkConfig(configuration)
val validatedConfiguration = validateConfiguration(configuration)
DbManager.saveConfigurations(Configuration(configuration))
logI("init. checkResult: $checkResult")
if (checkResult != ConfigUpdate.NOT_UPDATED && !MindboxPreferences.isFirstInitialize) {
logI("init. softReinitialization")
Expand Down Expand Up @@ -759,17 +759,34 @@ object Mindbox : MindboxLog {

private suspend fun setPushServiceHandler(
context: Context,
pushServices: List<MindboxPushService>? = null,
pushServices: List<MindboxPushService>,
): Unit = loggingRunCatchingSuspending {
if (pushServiceHandlers.isEmpty() && pushServices != null && !isPushServiceInitialized) {
isPushServiceInitialized = true
if (pushServices.isEmpty()) {
mindboxLogW("initPushServices: Push services list is empty")
return@loggingRunCatchingSuspending
}

if (pushServiceHandlers.isNotEmpty()) {
mindboxLogI("initPushServices: Push services already initialized")
return@loggingRunCatchingSuspending
}

pushServiceMutex.withLock {
if (pushServiceHandlers.isNotEmpty()) {
mindboxLogI("initPushServices: Push services already initialized")
return@withLock
}

mindboxLogI("initPushServices: " + pushServices.joinToString { it.tag })
Stopwatch.start(Stopwatch.INIT_PUSH_SERVICES)

pushServiceHandlers = selectPushServiceHandler(context, pushServices)

pushServiceHandlers.map { handler ->
mindboxScope.async { handler.initService(context) }
}.awaitAll()

mindboxLogI("initPushServices completed in " + Stopwatch.stop(Stopwatch.INIT_PUSH_SERVICES))
mindboxScope.launch {
if (!MindboxPreferences.isFirstInitialize) {
updateAppInfo(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal object Stopwatch : MindboxLog {

internal const val INIT_SDK = "INIT_SDK"
internal const val GET_PUSH_TOKENS = "GET_PUSH_TOKENS"
internal const val INIT_PUSH_SERVICES = "INIT_PUSH_SERVICES"

private val entries: MutableMap<String, Long> by lazy { mutableMapOf() }

Expand Down