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 @file:OptIn(InternalNoteTaskApi::class)
18 
19 package com.android.systemui.notetask
20 
21 import android.app.Activity
22 import android.app.Service
23 import android.app.role.RoleManager
24 import com.android.systemui.flags.FeatureFlags
25 import com.android.systemui.flags.Flags
26 import com.android.systemui.notetask.NoteTaskBubblesController.NoteTaskBubblesService
27 import com.android.systemui.notetask.quickaffordance.NoteTaskQuickAffordanceModule
28 import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity
29 import com.android.systemui.notetask.shortcut.LaunchNoteTaskActivity
30 import dagger.Binds
31 import dagger.Module
32 import dagger.Provides
33 import dagger.multibindings.ClassKey
34 import dagger.multibindings.IntoMap
35 
36 /** Compose all dependencies required by Note Task feature. */
37 @Module(includes = [NoteTaskQuickAffordanceModule::class])
38 interface NoteTaskModule {
39 
40     @[Binds IntoMap ClassKey(NoteTaskControllerUpdateService::class)]
bindNoteTaskControllerUpdateServicenull41     fun bindNoteTaskControllerUpdateService(service: NoteTaskControllerUpdateService): Service
42 
43     @[Binds IntoMap ClassKey(NoteTaskBubblesService::class)]
44     fun bindNoteTaskBubblesService(service: NoteTaskBubblesService): Service
45 
46     @[Binds IntoMap ClassKey(LaunchNoteTaskActivity::class)]
47     fun bindNoteTaskLauncherActivity(activity: LaunchNoteTaskActivity): Activity
48 
49     @[Binds IntoMap ClassKey(LaunchNotesRoleSettingsTrampolineActivity::class)]
50     fun bindLaunchNotesRoleSettingsTrampolineActivity(
51         activity: LaunchNotesRoleSettingsTrampolineActivity
52     ): Activity
53 
54     @[Binds IntoMap ClassKey(CreateNoteTaskShortcutActivity::class)]
55     fun bindNoteTaskShortcutActivity(activity: CreateNoteTaskShortcutActivity): Activity
56 
57     companion object {
58 
59         @[Provides NoteTaskEnabledKey]
60         fun provideIsNoteTaskEnabled(
61             featureFlags: FeatureFlags,
62             roleManager: RoleManager,
63         ): Boolean {
64             val isRoleAvailable = roleManager.isRoleAvailable(RoleManager.ROLE_NOTES)
65             val isFeatureEnabled = featureFlags.isEnabled(Flags.NOTE_TASKS)
66             return isRoleAvailable && isFeatureEnabled
67         }
68     }
69 }
70