summaryrefslogtreecommitdiff
path: root/permissionse
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-04-21 06:25:54 +0000
committerGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-04-21 06:25:54 +0000
commit6068cebe972e000872e4780dd9f75680a3abf073 (patch)
tree4785f6b44d121f95c840020441687bce5777a44f /permissionse
parent2df577ca97a674a4bd3875dc5137bb44df2c03ef (diff)
6556: add AdvancedPrivacy App Id in trackers stats to avoid appUid aliasing
Diffstat (limited to 'permissionse')
-rw-r--r--permissionse/libs/hidden-apis-stub/src/main/java/android/content/pm/PackageManager.java27
-rw-r--r--permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt99
2 files changed, 81 insertions, 45 deletions
diff --git a/permissionse/libs/hidden-apis-stub/src/main/java/android/content/pm/PackageManager.java b/permissionse/libs/hidden-apis-stub/src/main/java/android/content/pm/PackageManager.java
index 3f232bf..c6232ce 100644
--- a/permissionse/libs/hidden-apis-stub/src/main/java/android/content/pm/PackageManager.java
+++ b/permissionse/libs/hidden-apis-stub/src/main/java/android/content/pm/PackageManager.java
@@ -26,11 +26,26 @@ import androidx.annotation.NonNull;
import androidx.annotation.RequiresPermission;
import java.util.List;
+import android.util.AndroidException;
// Stub based on:
// https://gitlab.e.foundation/e/os/android_frameworks_base/-/blob/[SDK_VERSION]/core/java/android/content/pm/PackageManager.java
public abstract class PackageManager {
+ @TargetApi(29)
+ @DeprecatedSinceApi(
+ api = 34,
+ message = "Check availability in SDK34"
+ )
+ public static class NameNotFoundException extends AndroidException {
+ public NameNotFoundException() {
+ }
+
+ public NameNotFoundException(String name) {
+ super(name);
+ }
+ }
+
@TargetApi(29)
@DeprecatedSinceApi(
@@ -58,6 +73,18 @@ public abstract class PackageManager {
@TargetApi(29)
@DeprecatedSinceApi(
+ api = 33,
+ message = "@deprecated Use {@link #getApplicationInfoAsUser(String, ApplicationInfoFlags, int)} instead."
+ )
+ public abstract ApplicationInfo getApplicationInfoAsUser(
+ @NonNull String packageName,
+ int flags,
+ int userId
+ ) throws NameNotFoundException;
+
+
+ @TargetApi(29)
+ @DeprecatedSinceApi(
api = 34,
message = "Check disponibility in SDK34"
)
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
}
}