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 */ 34 data class LightPermInfo( 35 val name: String, 36 val packageName: String, 37 val group: String?, 38 val backgroundPermission: String?, 39 val protection: Int, 40 val protectionFlags: Int, 41 val flags: Int 42 ) { 43 constructor (permInfo: PermissionInfo): this(permInfo.name, permInfo.packageName, 44 permInfo.group, permInfo.backgroundPermission, permInfo.protection, 45 permInfo.protectionFlags, permInfo.flags) 46 47 /** 48 * Gets the PermissionInfo for this permission from the system. 49 * 50 * @param app The current application, which will be used to get the PermissionInfo 51 * 52 * @return The PermissionInfo corresponding to this permission, or null, if no 53 * such permission exists 54 */ toPermissionInfonull55 fun toPermissionInfo(app: Application): PermissionInfo? { 56 try { 57 return app.packageManager.getPermissionInfo(name, 0) 58 } catch (e: PackageManager.NameNotFoundException) { 59 } 60 return null 61 } 62 }