Skip to content

Commit 947ff60

Browse files
authored
Merge pull request #2511 from DataDog/yl/ih/change-upload-worker-visibility
RUM-8705: Change UploadWorker visibility from internal to public
2 parents fe2a4ca + 3f6b4bb commit 947ff60

File tree

8 files changed

+36
-11
lines changed

8 files changed

+36
-11
lines changed

dd-sdk-android-core/api/apiSurface

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ class com.datadog.android.core.SdkReference
193193
fun get(): com.datadog.android.api.SdkCore?
194194
fun <T> allowThreadDiskReads(() -> T): T
195195
fun <T> allowThreadDiskWrites(() -> T): T
196+
class com.datadog.android.core.UploadWorker : androidx.work.Worker
197+
constructor(android.content.Context, androidx.work.WorkerParameters)
198+
override fun doWork(): Result
199+
companion object
196200
enum com.datadog.android.core.configuration.BackPressureMitigation
197201
- DROP_OLDEST
198202
- IGNORE_NEWEST

dd-sdk-android-core/api/dd-sdk-android-core.api

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,15 @@ public final class com/datadog/android/core/StrictModeExtKt {
548548
public static final fun allowThreadDiskWrites (Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
549549
}
550550

551+
public final class com/datadog/android/core/UploadWorker : androidx/work/Worker {
552+
public static final field Companion Lcom/datadog/android/core/UploadWorker$Companion;
553+
public fun <init> (Landroid/content/Context;Landroidx/work/WorkerParameters;)V
554+
public fun doWork ()Landroidx/work/ListenableWorker$Result;
555+
}
556+
557+
public final class com/datadog/android/core/UploadWorker$Companion {
558+
}
559+
551560
public final class com/datadog/android/core/configuration/BackPressureMitigation : java/lang/Enum {
552561
public static final field DROP_OLDEST Lcom/datadog/android/core/configuration/BackPressureMitigation;
553562
public static final field IGNORE_NEWEST Lcom/datadog/android/core/configuration/BackPressureMitigation;
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright 2016-Present Datadog, Inc.
55
*/
66

7-
package com.datadog.android.core.internal.data.upload
7+
package com.datadog.android.core
88

99
import android.content.Context
1010
import androidx.annotation.WorkerThread
@@ -14,16 +14,28 @@ import com.datadog.android.Datadog
1414
import com.datadog.android.api.InternalLogger
1515
import com.datadog.android.api.context.DatadogContext
1616
import com.datadog.android.api.storage.RawBatchEvent
17-
import com.datadog.android.core.InternalSdkCore
1817
import com.datadog.android.core.internal.NoOpInternalSdkCore
1918
import com.datadog.android.core.internal.SdkFeature
19+
import com.datadog.android.core.internal.data.upload.DataUploader
20+
import com.datadog.android.core.internal.data.upload.UploadStatus
2021
import com.datadog.android.core.internal.metrics.RemovalReason
2122
import com.datadog.android.core.internal.persistence.BatchId
2223
import com.datadog.android.core.internal.utils.unboundInternalLogger
2324
import java.util.LinkedList
2425
import java.util.Queue
2526

26-
internal class UploadWorker(
27+
/**
28+
* `UploadWorker` is responsible for handling background upload tasks using WorkManager. This
29+
* worker is designed to process Datadog upload jobs asynchronously.
30+
*
31+
* ## Important:
32+
* **This worker must be used only when a custom WorkFactory is implemented.**
33+
*
34+
* @constructor Creates an instance of `UploadWorker`.
35+
* @param appContext The application context.
36+
* @param workerParams Parameters required for the worker execution.
37+
*/
38+
class UploadWorker(
2739
appContext: Context,
2840
workerParams: WorkerParameters
2941
) : Worker(appContext, workerParams) {
@@ -70,7 +82,7 @@ internal class UploadWorker(
7082

7183
// region Internal
7284

73-
class UploadNextBatchTask(
85+
internal class UploadNextBatchTask(
7486
private val taskQueue: Queue<UploadNextBatchTask>,
7587
private val sdkCore: InternalSdkCore,
7688
private val feature: SdkFeature
@@ -121,8 +133,8 @@ internal class UploadWorker(
121133

122134
companion object {
123135

124-
const val MESSAGE_NOT_INITIALIZED = "Datadog has not been initialized."
136+
internal const val MESSAGE_NOT_INITIALIZED = "Datadog has not been initialized."
125137

126-
const val DATADOG_INSTANCE_NAME = "_dd.sdk.instanceName"
138+
internal const val DATADOG_INSTANCE_NAME = "_dd.sdk.instanceName"
127139
}
128140
}

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/utils/WorkManagerUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import androidx.work.NetworkType
1414
import androidx.work.OneTimeWorkRequest
1515
import androidx.work.WorkManager
1616
import com.datadog.android.api.InternalLogger
17-
import com.datadog.android.core.internal.data.upload.UploadWorker
17+
import com.datadog.android.core.UploadWorker
1818
import java.util.concurrent.TimeUnit
1919

2020
internal const val CANCEL_ERROR_MESSAGE = "Error cancelling the UploadWorker"

dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/data/upload/UploadWorkerTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.datadog.android.Datadog
1515
import com.datadog.android.api.context.DatadogContext
1616
import com.datadog.android.api.storage.RawBatchEvent
1717
import com.datadog.android.core.InternalSdkCore
18+
import com.datadog.android.core.UploadWorker
1819
import com.datadog.android.core.internal.NoOpInternalSdkCore
1920
import com.datadog.android.core.internal.SdkFeature
2021
import com.datadog.android.core.internal.data.upload.UploadStatus.Companion.UNKNOWN_RESPONSE_CODE

dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallbackTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import androidx.work.ExistingWorkPolicy
1111
import androidx.work.OneTimeWorkRequest
1212
import androidx.work.impl.WorkManagerImpl
1313
import com.datadog.android.api.InternalLogger
14-
import com.datadog.android.core.internal.data.upload.UploadWorker
14+
import com.datadog.android.core.UploadWorker
1515
import com.datadog.android.core.internal.utils.TAG_DATADOG_UPLOAD
1616
import com.datadog.android.core.internal.utils.UPLOAD_WORKER_NAME
1717
import com.datadog.android.utils.config.ApplicationContextTestConfiguration

dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/utils/WorkManagerUtilsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import androidx.work.ExistingWorkPolicy
1111
import androidx.work.OneTimeWorkRequest
1212
import androidx.work.impl.WorkManagerImpl
1313
import com.datadog.android.api.InternalLogger
14+
import com.datadog.android.core.UploadWorker
1415
import com.datadog.android.core.internal.CoreFeature
15-
import com.datadog.android.core.internal.data.upload.UploadWorker
1616
import com.datadog.android.utils.config.ApplicationContextTestConfiguration
1717
import com.datadog.android.utils.forge.Configurator
1818
import com.datadog.tools.unit.annotations.TestConfigurationsProvider

dd-sdk-android-core/src/test/kotlin/com/datadog/android/error/internal/DatadogExceptionHandlerTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import com.datadog.android.api.InternalLogger
1515
import com.datadog.android.api.feature.Feature
1616
import com.datadog.android.api.feature.FeatureScope
1717
import com.datadog.android.core.InternalSdkCore
18+
import com.datadog.android.core.UploadWorker
1819
import com.datadog.android.core.feature.event.JvmCrash
1920
import com.datadog.android.core.internal.CoreFeature
20-
import com.datadog.android.core.internal.data.upload.UploadWorker
2121
import com.datadog.android.core.internal.thread.waitToIdle
2222
import com.datadog.android.core.internal.utils.TAG_DATADOG_UPLOAD
2323
import com.datadog.android.core.internal.utils.UPLOAD_WORKER_NAME
24-
import com.datadog.android.core.internal.utils.loggableStackTrace
2524
import com.datadog.android.internal.utils.loggableStackTrace
2625
import com.datadog.android.utils.config.ApplicationContextTestConfiguration
2726
import com.datadog.android.utils.forge.Configurator

0 commit comments

Comments
 (0)