• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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 FakeSecureSettingsRepository : SecureSettingsRepository {
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 
setBoolnull35     fun setBool(name: String, value: Boolean) {
36         settings.value =
37             settings.value.toMutableMap().apply { this[name] = (if (value) 1 else 0).toString() }
38     }
39 
setIntnull40     override suspend fun setInt(name: String, value: Int) {
41         settings.value = settings.value.toMutableMap().apply { this[name] = value.toString() }
42     }
43 
getIntnull44     override suspend fun getInt(name: String, defaultValue: Int): Int {
45         return settings.value[name]?.toInt() ?: defaultValue
46     }
47 
getStringnull48     override suspend fun getString(name: String): String? {
49         return settings.value[name]
50     }
51 }
52