1 /* 2 * Copyright (C) 2024 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.volume.dagger 18 19 import android.content.ContentResolver 20 import android.content.Context 21 import android.media.AudioManager 22 import com.android.settingslib.bluetooth.LocalBluetoothManager 23 import com.android.settingslib.statusbar.notification.domain.interactor.NotificationsSoundPolicyInteractor 24 import com.android.settingslib.volume.data.repository.AudioRepository 25 import com.android.settingslib.volume.data.repository.AudioRepositoryImpl 26 import com.android.settingslib.volume.data.repository.AudioSharingRepository 27 import com.android.settingslib.volume.data.repository.AudioSharingRepositoryImpl 28 import com.android.settingslib.volume.domain.interactor.AudioModeInteractor 29 import com.android.settingslib.volume.domain.interactor.AudioVolumeInteractor 30 import com.android.settingslib.volume.shared.AudioManagerEventsReceiver 31 import com.android.settingslib.volume.shared.AudioManagerEventsReceiverImpl 32 import com.android.systemui.dagger.SysUISingleton 33 import com.android.systemui.dagger.qualifiers.Application 34 import com.android.systemui.dagger.qualifiers.Background 35 import dagger.Module 36 import dagger.Provides 37 import kotlin.coroutines.CoroutineContext 38 import kotlinx.coroutines.CoroutineScope 39 40 /** Dagger module for audio code in the volume package */ 41 @Module 42 interface AudioModule { 43 44 companion object { 45 46 @Provides 47 @SysUISingleton provideAudioManagerIntentsReceivernull48 fun provideAudioManagerIntentsReceiver( 49 @Application context: Context, 50 @Application coroutineScope: CoroutineScope, 51 ): AudioManagerEventsReceiver = AudioManagerEventsReceiverImpl(context, coroutineScope) 52 53 @Provides 54 @SysUISingleton 55 fun provideAudioRepository( 56 intentsReceiver: AudioManagerEventsReceiver, 57 audioManager: AudioManager, 58 contentResolver: ContentResolver, 59 @Background coroutineContext: CoroutineContext, 60 @Application coroutineScope: CoroutineScope, 61 ): AudioRepository = 62 AudioRepositoryImpl( 63 intentsReceiver, 64 audioManager, 65 contentResolver, 66 coroutineContext, 67 coroutineScope, 68 ) 69 70 @Provides 71 @SysUISingleton 72 fun provideAudioSharingRepository( 73 localBluetoothManager: LocalBluetoothManager?, 74 @Background coroutineContext: CoroutineContext, 75 ): AudioSharingRepository = 76 AudioSharingRepositoryImpl(localBluetoothManager, coroutineContext) 77 78 @Provides 79 @SysUISingleton 80 fun provideAudioModeInteractor(repository: AudioRepository): AudioModeInteractor = 81 AudioModeInteractor(repository) 82 83 @Provides 84 @SysUISingleton 85 fun provideAudioVolumeInteractor( 86 audioRepository: AudioRepository, 87 notificationsSoundPolicyInteractor: NotificationsSoundPolicyInteractor, 88 ): AudioVolumeInteractor = 89 AudioVolumeInteractor(audioRepository, notificationsSoundPolicyInteractor) 90 } 91 } 92