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.systemui.notetask 18 19 import android.app.Activity 20 import android.app.KeyguardManager 21 import android.app.role.RoleManager 22 import android.content.Context 23 import android.os.UserManager 24 import androidx.core.content.getSystemService 25 import com.android.systemui.flags.FeatureFlags 26 import com.android.systemui.flags.Flags 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 import java.util.Optional 36 37 /** Compose all dependencies required by Note Task feature. */ 38 @Module(includes = [NoteTaskQuickAffordanceModule::class]) 39 internal interface NoteTaskModule { 40 41 @[Binds IntoMap ClassKey(LaunchNoteTaskActivity::class)] LaunchNoteTaskActivitynull42 fun LaunchNoteTaskActivity.bindNoteTaskLauncherActivity(): Activity 43 44 @[Binds IntoMap ClassKey(CreateNoteTaskShortcutActivity::class)] 45 fun CreateNoteTaskShortcutActivity.bindNoteTaskShortcutActivity(): Activity 46 47 companion object { 48 49 @[Provides NoteTaskEnabledKey] 50 fun provideIsNoteTaskEnabled( 51 featureFlags: FeatureFlags, 52 roleManager: RoleManager, 53 ): Boolean { 54 val isRoleAvailable = roleManager.isRoleAvailable(NoteTaskInfoResolver.ROLE_NOTES) 55 val isFeatureEnabled = featureFlags.isEnabled(Flags.NOTE_TASKS) 56 return isRoleAvailable && isFeatureEnabled 57 } 58 59 @Provides 60 fun provideOptionalKeyguardManager(context: Context): Optional<KeyguardManager> { 61 return Optional.ofNullable(context.getSystemService()) 62 } 63 64 @Provides 65 fun provideOptionalUserManager(context: Context): Optional<UserManager> { 66 return Optional.ofNullable(context.getSystemService()) 67 } 68 } 69 } 70