• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.PackageManager
21 import android.content.pm.PermissionInfo
22 
23 /**
24  * A light version of the system PermissionInfo
25  *
26  * @param name The name of this permission
27  * @param packageName The name of the package which defines this permission
28  * @param group The optional name of the group this permission is in
29  * @param backgroundPermission The background permission associated with this permission
30  * @param protection The protection level of this permission
31  * @param protection Extra information about the protection of this permission
32  * @param flags The system flags of this permission
33  * @param isSystem Whether this permission is defined by a system app
34  */
35 data class LightPermInfo(
36     val name: String,
37     val packageName: String,
38     val group: String?,
39     val backgroundPermission: String?,
40     val protection: Int,
41     val protectionFlags: Int,
42     val flags: Int,
43     val isSystem: Boolean?,
44 ) {
45     constructor(
46         permInfo: PermissionInfo,
47         isSystem: Boolean?
48     ) : this(
49         permInfo.name,
50         permInfo.packageName,
51         permInfo.group,
52         permInfo.backgroundPermission,
53         permInfo.protection,
54         permInfo.protectionFlags,
55         permInfo.flags,
56         isSystem
57     )
58 
59     /**
60      * Gets the PermissionInfo for this permission from the system.
61      *
62      * @param app The current application, which will be used to get the PermissionInfo
63      * @return The PermissionInfo corresponding to this permission, or null, if no such permission
64      *   exists
65      */
toPermissionInfonull66     fun toPermissionInfo(app: Application): PermissionInfo? {
67         try {
68             return app.packageManager.getPermissionInfo(name, 0)
69         } catch (e: PackageManager.NameNotFoundException) {}
70         return null
71     }
72 }
73