Skip to content

[BUG]: PlatformParemeterSyncUpWorkerFactory and MetricLogSchedulingWorkerFactory are not being initialised correctly #5989

@kkmurerwa

Description

@kkmurerwa

Describe the bug

The createWorkerMethod of the PlatformParemeterSyncUpWorkerFactory and MetricLogSchedulingWorkerFactory is not set up properly. This leads to instances such as duplicate factories being created and/or the worker not being initialised correctly once added to the DelegatingWorkerFactory on the WorkManagerConfigurationModule. This needs to be fixed in a similar way to what is shown below. The fix should also extend to the LogUploadWorkerFactory.

Sample fix;

LogUploadWorkerFactory

class LogUploadWorkerFactory @Inject constructor(
  private val workerFactory: LogUploadWorker.Factory
) : WorkerFactory() {

  override fun createWorker(
    appContext: Context,
    workerClassName: String,
    workerParameters: WorkerParameters
  ): ListenableWorker? {
    return if (workerClassName == LogUploadWorker::class.java.name) {
      workerFactory.create(appContext, workerParameters)
    } else null
  }
}

PlatformParameterSyncUpWorkerFactory

class PlatformParameterSyncUpWorkerFactory @Inject constructor(
  private val workerFactory: PlatformParameterSyncUpWorker.Factory
) : WorkerFactory() {

  override fun createWorker(
    context: Context,
    workerClassName: String,
    workerParameters: WorkerParameters
  ): ListenableWorker? {
    return if (workerClassName == PlatformParameterSyncUpWorker::class.java.name) {
      workerFactory.create(context, workerParameters)
    } else null
  }
}

MetricLogSchedulingWorkerFactory

class MetricLogSchedulingWorkerFactory @Inject constructor(
  private val workerFactory: MetricLogSchedulingWorker.Factory
) : WorkerFactory() {

  override fun createWorker(
    appContext: Context,
    workerClassName: String,
    workerParameters: WorkerParameters
  ): ListenableWorker? { // must be nullable!
    return if (workerClassName == MetricLogSchedulingWorker::class.java.name) {
      workerFactory.create(appContext, workerParameters)
    } else null
  }
}

Steps To Reproduce

  1. Uninstall the Oppia app or clear storage.
  2. Open logcat and filter by the keyword "Worker".
  3. Reinstall the app on a mobile device with Android 10 and below.
  4. Observe the logcat.
  5. You should be able to see the MetricLogSchedulingWorker and PlatformParameterSyncUpWorker reporting Failure results after they run.

Expected Behavior

Both workers should succeed.

Screenshots/Videos

Image

What device/emulator are you using?

No response

Which Android version is your device/emulator running?

Android 10

Which version of the Oppia Android app are you using?

No response

Additional Context

No response

Metadata

Metadata

Assignees

Labels

Impact: MediumModerate perceived user impact (non-blocking bugs and general improvements).Work: LowSolution is clear and broken into good-first-issue-sized chunks.bugEnd user-perceivable behaviors which are not desirable.good first issueThis item is good for new contributors to make their pull request.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions