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