Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class QonversionConfig internal constructor(
* Fallback file will be used in rare cases of network connection or Qonversion API issues for new users without a cache available.
* This allows purchases and entitlements to be processed for new users even if the Qonversion API faces issues.
* This also makes it possible to receive remote configs for cases when the network connection is unavailable.
* There is no need to use this function if you put qonversion_fallbacks.json into the `assets` folder.
* Use this function only if you put qonversion_fallbacks.json into the `res/raw` folder.
* In that case, `id` should look like `R.raw.qonversion_fallbacks`.
* There is no need to use this function if you put qonversion_android_fallbacks.json into the `assets` folder.
* Use this function only if you put a fallback JSON file into the `res/raw` folder.
* In that case, `id` should look like `R.raw.qonversion_android_fallbacks`.
*
* @param id the identifier for the fallback file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.qonversion.android.sdk.dto
enum class QRemoteConfigurationAssignmentType(val type: String) {
Auto("auto"),
Manual("manual"),
Unknown("unknown");
Unknown("unknown"),
Frozen("frozen");

companion object {
fun fromType(type: String): QRemoteConfigurationAssignmentType {
return when (type) {
"auto" -> Auto
"manual" -> Manual
"frozen" -> Frozen
else -> Unknown
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ internal class QProductCenterManager internal constructor(
handlePendingRequests()
fireIdentitySuccess(identityId)
} else {
internalConfig.uid = qonversionUid
remoteConfigManager.onUserUpdate()
remoteConfigManager.onUserUpdate {
internalConfig.uid = qonversionUid
}
launchResultCache.clearPermissionsCache()
launch(RequestTrigger.Identify, object : QonversionLaunchCallback {
override fun onSuccess(launchResult: QLaunchResult) {
Expand Down Expand Up @@ -472,13 +473,13 @@ internal class QProductCenterManager internal constructor(
val isLogoutNeeded = identityManager.logoutIfNeeded()

if (isLogoutNeeded) {
remoteConfigManager.onUserUpdate()
val userId = userInfoService.obtainUserId()
remoteConfigManager.onUserUpdate {
internalConfig.uid = userId
}
launchResultCache.clearPermissionsCache()

unhandledLogoutAvailable = true

val userId = userInfoService.obtainUserId()
internalConfig.uid = userId
}
}

Expand Down Expand Up @@ -527,8 +528,9 @@ internal class QProductCenterManager internal constructor(
)

userInfoService.storeQonversionUserId(newUserId)
internalConfig.uid = newUserId
remoteConfigManager.onUserUpdate()
remoteConfigManager.onUserUpdate {
internalConfig.uid = newUserId
}
launchResultCache.clearPermissionsCache()
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.qonversion.android.sdk.internal.provider.AppStateProvider
import com.qonversion.android.sdk.internal.services.QFallbacksService
import com.qonversion.android.sdk.internal.storage.LaunchResultCacheWrapper
import com.qonversion.android.sdk.internal.storage.PurchasesCache
import com.qonversion.android.sdk.internal.storage.PersistentRemoteConfigCache
import com.qonversion.android.sdk.internal.storage.RemoteConfigCache
import com.qonversion.android.sdk.internal.storage.SharedPreferencesCache
import com.squareup.moshi.Moshi
import dagger.Module
Expand Down Expand Up @@ -76,6 +78,15 @@ internal class AppModule(
return LaunchResultCacheWrapper(moshi, sharedPreferencesCache, internalConfig, fallbacksService)
}

@ApplicationScope
@Provides
fun provideRemoteConfigCache(
moshi: Moshi,
sharedPreferencesCache: SharedPreferencesCache,
): RemoteConfigCache {
return PersistentRemoteConfigCache(sharedPreferencesCache, internalConfig, moshi)
}

@ApplicationScope
@Provides
fun provideFallbackService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.android.billingclient.api.BillingClient
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.QonversionErrorCode
import com.qonversion.android.sdk.internal.billing.BillingError
import com.squareup.moshi.JsonDataException
import org.json.JSONException
import java.io.IOException

Expand Down Expand Up @@ -39,7 +40,7 @@ internal fun BillingError.toQonversionError(): QonversionError {

internal fun Throwable.toQonversionError(): QonversionError {
return when (this) {
is JSONException -> {
is JSONException, is JsonDataException -> {
QonversionError(QonversionErrorCode.ResponseParsingFailed, localizedMessage ?: "")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ internal class DefaultRepository internal constructor(
val body = it.body()
if (body == null) {
callback.onError(errorMapper.getErrorFromResponse(it))
} else if (body.any { config -> !config.isCorrect }) {
callback.onError(invalidRemoteConfigListError())
} else {
val res = QRemoteConfigList(body.filter { config -> config.isCorrect })
callback.onSuccess(res)
callback.onSuccess(QRemoteConfigList(body))
}
}

Expand All @@ -154,9 +155,10 @@ internal class DefaultRepository internal constructor(
val body = it.body()
if (body == null) {
callback.onError(errorMapper.getErrorFromResponse(it))
} else if (body.any { config -> !config.isCorrect }) {
callback.onError(invalidRemoteConfigListError())
} else {
val res = QRemoteConfigList(body.filter { config -> config.isCorrect })
callback.onSuccess(res)
callback.onSuccess(QRemoteConfigList(body))
}
}

Expand All @@ -167,6 +169,11 @@ internal class DefaultRepository internal constructor(
}
}

private fun invalidRemoteConfigListError() = QonversionError(
QonversionErrorCode.ResponseParsingFailed,
"Remote Config list contains an invalid element",
)

override fun attachUserToExperiment(
experimentId: String,
groupId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ internal interface Cache {
fun getLong(key: String, defValue: Long): Long

fun putString(key: String, value: String?)

fun updateStrings(values: Map<String, String?>, removedKeys: Set<String>) {
removedKeys.forEach(::remove)
values.forEach(::putString)
}

/**
* @param defValue is returned if the String preference for key does not exist
*/
Expand Down
Loading
Loading