Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DummyWorker as workaround for WorkManager bug #211

Merged
merged 2 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dp3t-sdk/sdk/src/main/java/org/dpppt/android/sdk/DP3T.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private static void executeInit(Context context, AppConfigManager appConfigManag

if (appConfigManager.isTracingEnabled()) {
SyncWorker.startSyncWorker(context);
DummyWorker.startDummyWorker(context);
BroadcastHelper.sendUpdateAndErrorBroadcast(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/
package org.dpppt.android.sdk.internal;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.work.*;

import java.util.concurrent.TimeUnit;

// This DummyWorker is used to be able to start a Worker with
// ExistingPeriodicWorkPolicy.REPLACE to ensure that the job (and all other jobs) is rescheduled
// as a workaround for https://issuetracker.google.com/166292069.
public class DummyWorker extends Worker {

private static final String WORK_TAG = "DummyWorker";

public static void startDummyWorker(Context context) {

Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
simonroesch marked this conversation as resolved.
Show resolved Hide resolved
.build();

PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(SyncWorker.class, 1, TimeUnit.DAYS)
.setConstraints(constraints)
.build();

WorkManager workManager = WorkManager.getInstance(context);
workManager.enqueueUniquePeriodicWork(WORK_TAG, ExistingPeriodicWorkPolicy.REPLACE, periodicWorkRequest);
}

public DummyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}

@NonNull
@Override
public Result doWork() {
return Result.success();
}

}