1 /*
2  * Copyright (C) 2022 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.settingslib.spaprivileged.tests.testutils
18 
19 import android.content.pm.ApplicationInfo
20 import androidx.compose.runtime.Composable
21 import androidx.compose.runtime.mutableStateOf
22 import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppListModel
23 import com.android.settingslib.spaprivileged.test.R
24 import kotlinx.coroutines.flow.Flow
25 
26 class TestTogglePermissionAppListModel(
27     isAllowed: Boolean? = null,
28     private val isChangeable: Boolean = false,
29 ) : TogglePermissionAppListModel<TestAppRecord> {
30     override val pageTitleResId = R.string.test_permission_title
31     override val switchTitleResId = R.string.test_permission_switch_title
32     override val footerResId = R.string.test_permission_footer
33 
34     private val isAllowedState = mutableStateOf(isAllowed)
35 
36     override fun transformItem(app: ApplicationInfo) = TestAppRecord(app = app)
37 
38     override fun filter(userIdFlow: Flow<Int>, recordListFlow: Flow<List<TestAppRecord>>) =
39         recordListFlow
40 
41     @Composable
42     override fun isAllowed(record: TestAppRecord) = isAllowedState
43 
44     override fun isChangeable(record: TestAppRecord) = isChangeable
45 
46     override fun setAllowed(record: TestAppRecord, newAllowed: Boolean) {
47         isAllowedState.value = newAllowed
48     }
49 }
50