diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-04-21 06:25:55 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-04-21 06:25:55 +0000 |
commit | ef669659db8c9fbab2a84dcbc8f3e99411eb1201 (patch) | |
tree | 4785f6b44d121f95c840020441687bce5777a44f /permissionse/src/main | |
parent | 2df577ca97a674a4bd3875dc5137bb44df2c03ef (diff) | |
parent | 6068cebe972e000872e4780dd9f75680a3abf073 (diff) |
Merge branch '6556-use_pname_for_trackers_2' into 'main'
6556: add AdvancedPrivacy App Id in trackers stats to avoid appUid aliasing
See merge request e/os/advanced-privacy!122
Diffstat (limited to 'permissionse/src/main')
-rw-r--r-- | permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt | 99 |
1 files changed, 54 insertions, 45 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 cde4afb..6d0a17c 100644 --- a/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt +++ b/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt @@ -26,6 +26,7 @@ import android.content.Context import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.content.pm.UserInfo +import android.graphics.drawable.Drawable import android.net.IConnectivityManager import android.net.VpnManager import android.net.VpnManager.TYPE_VPN_SERVICE @@ -36,6 +37,8 @@ import android.os.UserManager import android.util.Log import foundation.e.privacymodules.permissions.data.AppOpModes import foundation.e.privacymodules.permissions.data.ApplicationDescription +import foundation.e.privacymodules.permissions.data.ProfileType.MAIN +import foundation.e.privacymodules.permissions.data.ProfileType.WORK /** * Implements [IPermissionsPrivacyModule] with all privileges of a system app. @@ -88,6 +91,50 @@ class PermissionsPrivacyModule(context: Context) : APermissionsPrivacyModule(con return true } + override fun getApplications( + filter: ((PackageInfo) -> Boolean)? + ): List<ApplicationDescription> { + val pm = context.packageManager + val mainUserId = UserHandle.myUserId() + val workProfileId = getWorkProfile()?.id + + val userIds = listOf(mainUserId, workProfileId).filterNotNull() + return userIds.map { profileId -> + pm.getInstalledPackagesAsUser(PackageManager.GET_PERMISSIONS, profileId) + .filter { filter?.invoke(it) ?: true } + .map { + buildApplicationDescription( + appInfo = it.applicationInfo, + profileId = profileId, + profileType = if (profileId == mainUserId) MAIN else WORK + ) + } + }.flatten() + } + + override fun getApplicationIcon(app: ApplicationDescription): Drawable? { + return if (app.profileType == WORK) { + getWorkProfile()?.let { workProfile -> + val pm = context.packageManager + getApplicationIcon( + pm.getApplicationInfoAsUser(app.packageName, 0, workProfile.id) + )?.let { + pm.getUserBadgedIcon(it, workProfile.getUserHandle()) + } + } + } else getApplicationIcon(app.packageName) + } + + override fun setBlockable(notificationChannel: NotificationChannel) { + when (Build.VERSION.SDK_INT) { + 29 -> notificationChannel.setBlockableSystem(true) + 30, 31, 32, 33 -> notificationChannel.setBlockable(true) + else -> { + Log.e("Permissions-e", "Bad android sdk version") + } + } + } + override fun setVpnPackageAuthorization(packageName: String): Boolean { return when (Build.VERSION.SDK_INT) { 29 -> setVpnPackageAuthorizationSDK29(packageName) @@ -161,45 +208,6 @@ 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() @@ -236,13 +244,14 @@ class PermissionsPrivacyModule(context: Context) : APermissionsPrivacyModule(con } } - override fun setBlockable(notificationChannel: NotificationChannel) { - when (Build.VERSION.SDK_INT) { - 29 -> notificationChannel.setBlockableSystem(true) - 30, 31, 32, 33 -> notificationChannel.setBlockable(true) - else -> { - Log.e("Permissions-e", "Bad android sdk version") + 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 } } |