• 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.settings.spa.app.specialaccess
18 
19 import android.Manifest
20 import android.app.AppOpsManager
21 import android.app.settings.SettingsEnums
22 import android.content.Context
23 import com.android.settings.R
24 import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
25 import com.android.settingslib.spaprivileged.model.app.AppOps
26 import com.android.settingslib.spaprivileged.template.app.AppOpPermissionListModel
27 import com.android.settingslib.spaprivileged.template.app.AppOpPermissionRecord
28 import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppListProvider
29 
30 object LongBackgroundTasksAppListProvider : TogglePermissionAppListProvider {
31     override val permissionType = "LongBackgroundTasksApps"
createModelnull32     override fun createModel(context: Context) = LongBackgroundTasksAppsListModel(context)
33 }
34 
35 class LongBackgroundTasksAppsListModel(context: Context) : AppOpPermissionListModel(context) {
36     override val pageTitleResId = R.string.long_background_tasks_title
37     override val switchTitleResId = R.string.long_background_tasks_switch_title
38     override val footerResId = R.string.long_background_tasks_footer_title
39     override val appOps = AppOps(
40         op = AppOpsManager.OP_RUN_USER_INITIATED_JOBS,
41         setModeByUid = true,
42     )
43     override val permission = Manifest.permission.RUN_USER_INITIATED_JOBS
44 
45     override fun setAllowed(record: AppOpPermissionRecord, newAllowed: Boolean) {
46         super.setAllowed(record, newAllowed)
47         logPermissionChange(newAllowed)
48     }
49 
50     private fun logPermissionChange(newAllowed: Boolean) {
51         featureFactory.metricsFeatureProvider.action(
52             context,
53             SettingsEnums.ACTION_LONG_BACKGROUND_TASKS_TOGGLE,
54             if (newAllowed) 1 else 0
55         )
56     }
57 }