1 /* <lambda>null2 * 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.settings.spa.app.specialaccess 18 19 import android.Manifest 20 import android.app.AppOpsManager 21 import android.content.Context 22 import com.android.settings.R 23 import com.android.settingslib.spaprivileged.model.app.AppOps 24 import com.android.settingslib.spaprivileged.model.app.PackageManagers 25 import com.android.settingslib.spaprivileged.template.app.AppOpPermissionListModel 26 import com.android.settingslib.spaprivileged.template.app.AppOpPermissionRecord 27 import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppListProvider 28 import kotlinx.coroutines.flow.Flow 29 import kotlinx.coroutines.flow.map 30 31 object WriteSystemPreferencesAppListProvider : TogglePermissionAppListProvider { 32 override val permissionType = "WriteSystemPreferences" 33 override fun createModel(context: Context) = WriteSystemPreferencesAppListModel(context) 34 } 35 36 class WriteSystemPreferencesAppListModel(context: Context) : AppOpPermissionListModel(context) { 37 override val pageTitleResId = R.string.write_system_preferences_page_title 38 override val switchTitleResId = R.string.write_system_preferences_switch_title 39 override val footerResId = R.string.write_system_preferences_footer_description 40 override val appOps = AppOps( 41 op = AppOpsManager.OP_WRITE_SYSTEM_PREFERENCES, 42 setModeByUid = true, 43 ) 44 override val permission = Manifest.permission.WRITE_SYSTEM_PREFERENCES 45 filternull46 override fun filter(userIdFlow: Flow<Int>, recordListFlow: Flow<List<AppOpPermissionRecord>>): 47 Flow<List<AppOpPermissionRecord>> { 48 return super.filter(userIdFlow, recordListFlow).map { recordList -> 49 recordList.filter { app -> 50 // Only apps that have READ_SYSTEM_PREFERENCES can utilize WRITE_SYSTEM_PREFERENCES. 51 // This write permission is (currently) non-functionality without the corresponding 52 // read permission, and the read permission can only be granted via pre-grant or 53 // role. As such, we don't show apps that are "requesting" this permission without 54 // holding the read permission, as it would create confusion and not provide them 55 // any functionality. 56 with (PackageManagers) { 57 app.app.hasGrantPermission(Manifest.permission.READ_SYSTEM_PREFERENCES) 58 } 59 } 60 } 61 } 62 }