1 /* 2 * Copyright (C) 2023 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.qs.pipeline.data.repository 18 19 import com.android.systemui.qs.pipeline.data.model.RestoreData 20 import com.android.systemui.qs.pipeline.shared.TileSpec 21 import kotlinx.coroutines.flow.MutableStateFlow 22 import kotlinx.coroutines.flow.StateFlow 23 24 class FakeAutoAddRepository : AutoAddRepository { 25 26 private val autoAddedTilesPerUser = mutableMapOf<Int, MutableStateFlow<Set<TileSpec>>>() 27 autoAddedTilesnull28 override suspend fun autoAddedTiles(userId: Int): StateFlow<Set<TileSpec>> { 29 return getFlow(userId) 30 } 31 markTileAddednull32 override suspend fun markTileAdded(userId: Int, spec: TileSpec) { 33 if (spec == TileSpec.Invalid) return 34 with(getFlow(userId)) { value = value.toMutableSet().apply { add(spec) } } 35 } 36 unmarkTileAddednull37 override suspend fun unmarkTileAdded(userId: Int, spec: TileSpec) { 38 with(getFlow(userId)) { value = value.toMutableSet().apply { remove(spec) } } 39 } 40 getFlownull41 private fun getFlow(userId: Int): MutableStateFlow<Set<TileSpec>> = 42 autoAddedTilesPerUser.getOrPut(userId) { MutableStateFlow(emptySet()) } 43 reconcileRestorenull44 override suspend fun reconcileRestore(restoreData: RestoreData) { 45 with(getFlow(restoreData.userId)) { value = value + restoreData.restoredAutoAddedTiles } 46 } 47 } 48