@@ -0,0 +1,2487 @@
+/*%0A * Copyright 2019 Google LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.google.android.gnd.workers;%0A%0Aimport androidx.lifecycle.LiveData;%0Aimport androidx.work.Constraints;%0Aimport androidx.work.ExistingWorkPolicy;%0Aimport androidx.work.NetworkType;%0Aimport androidx.work.OneTimeWorkRequest;%0Aimport androidx.work.WorkInfo;%0Aimport androidx.work.WorkManager;%0A%0A/** Enqueues file download work to be done in the background. */%0Apublic class FileDownloadWorkManager %7B%0A  private final WorkManager workManager;%0A%0A  public FileDownloadWorkManager() %7B%0A    this.workManager = WorkManager.getInstance();%0A  %7D%0A%0A  /**%0A   * Enqueues a worker that downloads files when a network connection is available, returning live%0A   * data that contains %7B@link WorkInfo%7D. Observe the returned live data to do something with the%0A   * worker's result.%0A   */%0A  public LiveData%3CWorkInfo%3E enqueueFileDownloadWorker(String url, String filename) %7B%0A    return getWorkManager()%0A        .getWorkInfoByIdLiveData(enqueueFileDownloadWorkerInternal(url, filename).getId());%0A  %7D%0A%0A  private OneTimeWorkRequest enqueueFileDownloadWorkerInternal(String url, String filename) %7B%0A    OneTimeWorkRequest request = buildWorkerRequest(url, filename);%0A%0A    getWorkManager()%0A        .enqueueUniqueWork(FileDownloadWorker.class.getName(), ExistingWorkPolicy.APPEND, request);%0A%0A    // Return the request in order to fetch the %7B@link WorkInfo%7D for the request using the request id.%0A    return request;%0A  %7D%0A%0A  private WorkManager getWorkManager() %7B%0A    return workManager;%0A  %7D%0A%0A  private Constraints getWorkerConstraints() %7B%0A    return new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();%0A  %7D%0A%0A  private OneTimeWorkRequest buildWorkerRequest(String url, String filename) %7B%0A    return new OneTimeWorkRequest.Builder(FileDownloadWorker.class)%0A        .setConstraints(getWorkerConstraints())%0A        .setInputData(FileDownloadWorker.createInputData(url, filename))%0A        .build();%0A  %7D%0A%7D%0A

Add file download work manager