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.statusbar.pipeline.shared.data.repository
18 
19 import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlot
20 import com.android.systemui.statusbar.pipeline.shared.data.model.DefaultConnectionModel
21 import kotlinx.coroutines.flow.MutableStateFlow
22 import kotlinx.coroutines.flow.StateFlow
23 
24 /** Fake implementation of [ConnectivityRepository] exposing set methods for all the flows. */
25 class FakeConnectivityRepository : ConnectivityRepository {
26     private val _forceHiddenIcons: MutableStateFlow<Set<ConnectivitySlot>> =
27         MutableStateFlow(emptySet())
28     override val forceHiddenSlots: StateFlow<Set<ConnectivitySlot>> = _forceHiddenIcons
29 
30     override val defaultConnections: MutableStateFlow<DefaultConnectionModel> =
31         MutableStateFlow(DefaultConnectionModel())
32 
33     override val vcnSubId: MutableStateFlow<Int?> = MutableStateFlow(null)
34 
35     fun setForceHiddenIcons(hiddenIcons: Set<ConnectivitySlot>) {
36         _forceHiddenIcons.value = hiddenIcons
37     }
38 
39     /**
40      * Convenience for setting mobile data connected, disconnected, or validated. Defaults to
41      * setting mobile connected && validated, since the default state is disconnected && not
42      * validated
43      */
44     fun setMobileConnected(
45         default: Boolean = true,
46         validated: Boolean = true,
47     ) {
48         defaultConnections.value =
49             DefaultConnectionModel(
50                 mobile = DefaultConnectionModel.Mobile(default),
51                 isValidated = validated,
52             )
53     }
54 
55     /** Similar convenience method for ethernet */
56     fun setEthernetConnected(
57         default: Boolean = true,
58         validated: Boolean = true,
59     ) {
60         defaultConnections.value =
61             DefaultConnectionModel(
62                 ethernet = DefaultConnectionModel.Ethernet(default),
63                 isValidated = validated,
64             )
65     }
66 
67     fun setWifiConnected(
68         default: Boolean = true,
69         validated: Boolean = true,
70     ) {
71         defaultConnections.value =
72             DefaultConnectionModel(
73                 wifi = DefaultConnectionModel.Wifi(default),
74                 isValidated = validated,
75             )
76     }
77 }
78