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(
45         pII: PackageItemInfo
46     ) : this(pII.name, pII.packageName, pII.labelRes, pII.icon, 0, pII is PermissionInfo)
47 
48     constructor(
49         pGI: PermissionGroupInfo
50     ) : this(pGI.name, pGI.packageName, pGI.labelRes, pGI.icon, pGI.descriptionRes, false)
51 
52     /**
53      * Gets the PackageItemInfo for this permission group from the system.
54      *
55      * @param app The current application, which will be used to get the PackageItemInfo
56      * @return The PackageItemInfo corresponding to this permission group, or null, if no such group
57      *   exists
58      */
toPackageItemInfonull59     fun toPackageItemInfo(app: Application): PackageItemInfo? {
60         return Utils.getGroupInfo(name, app.applicationContext)
61     }
62 }
63