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.lifecycle 18 19 import androidx.compose.runtime.getValue 20 import kotlinx.coroutines.flow.Flow 21 import kotlinx.coroutines.flow.MutableStateFlow 22 import kotlinx.coroutines.flow.StateFlow 23 import kotlinx.coroutines.flow.asStateFlow 24 import kotlinx.coroutines.flow.flowOf 25 26 class FakeSysUiViewModel( <lambda>null27 private val onActivation: () -> Unit = {}, <lambda>null28 private val onDeactivation: () -> Unit = {}, 29 upstreamFlow: Flow<Boolean> = flowOf(true), 30 upstreamStateFlow: StateFlow<Boolean> = MutableStateFlow(true).asStateFlow(), 31 ) : ExclusiveActivatable() { 32 33 var activationCount = 0 34 var cancellationCount = 0 35 36 private val hydrator = Hydrator("test") 37 val stateBackedByFlow: Boolean by 38 hydrator.hydratedStateOf( 39 traceName = "test", 40 initialValue = true, 41 source = upstreamFlow, 42 ) 43 val stateBackedByStateFlow: Boolean by 44 hydrator.hydratedStateOf( 45 traceName = "test", 46 source = upstreamStateFlow, 47 ) 48 onActivatednull49 override suspend fun onActivated(): Nothing { 50 activationCount++ 51 onActivation() 52 try { 53 hydrator.activate() 54 } finally { 55 cancellationCount++ 56 onDeactivation() 57 } 58 } 59 } 60