diff options
Diffstat (limited to 'privacymodule-api/src/main/java/foundation')
3 files changed, 44 insertions, 42 deletions
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt index d0e2e75..64b2292 100644 --- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt +++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt @@ -1,5 +1,6 @@ /* - * Copyright (C) 2021 E FOUNDATION, 2022 MURENA SAS + * Copyright (C) 2022 - 2023 MURENA SAS + * Copyright (C) 2021 E FOUNDATION * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +30,7 @@ import android.util.Log import foundation.e.privacymodules.permissions.data.AppOpModes import foundation.e.privacymodules.permissions.data.ApplicationDescription import foundation.e.privacymodules.permissions.data.PermissionDescription +import foundation.e.privacymodules.permissions.data.ProfileType /** * Implementation of the commons functionality between privileged and standard @@ -40,28 +42,12 @@ abstract class APermissionsPrivacyModule(protected val context: Context) : IPerm companion object { private const val TAG = "PermissionsModule" } - /** - * @see IPermissionsPrivacyModule.getAllApplications - */ - override fun getAllApplications(): List<ApplicationDescription> { - val appInfos = context.packageManager.getInstalledApplications(0) - return appInfos.map { buildApplicationDescription(it, false) } - } - - /** - * @see IPermissionsPrivacyModule.getInstalledApplications - */ - override fun getInstalledApplications(): List<ApplicationDescription> { - return context.packageManager.getInstalledApplications(0) - .filter { it.flags and ApplicationInfo.FLAG_SYSTEM == 0 } - .map { buildApplicationDescription(it, false) } - } /** * @see IPermissionsPrivacyModule.getInstalledApplications */ override fun getApplicationDescription(packageName: String, withIcon: Boolean): ApplicationDescription { - val appDesc = buildApplicationDescription(context.packageManager.getApplicationInfo(packageName, 0), false) + val appDesc = buildApplicationDescription(context.packageManager.getApplicationInfo(packageName, 0)) if (withIcon) { appDesc.icon = getApplicationIcon(appDesc.packageName) } @@ -144,13 +130,19 @@ abstract class APermissionsPrivacyModule(protected val context: Context) : IPerm } } - override fun buildApplicationDescription(appInfo: ApplicationInfo, withIcon: Boolean): + override fun buildApplicationDescription( + appInfo: ApplicationInfo, + profileId: Int, + profileType: ProfileType + ): ApplicationDescription { return ApplicationDescription( packageName = appInfo.packageName, uid = appInfo.uid, label = getAppLabel(appInfo), - icon = if (withIcon) getApplicationIcon(appInfo) else null + icon = null, + profileId = profileId, + profileType = profileType, ) } @@ -158,7 +150,7 @@ abstract class APermissionsPrivacyModule(protected val context: Context) : IPerm return context.packageManager.getApplicationLabel(appInfo) } - private fun getApplicationIcon(appInfo: ApplicationInfo): Drawable? { + fun getApplicationIcon(appInfo: ApplicationInfo): Drawable? { return context.packageManager.getApplicationIcon(appInfo) } diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt index b64762f..39c726a 100644 --- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt +++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt @@ -1,5 +1,6 @@ /* - * Copyright (C) 2021 E FOUNDATION, 2022 MURENA SAS + * Copyright (C) 2022 - 2023 MURENA SAS + * Copyright (C) 2021 E FOUNDATION * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,7 @@ import android.graphics.drawable.Drawable import foundation.e.privacymodules.permissions.data.AppOpModes import foundation.e.privacymodules.permissions.data.ApplicationDescription import foundation.e.privacymodules.permissions.data.PermissionDescription +import foundation.e.privacymodules.permissions.data.ProfileType /** * List applications and manage theirs permissions. @@ -32,32 +34,15 @@ interface IPermissionsPrivacyModule { fun buildApplicationDescription( appInfo: ApplicationInfo, - withIcon: Boolean = true + profileId: Int = -1, + profileType: ProfileType = ProfileType.MAIN ): ApplicationDescription fun getApplications( filter: ((PackageInfo) -> Boolean)?, - withIcon: Boolean - ): List<ApplicationDescription> - - fun getWorkProfileApplications( - filter: ((PackageInfo) -> Boolean)?, - withIcon: Boolean ): List<ApplicationDescription> /** - * List the installed application on the device which have not the FLAGS_SYSTEM. - * @return list of filled up [ApplicationDescription] - */ - fun getInstalledApplications(): List<ApplicationDescription> - - /** - * List all the installed application on the device. - * @return list of filled up [ApplicationDescription] - */ - fun getAllApplications(): List<ApplicationDescription> - - /** * List of permissions names used by an app, specified by its [packageName]. * @param packageName the appId of the app * @return the list off permission, in the "android.permission.PERMISSION" format. @@ -131,6 +116,11 @@ interface IPermissionsPrivacyModule { fun getApplicationIcon(packageName: String): Drawable? /** + * Get the application icon. + */ + fun getApplicationIcon(app: ApplicationDescription): Drawable? + + /** * Authorize the specified package to be used as Vpn. * @return true if authorization has been set, false if an error has occurred. */ diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt index cafe256..4fa1bb9 100644 --- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt +++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt @@ -1,4 +1,5 @@ /* + * Copyright (C) 2023 MURENA SAS * Copyright (C) 2022 E FOUNDATION * * This program is free software: you can redistribute it and/or modify @@ -25,6 +26,25 @@ import android.graphics.drawable.Drawable data class ApplicationDescription( val packageName: String, val uid: Int, + val profileId: Int, + val profileType: ProfileType, var label: CharSequence?, var icon: Drawable? -) +) { + val profileFlag = when (profileType) { + ProfileType.MAIN -> PROFILE_FLAG_MAIN + ProfileType.WORK -> PROFILE_FLAG_WORK + else -> profileId + } + + val apId: String get() = "${profileFlag}_$packageName" + + companion object { + const val PROFILE_FLAG_MAIN = -1 + const val PROFILE_FLAG_WORK = -2 + } +} + +enum class ProfileType { + MAIN, WORK, OTHER +} |