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.kt32
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt41
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt158
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt127
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt43
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt30
-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/IBlockTrackersPrivacyModule.kt96
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt26
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt96
-rw-r--r--privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt28
11 files changed, 703 insertions, 0 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
new file mode 100644
index 0000000..bcf82d2
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt
@@ -0,0 +1,32 @@
+/*
+ * 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
+} \ No newline at end of file
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt
new file mode 100644
index 0000000..ecad2a4
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt
@@ -0,0 +1,41 @@
+/*
+ * 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.location
+
+/**
+ * Manage a fake location on the device.
+ */
+interface IFakeLocationModule {
+ /**
+ * Start to fake the location module. Call [setFakeLocation] after to set the fake
+ * position.
+ */
+ fun startFakeLocation()
+
+ /**
+ * Set or update the faked position.
+ * @param latitude the latitude of the fake position in degrees.
+ * @param longitude the longitude of the fake position in degrees.
+ */
+ fun setFakeLocation(latitude: Double, longitude: Double)
+
+ /**
+ * Stop the fake location module, giving back hand to the true location modules.
+ */
+ fun stopFakeLocation()
+}
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
new file mode 100644
index 0000000..68f7ee1
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt
@@ -0,0 +1,158 @@
+/*
+ * 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
+
+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
+
+/**
+ * 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.getAllApplications
+ */
+ override fun getAllApplications(): List<ApplicationDescription> {
+ val appInfos = context.packageManager.getInstalledApplications(0)
+ return appInfos.map { buildApplicationDescription(it, false) }
+ }
+
+ /**
+ * @see IPermissionsPrivacyModule.getInstalledApplications
+ */
+ override fun getInstalledApplications(): List<ApplicationDescription> {
+ return context.packageManager.getInstalledApplications(0)
+ .filter { it.flags and ApplicationInfo.FLAG_SYSTEM == 0 }
+ .map { buildApplicationDescription(it, false) }
+ }
+
+ /**
+ * @see IPermissionsPrivacyModule.getInstalledApplications
+ */
+ override fun getApplicationDescription(packageName: String): ApplicationDescription {
+ val appDesc = buildApplicationDescription(context.packageManager.getApplicationInfo(packageName, 0), false)
+ 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, withIcon: Boolean)
+ : ApplicationDescription {
+ return ApplicationDescription(
+ packageName = appInfo.packageName,
+ uid = appInfo.uid,
+ label = getAppLabel(appInfo),
+ icon = if (withIcon) getApplicationIcon(appInfo.packageName) else null
+ )
+ }
+
+ private fun getAppLabel(appInfo: ApplicationInfo): CharSequence {
+ return context.packageManager.getApplicationLabel(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
new file mode 100644
index 0000000..ba85f13
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt
@@ -0,0 +1,127 @@
+/*
+ * 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
+
+import android.content.pm.ApplicationInfo
+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
+
+/**
+ * List applications and manage theirs permissions.
+ */
+interface IPermissionsPrivacyModule {
+
+ fun buildApplicationDescription(appInfo: ApplicationInfo, withIcon: Boolean = true): ApplicationDescription
+
+ /**
+ * List the installed application on the device which have not the FLAGS_SYSTEM.
+ * @return list of filled up [ApplicationDescription]
+ */
+ fun getInstalledApplications(): List<ApplicationDescription>
+
+ /**
+ * List all the installed application on the device.
+ * @return list of filled up [ApplicationDescription]
+ */
+ fun getAllApplications(): 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): 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?
+
+ /**
+ * 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
+
+} \ No newline at end of file
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
new file mode 100644
index 0000000..367645d
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt
@@ -0,0 +1,43 @@
+/*
+ * 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.*
+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
new file mode 100644
index 0000000..cafe256
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt
@@ -0,0 +1,30 @@
+/*
+ * 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,
+ var label: CharSequence?,
+ var icon: Drawable?
+)
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
new file mode 100644
index 0000000..9ed297d
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt
@@ -0,0 +1,26 @@
+/*
+ * 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?
+) \ No newline at end of file
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt
new file mode 100644
index 0000000..53b540e
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt
@@ -0,0 +1,96 @@
+/*
+ * 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
+
+
+/**
+ * Manage trackers blocking and whitelisting.
+ */
+interface IBlockTrackersPrivacyModule {
+
+
+ /**
+ * Get the state of the blockin module
+ * @return true when blocking is enabled, false otherwise.
+ */
+ fun isBlockingEnabled(): Boolean
+
+ /**
+ * Enable blocking, using the previously configured whitelists
+ */
+ fun enableBlocking()
+
+ /**
+ * Disable blocking
+ */
+ fun disableBlocking()
+
+ /**
+ * Set or unset in whitelist the App with the specified uid.
+ * @param appUid the uid of the app
+ * @param isWhiteListed true, the app will appears in whitelist, false, it won't
+ */
+ fun setWhiteListed(appUid: Int, isWhiteListed: Boolean)
+
+ /**
+ * Set or unset in whitelist the specifid tracked, for the App specified by its uid.
+ * @param tracker the tracker
+ * @param appUid the uid of the app
+ * @param isWhiteListed true, the app will appears in whitelist, false, it won't
+ */
+ fun setWhiteListed(tracker: Tracker, appUid: Int, isWhiteListed: Boolean)
+
+ /**
+ * Return true if nothing has been added to the whitelist : everything is blocked.
+ */
+ fun isWhiteListEmpty(): Boolean
+
+ /**
+ * Return the white listed App, by their UID
+ */
+ fun getWhiteListedApp(): List<Int>
+
+ /**
+ * Return true if the App is whitelisted for trackers blocking.
+ */
+ fun isWhitelisted(appUid: Int): Boolean
+
+
+ /**
+ * List the white listed trackers for an App specified by it uid
+ */
+ fun getWhiteList(appUid: Int): List<Tracker>
+
+ /**
+ * Callback interface to get updates about the state of the Block trackers module.
+ */
+ interface Listener {
+
+ /**
+ * Called when the trackers blocking is activated or deactivated.
+ * @param isBlocking true when activated, false otherwise.
+ */
+ fun onBlockingToggle(isBlocking: Boolean)
+ }
+
+ fun addListener(listener: Listener)
+
+ fun removeListener(listener: Listener)
+
+ fun clearListeners()
+}
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
new file mode 100644
index 0000000..a132aef
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt
@@ -0,0 +1,26 @@
+/*
+ * 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
+}
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt
new file mode 100644
index 0000000..139290e
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt
@@ -0,0 +1,96 @@
+/*
+ * 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
+
+/**
+ * Get reporting about trackers calls.
+ */
+interface ITrackTrackersPrivacyModule {
+
+ fun start(trackers: List<Tracker>, enableNotification: Boolean = true)
+
+ /**
+ * List all the trackers encountered for a specific app.
+ */
+ fun getTrackersForApp(appUid: Int): List<Tracker>
+
+ /**
+ * Return the number of encountered trackers since "ever"
+ */
+ fun getTrackersCount(): Int
+
+ /**
+ * Return the number of encountere trackers since "ever", for each app uid.
+ */
+ fun getTrackersCountByApp(): Map<Int, Int>
+
+ /**
+ * Return the number of encountered trackers for the last 24 hours
+ */
+ fun getPastDayTrackersCount(): Int
+
+ /**
+ * Return the number of encountered trackers for the last month
+ */
+ fun getPastMonthTrackersCount(): Int
+
+ /**
+ * Return the number of encountered trackers for the last year
+ */
+ fun getPastYearTrackersCount(): Int
+
+
+ /**
+ * Return number of trackers calls by hours, for the last 24hours.
+ * @return list of 24 numbers of trackers calls by hours
+ */
+ fun getPastDayTrackersCalls(): List<Pair<Int, Int>>
+
+ /**
+ * Return number of trackers calls by day, for the last 30 days.
+ * @return list of 30 numbers of trackers calls by day
+ */
+ fun getPastMonthTrackersCalls(): List<Pair<Int, Int>>
+
+ /**
+ * Return number of trackers calls by month, for the last 12 month.
+ * @return list of 12 numbers of trackers calls by month
+ */
+ fun getPastYearTrackersCalls(): List<Pair<Int, Int>>
+
+ fun getPastDayTrackersCallsByApps(): Map<Int, Pair<Int, Int>>
+
+ fun getPastDayTrackersCallsForApp(appUId: Int): Pair<Int, Int>
+
+ fun getPastDayMostLeakedApp(): Int
+
+ interface Listener {
+
+ /**
+ * Called when a new tracker attempt is logged. Consumer may choose to call other methods
+ * to refresh the data.
+ */
+ fun onNewData()
+ }
+
+ fun addListener(listener: Listener)
+
+ fun removeListener(listener: Listener)
+
+ fun clearListeners()
+} \ No newline at end of file
diff --git a/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt
new file mode 100644
index 0000000..0a4395a
--- /dev/null
+++ b/privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt
@@ -0,0 +1,28 @@
+/*
+ * 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
+
+/**
+ * Describe a tracker.
+ */
+data class Tracker(
+ val id: String,
+ val hostnames: Set<String>,
+ val label: String,
+ val exodusId: String?
+)