1 /*
2  * Copyright (C) 2021 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.permissioncontroller.permission.ui.auto
18 
19 import android.app.Application
20 import android.content.Context
21 import android.os.UserHandle
22 import com.android.car.ui.preference.CarUiTwoActionIconPreference
23 import com.android.permissioncontroller.R
24 import com.android.permissioncontroller.permission.ui.RemovablePref
25 import com.android.permissioncontroller.permission.utils.KotlinUtils
26 
27 /**
28  * A Auto-styled preference which represents an app that has been auto revoked. Has the app icon and
29  * label, as well as a button to uninstall/disable the app, and a button to open the app.
30  *
31  * @param app The current application
32  * @param packageName The name of the package whose icon this preference will retrieve
33  * @param user The user whose package icon will be retrieved
34  * @param context The current context
35  */
36 class AutoUnusedAppsPreference(
37     app: Application,
38     packageName: String,
39     user: UserHandle,
40     context: Context
41 ) : CarUiTwoActionIconPreference(context), RemovablePref {
42 
43     init {
44         icon = KotlinUtils.getBadgedPackageIcon(app, packageName, user)
45         setSecondaryActionIcon(R.drawable.ic_settings_delete)
46     }
47 
setRemoveClickRunnablenull48     override fun setRemoveClickRunnable(runnable: Runnable) {
49         setOnSecondaryActionClickListener(runnable)
50     }
51 
setRemoveComponentEnablednull52     override fun setRemoveComponentEnabled(enabled: Boolean) {
53         setSecondaryActionEnabled(enabled)
54     }
55 }
56