summaryrefslogtreecommitdiff
path: root/permissionse/src/main/java/foundation
diff options
context:
space:
mode:
Diffstat (limited to 'permissionse/src/main/java/foundation')
-rw-r--r--permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt99
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
}
}