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(default: Boolean = true, validated: Boolean = true) { 46 defaultConnections.value = 47 DefaultConnectionModel( 48 mobile = DefaultConnectionModel.Mobile(default), 49 isValidated = validated, 50 ) 51 } 52 53 /** Similar convenience method for ethernet */ 54 @JvmOverloads setEthernetConnectednull55 fun setEthernetConnected(default: Boolean = true, validated: Boolean = true) { 56 defaultConnections.value = 57 DefaultConnectionModel( 58 ethernet = DefaultConnectionModel.Ethernet(default), 59 isValidated = validated, 60 ) 61 } 62 63 @JvmOverloads setWifiConnectednull64 fun setWifiConnected(default: Boolean = true, validated: Boolean = true) { 65 defaultConnections.value = 66 DefaultConnectionModel( 67 wifi = DefaultConnectionModel.Wifi(default), 68 isValidated = validated, 69 ) 70 } 71 } 72 73 val ConnectivityRepository.fake 74 get() = this as FakeConnectivityRepository 75