1 /*
2  * Copyright (C) 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 
17 package com.android.systemui.assist;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.os.HandlerThread;
22 import android.os.SystemClock;
23 
24 import androidx.slice.Clock;
25 
26 import com.android.internal.app.AssistUtils;
27 import com.android.systemui.ScreenDecorations;
28 import com.android.systemui.SysUiServiceProvider;
29 
30 import java.util.EnumMap;
31 import java.util.Map;
32 
33 import javax.inject.Named;
34 import javax.inject.Singleton;
35 
36 import dagger.Module;
37 import dagger.Provides;
38 
39 /** Module for dagger injections related to the Assistant. */
40 @Module
41 public abstract class AssistModule {
42 
43     static final String ASSIST_HANDLE_THREAD_NAME = "assist_handle_thread";
44     static final String UPTIME_NAME = "uptime";
45 
46     @Provides
47     @Singleton
48     @Named(ASSIST_HANDLE_THREAD_NAME)
provideBackgroundHandler()49     static Handler provideBackgroundHandler() {
50         final HandlerThread backgroundHandlerThread =
51                 new HandlerThread("AssistHandleThread");
52         backgroundHandlerThread.start();
53         return backgroundHandlerThread.getThreadHandler();
54     }
55 
56     @Provides
57     @Singleton
58     static Map<AssistHandleBehavior, AssistHandleBehaviorController.BehaviorController>
provideAssistHandleBehaviorControllerMap( AssistHandleOffBehavior offBehavior, AssistHandleLikeHomeBehavior likeHomeBehavior, AssistHandleReminderExpBehavior reminderExpBehavior)59             provideAssistHandleBehaviorControllerMap(
60                     AssistHandleOffBehavior offBehavior,
61                     AssistHandleLikeHomeBehavior likeHomeBehavior,
62                     AssistHandleReminderExpBehavior reminderExpBehavior) {
63         Map<AssistHandleBehavior, AssistHandleBehaviorController.BehaviorController> map =
64                 new EnumMap<>(AssistHandleBehavior.class);
65         map.put(AssistHandleBehavior.OFF, offBehavior);
66         map.put(AssistHandleBehavior.LIKE_HOME, likeHomeBehavior);
67         map.put(AssistHandleBehavior.REMINDER_EXP, reminderExpBehavior);
68         return map;
69     }
70 
71     @Provides
provideScreenDecorations(Context context)72     static ScreenDecorations provideScreenDecorations(Context context) {
73         return SysUiServiceProvider.getComponent(context, ScreenDecorations.class);
74     }
75 
76     @Provides
77     @Singleton
provideAssistUtils(Context context)78     static AssistUtils provideAssistUtils(Context context) {
79         return new AssistUtils(context);
80     }
81 
82     @Provides
83     @Singleton
84     @Named(UPTIME_NAME)
provideSystemClock()85     static Clock provideSystemClock() {
86         return SystemClock::uptimeMillis;
87     }
88 }
89