1 /* 2 * Copyright 2019 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 package androidx.work 17 18 import androidx.annotation.RestrictTo 19 20 /** 21 * A factory object that creates [InputMerger] instances. The factory is invoked every time a work 22 * runs. You can override the default implementation of this factory by manually initializing 23 * [WorkManager] (see [WorkManager.initialize] and specifying a new [InputMergerFactory] in 24 * [Configuration.Builder.setInputMergerFactory]. 25 */ 26 abstract class InputMergerFactory { 27 /** 28 * Override this method to create an instance of a [InputMerger] given its fully qualified class 29 * name. 30 * 31 * Throwing an [Exception] here will crash the application. If an [InputMergerFactory] is unable 32 * to create an instance of a [InputMerger], it should return `null` so it can delegate to the 33 * default [InputMergerFactory]. 34 * 35 * @param className The fully qualified class name for the [InputMerger] 36 * @return an instance of [InputMerger] 37 */ createInputMergernull38 abstract fun createInputMerger(className: String): InputMerger? 39 40 /** 41 * Creates an instance of a [InputMerger] given its fully qualified class name with the correct 42 * fallback behavior. 43 * 44 * @param className The fully qualified class name for the [InputMerger] 45 * @return an instance of [InputMerger] 46 */ 47 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 48 fun createInputMergerWithDefaultFallback(className: String): InputMerger? { 49 var inputMerger = createInputMerger(className) 50 if (inputMerger == null) { 51 inputMerger = fromClassName(className) 52 } 53 return inputMerger 54 } 55 } 56 57 internal object NoOpInputMergerFactory : InputMergerFactory() { createInputMergernull58 override fun createInputMerger(className: String) = null 59 } 60