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.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 setForceHiddenIconsnull35 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 @JvmOverloads setMobileConnectednull45 fun setMobileConnected( 46 default: Boolean = true, 47 validated: Boolean = true, 48 ) { 49 defaultConnections.value = 50 DefaultConnectionModel( 51 mobile = DefaultConnectionModel.Mobile(default), 52 isValidated = validated, 53 ) 54 } 55 56 /** Similar convenience method for ethernet */ 57 @JvmOverloads setEthernetConnectednull58 fun setEthernetConnected( 59 default: Boolean = true, 60 validated: Boolean = true, 61 ) { 62 defaultConnections.value = 63 DefaultConnectionModel( 64 ethernet = DefaultConnectionModel.Ethernet(default), 65 isValidated = validated, 66 ) 67 } 68 69 @JvmOverloads setWifiConnectednull70 fun setWifiConnected( 71 default: Boolean = true, 72 validated: Boolean = true, 73 ) { 74 defaultConnections.value = 75 DefaultConnectionModel( 76 wifi = DefaultConnectionModel.Wifi(default), 77 isValidated = validated, 78 ) 79 } 80 } 81