Skip to content

Commit

Permalink
Don't disable SDK until the next cold start
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed Sep 17, 2024
1 parent 40a44b0 commit b28030b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ internal class EmbraceConfigService(
override fun onForeground(coldStart: Boolean, timestamp: Long) {
// Refresh the config on resume if it has expired
getConfig()
foregroundAction()
}

override val appFramework: AppFramework = localConfig.sdkConfig.appFramework?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,6 @@ internal class EmbraceConfigServiceTest {
assertTrue(configListenerTriggered)
}

@Test
fun `test onForeground() with sdk started and config sdkDisabled=true stops the SDK`() {
var stopped = false
service = createService(worker) {
stopped = true
}
fakePreferenceService.sdkDisabled = true
service.onForeground(true, 1100L)
assertTrue(stopped)
}

@Test
fun `test isSdkDisabled returns true`() {
fakePreferenceService.sdkDisabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@file:Suppress("DEPRECATION")

package io.embrace.android.embracesdk.testcases

import android.os.Build.VERSION_CODES.TIRAMISU
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace.AppFramework
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config

/**
* Validation of the basic and miscellaneous functionality of the Android SDK
*/
@Config(sdk = [TIRAMISU])
@RunWith(AndroidJUnit4::class)
internal class ConfigServiceTest {
@Rule
@JvmField
val testRule: IntegrationTestRule = IntegrationTestRule {
IntegrationTestRule.Harness(startImmediately = false)
}

@Test
fun `SDK can start`() {
with(testRule) {
assertFalse(embrace.isStarted)
startSdk()
assertEquals(AppFramework.NATIVE, harness.appFramework)
assertFalse(harness.overriddenConfigService.isSdkDisabled())
assertTrue(embrace.isStarted)
}
}

@Test
fun `SDK disabled via config cannot start`() {
with(testRule) {
harness.overriddenConfigService.sdkDisabled = true
startSdk()
assertFalse(embrace.isStarted)
}
}

@Test
fun `disabling SDK will not resort to a stopping after foregrounding agian`() {
with(testRule) {
startSdk()
assertTrue(embrace.isStarted)
with(harness) {
val session = recordSession {
harness.overriddenConfigService.sdkDisabled = true
harness.overriddenConfigService.updateListeners()
}
assertNotNull(session)
assertNotNull(recordSession())
assertTrue(embrace.isStarted)
}
}
}
}

0 comments on commit b28030b

Please sign in to comment.