Skip to content

Commit

Permalink
refactor: remove apk tools config
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jul 29, 2024
1 parent a7d76f3 commit d0d514c
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ package io.embrace.android.embracesdk.testcases

import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.internal.EventType
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.LogType
import io.embrace.android.embracesdk.internal.arch.schema.EmbType
import io.embrace.android.embracesdk.findEventOfType
import io.embrace.android.embracesdk.findSessionSpan
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.EventType
import io.embrace.android.embracesdk.internal.arch.schema.EmbType
import io.embrace.android.embracesdk.internal.payload.Span
import io.embrace.android.embracesdk.internal.spans.findAttributeValue
import io.embrace.android.embracesdk.network.EmbraceNetworkRequest
import io.embrace.android.embracesdk.network.http.HttpMethod
import io.embrace.android.embracesdk.recordSession
import io.embrace.android.embracesdk.spans.ErrorCode
import java.net.SocketException
import io.opentelemetry.semconv.HttpAttributes
import java.net.SocketException
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -42,11 +40,6 @@ internal class EmbraceInternalInterfaceTest {
IntegrationTestRule.Harness(startImmediately = false)
}

@Before
fun setup() {
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = false
}

@Test
fun `no NPEs when SDK not started`() {
assertFalse(testRule.embrace.isStarted)
Expand Down Expand Up @@ -230,11 +223,10 @@ internal class EmbraceInternalInterfaceTest {

@Test
fun `test isInternalNetworkCaptureDisabled`() {
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = true
with(testRule) {
assertFalse(embrace.internalInterface.isInternalNetworkCaptureDisabled())
startSdk(context = harness.overriddenCoreModule.context)
assertTrue(embrace.internalInterface.isInternalNetworkCaptureDisabled())
assertFalse(embrace.internalInterface.isInternalNetworkCaptureDisabled())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import io.embrace.android.embracesdk.fakes.FakeClock
import io.embrace.android.embracesdk.fakes.injection.FakeInitModule
import io.embrace.android.embracesdk.fakes.injection.FakeWorkerThreadModule
import io.embrace.android.embracesdk.getLastSentLog
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.payload.AppFramework
import io.embrace.android.embracesdk.internal.spans.findAttributeValue
import io.embrace.android.embracesdk.recordSession
import io.embrace.android.embracesdk.internal.worker.WorkerName
import io.embrace.android.embracesdk.recordSession
import io.opentelemetry.api.logs.Severity
import io.opentelemetry.semconv.ExceptionAttributes
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -49,11 +47,6 @@ internal class FlutterInternalInterfaceTest {
)
}

@Before
fun setup() {
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = false
}

@Test
fun `flutter without values should return defaults`() {
with(testRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.IdGeneratorTest.Companion.validPattern
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert.assertEquals
Expand All @@ -15,7 +14,6 @@ import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -33,11 +31,6 @@ internal class PublicApiTest {
IntegrationTestRule.Harness(startImmediately = false)
}

@Before
fun before() {
ApkToolsConfig.IS_SDK_DISABLED = false
}

@Test
fun `SDK can start`() {
with(testRule) {
Expand All @@ -59,15 +52,6 @@ internal class PublicApiTest {
}
}

@Test
fun `SDK disabled via the binary cannot start`() {
with(testRule) {
ApkToolsConfig.IS_SDK_DISABLED = true
startSdk(context = harness.overriddenCoreModule.context)
assertFalse(embrace.isStarted)
}
}

@Test
fun `SDK disabled via config cannot start`() {
with(testRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.internal.arch.schema.EmbType
import io.embrace.android.embracesdk.findSpanSnapshotsOfType
import io.embrace.android.embracesdk.findSpansByName
import io.embrace.android.embracesdk.findSpansOfType
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.arch.schema.EmbType
import io.embrace.android.embracesdk.internal.clock.nanosToMillis
import io.embrace.android.embracesdk.internal.payload.AppFramework
import io.embrace.android.embracesdk.internal.spans.findAttributeValue
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -35,11 +33,6 @@ internal class ReactNativeInternalInterfaceTest {
IntegrationTestRule.Harness(appFramework = Embrace.AppFramework.REACT_NATIVE)
}

@Before
fun setup() {
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = false
}

@Test
fun `react native without values should return defaults`() {
with(testRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.payload.AppFramework
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -29,11 +27,6 @@ internal class UnityInternalInterfaceTest {
IntegrationTestRule.Harness(appFramework = Embrace.AppFramework.UNITY)
}

@Before
fun setup() {
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = false
}

@Test
fun `unity without values should return defaults`() {
with(testRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.embrace.android.embracesdk
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.EmbraceInternalInterface
import io.embrace.android.embracesdk.internal.EventType
import io.embrace.android.embracesdk.internal.Systrace.endSynchronous
Expand Down Expand Up @@ -167,12 +166,6 @@ internal class EmbraceImpl @JvmOverloads constructor(
return
}

if (ApkToolsConfig.IS_SDK_DISABLED) {
logger.logInfo("SDK disabled through ApkToolsConfig", null)
stop()
return
}

val startTimeMs = sdkClock.now()

val appFramework = fromFramework(framework)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.embrace.android.embracesdk.EmbraceImpl
import io.embrace.android.embracesdk.LogExceptionType
import io.embrace.android.embracesdk.LogType
import io.embrace.android.embracesdk.Severity
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.EmbraceInternalInterface
import io.embrace.android.embracesdk.internal.EventType
import io.embrace.android.embracesdk.internal.InternalTracingApi
Expand Down Expand Up @@ -173,7 +172,7 @@ internal class EmbraceInternalInterfaceImpl(

override fun getSdkCurrentTime(): Long = initModule.clock.now()

override fun isInternalNetworkCaptureDisabled(): Boolean = ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED
override fun isInternalNetworkCaptureDisabled(): Boolean = false

override fun isAnrCaptureEnabled(): Boolean = configService.anrBehavior.isAnrCaptureEnabled()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.internal.capture.crash

import io.embrace.android.embracesdk.Severity
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.anr.AnrService
import io.embrace.android.embracesdk.internal.arch.datasource.LogDataSourceImpl
import io.embrace.android.embracesdk.internal.arch.destination.LogWriter
Expand Down Expand Up @@ -56,9 +55,7 @@ internal class CrashDataSourceImpl(
private var jsException: JsException? = null

init {
if (configService.autoDataCaptureBehavior.isUncaughtExceptionHandlerEnabled() &&
!ApkToolsConfig.IS_EXCEPTION_CAPTURE_DISABLED
) {
if (configService.autoDataCaptureBehavior.isUncaughtExceptionHandlerEnabled()) {
registerExceptionHandler()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.embrace.android.embracesdk.internal.config
import android.content.res.Resources.NotFoundException
import android.util.Base64
import io.embrace.android.embracesdk.internal.AndroidResourcesService
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.config.local.LocalConfig
import io.embrace.android.embracesdk.internal.config.local.SdkLocalConfig
import io.embrace.android.embracesdk.internal.logging.EmbLogger
Expand Down Expand Up @@ -59,7 +58,7 @@ internal object LocalConfigParser {
)

else -> NDK_ENABLED_DEFAULT
} && !ApkToolsConfig.IS_NDK_DISABLED
}
val sdkConfigJsonId =
resources.getIdentifier(BUILD_INFO_SDK_CONFIG, "string", packageName)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.embrace.android.embracesdk.internal.config.behavior

import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.config.local.LocalConfig
import io.embrace.android.embracesdk.internal.config.remote.RemoteConfig
import io.embrace.android.embracesdk.internal.utils.Provider
Expand Down Expand Up @@ -77,7 +76,7 @@ internal class AutoDataCaptureBehaviorImpl(
?: local?.sdkConfig?.sigHandlerDetection ?: true
}

override fun isNdkEnabled(): Boolean = local?.ndkEnabled ?: false && !ApkToolsConfig.IS_NDK_DISABLED
override fun isNdkEnabled(): Boolean = local?.ndkEnabled ?: false

override fun isDiskUsageReportingEnabled(): Boolean =
local?.sdkConfig?.app?.reportDiskUsage ?: REPORT_DISK_USAGE_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.internal.injection

import android.os.Looper
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.SharedObjectLoader
import io.embrace.android.embracesdk.internal.anr.AnrOtelMapper
import io.embrace.android.embracesdk.internal.anr.AnrService
Expand All @@ -27,7 +26,7 @@ internal class AnrModuleImpl(
private val configService = essentialServiceModule.configService

override val anrService: AnrService by singleton {
if (configService.autoDataCaptureBehavior.isAnrServiceEnabled() && !ApkToolsConfig.IS_ANR_MONITORING_DISABLED) {
if (configService.autoDataCaptureBehavior.isAnrServiceEnabled()) {
// the customer didn't enable early ANR detection, so construct the service
// as part of normal initialization.
EmbraceAnrService(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.internal.logging

import android.util.Log
import io.embrace.android.embracesdk.internal.ApkToolsConfig

internal const val EMBRACE_TAG = "[Embrace]"

Expand Down Expand Up @@ -52,7 +51,7 @@ internal class EmbLoggerImpl : EmbLogger {
*/
@Suppress("NOTHING_TO_INLINE") // hot path - optimize by inlining
private inline fun log(msg: String, severity: EmbLogger.Severity, throwable: Throwable?) {
if (severity >= EmbLogger.Severity.INFO || ApkToolsConfig.IS_DEVELOPER_LOGGING_ENABLED) {
if (severity >= EmbLogger.Severity.INFO) {
logcatImpl(throwable, severity, msg)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Base64
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.DeviceArchitecture
import io.embrace.android.embracesdk.internal.EventType
import io.embrace.android.embracesdk.internal.SharedObjectLoader
Expand Down Expand Up @@ -236,7 +235,7 @@ internal class EmbraceNdkService(
nativeCrashId,
Build.VERSION.SDK_INT,
is32bit,
ApkToolsConfig.IS_DEVELOPER_LOGGING_ENABLED
false
)
}
Systrace.traceSynchronous("update-metadata") { updateDeviceMetaData() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.embrace.android.embracesdk.fakes.fakeAnrBehavior
import io.embrace.android.embracesdk.fakes.fakeAutoDataCaptureBehavior
import io.embrace.android.embracesdk.fakes.fakeNetworkSpanForwardingBehavior
import io.embrace.android.embracesdk.fakes.injection.FakeInitModule
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.EventType
import io.embrace.android.embracesdk.internal.api.delegate.EmbraceInternalInterfaceImpl
import io.embrace.android.embracesdk.internal.config.local.LocalConfig
Expand Down Expand Up @@ -62,7 +61,6 @@ internal class EmbraceInternalInterfaceImplTest {
fakeConfigService,
initModule.openTelemetryModule.internalTracer
)
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = false
}

@Test
Expand Down Expand Up @@ -207,8 +205,6 @@ internal class EmbraceInternalInterfaceImplTest {
@Test
fun `test isInternalNetworkCaptureDisabled`() {
assertFalse(internalImpl.isInternalNetworkCaptureDisabled())
ApkToolsConfig.IS_NETWORK_CAPTURE_DISABLED = true
assertTrue(internalImpl.isInternalNetworkCaptureDisabled())
}

@Test
Expand Down
Loading

0 comments on commit d0d514c

Please sign in to comment.