• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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
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 
29 object DisplayOverOtherAppsAppListProvider : TogglePermissionAppListProvider {
30     override val permissionType = "DisplayOverOtherApps"
createModelnull31     override fun createModel(context: Context) = DisplayOverOtherAppsListModel(context)
32 }
33 
34 class DisplayOverOtherAppsListModel(context: Context) : AppOpPermissionListModel(context) {
35     override val pageTitleResId = R.string.system_alert_window_settings
36     override val switchTitleResId = R.string.permit_draw_overlay
37     override val footerResId = R.string.allow_overlay_description
38     override val appOp = AppOpsManager.OP_SYSTEM_ALERT_WINDOW
39     override val permission = Manifest.permission.SYSTEM_ALERT_WINDOW
40 
41     override fun setAllowed(record: AppOpPermissionRecord, newAllowed: Boolean) {
42         super.setAllowed(record, newAllowed)
43         logPermissionChange(newAllowed)
44     }
45 
46     private fun logPermissionChange(newAllowed: Boolean) {
47         val category = when {
48             newAllowed -> SettingsEnums.APP_SPECIAL_PERMISSION_APPDRAW_ALLOW
49             else -> SettingsEnums.APP_SPECIAL_PERMISSION_APPDRAW_DENY
50         }
51         FeatureFactory.getFactory(context).metricsFeatureProvider.action(context, category, "")
52     }
53 }
54