Skip to content

Commit

Permalink
RUMM-55 persist application packageName at init
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusc83 committed Dec 6, 2019
1 parent 99b4091 commit e957fd8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 7 additions & 6 deletions dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ object Datadog {
private lateinit var logStrategy: LogStrategy
private lateinit var networkInfoProvider: BroadcastReceiverNetworkInfoProvider
private lateinit var handlerThread: LogHandlerThread
private lateinit var contextRef: WeakReference<Context>
private var contextRef: WeakReference<Context> = WeakReference<Context>(null)
private lateinit var uploader: LogUploader
private var endpointUrl: String = DATADOG_US
internal var packageName: String = ""

/**
* Initializes the Datadog SDK.
Expand All @@ -67,6 +67,7 @@ object Datadog {
check(!initialized) { "Datadog has already been initialized." }

val appContext = context.applicationContext
packageName = context.packageName
contextRef = WeakReference(appContext)
this.clientToken = clientToken
logStrategy = LogFileStrategy(appContext)
Expand Down Expand Up @@ -101,13 +102,13 @@ object Datadog {
logStrategy.getLogReader().dropAllBatches()
sdkLogger.w(
"$TAG: old logs targeted at $endpointUrl " +
"will now be deleted"
"will now be deleted"
)
}
EndpointUpdateStrategy.SEND_OLD_LOGS_TO_NEW_ENDPOINT -> {
sdkLogger.w(
"$TAG: old logs targeted at $endpointUrl " +
"will now be sent to $endpointUrl"
"will now be sent to $endpointUrl"
)
}
}
Expand Down Expand Up @@ -144,8 +145,8 @@ object Datadog {
private fun checkInitialized() {
check(initialized) {
"Datadog has not been initialized.\n" +
"Please add the following code in your application's onCreate() method:\n" +
"Datadog.initialized(context, \"CLIENT_TOKEN\");"
"Please add the following code in your application's onCreate() method:\n" +
"Datadog.initialized(context, \"CLIENT_TOKEN\");"
}
}

Expand Down
11 changes: 11 additions & 0 deletions dd-sdk-android/src/test/kotlin/com/datadog/android/DatadogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ internal class DatadogTest {

lateinit var fakeToken: String

lateinit var packageName: String

@BeforeEach
fun `set up`(forge: Forge) {
fakeToken = forge.anHexadecimalString()
Expand All @@ -77,6 +79,9 @@ internal class DatadogTest {
whenever(mockConnectivityMgr.activeNetworkInfo) doReturn mockNetworkInfo
whenever(mockNetworkInfo.isConnected) doReturn true
whenever(mockNetworkInfo.type) doReturn ConnectivityManager.TYPE_WIFI

packageName = forge.anAlphabeticalString()
whenever(mockContext.packageName) doReturn packageName
}

@AfterEach
Expand All @@ -88,6 +93,12 @@ internal class DatadogTest {
}
}

fun `it will initialize all dependencies at initialize`(){
Datadog.initialize(mockContext, fakeToken)

assertThat(Datadog.packageName).isEqualTo(packageName)
}

@Test
fun `registers broadcast receiver on initialize`() {
Datadog.initialize(mockContext, fakeToken)
Expand Down

0 comments on commit e957fd8

Please sign in to comment.