From d7a1777a43a7c2f8329eee318945d8f7705d2b68 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Thu, 18 Aug 2022 07:06:22 +0000 Subject: 2-Change artifactId for api module, to help cohabitation with permissions module. --- README.md | 14 +- api/.gitignore | 1 - api/build.gradle | 90 ------------ api/consumer-rules.pro | 0 api/proguard-rules.pro | 21 --- api/src/main/AndroidManifest.xml | 21 --- .../e/privacymodules/DependencyInjector.kt | 32 ----- .../privacymodules/location/IFakeLocationModule.kt | 41 ------ .../permissions/APermissionsPrivacyModule.kt | 158 --------------------- .../permissions/IPermissionsPrivacyModule.kt | 127 ----------------- .../privacymodules/permissions/data/AppOpModes.kt | 43 ------ .../permissions/data/ApplicationDescription.kt | 30 ---- .../permissions/data/PermissionDescription.kt | 26 ---- .../trackers/IBlockTrackersPrivacyModule.kt | 96 ------------- .../e/privacymodules/trackers/IDNSBlocker.kt | 26 ---- .../trackers/ITrackTrackersPrivacyModule.kt | 96 ------------- .../e/privacymodules/trackers/Tracker.kt | 28 ---- app/build.gradle | 29 ++-- build.gradle | 17 +++ dependencies.gradle | 17 +++ fakelocation/fakelocationdemo/build.gradle | 2 +- permissionsstandalone/build.gradle | 2 +- privacymodule-api/.gitignore | 1 + privacymodule-api/build.gradle | 112 +++++++++++++++ privacymodule-api/consumer-rules.pro | 0 privacymodule-api/proguard-rules.pro | 21 +++ privacymodule-api/src/main/AndroidManifest.xml | 21 +++ .../e/privacymodules/DependencyInjector.kt | 32 +++++ .../privacymodules/location/IFakeLocationModule.kt | 41 ++++++ .../permissions/APermissionsPrivacyModule.kt | 158 +++++++++++++++++++++ .../permissions/IPermissionsPrivacyModule.kt | 127 +++++++++++++++++ .../privacymodules/permissions/data/AppOpModes.kt | 43 ++++++ .../permissions/data/ApplicationDescription.kt | 30 ++++ .../permissions/data/PermissionDescription.kt | 26 ++++ .../trackers/IBlockTrackersPrivacyModule.kt | 96 +++++++++++++ .../e/privacymodules/trackers/IDNSBlocker.kt | 26 ++++ .../trackers/ITrackTrackersPrivacyModule.kt | 96 +++++++++++++ .../e/privacymodules/trackers/Tracker.kt | 28 ++++ settings.gradle | 2 +- trackers/build.gradle | 5 +- 40 files changed, 926 insertions(+), 856 deletions(-) delete mode 100644 api/.gitignore delete mode 100644 api/build.gradle delete mode 100644 api/consumer-rules.pro delete mode 100644 api/proguard-rules.pro delete mode 100644 api/src/main/AndroidManifest.xml delete mode 100644 api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt delete mode 100644 api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt create mode 100644 privacymodule-api/.gitignore create mode 100644 privacymodule-api/build.gradle create mode 100644 privacymodule-api/consumer-rules.pro create mode 100644 privacymodule-api/proguard-rules.pro create mode 100644 privacymodule-api/src/main/AndroidManifest.xml create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt create mode 100644 privacymodule-api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt diff --git a/README.md b/README.md index 6a9ec45..5cc125d 100644 --- a/README.md +++ b/README.md @@ -95,11 +95,13 @@ This app requires different modules that must be built indivually and pushed to modules must be build and deployed in the following order: -- [privacymodulesapi](../../../e_privacycentral_privacymodulesapi) -- [privacymodulese](../../../e_privacycentral_privacymodulese) -- [privacymoduletor](../../../e_privacycentral_privacymoduletor) -- [privacymoduletrackerfilter](../../../e_privacycentral_privacymoduletrackerfilter) - +- privacymodule-api : + - ./gradlew :privacymodule-api:assembleRelease + - ./gradlew --console=verbose publishToMavenLocal // To make it available locally for dev. + - ./gradlew --console=verbose publish // To publish it on gitlab for release. +- [privacymodule-e](../../../e_privacycentral_privacymodulese) +- [privacymodule-tor](../../../e_privacycentral_privacymoduletor) +- [app] ## Build If you'd like to build PrivacyCentral locally, you should be able to just clone and build with no issues. @@ -147,7 +149,7 @@ PrivacyCentral needs to be installed as system app and whitelisting in order to ### To run apk on stock android devices You can simply install the apk. Keep in that mind all features won't be available on stock android devices. -> Volla!!!, PrivacyCentral is installed successfully in your device. +> Voila !!!, PrivacyCentral is installed successfully in your device. # Distribution This project can be distributed as prebuilt apk with /e/OS or it can be published on other app stores for non /e/OS devices. diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/api/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/api/build.gradle b/api/build.gradle deleted file mode 100644 index b8ced30..0000000 --- a/api/build.gradle +++ /dev/null @@ -1,90 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'maven-publish' - -android { - compileSdkVersion buildConfig.compileSdk - - defaultConfig { - minSdkVersion buildConfig.minSdk - targetSdkVersion buildConfig.targetSdk - - consumerProguardFiles "consumer-rules.pro" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation( - Libs.Kotlin.stdlib, - Libs.AndroidX.coreKtxAPI29, - Libs.Coroutines.core - ) -} - -//url "https://gitlab.e.foundation/api/v4/groups/e/privacy-central/-/packages/maven" - -publishing { - publications { - maven(MavenPublication) { - groupId 'foundation.e' - //You can either define these here or get them from project conf elsewhere - artifactId 'privacymodule.api' - version buildConfig.version.name - artifact "$buildDir/outputs/aar/api-release.aar" - //aar artifact you want to publish - - //generate pom nodes for dependencies - pom.withXml { - def dependenciesNode = asNode().appendNode('dependencies') - configurations.implementation.allDependencies.each { dependency -> - if (dependency.name != 'unspecified') { - def dependencyNode = dependenciesNode.appendNode('dependency') - dependencyNode.appendNode('groupId', dependency.group) - dependencyNode.appendNode('artifactId', dependency.name) - dependencyNode.appendNode('version', dependency.version) - } - } - } - repositories { - def ciJobToken = System.getenv("CI_JOB_TOKEN") - def ciApiV4Url = System.getenv("CI_API_V4_URL") - if (ciJobToken != null) { - maven { - url "${ciApiV4Url}/projects/900/packages/maven" - credentials(HttpHeaderCredentials) { - name = 'Job-Token' - value = ciJobToken - } - authentication { - header(HttpHeaderAuthentication) - } - } - } else { - maven { - url "https://gitlab.e.foundation/api/v4/projects/900/packages/maven" - credentials(HttpHeaderCredentials) { - name = "Private-Token" - value = gitLabPrivateToken - // the variable resides in ~/.gradle/gradle.properties - } - authentication { - header(HttpHeaderAuthentication) - } - } - } - } - } - } -} diff --git a/api/consumer-rules.pro b/api/consumer-rules.pro deleted file mode 100644 index e69de29..0000000 diff --git a/api/proguard-rules.pro b/api/proguard-rules.pro deleted file mode 100644 index 481bb43..0000000 --- a/api/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/api/src/main/AndroidManifest.xml b/api/src/main/AndroidManifest.xml deleted file mode 100644 index 937e285..0000000 --- a/api/src/main/AndroidManifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - \ No newline at end of file diff --git a/api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt b/api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt deleted file mode 100644 index bcf82d2..0000000 --- a/api/src/main/java/foundation/e/privacymodules/DependencyInjector.kt +++ /dev/null @@ -1,32 +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 . - */ - -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/api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt b/api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt deleted file mode 100644 index ecad2a4..0000000 --- a/api/src/main/java/foundation/e/privacymodules/location/IFakeLocationModule.kt +++ /dev/null @@ -1,41 +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 . - */ - -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/api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt b/api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt deleted file mode 100644 index 68f7ee1..0000000 --- a/api/src/main/java/foundation/e/privacymodules/permissions/APermissionsPrivacyModule.kt +++ /dev/null @@ -1,158 +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 . - */ -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 { - val appInfos = context.packageManager.getInstalledApplications(0) - return appInfos.map { buildApplicationDescription(it, false) } - } - - /** - * @see IPermissionsPrivacyModule.getInstalledApplications - */ - override fun getInstalledApplications(): List { - 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 { - 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/api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt b/api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt deleted file mode 100644 index ba85f13..0000000 --- a/api/src/main/java/foundation/e/privacymodules/permissions/IPermissionsPrivacyModule.kt +++ /dev/null @@ -1,127 +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 . - */ - -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 - - /** - * List all the installed application on the device. - * @return list of filled up [ApplicationDescription] - */ - fun getAllApplications(): List - - /** - * 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 - - 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/api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt b/api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt deleted file mode 100644 index 367645d..0000000 --- a/api/src/main/java/foundation/e/privacymodules/permissions/data/AppOpModes.kt +++ /dev/null @@ -1,43 +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 . - */ - -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/api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt b/api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt deleted file mode 100644 index cafe256..0000000 --- a/api/src/main/java/foundation/e/privacymodules/permissions/data/ApplicationDescription.kt +++ /dev/null @@ -1,30 +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 . - */ - -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/api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt b/api/src/main/java/foundation/e/privacymodules/permissions/data/PermissionDescription.kt deleted file mode 100644 index 9ed297d..0000000 --- a/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 . - */ - -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/api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt b/api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt deleted file mode 100644 index 53b540e..0000000 --- a/api/src/main/java/foundation/e/privacymodules/trackers/IBlockTrackersPrivacyModule.kt +++ /dev/null @@ -1,96 +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 . - */ - -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 - - /** - * 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 - - /** - * 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/api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt b/api/src/main/java/foundation/e/privacymodules/trackers/IDNSBlocker.kt deleted file mode 100644 index a132aef..0000000 --- a/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 . - */ - -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/api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt b/api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt deleted file mode 100644 index 139290e..0000000 --- a/api/src/main/java/foundation/e/privacymodules/trackers/ITrackTrackersPrivacyModule.kt +++ /dev/null @@ -1,96 +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 . - */ - -package foundation.e.privacymodules.trackers - -/** - * Get reporting about trackers calls. - */ -interface ITrackTrackersPrivacyModule { - - fun start(trackers: List, enableNotification: Boolean = true) - - /** - * List all the trackers encountered for a specific app. - */ - fun getTrackersForApp(appUid: Int): List - - /** - * 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 - - /** - * 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> - - /** - * 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> - - /** - * 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> - - fun getPastDayTrackersCallsByApps(): Map> - - fun getPastDayTrackersCallsForApp(appUId: Int): Pair - - 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/api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt b/api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt deleted file mode 100644 index 0a4395a..0000000 --- a/api/src/main/java/foundation/e/privacymodules/trackers/Tracker.kt +++ /dev/null @@ -1,28 +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 . - */ - -package foundation.e.privacymodules.trackers - -/** - * Describe a tracker. - */ -data class Tracker( - val id: String, - val hostnames: Set, - val label: String, - val exodusId: String? -) diff --git a/app/build.gradle b/app/build.gradle index 61ee623..9cfc65b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,20 @@ +/* + * 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 . + */ + plugins { id 'com.android.application' id 'kotlin-android' @@ -111,17 +128,11 @@ android { } dependencies { - implementation project(':api') - + implementation project(':privacymodule-api') standaloneImplementation project(':permissionsstandalone') - e29Implementation('foundation.e:privacymodule.e-29:1.2.0') { - exclude group: 'foundation.e', module: 'privacymodule.api' - } - e30Implementation('foundation.e:privacymodule.e-30:1.2.0') { - exclude group: 'foundation.e', module: 'privacymodule.api' - } - + e29Implementation 'foundation.e:privacymodule-e-29:1.2.0' + e30Implementation 'foundation.e:privacymodule-e-30:1.2.0' implementation project(':fakelocation') e29CompileOnly files('libs/e-ui-sdk-1.0.1-q.jar') diff --git a/build.gradle b/build.gradle index 5222057..ec8cf14 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,20 @@ +/* + * 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 . + */ + import foundation.e.privacycentral.buildsrc.DependencyUpdates import foundation.e.privacycentral.buildsrc.ReleaseType diff --git a/dependencies.gradle b/dependencies.gradle index ed329c7..6c4acb3 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,3 +1,20 @@ +/* + * 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 . + */ + def libs = [:] ext.Libs = libs diff --git a/fakelocation/fakelocationdemo/build.gradle b/fakelocation/fakelocationdemo/build.gradle index 12ed2e7..c182b2f 100644 --- a/fakelocation/fakelocationdemo/build.gradle +++ b/fakelocation/fakelocationdemo/build.gradle @@ -54,7 +54,7 @@ android { } dependencies { - implementation project(':api') + implementation project(':privacymodule-api') implementation project(':fakelocation') implementation project(':permissionsstandalone') diff --git a/permissionsstandalone/build.gradle b/permissionsstandalone/build.gradle index aadb84f..ef03f2b 100644 --- a/permissionsstandalone/build.gradle +++ b/permissionsstandalone/build.gradle @@ -51,8 +51,8 @@ dependencies { Libs.AndroidX.coreKtx, Libs.Coroutines.core ) + implementation project(':privacymodule-api') - implementation project(':api') testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' diff --git a/privacymodule-api/.gitignore b/privacymodule-api/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/privacymodule-api/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/privacymodule-api/build.gradle b/privacymodule-api/build.gradle new file mode 100644 index 0000000..c0b1303 --- /dev/null +++ b/privacymodule-api/build.gradle @@ -0,0 +1,112 @@ +/* + * 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 . + */ + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'maven-publish' + +group 'foundation.e' + +android { + compileSdkVersion buildConfig.compileSdk + + defaultConfig { + minSdkVersion buildConfig.minSdk + targetSdkVersion buildConfig.targetSdk + + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation( + Libs.Kotlin.stdlib, + Libs.AndroidX.coreKtxAPI29, + Libs.Coroutines.core + ) +} + +//url "https://gitlab.e.foundation/api/v4/groups/e/privacy-central/-/packages/maven" + +publishing { + publications { + maven(MavenPublication) { + groupId 'foundation.e' + //You can either define these here or get them from project conf elsewhere + artifactId 'privacymodule-api' + version buildConfig.version.name + artifact "$buildDir/outputs/aar/privacymodule-api-release.aar" + //aar artifact you want to publish + + //generate pom nodes for dependencies + pom.withXml { + def dependenciesNode = asNode().appendNode('dependencies') + configurations.implementation.allDependencies.each { dependency -> + if (dependency.name != 'unspecified') { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', dependency.group) + dependencyNode.appendNode('artifactId', dependency.name) + dependencyNode.appendNode('version', dependency.version) + } + } + } + repositories { + def ciJobToken = System.getenv("CI_JOB_TOKEN") + def ciApiV4Url = System.getenv("CI_API_V4_URL") + if (ciJobToken != null) { + maven { + url "${ciApiV4Url}/projects/900/packages/maven" + credentials(HttpHeaderCredentials) { + name = 'Job-Token' + value = ciJobToken + } + authentication { + header(HttpHeaderAuthentication) + } + } + } else { + maven { +// url "https://gitlab.e.foundation/api/v4/projects/900/packages/maven" + // Use privacymodule-e repository (id = 781) for now, + // because repository not activated on Advanced Privacy (id = 900) + url "https://gitlab.e.foundation/api/v4/projects/781/packages/maven" + credentials(HttpHeaderCredentials) { + name = "Private-Token" + value = gitLabPrivateToken + // the variable resides in ~/.gradle/gradle.properties + } + authentication { + header(HttpHeaderAuthentication) + } + } + } + } + } + } +} diff --git a/privacymodule-api/consumer-rules.pro b/privacymodule-api/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/privacymodule-api/proguard-rules.pro b/privacymodule-api/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/privacymodule-api/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/privacymodule-api/src/main/AndroidManifest.xml b/privacymodule-api/src/main/AndroidManifest.xml new file mode 100644 index 0000000..937e285 --- /dev/null +++ b/privacymodule-api/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file 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 . + */ + +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 . + */ + +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 . + */ +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 { + val appInfos = context.packageManager.getInstalledApplications(0) + return appInfos.map { buildApplicationDescription(it, false) } + } + + /** + * @see IPermissionsPrivacyModule.getInstalledApplications + */ + override fun getInstalledApplications(): List { + 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 { + 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 . + */ + +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 + + /** + * List all the installed application on the device. + * @return list of filled up [ApplicationDescription] + */ + fun getAllApplications(): List + + /** + * 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 + + 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 . + */ + +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 . + */ + +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 . + */ + +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 . + */ + +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 + + /** + * 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 + + /** + * 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 . + */ + +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 . + */ + +package foundation.e.privacymodules.trackers + +/** + * Get reporting about trackers calls. + */ +interface ITrackTrackersPrivacyModule { + + fun start(trackers: List, enableNotification: Boolean = true) + + /** + * List all the trackers encountered for a specific app. + */ + fun getTrackersForApp(appUid: Int): List + + /** + * 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 + + /** + * 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> + + /** + * 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> + + /** + * 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> + + fun getPastDayTrackersCallsByApps(): Map> + + fun getPastDayTrackersCallsForApp(appUId: Int): Pair + + 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 . + */ + +package foundation.e.privacymodules.trackers + +/** + * Describe a tracker. + */ +data class Tracker( + val id: String, + val hostnames: Set, + val label: String, + val exodusId: String? +) diff --git a/settings.gradle b/settings.gradle index 24b6eef..547bbd1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,6 @@ include ':app' rootProject.name = "PrivacyCentralApp" include ':fakelocation' include ':fakelocation:fakelocationdemo' -include ':api' +include ':privacymodule-api' include ':permissionsstandalone' include ':trackers' diff --git a/trackers/build.gradle b/trackers/build.gradle index 51f8448..dec05ff 100644 --- a/trackers/build.gradle +++ b/trackers/build.gradle @@ -40,6 +40,7 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } } -dependencies{ - implementation project(":api") + +dependencies { + implementation project(':privacymodule-api') } -- cgit v1.2.1