Last active
March 8, 2023 10:14
-
-
Save tunjid/b064bba5969d428ebc44c8aaa90c5f37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
class DelegatingWorker( | |
appContext: Context, | |
workerParams: WorkerParameters, | |
) : CoroutineWorker(appContext, workerParams) { | |
private val workerClassName = | |
workerParams.inputData.getString(WORKER_CLASS_NAME) ?: "" | |
private val delegateWorker = | |
EntryPointAccessors.fromApplication<HiltWorkerFactoryEntryPoint>(appContext) | |
.hiltWorkerFactory() | |
.createWorker(appContext, workerClassName, workerParams) | |
as? CoroutineWorker | |
?: throw IllegalArgumentException("Unable to find appropriate worker") | |
override suspend fun getForegroundInfo(): ForegroundInfo = | |
delegateWorker.getForegroundInfo() | |
override suspend fun doWork(): Result = | |
delegateWorker.doWork() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment