diff --git a/app/build.gradle b/app/build.gradle index 3e6e293..31470ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,13 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: "org.jetbrains.kotlin.plugin.compose" def keystorePropertiesFile= project.file("keystore.properties") def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { - compileSdk 34 + compileSdk 36 signingConfigs { release { keyAlias keystoreProperties['RELEASE_KEY_ALIAS'] @@ -26,7 +27,7 @@ android { applicationId "com.abtasty.flagshipqa" minSdkVersion 21 - targetSdk 34 + targetSdk 36 versionCode 1 versionName "1.0" multiDexEnabled true @@ -48,11 +49,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = "17" } namespace 'com.abtasty.flagshipqa' @@ -70,19 +71,19 @@ dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.12.0' - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.10.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.navigation:navigation-fragment-ktx:2.7.4' - implementation 'androidx.navigation:navigation-ui-ktx:2.7.4' + implementation 'androidx.core:core-ktx:1.17.0' + implementation 'androidx.appcompat:appcompat:1.7.1' + implementation 'com.google.android.material:material:1.13.0' + implementation 'androidx.constraintlayout:constraintlayout:2.2.1' + implementation 'androidx.navigation:navigation-fragment-ktx:2.9.4' + implementation 'androidx.navigation:navigation-ui-ktx:2.9.4' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation "org.jetbrains.kotlin:kotlin-reflect:1.9.10" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation project(path: ':flagship') - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7' - implementation 'androidx.activity:activity-compose:1.8.0' - implementation platform('androidx.compose:compose-bom:2024.04.01') + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.9.4' + implementation 'androidx.activity:activity-compose:1.11.0' + implementation platform('androidx.compose:compose-bom:2025.09.00') implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' @@ -90,9 +91,9 @@ dependencies { // implementation 'com.abtasty:flagship-android:4.0.0' //Use remote maven repository testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - androidTestImplementation platform('androidx.compose:compose-bom:2024.04.01') + androidTestImplementation 'androidx.test.ext:junit:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0' + androidTestImplementation platform('androidx.compose:compose-bom:2025.09.00') androidTestImplementation 'androidx.compose.ui:ui-test-junit4' debugImplementation 'androidx.compose.ui:ui-tooling' debugImplementation 'androidx.compose.ui:ui-test-manifest' diff --git a/app/src/main/java/com/abtasty/flagshipqa/MainActivity.kt b/app/src/main/java/com/abtasty/flagshipqa/MainActivity.kt index 06b6fed..cf5e318 100644 --- a/app/src/main/java/com/abtasty/flagshipqa/MainActivity.kt +++ b/app/src/main/java/com/abtasty/flagshipqa/MainActivity.kt @@ -10,6 +10,8 @@ import com.google.android.material.bottomnavigation.BottomNavigationView class MainActivity : AppCompatActivity() { + var cnt = 0 + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -34,7 +36,10 @@ class MainActivity : AppCompatActivity() { override fun onResume() { super.onResume() -// val intent = Intent(this, MainActivity3::class.java) -// startActivity(intent) +//// if (cnt % 2 == 0) { +// val intent = Intent(this, MainActivity3::class.java) +// startActivity(intent) +// cnt++ +//// } } } \ No newline at end of file diff --git a/app/src/main/java/com/abtasty/flagshipqa/MainActivity3.kt b/app/src/main/java/com/abtasty/flagshipqa/MainActivity3.kt index 8edb02f..6a0a13d 100644 --- a/app/src/main/java/com/abtasty/flagshipqa/MainActivity3.kt +++ b/app/src/main/java/com/abtasty/flagshipqa/MainActivity3.kt @@ -33,10 +33,14 @@ import androidx.compose.ui.tooling.preview.Preview import com.abtasty.flagship.main.Flagship import com.abtasty.flagship.main.FlagshipConfig import com.abtasty.flagshipqa.ui.theme.FlagshipandroidTheme +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async +import kotlinx.coroutines.cancel import kotlinx.coroutines.delay +import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.isActive class MainActivity3 : ComponentActivity() { @@ -49,16 +53,17 @@ class MainActivity3 : ComponentActivity() { val callbackWrapper: WindowCallback = WindowCallback(windowCallback) window.callback = callbackWrapper -// CoroutineScope(Dispatchers.Default).async { -// delay(5000) + CoroutineScope(Dispatchers.IO).async { + println("isActive: ${this.isActive}") Flagship.start( application, "", "", - FlagshipConfig.DecisionApi() - ) - -// } + FlagshipConfig.Bucketing() + .withFlagshipStatusListener { status -> println("NEW STATUS = " + status) } + ).await() + println("END OF START \$status = " + Flagship.getStatus()) + } enableEdgeToEdge() setContent { FlagshipandroidTheme { @@ -76,8 +81,9 @@ class MainActivity3 : ComponentActivity() { super.onResume() Flagship.runOnFlagshipIsInitialized { - val visitor = Flagship.newVisitor("toto_89edfe742qesq", true).build() + val visitor = Flagship.newVisitor("t9BKJZGJDIe62NKSCFs", true).build() visitor.collectEmotionsAIEvents(this@MainActivity3) + visitor.fetchFlags() } } } diff --git a/app/src/main/java/com/abtasty/flagshipqa/ui/modifications/ModificationViewModel.kt b/app/src/main/java/com/abtasty/flagshipqa/ui/modifications/ModificationViewModel.kt index 2d16641..69aed3a 100644 --- a/app/src/main/java/com/abtasty/flagshipqa/ui/modifications/ModificationViewModel.kt +++ b/app/src/main/java/com/abtasty/flagshipqa/ui/modifications/ModificationViewModel.kt @@ -2,6 +2,7 @@ package com.abtasty.flagshipqa.ui.modifications import android.app.Application import android.widget.Toast +import androidx.compose.ui.text.intl.Locale import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData import com.abtasty.flagship.main.Flagship @@ -59,7 +60,7 @@ class ModificationViewModel(val appContext: Application) : AndroidViewModel(appC return when (type) { "Null" -> null "String" -> default - "Boolean" -> default.toLowerCase().toBoolean() + "Boolean" -> default.lowercase().toBoolean() "Number" -> { try { default.toInt() diff --git a/build.gradle b/build.gradle index 1e65417..65f8cef 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { ext { - kotlin_version = '1.9.25' + kotlin_version = '2.2.20' maven_artifact_id = "flagship-android" maven_repo = "flagship-android" maven_group_id = "com.abtasty" @@ -10,8 +10,8 @@ buildscript { if (!maven_variant.isEmpty()) { maven_artifact_id = maven_artifact_id + '-' + maven_variant } - flagship_version_name = System.getenv('FLAGSHIP_VERSION_NAME') ?: "4.0.0-beta2" - flagship_version_code = System.getenv('FLAGSHIP_VERSION_CODE') ?: 21 + flagship_version_name = System.getenv('FLAGSHIP_VERSION_NAME') ?: "4.0.0-beta3" + flagship_version_code = System.getenv('FLAGSHIP_VERSION_CODE') ?: 24 } repositories { @@ -19,15 +19,15 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.5.2' + classpath 'com.android.tools.build:gradle:8.12.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.16" -// classpath "io.github.gradle-nexus:publish-plugin:1.3.0" + classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.18" + classpath "org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:$kotlin_version" } } plugins { - id 'com.google.devtools.ksp' version '1.9.25-1.0.20' apply false + id 'com.google.devtools.ksp' version '2.2.20-2.0.3' apply false id("io.github.gradle-nexus.publish-plugin") version "1.3.0" id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false } diff --git a/flagship/build.gradle b/flagship/build.gradle index a942461..8971311 100644 --- a/flagship/build.gradle +++ b/flagship/build.gradle @@ -1,26 +1,25 @@ -import com.vanniktech.maven.publish.SonatypeHost plugins { id 'com.android.library' id 'kotlin-android' id 'kotlin-parcelize' id 'com.google.devtools.ksp' - id 'com.vanniktech.maven.publish' version "0.30.0" + id 'com.vanniktech.maven.publish' version "0.34.0" id 'jacoco' } kotlin { - jvmToolchain(11) + jvmToolchain(17) } android { namespace 'com.abtasty.flagship' - compileSdk 34 + compileSdk 36 defaultConfig { minSdkVersion 21 - compileSdk 34 - targetSdkVersion 34 + compileSdk 36 + targetSdkVersion 36 ksp { arg("room.schemaLocation", "$projectDir/schemas".toString()) @@ -60,11 +59,11 @@ android { } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } android.libraryVariants.configureEach { variant -> @@ -81,21 +80,19 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.room:room-runtime:2.6.1' - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0") - implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'androidx.room:room-runtime:2.7.2' + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") + implementation 'androidx.appcompat:appcompat:1.7.1' testImplementation 'junit:junit:4.13.2' - testImplementation 'androidx.test:core:1.6.1' - testImplementation 'org.robolectric:robolectric:4.14.1' + testImplementation 'androidx.test:core:1.7.0' + testImplementation 'org.robolectric:robolectric:4.16' testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0" - + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2" implementation 'com.squareup.okhttp3:okhttp:4.12.0' - implementation 'androidx.lifecycle:lifecycle-process:2.8.7' - - annotationProcessor("androidx.room:room-compiler:2.6.1") - ksp 'androidx.room:room-compiler:2.6.1' + implementation 'androidx.lifecycle:lifecycle-process:2.9.4' + annotationProcessor("androidx.room:room-compiler:2.7.2") + ksp 'androidx.room:room-compiler:2.7.2' } @@ -106,12 +103,10 @@ repositories { mavenPublishing { - publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) +// publishToMavenCentral("CENTRAL_PORTAL") signAllPublications() - coordinates(maven_group_id, maven_artifact_id, flagship_version_name) - pom { name = maven_artifact_id description = 'Visit https://developers.flagship.io/ to get started with Flagship.' diff --git a/flagship/src/main/java/com/abtasty/flagship/api/HttpManager.kt b/flagship/src/main/java/com/abtasty/flagship/api/HttpManager.kt index dbbd4dc..9fd7f8a 100644 --- a/flagship/src/main/java/com/abtasty/flagship/api/HttpManager.kt +++ b/flagship/src/main/java/com/abtasty/flagship/api/HttpManager.kt @@ -62,17 +62,21 @@ object HttpManager { } private fun initThreadPoolExecutor() { - workers = Runtime.getRuntime().availableProcessors() * 2 - threadPoolExecutor = ThreadPoolExecutor( - workers, workers, - workerTimeout, workerTimeoutUnit, - LinkedBlockingQueue() - ) { r: Runnable? -> - val t = Thread(r, "Flagship Worker") - t.isDaemon = true - t + try { + workers = Runtime.getRuntime().availableProcessors() * 2 + threadPoolExecutor = ThreadPoolExecutor( + workers, workers, + workerTimeout, workerTimeoutUnit, + LinkedBlockingQueue() + ) { r: Runnable? -> + val t = Thread(r, "Flagship Worker") + t.isDaemon = true + t + } + threadPoolExecutor?.allowCoreThreadTimeOut(true) + } catch (e: Exception) { + FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) } - threadPoolExecutor?.allowCoreThreadTimeOut(true) } private fun getTrustManagerFactory(): TrustManagerFactory { diff --git a/flagship/src/main/java/com/abtasty/flagship/cache/DefaultCacheManager.kt b/flagship/src/main/java/com/abtasty/flagship/cache/DefaultCacheManager.kt index b72d8dc..ef1c08b 100644 --- a/flagship/src/main/java/com/abtasty/flagship/cache/DefaultCacheManager.kt +++ b/flagship/src/main/java/com/abtasty/flagship/cache/DefaultCacheManager.kt @@ -25,13 +25,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC override fun openDatabase(envId: String) { if (db == null || db?.isOpen == false) { db = Room.databaseBuilder(Flagship.application, DefaultDatabase::class.java, "flagship-$envId-cache.db") - .addCallback(object : RoomDatabase.Callback() { - override fun onOpen(db: SupportSQLiteDatabase) { - super.onOpen(db) - db.execSQL("CREATE TEMP TABLE IF NOT EXISTS room_table_modification_log(table_id INTEGER PRIMARY KEY, invalidated INTEGER NOT NULL DEFAULT 0)") - } - }) -// .fallbackToDestructiveMigrationFrom(2) .addMigrations(DefaultDatabase.Companion.Migrations.MIGRATION_2_3.getDatabaseMigration()) .build() } @@ -41,7 +34,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC override fun closeDatabase() { db?.close() super.closeDatabase() -// db?.close() db = null } @@ -56,8 +48,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC ) ) } - } else { - //todo database has been closed } } @@ -80,8 +70,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC FlagshipLogManager.exception(FlagshipException(e)) } } - } else { - //todo database has been closed } return result } @@ -94,8 +82,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC FlagshipConstants.Debug.DEFAULT_CACHE_MANAGER_FLUSH_VISITOR.format(visitorId) ) } - } else { - //todo database has been closed } } @@ -116,13 +102,12 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC ) } } else { - //todo databse has been closed + //todo database has been closed } } override fun lookupHits(): HashMap { val hits = HashMap() -// db?.hitDao()?.popAll()?.let { results -> if (db?.isOpen == true) { db?.hitDao()?.getAll()?.let { results -> for (h in results) { @@ -135,8 +120,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC ) ) } - } else { - //todo database has been closed } return hits } @@ -151,8 +134,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC ) ) } - } else { - //Todo database has been closed } } @@ -163,8 +144,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC FlagshipLogManager.Tag.DEFAULT_CACHE_MANAGER, LogManager.Level.INFO, FlagshipConstants.Debug.DEFAULT_CACHE_MANAGER_FLUSH_ALL_HITS ) - } else { - //todo database has been closed } } @@ -175,8 +154,6 @@ class DefaultCacheManager() : CacheManager(), IVisitorCacheImplementation, IHitC FlagshipLogManager.Tag.DEFAULT_CACHE_MANAGER, LogManager.Level.INFO, FlagshipConstants.Debug.DEFAULT_CACHE_MANAGER_FLUSH_ALL_VISITORS ) - } else { - //todo database has been closed } } } \ No newline at end of file diff --git a/flagship/src/main/java/com/abtasty/flagship/decision/ApiManager.kt b/flagship/src/main/java/com/abtasty/flagship/decision/ApiManager.kt index ee8f0b5..4db0b33 100644 --- a/flagship/src/main/java/com/abtasty/flagship/decision/ApiManager.kt +++ b/flagship/src/main/java/com/abtasty/flagship/decision/ApiManager.kt @@ -35,19 +35,6 @@ class ApiManager(flagshipConfig: FlagshipConfig<*>) : DecisionManager(flagshipCo initialized = true } -// override fun parseTroubleShooting(json: JSONObject) { -// try { -// val troubleshootingJson = json.getJSONObject("extras") -// .getJSONObject("accountSettings") -// .getJSONObject("troubleshooting") -// super.parseTroubleShootingJson(troubleshootingJson) -// -// } catch (e: Exception) { -// flagshipConfig.troubleShootingStartTimestamp = -1 -// flagshipConfig.troubleShootingEndTimestamp = -1 -// } -// } - @Throws(IOException::class) private fun sendCampaignRequest(visitorDelegateDTO: VisitorDelegateDTO): ArrayList? { var results : ArrayList? = null diff --git a/flagship/src/main/java/com/abtasty/flagship/decision/BucketingManager.kt b/flagship/src/main/java/com/abtasty/flagship/decision/BucketingManager.kt index 0a1b634..2a4d58f 100644 --- a/flagship/src/main/java/com/abtasty/flagship/decision/BucketingManager.kt +++ b/flagship/src/main/java/com/abtasty/flagship/decision/BucketingManager.kt @@ -38,17 +38,6 @@ class BucketingManager(flagshipConfig: FlagshipConfig<*>) : DecisionManager(flag initialized = true } -// override fun parseTroubleShooting(json: JSONObject) { -// try { -// val troubleshootingJson = json.getJSONObject("accountSettings") -// .getJSONObject("troubleshooting") -// super.parseTroubleShootingJson(troubleshootingJson) -// } catch (e: Exception) { -// flagshipConfig.troubleShootingStartTimestamp = -1 -// flagshipConfig.troubleShootingEndTimestamp = -1 -// } -// } - fun startPolling() { if (executor == null) { executor = Executors.newSingleThreadScheduledExecutor { r -> @@ -81,7 +70,8 @@ class BucketingManager(flagshipConfig: FlagshipConfig<*>) : DecisionManager(flag if (decisionFile == null) decisionFile = loadDecisionFile() if (lastModified != null) headers["If-Modified-Since"] = lastModified!! val response = try { - HttpManager.sendHttpRequest(HttpManager.RequestType.GET, String.format(BUCKETING, flagshipConfig.envId), headers, null) + val res = HttpManager.sendHttpRequest(HttpManager.RequestType.GET, String.format(BUCKETING, flagshipConfig.envId), headers, null) + res } catch (e: Exception) { FlagshipLogManager.log(FlagshipLogManager.Tag.BUCKETING, LogManager.Level.ERROR, BUCKETING_POLLING_ERROR.format(e.message ?: "")) decisionFile?.let { decisionFile -> diff --git a/flagship/src/main/java/com/abtasty/flagship/main/ConfigManager.kt b/flagship/src/main/java/com/abtasty/flagship/main/ConfigManager.kt index f44fa0b..6b4180c 100644 --- a/flagship/src/main/java/com/abtasty/flagship/main/ConfigManager.kt +++ b/flagship/src/main/java/com/abtasty/flagship/main/ConfigManager.kt @@ -13,6 +13,8 @@ import com.abtasty.flagship.decision.DecisionManager import com.abtasty.flagship.eai.EAIManager import com.abtasty.flagship.main.Flagship.DecisionMode import com.abtasty.flagship.main.FlagshipConfig.DecisionApi +import com.abtasty.flagship.utils.FlagshipConstants +import com.abtasty.flagship.utils.FlagshipLogManager import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -42,8 +44,9 @@ class ConfigManager : DefaultLifecycleObserver { initCacheManager() initTrackingManager() initDecisionManager() - if (flagshipConfig.eaiCollectEnabled || flagshipConfig.eaiActivationEnabled) + if (flagshipConfig.eaiCollectEnabled || flagshipConfig.eaiActivationEnabled) { initEAIManager() + } } private fun initTrackingManager() { @@ -53,7 +56,11 @@ class ConfigManager : DefaultLifecycleObserver { private fun initCacheManager() { cacheManager = flagshipConfig.cacheManager ?: NoCache() - cacheManager.openDatabase(this.flagshipConfig.envId) + try { + cacheManager.openDatabase(this.flagshipConfig.envId) + } catch (e: Exception) { + FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) + } } private fun initDecisionManager() { diff --git a/flagship/src/main/java/com/abtasty/flagship/main/Flagship.kt b/flagship/src/main/java/com/abtasty/flagship/main/Flagship.kt index ea24f0e..84f5316 100644 --- a/flagship/src/main/java/com/abtasty/flagship/main/Flagship.kt +++ b/flagship/src/main/java/com/abtasty/flagship/main/Flagship.kt @@ -20,7 +20,6 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import java.util.UUID -import java.util.concurrent.CountDownLatch object Flagship { @@ -62,7 +61,7 @@ object Flagship { * Flagship SDK is initializing. */ INITIALIZING(0x1), - + /** * Flagship SDK is ready but is running in Panic mode: All features are disabled except the one which refresh this status. @@ -88,7 +87,8 @@ object Flagship { private var singleVisitorInstance: Visitor? = null private var status = FlagshipStatus.NOT_INITIALIZED internal var deviceContext = HashMap, Any>() -// internal var eaiCollectEnabled = false + + // internal var eaiCollectEnabled = false // internal var eaiActivationEnabled = false // internal var oneVisitorOneTestEnabled = false // internal var xpcEnabled = false @@ -102,30 +102,36 @@ object Flagship { * @param config : SDK configuration. @see FlagshipConfig */ @JvmStatic - fun start(application: Application, envId: String, apiKey: String, config: FlagshipConfig<*>) = mainCoroutineScope().async { - stop().await() - Flagship.application = application - instanceId = UUID.randomUUID().toString() - initializationTimeStamp = System.currentTimeMillis() - supervisorJob = SupervisorJob() - flagshipCoroutineScope = CoroutineScope(supervisorJob + Dispatchers.IO) - val handler = Handler(Looper.getMainLooper()) - handler.post { - ProcessLifecycleOwner.get().lifecycle.addObserver(configManager) - } - updateStatus(FlagshipStatus.INITIALIZING) - deviceContext.putAll(FlagshipContext.loadAndroidContext(application)) - configManager.init(envId, apiKey, config) { status -> - updateStatus(status) - } - if (!configManager.isSet()) { + fun start(application: Application, envId: String, apiKey: String, config: FlagshipConfig<*>) = + mainCoroutineScope().async { + try { + stop().await() + Flagship.application = application + instanceId = UUID.randomUUID().toString() + initializationTimeStamp = System.currentTimeMillis() + supervisorJob = SupervisorJob() + flagshipCoroutineScope = CoroutineScope(supervisorJob + Dispatchers.IO) + val handler = Handler(Looper.getMainLooper()) + handler.post { + ProcessLifecycleOwner.get().lifecycle.addObserver(configManager) + } + updateStatus(FlagshipStatus.INITIALIZING) + deviceContext.putAll(FlagshipContext.loadAndroidContext(application)) + configManager.init(envId, apiKey, config) { status -> + updateStatus(status) + } + if (!configManager.isSet()) { + updateStatus(FlagshipStatus.NOT_INITIALIZED) + FlagshipLogManager.log( + FlagshipLogManager.Tag.INITIALIZATION, LogManager.Level.ERROR, + FlagshipConstants.Errors.INITIALIZATION_PARAM_ERROR + ) + } + readinessLatch.countDown() + } catch (e: Exception) { + FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) updateStatus(FlagshipStatus.NOT_INITIALIZED) - FlagshipLogManager.log( - FlagshipLogManager.Tag.INITIALIZATION, LogManager.Level.ERROR, - FlagshipConstants.Errors.INITIALIZATION_PARAM_ERROR - ) } - readinessLatch.countDown() } /** @@ -137,7 +143,11 @@ object Flagship { * @return Visitor.Builder */ @JvmStatic - fun newVisitor(visitorId: String, consent: Boolean, instanceType: Visitor.Instance = Visitor.Instance.SINGLE_INSTANCE): Visitor.Builder { + fun newVisitor( + visitorId: String, + consent: Boolean, + instanceType: Visitor.Instance = Visitor.Instance.SINGLE_INSTANCE + ): Visitor.Builder { return Visitor.Builder(this.configManager, instanceType, visitorId, consent) } @@ -188,7 +198,7 @@ object Flagship { * This method will return any previous created visitor instance initialized with the SINGLE_INSTANCE (Set by default) option. */ @JvmStatic - fun getVisitor() : Visitor? { + fun getVisitor(): Visitor? { return this.singleVisitorInstance } @@ -205,8 +215,8 @@ object Flagship { * Stop the Flagship SDK. Any data and background job will be cleared or stopped. */ fun stop() = mainCoroutineScope().async { - if (Flagship::application.isInitialized) { - try { + try { + if (Flagship::application.isInitialized) { if (readinessLatch.count == 1L) readinessLatch.cancel() readinessLatch = Utils.Companion.CompatScreenMetric.CancelableCountDownLatch(1) @@ -220,9 +230,10 @@ object Flagship { status = FlagshipStatus.NOT_INITIALIZED if (flagshipCoroutineScope.isActive) flagshipCoroutineScope.cancel() - } catch (e: Exception) { - e.printStackTrace() + } + } catch (e: Exception) { + e.printStackTrace() } } } \ No newline at end of file diff --git a/flagship/src/main/java/com/abtasty/flagship/model/Variation.kt b/flagship/src/main/java/com/abtasty/flagship/model/Variation.kt index 359c74f..2e71022 100644 --- a/flagship/src/main/java/com/abtasty/flagship/model/Variation.kt +++ b/flagship/src/main/java/com/abtasty/flagship/model/Variation.kt @@ -56,7 +56,7 @@ data class Variation( FlagshipLogManager.log( FlagshipLogManager.Tag.PARSING, LogManager.Level.ERROR, - FlagshipConstants.Errors.PARSING_MODIFICATION_ERROR + " _ _ 1 _ _ " + FlagshipConstants.Errors.PARSING_MODIFICATION_ERROR + "[$value]" ) } flags @@ -65,7 +65,7 @@ data class Variation( FlagshipLogManager.log( FlagshipLogManager.Tag.PARSING, LogManager.Level.ERROR, - FlagshipConstants.Errors.PARSING_MODIFICATION_ERROR + " _ _ 2 _ _ " + FlagshipConstants.Errors.PARSING_MODIFICATION_ERROR + ": ${modificationsObj.toString()}" ) null } diff --git a/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt b/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt index 495dfc6..01d731f 100644 --- a/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt +++ b/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt @@ -293,16 +293,20 @@ abstract class FlagshipContext( internal fun loadAndroidContext(applicationContext : Context) : HashMap, Any> { val androidContext = HashMap, Any>() - if (autoLoading) { - for (flagshipContext in ALL) { - try { - flagshipContext.load(applicationContext)?.let { value: Any -> - androidContext.put(flagshipContext, value) + try { + if (autoLoading) { + for (flagshipContext in ALL) { + try { + flagshipContext.load(applicationContext)?.let { value: Any -> + androidContext.put(flagshipContext, value) + } + } catch (e: Exception) { + FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) } - } catch (e : Exception) { - FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) } } + } catch (e: Exception) { + FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) } return androidContext } diff --git a/gradle.properties b/gradle.properties index ea1a9a4..1bdc165 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m +org.gradle.jvmargs=-Xmx2048m -XX:-UseContainerSupport # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects @@ -29,4 +29,4 @@ signing.keyId= signing.password= signing.secretKeyRingFile= -org.gradle.caching=true \ No newline at end of file +org.gradle.caching=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f590bc3..5161965 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Thu Jun 15 19:32:02 CEST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists