1 /*
<lambda>null2  * 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.domain.startable
18 
19 import com.android.internal.logging.UiEventLogger
20 import com.android.settingslib.volume.domain.interactor.AudioModeInteractor
21 import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope
22 import com.android.systemui.volume.panel.domain.VolumePanelStartable
23 import com.android.systemui.volume.panel.ui.VolumePanelUiEvent
24 import javax.inject.Inject
25 import kotlinx.coroutines.CoroutineScope
26 import kotlinx.coroutines.flow.distinctUntilChanged
27 import kotlinx.coroutines.launch
28 
29 /** Logger for audio mode */
30 @VolumePanelScope
31 class AudioModeLoggerStartable
32 @Inject
33 constructor(
34     @VolumePanelScope private val scope: CoroutineScope,
35     private val uiEventLogger: UiEventLogger,
36     private val audioModeInteractor: AudioModeInteractor,
37 ) : VolumePanelStartable {
38 
39     override fun start() {
40         scope.launch {
41             audioModeInteractor.isOngoingCall.distinctUntilChanged().collect { ongoingCall ->
42                 uiEventLogger.log(
43                     if (ongoingCall) VolumePanelUiEvent.VOLUME_PANEL_AUDIO_MODE_CHANGE_TO_CALLING
44                     else VolumePanelUiEvent.VOLUME_PANEL_AUDIO_MODE_CHANGE_TO_NORMAL
45                 )
46             }
47         }
48     }
49 }
50