1 /* 2 * Copyright (C) 2022 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 com.android.keyguard.dagger; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.os.Vibrator; 22 import android.view.LayoutInflater; 23 24 import androidx.annotation.Nullable; 25 26 import com.android.systemui.dagger.SysUISingleton; 27 import com.android.systemui.dagger.qualifiers.Application; 28 import com.android.systemui.dagger.qualifiers.Background; 29 import com.android.systemui.dagger.qualifiers.Main; 30 import com.android.systemui.flags.FeatureFlags; 31 import com.android.systemui.flags.Flags; 32 import com.android.systemui.plugins.PluginManager; 33 import com.android.systemui.plugins.clocks.ClockMessageBuffers; 34 import com.android.systemui.res.R; 35 import com.android.systemui.shade.ShadeDisplayAware; 36 import com.android.systemui.shared.clocks.ClockRegistry; 37 import com.android.systemui.shared.clocks.DefaultClockProvider; 38 import com.android.systemui.util.ThreadAssert; 39 40 import dagger.Module; 41 import dagger.Provides; 42 43 import kotlinx.coroutines.CoroutineDispatcher; 44 import kotlinx.coroutines.CoroutineScope; 45 46 /** Dagger Module for clocks. */ 47 @Module 48 public abstract class ClockRegistryModule { 49 /** Provide the ClockRegistry as a singleton so that it is not instantiated more than once. */ 50 @Provides 51 @SysUISingleton getClockRegistry( @hadeDisplayAware Context context, PluginManager pluginManager, @Application CoroutineScope scope, @Main CoroutineDispatcher mainDispatcher, @Background CoroutineDispatcher bgDispatcher, FeatureFlags featureFlags, @Main Resources resources, LayoutInflater layoutInflater, ClockMessageBuffers clockBuffers, @Nullable Vibrator vibrator)52 public static ClockRegistry getClockRegistry( 53 @ShadeDisplayAware Context context, 54 PluginManager pluginManager, 55 @Application CoroutineScope scope, 56 @Main CoroutineDispatcher mainDispatcher, 57 @Background CoroutineDispatcher bgDispatcher, 58 FeatureFlags featureFlags, 59 @Main Resources resources, 60 LayoutInflater layoutInflater, 61 ClockMessageBuffers clockBuffers, 62 @Nullable Vibrator vibrator) { 63 ClockRegistry registry = new ClockRegistry( 64 context, 65 pluginManager, 66 scope, 67 mainDispatcher, 68 bgDispatcher, 69 com.android.systemui.shared.Flags.lockscreenCustomClocks() 70 || featureFlags.isEnabled(Flags.LOCKSCREEN_CUSTOM_CLOCKS), 71 /* handleAllUsers= */ true, 72 new DefaultClockProvider( 73 context, 74 layoutInflater, 75 resources, 76 com.android.systemui.shared.Flags.clockReactiveVariants(), 77 vibrator 78 ), 79 context.getString(R.string.lockscreen_clock_id_fallback), 80 clockBuffers, 81 /* keepAllLoaded = */ false, 82 /* subTag = */ "System", 83 new ThreadAssert()); 84 registry.registerListeners(); 85 return registry; 86 } 87 } 88