summaryrefslogtreecommitdiff
path: root/permissionse/src/main/java/foundation/e
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-01-02 08:35:21 +0000
committerGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-01-02 08:35:21 +0000
commitf1e0961daf535628252f18c06fe22001f84015b5 (patch)
tree78a37bc4da310662f44c4e6c362c0d58de2cc2e6 /permissionse/src/main/java/foundation/e
parent7333a0d80ef3fb879fb6d261988deb78b4857393 (diff)
parentf1d5b12dd11019508208571db5e5f57f43e3c4b6 (diff)
Merge branch '5648-apps_pro_profile' into 'main'
5648: display trackers for pro-profile app instances. See merge request e/os/advanced-privacy!100
Diffstat (limited to 'permissionse/src/main/java/foundation/e')
-rw-r--r--permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt45
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()