summaryrefslogtreecommitdiff
path: root/privacymodule-api/src/main/java/foundation
diff options
context:
space:
mode:
Diffstat (limited to 'privacymodule-api/src/main/java/foundation')
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt31
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt160
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt143
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt47
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt50
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt26
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt26
7 files changed, 0 insertions, 483 deletions
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt
deleted file mode 100644
index 9bf8aba..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2022 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules
-
-import foundation.e.privacymodules.trackers.IDNSBlocker
-
-object DependencyInjector {
- fun initialize(
- dnsBlocker: IDNSBlocker
- ) {
- this.dnsBlocker = dnsBlocker
- }
-
- lateinit var dnsBlocker: IDNSBlocker
- private set
-}
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt
deleted file mode 100644
index 64b2292..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (C) 2022 - 2023 MURENA SAS
- * Copyright (C) 2021 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.permissions
-
-import android.app.AppOpsManager
-import android.content.Context
-import android.content.pm.ApplicationInfo
-import android.content.pm.PackageManager
-import android.content.pm.PermissionInfo
-import android.content.pm.PermissionInfo.PROTECTION_DANGEROUS
-import android.graphics.drawable.Drawable
-import android.os.Build
-import android.util.Log
-import foundation.e.privacymodules.permissions.data.AppOpModes
-import foundation.e.privacymodules.permissions.data.ApplicationDescription
-import foundation.e.privacymodules.permissions.data.PermissionDescription
-import foundation.e.privacymodules.permissions.data.ProfileType
-
-/**
- * Implementation of the commons functionality between privileged and standard
- * versions of the module.
- * @param context an Android context, to retrieve packageManager for example.
- */
-abstract class APermissionsPrivacyModule(protected val context: Context) : IPermissionsPrivacyModule {
-
- companion object {
- private const val TAG = "PermissionsModule"
- }
-
- /**
- * @see IPermissionsPrivacyModule.getInstalledApplications
- */
- override fun getApplicationDescription(packageName: String, withIcon: Boolean): ApplicationDescription {
- val appDesc = buildApplicationDescription(context.packageManager.getApplicationInfo(packageName, 0))
- if (withIcon) {
- appDesc.icon = getApplicationIcon(appDesc.packageName)
- }
- return appDesc
- }
-
- /**
- * * @see IPermissionsPrivacyModule.getPermissions
- */
- override fun getPermissions(packageName: String): List<String> {
- val packageInfo = context.packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)
- return packageInfo.requestedPermissions?.asList() ?: emptyList()
- }
-
- override fun getPermissionDescription(permissionName: String): PermissionDescription {
- val info = context.packageManager.getPermissionInfo(permissionName, 0)
- return PermissionDescription(
- name = permissionName,
- isDangerous = isPermissionsDangerous(info),
- group = null,
- label = info.loadLabel(context.packageManager),
- description = info.loadDescription(context.packageManager)
- )
- }
-
- /**
- * @see IPermissionsPrivacyModule.isDangerousPermissionGranted
- */
- override fun isDangerousPermissionGranted(packageName: String, permissionName: String): Boolean {
- return context.packageManager
- .checkPermission(permissionName, packageName) == PackageManager.PERMISSION_GRANTED
- }
-
- // on google version, work only for the current package.
- @Suppress("DEPRECATION")
- override fun getAppOpMode(
- appDesc: ApplicationDescription,
- appOpPermissionName: String
- ): AppOpModes {
-
- val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
-
- val mode = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
- appOps.checkOpNoThrow(
- appOpPermissionName,
-
- appDesc.uid, appDesc.packageName
- )
- } else {
- appOps.unsafeCheckOpNoThrow(
- appOpPermissionName,
- appDesc.uid, appDesc.packageName
- )
- }
-
- return AppOpModes.getByModeValue(mode)
- }
-
- override fun isPermissionsDangerous(permissionName: String): Boolean {
- try {
- val permissionInfo = context.packageManager.getPermissionInfo(permissionName, 0)
- return isPermissionsDangerous(permissionInfo)
- } catch (e: Exception) {
- Log.w(TAG, "exception in isPermissionsDangerous(String)", e)
- return false
- }
- }
-
- @Suppress("DEPRECATION")
- private fun isPermissionsDangerous(permissionInfo: PermissionInfo): Boolean {
- try {
- return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
- permissionInfo.protectionLevel and PROTECTION_DANGEROUS == 1
- } else {
- permissionInfo.protection == PROTECTION_DANGEROUS
- }
- } catch (e: Exception) {
- Log.w(TAG, "exception in isPermissionsDangerous(PermissionInfo)", e)
- return false
- }
- }
-
- override fun buildApplicationDescription(
- appInfo: ApplicationInfo,
- profileId: Int,
- profileType: ProfileType
- ):
- ApplicationDescription {
- return ApplicationDescription(
- packageName = appInfo.packageName,
- uid = appInfo.uid,
- label = getAppLabel(appInfo),
- icon = null,
- profileId = profileId,
- profileType = profileType,
- )
- }
-
- private fun getAppLabel(appInfo: ApplicationInfo): CharSequence {
- return context.packageManager.getApplicationLabel(appInfo)
- }
-
- fun getApplicationIcon(appInfo: ApplicationInfo): Drawable? {
- return context.packageManager.getApplicationIcon(appInfo)
- }
-
- override fun getApplicationIcon(packageName: String): Drawable? {
- return context.packageManager.getApplicationIcon(packageName)
- }
-}
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt
deleted file mode 100644
index 39c726a..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2022 - 2023 MURENA SAS
- * Copyright (C) 2021 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.permissions
-
-import android.app.NotificationChannel
-import android.content.pm.ApplicationInfo
-import android.content.pm.PackageInfo
-import android.graphics.drawable.Drawable
-import foundation.e.privacymodules.permissions.data.AppOpModes
-import foundation.e.privacymodules.permissions.data.ApplicationDescription
-import foundation.e.privacymodules.permissions.data.PermissionDescription
-import foundation.e.privacymodules.permissions.data.ProfileType
-
-/**
- * List applications and manage theirs permissions.
- */
-interface IPermissionsPrivacyModule {
-
- fun buildApplicationDescription(
- appInfo: ApplicationInfo,
- profileId: Int = -1,
- profileType: ProfileType = ProfileType.MAIN
- ): ApplicationDescription
-
- fun getApplications(
- filter: ((PackageInfo) -> Boolean)?,
- ): List<ApplicationDescription>
-
- /**
- * List of permissions names used by an app, specified by its [packageName].
- * @param packageName the appId of the app
- * @return the list off permission, in the "android.permission.PERMISSION" format.
- */
- fun getPermissions(packageName: String): List<String>
-
- fun getPermissionDescription(permissionName: String): PermissionDescription
-
- /**
- * Get the filled up [ApplicationDescription] for the app specified by its [packageName]
- * @param packageName the appId of the app
- * @return the informations about the app.
- */
- fun getApplicationDescription(packageName: String, withIcon: Boolean = true): ApplicationDescription
-
- /**
- * Check if the current runtime permission is granted for the specified app.
- *
- * @param packageName the packageName of the app
- * @param permissionName the name of the permission in "android.permission.PERMISSION" format.
- * @return the current status for this permission.
- */
- fun isDangerousPermissionGranted(packageName: String, permissionName: String): Boolean
-
- /**
- * Get the appOps mode for the specified [appOpPermissionName] of the specified application.
- *
- * @param appDesc the application
- * @param appOpPermissionName the AppOps permission name.
- * @return mode, as a [AppOpModes]
- */
- fun getAppOpMode(appDesc: ApplicationDescription, appOpPermissionName: String): AppOpModes
-
- /**
- * Grant or revoke the specified permission for the specigfied app.
- * If their is not enough privileges to get the permission, return the false
- *
- * @param appDesc the application
- * @param permissionName the name of the permission in "android.permission.PERMISSION" format.
- * @param grant true grant the permission, false revoke it.
- * @return true if the permission is or has just been granted, false if
- * user has to do it himself.
- */
- fun toggleDangerousPermission(
- appDesc: ApplicationDescription,
- permissionName: String,
- grant: Boolean
- ): Boolean
-
- /**
- * Change the appOp Mode for the specified appOpPermission and application.
- * @param appDesc the application
- * @param appOpPermissionName the AppOps permission name.
- * @return true if the mode has been changed, false if
- * user has to do it himself.
- */
- fun setAppOpMode(
- appDesc: ApplicationDescription,
- appOpPermissionName: String,
- status: AppOpModes
- ): Boolean
-
- /**
- * Return true if the application is flagged Dangerous.
- */
- fun isPermissionsDangerous(permissionName: String): Boolean
-
- /**
- * Get the application icon.
- */
- fun getApplicationIcon(packageName: String): Drawable?
-
- /**
- * Get the application icon.
- */
- fun getApplicationIcon(app: ApplicationDescription): Drawable?
-
- /**
- * Authorize the specified package to be used as Vpn.
- * @return true if authorization has been set, false if an error has occurred.
- */
- fun setVpnPackageAuthorization(packageName: String): Boolean
-
- /**
- * Returns the package name of the currently set always-on VPN application, or null.
- */
- fun getAlwaysOnVpnPackage(): String?
-
- /**
- * Allows users to block notifications sent through this channel, if this channel belongs to
- * a package that is signed with the system signature.
- *
- * If the channel does not belong to a package that is signed with the system signature, this
- * method does nothing, since such channels are blockable by default and cannot be set to be
- * unblockable.
- */
- fun setBlockable(notificationChannel: NotificationChannel)
-}
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt
deleted file mode 100644
index 4764596..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2022 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.permissions.data
-
-import android.app.AppOpsManager.MODE_ALLOWED
-import android.app.AppOpsManager.MODE_DEFAULT
-import android.app.AppOpsManager.MODE_ERRORED
-import android.app.AppOpsManager.MODE_FOREGROUND
-import android.app.AppOpsManager.MODE_IGNORED
-import android.os.Build
-
-enum class AppOpModes(val modeValue: Int) {
- ALLOWED(MODE_ALLOWED),
- IGNORED(MODE_IGNORED),
- ERRORED(MODE_ERRORED),
- DEFAULT(MODE_DEFAULT),
- FOREGROUND(if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) MODE_ALLOWED else MODE_FOREGROUND);
-
- companion object {
- private val byMode = mapOf(
- FOREGROUND.modeValue to FOREGROUND,
- ALLOWED.modeValue to ALLOWED,
- IGNORED.modeValue to IGNORED,
- ERRORED.modeValue to ERRORED,
- DEFAULT.modeValue to DEFAULT,
- )
-
- fun getByModeValue(modeValue: Int): AppOpModes {
- return byMode.get(modeValue) ?: DEFAULT
- }
- }
-}
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt
deleted file mode 100644
index 4fa1bb9..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2023 MURENA SAS
- * Copyright (C) 2022 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.permissions.data
-
-import android.graphics.drawable.Drawable
-
-/**
- * Useful informations to identify and describe an application.
- */
-data class ApplicationDescription(
- val packageName: String,
- val uid: Int,
- val profileId: Int,
- val profileType: ProfileType,
- var label: CharSequence?,
- var icon: Drawable?
-) {
- val profileFlag = when (profileType) {
- ProfileType.MAIN -> PROFILE_FLAG_MAIN
- ProfileType.WORK -> PROFILE_FLAG_WORK
- else -> profileId
- }
-
- val apId: String get() = "${profileFlag}_$packageName"
-
- companion object {
- const val PROFILE_FLAG_MAIN = -1
- const val PROFILE_FLAG_WORK = -2
- }
-}
-
-enum class ProfileType {
- MAIN, WORK, OTHER
-}
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt
deleted file mode 100644
index 127192b..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2022 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.permissions.data
-
-data class PermissionDescription(
- val name: String,
- var isDangerous: Boolean,
- val group: String?,
- var label: CharSequence?,
- var description: CharSequence?
-)
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt
deleted file mode 100644
index a132aef..0000000
--- a/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2022 E FOUNDATION
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.trackers
-
-interface IDNSBlocker {
- companion object {
- const val DUMMY_APP_UID = -1
- }
-
- fun shouldBlock(hostname: String, appUid: Int): Boolean
-}