1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.work.impl.utils; 18 19 import android.support.annotation.RestrictTo; 20 21 import androidx.work.impl.WorkDatabase; 22 import androidx.work.impl.WorkManagerImpl; 23 import androidx.work.impl.model.WorkSpecDao; 24 25 /** 26 * A Runnable that prunes work in the background. Pruned work meets the following criteria: 27 * - Is finished (succeeded, failed, or cancelled) 28 * - Has zero unfinished dependents 29 * 30 * @hide 31 */ 32 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 33 public class PruneWorkRunnable implements Runnable { 34 35 private WorkManagerImpl mWorkManagerImpl; 36 37 public PruneWorkRunnable(WorkManagerImpl workManagerImpl) { 38 mWorkManagerImpl = workManagerImpl; 39 } 40 41 @Override 42 public void run() { 43 WorkDatabase workDatabase = mWorkManagerImpl.getWorkDatabase(); 44 WorkSpecDao workSpecDao = workDatabase.workSpecDao(); 45 workSpecDao.pruneFinishedWorkWithZeroDependentsIgnoringKeepForAtLeast(); 46 } 47 } 48