From 75fe0559f2482378164a141b9e58b8a0bbac0813 Mon Sep 17 00:00:00 2001 From: Asim Ribo Date: Mon, 1 Jul 2024 20:29:26 +0200 Subject: [PATCH 01/11] Remove 2 provider setups and include the same setup in no-op manifest --- sentinel-no-op/src/main/AndroidManifest.xml | 5 +++++ sentinel/src/main/AndroidManifest.xml | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sentinel-no-op/src/main/AndroidManifest.xml b/sentinel-no-op/src/main/AndroidManifest.xml index ce089bd..287a45e 100644 --- a/sentinel-no-op/src/main/AndroidManifest.xml +++ b/sentinel-no-op/src/main/AndroidManifest.xml @@ -11,6 +11,11 @@ + + diff --git a/sentinel/src/main/AndroidManifest.xml b/sentinel/src/main/AndroidManifest.xml index 5d3da56..13a1b6f 100644 --- a/sentinel/src/main/AndroidManifest.xml +++ b/sentinel/src/main/AndroidManifest.xml @@ -112,13 +112,7 @@ - - Date: Fri, 5 Jul 2024 12:55:41 +0200 Subject: [PATCH 02/11] Revert "Remove 2 provider setups and include the same setup in no-op manifest" This reverts commit 75fe0559f2482378164a141b9e58b8a0bbac0813. --- sentinel-no-op/src/main/AndroidManifest.xml | 5 ----- sentinel/src/main/AndroidManifest.xml | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sentinel-no-op/src/main/AndroidManifest.xml b/sentinel-no-op/src/main/AndroidManifest.xml index 287a45e..ce089bd 100644 --- a/sentinel-no-op/src/main/AndroidManifest.xml +++ b/sentinel-no-op/src/main/AndroidManifest.xml @@ -11,11 +11,6 @@ - - diff --git a/sentinel/src/main/AndroidManifest.xml b/sentinel/src/main/AndroidManifest.xml index 13a1b6f..5d3da56 100644 --- a/sentinel/src/main/AndroidManifest.xml +++ b/sentinel/src/main/AndroidManifest.xml @@ -112,7 +112,13 @@ + + Date: Fri, 5 Jul 2024 14:10:27 +0200 Subject: [PATCH 03/11] Add check if WorkManager is initialized --- .../certificates/observer/SentinelWorkManager.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt index 944d7b3..8f2bef8 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt @@ -37,13 +37,15 @@ internal class SentinelWorkManager( } init { - WorkManager.initialize( - context, - Configuration.Builder() - .setMinimumLoggingLevel(android.util.Log.INFO) - .setWorkerFactory(workerFactory) - .build() - ) + if (WorkManager.isInitialized().not()) { + WorkManager.initialize( + context, + Configuration.Builder() + .setMinimumLoggingLevel(android.util.Log.INFO) + .setWorkerFactory(workerFactory) + .build() + ) + } } @RequiresApi(Build.VERSION_CODES.O) From d10925cb5e826228802636a13b344b5e50ff1308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Sun, 7 Jul 2024 15:43:24 +0200 Subject: [PATCH 04/11] Add delegate worker for certificate check To bypass restriction of now passing workerFactory to WorkManager configuration --- .../sentinel/di/component/DomainComponent.kt | 6 +- .../certificates/observer/DelegateWorker.kt | 69 +++++++++++++++++++ .../observer/SentinelWorkManager.kt | 29 ++++---- .../infinum/sentinel/ui/shared/Constants.kt | 2 + 4 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt index 2301cae..d51bef2 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt @@ -48,7 +48,9 @@ import com.infinum.sentinel.extensions.sizeTree import com.infinum.sentinel.ui.bundles.callbacks.BundleMonitorActivityCallbacks import com.infinum.sentinel.ui.bundles.callbacks.BundleMonitorNotificationCallbacks import com.infinum.sentinel.ui.bundles.details.BundleDetailsActivity +import com.infinum.sentinel.ui.certificates.observer.CertificateCheckWorker import com.infinum.sentinel.ui.certificates.observer.CertificatesObserver +import com.infinum.sentinel.ui.certificates.observer.DelegateWorker import com.infinum.sentinel.ui.certificates.observer.SentinelWorkManager import com.infinum.sentinel.ui.certificates.observer.SentinelWorkerFactory import com.infinum.sentinel.ui.crash.anr.SentinelAnrObserver @@ -160,7 +162,9 @@ internal abstract class DomainComponent( @Provides @DomainScope fun sentinelWorkerFactory(): SentinelWorkerFactory = - SentinelWorkerFactory(collectors, notificationFactory) + SentinelWorkerFactory(collectors, notificationFactory).also { + DelegateWorker.workerFactories[CertificateCheckWorker.NAME] = it + } @Provides @DomainScope diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt new file mode 100644 index 0000000..7a78d21 --- /dev/null +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt @@ -0,0 +1,69 @@ +package com.infinum.sentinel.ui.certificates.observer + +import android.content.Context +import android.util.Log +import androidx.work.Data +import androidx.work.ListenableWorker +import androidx.work.WorkerFactory +import androidx.work.WorkerParameters +import com.google.common.util.concurrent.ListenableFuture +import com.infinum.sentinel.ui.shared.Constants.Keys.WORKER_CLASS_NAME +import com.infinum.sentinel.ui.shared.Constants.Keys.WORKER_ID +import java.util.concurrent.Executor +import java.util.concurrent.TimeUnit + +/** + * A worker to delegate work requests from within the library to workers + * that require factories with custom dependencies. + */ +internal class DelegateWorker( + appContext: Context, + parameters: WorkerParameters, +) : ListenableWorker(appContext, parameters) { + + private val workerClassName = + parameters.inputData.getString(WORKER_CLASS_NAME) ?: "" + private val workerId = parameters.inputData.getString(WORKER_ID) + private val delegateWorkerFactory = workerFactories[workerId] + private val delegateWorker = delegateWorkerFactory?.createWorker(appContext, workerClassName, parameters) + + override fun startWork(): ListenableFuture { + return if (delegateWorker != null) { + delegateWorker.startWork() + } else { + val errorMessage = "No delegateWorker available for $workerId" + + " with workerClassName of $workerClassName. Is the " + + "RouterWorker.workerFactories populated correctly?" + + Log.w("Sentinel", errorMessage) + + val errorData = Data.Builder().putString("Reason", errorMessage).build() + + object : ListenableFuture { + override fun isDone(): Boolean = true + override fun get(): Result = Result.failure(errorData) + override fun get(timeout: Long, unit: TimeUnit): Result = Result.failure(errorData) + override fun cancel(mayInterruptIfRunning: Boolean): Boolean = false + override fun isCancelled(): Boolean = false + override fun addListener(listener: Runnable, executor: Executor) = listener.run() + } + } + } + + companion object { + const val DELEGATE_WORKER_ID = "com.infinum.sentinel.ui.certificates.observer.CertificateCheckWorker" + + val workerFactories = object : AbstractMutableMap() { + + private val backingWorkerMap = mutableMapOf() + + // should be invoked only from the main thread + override fun put(key: String, value: WorkerFactory): WorkerFactory? { + return backingWorkerMap.put(key, value) + } + + override val entries: MutableSet> + get() = backingWorkerMap.entries + } + } +} \ No newline at end of file diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt index 8f2bef8..f847dc2 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt @@ -19,6 +19,8 @@ import com.infinum.sentinel.ui.shared.Constants.Keys.EXPIRE_IN_AMOUNT import com.infinum.sentinel.ui.shared.Constants.Keys.EXPIRE_IN_UNIT import com.infinum.sentinel.ui.shared.Constants.Keys.NOTIFY_INVALID_NOW import com.infinum.sentinel.ui.shared.Constants.Keys.NOTIFY_TO_EXPIRE +import com.infinum.sentinel.ui.shared.Constants.Keys.WORKER_CLASS_NAME +import com.infinum.sentinel.ui.shared.Constants.Keys.WORKER_ID import java.time.Duration import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf @@ -49,25 +51,26 @@ internal class SentinelWorkManager( } @RequiresApi(Build.VERSION_CODES.O) - fun startCertificatesCheck(entity: CertificateMonitorEntity) = + fun startCertificatesCheck(entity: CertificateMonitorEntity) { + + val delegatedWorkData = workDataOf( + WORKER_CLASS_NAME to CertificateCheckWorker::class.qualifiedName, + WORKER_ID to CertificateCheckWorker.NAME, + NOTIFY_INVALID_NOW to entity.notifyInvalidNow, + NOTIFY_TO_EXPIRE to entity.notifyToExpire, + EXPIRE_IN_AMOUNT to entity.expireInAmount, + EXPIRE_IN_UNIT to entity.expireInUnit.name + ) WorkManager.getInstance(context) .enqueueUniquePeriodicWork( - CertificateCheckWorker.NAME, + DelegateWorker.DELEGATE_WORKER_ID, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, - PeriodicWorkRequestBuilder( + PeriodicWorkRequestBuilder( when (BuildConfig.DEBUG) { true -> Duration.ofMinutes(DEBUG_INTERVAL) false -> Duration.ofMinutes(RELEASE_INTERVAL) } - ) - .setInputData( - workDataOf( - NOTIFY_INVALID_NOW to entity.notifyInvalidNow, - NOTIFY_TO_EXPIRE to entity.notifyToExpire, - EXPIRE_IN_AMOUNT to entity.expireInAmount, - EXPIRE_IN_UNIT to entity.expireInUnit.name - ) - ) + ).setInputData(delegatedWorkData) .setConstraints( Constraints.Builder() .setRequiredNetworkType(NetworkType.NOT_REQUIRED) @@ -83,6 +86,8 @@ internal class SentinelWorkManager( .build() ) + } + fun certificatesCheckState(): Flow = WorkManager.getInstance(context) .getWorkInfosForUniqueWork(CertificateCheckWorker.NAME) diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/shared/Constants.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/shared/Constants.kt index 3e4004f..5ae33f0 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/shared/Constants.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/shared/Constants.kt @@ -14,5 +14,7 @@ internal object Constants { const val NOTIFY_TO_EXPIRE: String = "KEY_NOTIFY_TO_EXPIRE" const val EXPIRE_IN_AMOUNT: String = "KEY_EXPIRE_IN_AMOUNT" const val EXPIRE_IN_UNIT: String = "KEY_EXPIRE_IN_UNIT" + const val WORKER_CLASS_NAME = "WORKER_CLASS_NAME" + const val WORKER_ID = "WORKER_ID" } } From b2bb4e75a313bbd5de8c30ba8e2035e766f4227a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Sun, 7 Jul 2024 15:49:03 +0200 Subject: [PATCH 05/11] Fix lint --- .../sentinel/ui/certificates/observer/DelegateWorker.kt | 8 ++++---- .../ui/certificates/observer/SentinelWorkManager.kt | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt index 7a78d21..6d06639 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt @@ -25,11 +25,11 @@ internal class DelegateWorker( parameters.inputData.getString(WORKER_CLASS_NAME) ?: "" private val workerId = parameters.inputData.getString(WORKER_ID) private val delegateWorkerFactory = workerFactories[workerId] - private val delegateWorker = delegateWorkerFactory?.createWorker(appContext, workerClassName, parameters) + private val delegatedWorker = delegateWorkerFactory?.createWorker(appContext, workerClassName, parameters) override fun startWork(): ListenableFuture { - return if (delegateWorker != null) { - delegateWorker.startWork() + return if (delegatedWorker != null) { + delegatedWorker.startWork() } else { val errorMessage = "No delegateWorker available for $workerId" + " with workerClassName of $workerClassName. Is the " + @@ -66,4 +66,4 @@ internal class DelegateWorker( get() = backingWorkerMap.entries } } -} \ No newline at end of file +} diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt index f847dc2..8b7af79 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt @@ -85,7 +85,6 @@ internal class SentinelWorkManager( ) .build() ) - } fun certificatesCheckState(): Flow = From e80a050f6037fcd28ba0630acac36454ce045e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Sun, 14 Jul 2024 15:40:52 +0200 Subject: [PATCH 06/11] Add annotation to UI thread only method --- .../sentinel/ui/certificates/observer/DelegateWorker.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt index 6d06639..aea177b 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt @@ -2,6 +2,7 @@ package com.infinum.sentinel.ui.certificates.observer import android.content.Context import android.util.Log +import androidx.annotation.UiThread import androidx.work.Data import androidx.work.ListenableWorker import androidx.work.WorkerFactory @@ -57,7 +58,7 @@ internal class DelegateWorker( private val backingWorkerMap = mutableMapOf() - // should be invoked only from the main thread + @UiThread override fun put(key: String, value: WorkerFactory): WorkerFactory? { return backingWorkerMap.put(key, value) } From f7666a1fa97998a696ff363c2f1f85df14cf99f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Sun, 14 Jul 2024 15:48:08 +0200 Subject: [PATCH 07/11] Remove redundant manifest tags --- sentinel/src/main/AndroidManifest.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sentinel/src/main/AndroidManifest.xml b/sentinel/src/main/AndroidManifest.xml index 5d3da56..13a1b6f 100644 --- a/sentinel/src/main/AndroidManifest.xml +++ b/sentinel/src/main/AndroidManifest.xml @@ -112,13 +112,7 @@ - - Date: Wed, 17 Jul 2024 16:56:11 +0200 Subject: [PATCH 08/11] Remove unnecessary work manager initialization --- sentinel/src/main/AndroidManifest.xml | 11 +++-------- .../ui/certificates/observer/SentinelWorkManager.kt | 13 ------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/sentinel/src/main/AndroidManifest.xml b/sentinel/src/main/AndroidManifest.xml index bdf9379..61a5144 100644 --- a/sentinel/src/main/AndroidManifest.xml +++ b/sentinel/src/main/AndroidManifest.xml @@ -13,10 +13,10 @@ android:name=".ui.main.SentinelActivity" android:exported="true" android:label="@string/sentinel_name" + android:permission="com.infinum.sentinel.permission.ACCESS_SENTINEL" android:taskAffinity="com.infinum.sentinel" - android:theme="@style/Sentinel.Theme" - android:permission="com.infinum.sentinel.permission.ACCESS_SENTINEL"> - + @@ -117,11 +117,6 @@ - - diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt index 8b7af79..1059309 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Build import androidx.annotation.RequiresApi import androidx.lifecycle.asFlow -import androidx.work.Configuration import androidx.work.Constraints import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.NetworkType @@ -38,18 +37,6 @@ internal class SentinelWorkManager( private const val RELEASE_INTERVAL = 1440L } - init { - if (WorkManager.isInitialized().not()) { - WorkManager.initialize( - context, - Configuration.Builder() - .setMinimumLoggingLevel(android.util.Log.INFO) - .setWorkerFactory(workerFactory) - .build() - ) - } - } - @RequiresApi(Build.VERSION_CODES.O) fun startCertificatesCheck(entity: CertificateMonitorEntity) { From 337d91f8c12870ce2e4a1a13346b9d573cfbc800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Wed, 17 Jul 2024 17:01:00 +0200 Subject: [PATCH 09/11] Typo fix --- .../infinum/sentinel/ui/certificates/observer/DelegateWorker.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt index aea177b..a063255 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt @@ -34,7 +34,7 @@ internal class DelegateWorker( } else { val errorMessage = "No delegateWorker available for $workerId" + " with workerClassName of $workerClassName. Is the " + - "RouterWorker.workerFactories populated correctly?" + "DelegateWorker.workerFactories populated correctly?" Log.w("Sentinel", errorMessage) From fbdf3a92cd144073d19035f01b8d5704cd44e9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Wed, 17 Jul 2024 17:04:37 +0200 Subject: [PATCH 10/11] Replace failure result with exception --- .../ui/certificates/observer/DelegateWorker.kt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt index a063255..b4b503b 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt @@ -35,19 +35,7 @@ internal class DelegateWorker( val errorMessage = "No delegateWorker available for $workerId" + " with workerClassName of $workerClassName. Is the " + "DelegateWorker.workerFactories populated correctly?" - - Log.w("Sentinel", errorMessage) - - val errorData = Data.Builder().putString("Reason", errorMessage).build() - - object : ListenableFuture { - override fun isDone(): Boolean = true - override fun get(): Result = Result.failure(errorData) - override fun get(timeout: Long, unit: TimeUnit): Result = Result.failure(errorData) - override fun cancel(mayInterruptIfRunning: Boolean): Boolean = false - override fun isCancelled(): Boolean = false - override fun addListener(listener: Runnable, executor: Executor) = listener.run() - } + throw IllegalStateException(errorMessage) } } From bbd0d8a2a0eb7c1e392d08055dde0227f719b60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20=C4=8Ceh?= Date: Wed, 17 Jul 2024 17:42:01 +0200 Subject: [PATCH 11/11] Improve DI setup for work manager --- .../com/infinum/sentinel/di/LibraryComponents.kt | 1 + .../infinum/sentinel/di/WorkManagerInitializer.kt | 14 ++++++++++++++ .../sentinel/di/component/DomainComponent.kt | 14 +------------- .../ui/certificates/observer/DelegateWorker.kt | 4 ---- .../certificates/observer/SentinelWorkManager.kt | 2 -- 5 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 sentinel/src/main/kotlin/com/infinum/sentinel/di/WorkManagerInitializer.kt diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/di/LibraryComponents.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/di/LibraryComponents.kt index 72d71cb..68800d7 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/di/LibraryComponents.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/di/LibraryComponents.kt @@ -42,6 +42,7 @@ internal object LibraryComponents { tools.filterIsInstance().firstOrNull()?.userCertificates.orEmpty(), onTriggered ) + WorkManagerInitializer.init(domainComponent) domainComponent.setup() } diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/di/WorkManagerInitializer.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/di/WorkManagerInitializer.kt new file mode 100644 index 0000000..49f278c --- /dev/null +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/di/WorkManagerInitializer.kt @@ -0,0 +1,14 @@ +package com.infinum.sentinel.di + +import com.infinum.sentinel.di.component.DomainComponent +import com.infinum.sentinel.ui.certificates.observer.CertificateCheckWorker +import com.infinum.sentinel.ui.certificates.observer.DelegateWorker +import com.infinum.sentinel.ui.certificates.observer.SentinelWorkerFactory + +internal object WorkManagerInitializer { + + fun init(domainComponent: DomainComponent) { + DelegateWorker.workerFactories[CertificateCheckWorker.NAME] = + SentinelWorkerFactory(domainComponent.collectors, domainComponent.notificationFactory) + } +} diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt index d51bef2..f994549 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/di/component/DomainComponent.kt @@ -48,11 +48,8 @@ import com.infinum.sentinel.extensions.sizeTree import com.infinum.sentinel.ui.bundles.callbacks.BundleMonitorActivityCallbacks import com.infinum.sentinel.ui.bundles.callbacks.BundleMonitorNotificationCallbacks import com.infinum.sentinel.ui.bundles.details.BundleDetailsActivity -import com.infinum.sentinel.ui.certificates.observer.CertificateCheckWorker import com.infinum.sentinel.ui.certificates.observer.CertificatesObserver -import com.infinum.sentinel.ui.certificates.observer.DelegateWorker import com.infinum.sentinel.ui.certificates.observer.SentinelWorkManager -import com.infinum.sentinel.ui.certificates.observer.SentinelWorkerFactory import com.infinum.sentinel.ui.crash.anr.SentinelAnrObserver import com.infinum.sentinel.ui.crash.anr.SentinelAnrObserverRunnable import com.infinum.sentinel.ui.crash.anr.SentinelUiAnrObserver @@ -93,8 +90,6 @@ internal abstract class DomainComponent( abstract val sentinelAnrObserver: SentinelAnrObserver - abstract val sentinelWorkerFactory: SentinelWorkerFactory - abstract val sentinelWorkManager: SentinelWorkManager abstract val sentinelAnrObserverRunnable: SentinelAnrObserverRunnable @@ -159,17 +154,10 @@ internal abstract class DomainComponent( fun sentinelAnrObserverRunnable(dao: CrashesDao): SentinelAnrObserverRunnable = SentinelAnrObserverRunnable(context, notificationFactory, dao) - @Provides - @DomainScope - fun sentinelWorkerFactory(): SentinelWorkerFactory = - SentinelWorkerFactory(collectors, notificationFactory).also { - DelegateWorker.workerFactories[CertificateCheckWorker.NAME] = it - } - @Provides @DomainScope fun sentinelWorkManager(): SentinelWorkManager = - SentinelWorkManager(context, sentinelWorkerFactory) + SentinelWorkManager(context) @Provides @DomainScope diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt index b4b503b..318599d 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/DelegateWorker.kt @@ -1,17 +1,13 @@ package com.infinum.sentinel.ui.certificates.observer import android.content.Context -import android.util.Log import androidx.annotation.UiThread -import androidx.work.Data import androidx.work.ListenableWorker import androidx.work.WorkerFactory import androidx.work.WorkerParameters import com.google.common.util.concurrent.ListenableFuture import com.infinum.sentinel.ui.shared.Constants.Keys.WORKER_CLASS_NAME import com.infinum.sentinel.ui.shared.Constants.Keys.WORKER_ID -import java.util.concurrent.Executor -import java.util.concurrent.TimeUnit /** * A worker to delegate work requests from within the library to workers diff --git a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt index 1059309..6d3103e 100644 --- a/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt +++ b/sentinel/src/main/kotlin/com/infinum/sentinel/ui/certificates/observer/SentinelWorkManager.kt @@ -10,7 +10,6 @@ import androidx.work.NetworkType import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkInfo import androidx.work.WorkManager -import androidx.work.WorkerFactory import androidx.work.workDataOf import com.infinum.sentinel.BuildConfig import com.infinum.sentinel.data.models.local.CertificateMonitorEntity @@ -29,7 +28,6 @@ import me.tatarka.inject.annotations.Inject @Inject internal class SentinelWorkManager( private val context: Context, - private val workerFactory: WorkerFactory ) { companion object {