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.shared.settings.data.repository 18 19 import kotlinx.coroutines.flow.Flow 20 import kotlinx.coroutines.flow.MutableStateFlow 21 import kotlinx.coroutines.flow.map 22 23 class FakeSystemSettingsRepository : SystemSettingsRepository { 24 25 private val settings = MutableStateFlow<Map<String, String>>(mutableMapOf()) 26 intSettingnull27 override fun intSetting(name: String, defaultValue: Int): Flow<Int> { 28 return settings.map { it.getOrDefault(name, defaultValue.toString()) }.map { it.toInt() } 29 } 30 boolSettingnull31 override fun boolSetting(name: String, defaultValue: Boolean): Flow<Boolean> { 32 return intSetting(name, if (defaultValue) 1 else 0).map { it != 0 } 33 } 34 setIntnull35 override suspend fun setInt(name: String, value: Int) { 36 settings.value = settings.value.toMutableMap().apply { this[name] = value.toString() } 37 } 38 getIntnull39 override suspend fun getInt(name: String, defaultValue: Int): Int { 40 return settings.value[name]?.toInt() ?: defaultValue 41 } 42 getStringnull43 override suspend fun getString(name: String): String? { 44 return settings.value[name] 45 } 46 } 47