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.annotation.Nullable;
25 import androidx.slice.Clock;
26 
27 import com.android.internal.app.AssistUtils;
28 import com.android.systemui.statusbar.NavigationBarController;
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
72     @Nullable
provideAssistHandleViewController( NavigationBarController navigationBarController)73     static AssistHandleViewController provideAssistHandleViewController(
74             NavigationBarController navigationBarController) {
75         return navigationBarController.getAssistHandlerViewController();
76     }
77 
78     @Provides
79     @Singleton
provideAssistUtils(Context context)80     static AssistUtils provideAssistUtils(Context context) {
81         return new AssistUtils(context);
82     }
83 
84     @Provides
85     @Singleton
86     @Named(UPTIME_NAME)
provideSystemClock()87     static Clock provideSystemClock() {
88         return SystemClock::uptimeMillis;
89     }
90 }
91