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.statusbar.phone.ongoingcall.data.repository
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallModel
21 import javax.inject.Inject
22 import kotlinx.coroutines.flow.MutableStateFlow
23 import kotlinx.coroutines.flow.StateFlow
24 import kotlinx.coroutines.flow.asStateFlow
25 
26 /**
27  * Repository storing whether there's current an ongoing call notification.
28  *
29  * This class is used to break a dependency cycle between
30  * [com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController] and
31  * [com.android.systemui.statusbar.data.repository.StatusBarModeRepositoryStore]. Instead, those two
32  * classes both refer to this repository.
33  */
34 @SysUISingleton
35 class OngoingCallRepository @Inject constructor() {
36     private val _ongoingCallState = MutableStateFlow<OngoingCallModel>(OngoingCallModel.NoCall)
37     /** The current ongoing call state. */
38     val ongoingCallState: StateFlow<OngoingCallModel> = _ongoingCallState.asStateFlow()
39 
40     /**
41      * Sets the current ongoing call state, based on notifications. Should only be set from
42      * [com.android.systemui.statusbar.phone.ongoingcall.OngoingCallController].
43      */
setOngoingCallStatenull44     fun setOngoingCallState(state: OngoingCallModel) {
45         _ongoingCallState.value = state
46     }
47 }
48