diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-01-02 08:35:20 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-01-02 08:35:20 +0000 |
commit | f1d5b12dd11019508208571db5e5f57f43e3c4b6 (patch) | |
tree | af6a9f8aaf75beba32cce096e2ec19a8a319d6d3 /permissionse/src/main/java/foundation | |
parent | ae2feae022ba6485b020afa6b5f5c78049ecf1d4 (diff) |
5648: display trackers for pro-profile app instances.
Diffstat (limited to 'permissionse/src/main/java/foundation')
-rw-r--r-- | permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt b/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt index c07f367..c2e3e2c 100644 --- a/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt +++ b/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 E FOUNDATION + * Copyright (C) 2021 E FOUNDATION, 2022 MURENA SAS * * 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 @@ -23,12 +23,16 @@ import android.app.AppOpsManager.OP_NONE import android.app.AppOpsManager.strOpToOp import android.app.NotificationChannel import android.content.Context +import android.content.pm.PackageInfo +import android.content.pm.PackageManager +import android.content.pm.UserInfo import android.net.IConnectivityManager import android.net.VpnManager import android.net.VpnManager.TYPE_VPN_SERVICE import android.os.Build import android.os.ServiceManager import android.os.UserHandle +import android.os.UserManager import android.util.Log import foundation.e.privacymodules.permissions.data.AppOpModes import foundation.e.privacymodules.permissions.data.ApplicationDescription @@ -157,6 +161,45 @@ class PermissionsPrivacyModule(context: Context) : APermissionsPrivacyModule(con return false } + private fun getWorkProfile(): UserInfo? { + val userManager: UserManager = context.getSystemService(UserManager::class.java) + val userId = UserHandle.myUserId() + for (user in userManager.getProfiles(UserHandle.myUserId())) { + if (user.id != userId && userManager.isManagedProfile(user.id)) { + return user + } + } + return null + } + + override fun getApplications( + filter: ((PackageInfo) -> Boolean)?, + withIcon: Boolean + ): List<ApplicationDescription> { + return context.packageManager + .getInstalledPackages(PackageManager.GET_PERMISSIONS) + .filter { filter?.invoke(it) ?: true } + .map { buildApplicationDescription(it.applicationInfo, withIcon = withIcon) } + } + + override fun getWorkProfileApplications( + filter: ((PackageInfo) -> Boolean)?, + withIcon: Boolean + ): List<ApplicationDescription> { + val pm = context.packageManager + return getWorkProfile()?.let { workProfile -> + pm.getInstalledPackagesAsUser(PackageManager.GET_PERMISSIONS, workProfile.id) + .filter { filter?.invoke(it) ?: true } + .map { + val appDesc = buildApplicationDescription(it.applicationInfo, withIcon = withIcon) + appDesc.icon = appDesc.icon?.let { + pm.getUserBadgedIcon(it, workProfile.getUserHandle()) + } + appDesc + } + } ?: emptyList() + } + override fun getAlwaysOnVpnPackage(): String? { return when (Build.VERSION.SDK_INT) { 29, 30 -> getAlwaysOnVpnPackageSDK29() |