1 /*
2  * Copyright 2021 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;
18 
19 import android.content.Context;
20 
21 import androidx.startup.Initializer;
22 
23 import org.jspecify.annotations.NonNull;
24 
25 import java.util.Collections;
26 import java.util.List;
27 
28 /**
29  * Initializes {@link androidx.work.WorkManager} using {@code androidx.startup}.
30  */
31 public final class WorkManagerInitializer implements Initializer<WorkManager> {
32 
33     private static final String TAG = Logger.tagWithPrefix("WrkMgrInitializer");
34 
35     @Override
create(@onNull Context context)36     public @NonNull WorkManager create(@NonNull Context context) {
37         // Initialize WorkManager with the default configuration.
38         Logger.get().debug(TAG, "Initializing WorkManager with default configuration.");
39         WorkManager.initialize(context, new Configuration.Builder().build());
40         return WorkManager.getInstance(context);
41     }
42 
43     @Override
dependencies()44     public @NonNull List<Class<? extends androidx.startup.Initializer<?>>> dependencies() {
45         return Collections.emptyList();
46     }
47 }
48