mirror of
https://github.com/androidx/media.git
synced 2025-05-16 12:09:50 +08:00
Migrate WorkManagerScheduler to non-deprecated WorkManager.getInstance
PiperOrigin-RevId: 322143769
This commit is contained in:
parent
0cd15d9158
commit
df1536ab24
@ -46,16 +46,27 @@ public final class WorkManagerScheduler implements Scheduler {
|
|||||||
| Requirements.DEVICE_CHARGING
|
| Requirements.DEVICE_CHARGING
|
||||||
| Requirements.DEVICE_STORAGE_NOT_LOW;
|
| Requirements.DEVICE_STORAGE_NOT_LOW;
|
||||||
|
|
||||||
|
private final WorkManager workManager;
|
||||||
private final String workName;
|
private final String workName;
|
||||||
|
|
||||||
|
/** @deprecated Call {@link #WorkManagerScheduler(Context, String)} instead. */
|
||||||
|
@Deprecated
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public WorkManagerScheduler(String workName) {
|
||||||
|
this.workName = workName;
|
||||||
|
workManager = WorkManager.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param context A context.
|
||||||
* @param workName A name for work scheduled by this instance. If the same name was used by a
|
* @param workName A name for work scheduled by this instance. If the same name was used by a
|
||||||
* previous instance, anything scheduled by the previous instance will be canceled by this
|
* previous instance, anything scheduled by the previous instance will be canceled by this
|
||||||
* instance if {@link #schedule(Requirements, String, String)} or {@link #cancel()} are
|
* instance if {@link #schedule(Requirements, String, String)} or {@link #cancel()} are
|
||||||
* called.
|
* called.
|
||||||
*/
|
*/
|
||||||
public WorkManagerScheduler(String workName) {
|
public WorkManagerScheduler(Context context, String workName) {
|
||||||
this.workName = workName;
|
this.workName = workName;
|
||||||
|
workManager = WorkManager.getInstance(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,13 +74,13 @@ public final class WorkManagerScheduler implements Scheduler {
|
|||||||
Constraints constraints = buildConstraints(requirements);
|
Constraints constraints = buildConstraints(requirements);
|
||||||
Data inputData = buildInputData(requirements, servicePackage, serviceAction);
|
Data inputData = buildInputData(requirements, servicePackage, serviceAction);
|
||||||
OneTimeWorkRequest workRequest = buildWorkRequest(constraints, inputData);
|
OneTimeWorkRequest workRequest = buildWorkRequest(constraints, inputData);
|
||||||
WorkManager.getInstance().enqueueUniqueWork(workName, ExistingWorkPolicy.REPLACE, workRequest);
|
workManager.enqueueUniqueWork(workName, ExistingWorkPolicy.REPLACE, workRequest);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
WorkManager.getInstance().cancelUniqueWork(workName);
|
workManager.cancelUniqueWork(workName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user