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