1 /*
2  * Copyright (C) 2019 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.model.livedatatypes
18 
19 import android.app.Application
20 import android.content.pm.PackageItemInfo
21 import android.content.pm.PermissionGroupInfo
22 import android.content.pm.PermissionInfo
23 import com.android.permissioncontroller.permission.utils.Utils
24 
25 /**
26  * A light version of a PackageItemInfo, representing information about a permission group.
27  *
28  * @param name The name of this group
29  * @param packageName The name of the package which defines this group
30  * @param labelRes The resource ID of this group's label
31  * @param icon The resource ID of this group's icon
32  * @param descriptionRes The resource ID of this group's desctiption
33  * @param isSinglePermGroup Whether or not this is a group with a single permission in it
34  */
35 data class LightPermGroupInfo(
36     val name: String,
37     val packageName: String,
38     val labelRes: Int,
39     val icon: Int,
40     val descriptionRes: Int,
41     val isSinglePermGroup: Boolean
42 ) {
43 
44     constructor(pII: PackageItemInfo): this(pII.name, pII.packageName, pII.labelRes, pII.icon,
45         0, pII is PermissionInfo)
46 
47     constructor(pGI: PermissionGroupInfo): this(pGI.name, pGI.packageName, pGI.labelRes, pGI.icon,
48         pGI.descriptionRes, pGI is PermissionInfo)
49 
50     /**
51      * Gets the PackageItemInfo for this permission group from the system.
52      *
53      * @param app The current application, which will be used to get the PackageItemInfo
54      *
55      * @return The PackageItemInfo corresponding to this permission group, or null, if no
56      * such group exists
57      */
toPackageItemInfonull58     fun toPackageItemInfo(app: Application): PackageItemInfo? {
59         return Utils.getGroupInfo(name, app.applicationContext)
60     }
61 }