1 /*
2  * Copyright (C) 2020 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.handheld
18 
19 import android.app.Application
20 import android.content.Context
21 import android.os.UserHandle
22 import android.view.View
23 import android.widget.ImageButton
24 import androidx.preference.PreferenceViewHolder
25 import com.android.permissioncontroller.R
26 
27 /**
28  * A preference which represents an app that has been auto revoked. Has the app icon and label, as
29  * 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 AutoRevokePermissionPreference(
37     app: Application,
38     packageName: String,
39     user: UserHandle,
40     context: Context
41 ) : SmartIconLoadPackagePermissionPreference(app, packageName, user, context) {
42     private var removeButton: ImageButton? = null
43     var removeClickListener: View.OnClickListener? = null
44         set(listener) {
45             removeButton?.setOnClickListener(listener)
46             field = listener
47         }
48 
49     init {
50         widgetLayoutResource = R.xml.uninstall_button_preference_widget
51     }
52 
onBindViewHoldernull53     override fun onBindViewHolder(holder: PreferenceViewHolder) {
54         super.onBindViewHolder(holder)
55 
56         removeButton = holder.findViewById(R.id.uninstall_button) as ImageButton
57         removeButton?.setOnClickListener(removeClickListener)
58     }
59 }