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.view.LayoutInflater;
22 
23 import com.android.systemui.R;
24 import com.android.systemui.dagger.SysUISingleton;
25 import com.android.systemui.dagger.qualifiers.Application;
26 import com.android.systemui.dagger.qualifiers.Background;
27 import com.android.systemui.dagger.qualifiers.Main;
28 import com.android.systemui.flags.FeatureFlags;
29 import com.android.systemui.flags.Flags;
30 import com.android.systemui.log.LogBuffer;
31 import com.android.systemui.log.dagger.KeyguardClockLog;
32 import com.android.systemui.plugins.PluginManager;
33 import com.android.systemui.shared.clocks.ClockRegistry;
34 import com.android.systemui.shared.clocks.DefaultClockProvider;
35 
36 import dagger.Module;
37 import dagger.Provides;
38 
39 import kotlinx.coroutines.CoroutineDispatcher;
40 import kotlinx.coroutines.CoroutineScope;
41 
42 /** Dagger Module for clocks. */
43 @Module
44 public abstract class ClockRegistryModule {
45     /** Provide the ClockRegistry as a singleton so that it is not instantiated more than once. */
46     @Provides
47     @SysUISingleton
getClockRegistry( @pplication Context context, PluginManager pluginManager, @Application CoroutineScope scope, @Main CoroutineDispatcher mainDispatcher, @Background CoroutineDispatcher bgDispatcher, FeatureFlags featureFlags, @Main Resources resources, LayoutInflater layoutInflater, @KeyguardClockLog LogBuffer logBuffer)48     public static ClockRegistry getClockRegistry(
49             @Application Context context,
50             PluginManager pluginManager,
51             @Application CoroutineScope scope,
52             @Main CoroutineDispatcher mainDispatcher,
53             @Background CoroutineDispatcher bgDispatcher,
54             FeatureFlags featureFlags,
55             @Main Resources resources,
56             LayoutInflater layoutInflater,
57             @KeyguardClockLog LogBuffer logBuffer) {
58         ClockRegistry registry = new ClockRegistry(
59                 context,
60                 pluginManager,
61                 scope,
62                 mainDispatcher,
63                 bgDispatcher,
64                 featureFlags.isEnabled(Flags.LOCKSCREEN_CUSTOM_CLOCKS),
65                 /* handleAllUsers= */ true,
66                 new DefaultClockProvider(
67                         context,
68                         layoutInflater,
69                         resources,
70                         featureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION)),
71                 context.getString(R.string.lockscreen_clock_id_fallback),
72                 logBuffer,
73                 /* keepAllLoaded = */ false,
74                 /* subTag = */ "System",
75                 /* isTransitClockEnabled = */ featureFlags.isEnabled(Flags.TRANSIT_CLOCK));
76         registry.registerListeners();
77         return registry;
78     }
79 }
80