summaryrefslogtreecommitdiff
path: root/trackers/src
diff options
context:
space:
mode:
Diffstat (limited to 'trackers/src')
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerRunnable.kt305
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt31
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/ForegroundStarter.kt33
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/TrackersLogger.kt33
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/api/BlockTrackersPrivacyModule.kt39
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/api/IBlockTrackersPrivacyModule.kt2
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt3
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt33
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt49
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt33
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/data/TrackersRepository.kt33
-rw-r--r--trackers/src/main/java/foundation/e/privacymodules/trackers/data/WhitelistRepository.kt48
12 files changed, 301 insertions, 341 deletions
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerRunnable.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerRunnable.kt
index 01ae5b7..42037e2 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerRunnable.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerRunnable.kt
@@ -1,164 +1,141 @@
-/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
- */
-/*
- PersonalDNSFilter 1.5
- Copyright (C) 2017 Ingo Zenz
- Copyright (C) 2021 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
- */
-package foundation.e.privacymodules.trackers
-
-import android.content.Context
-import android.content.pm.PackageManager
-import android.net.LocalServerSocket
-import android.system.ErrnoException
-import android.system.Os
-import android.system.OsConstants
-import android.util.Log
-import foundation.e.privacymodules.trackers.data.TrackersRepository
-import foundation.e.privacymodules.trackers.data.WhitelistRepository
-import java.io.BufferedReader
-import java.io.IOException
-import java.io.InputStreamReader
-import java.io.PrintWriter
-
-class DNSBlockerRunnable(
- ct: Context,
- private val trackersLogger: TrackersLogger,
- private val trackersRepository: TrackersRepository,
- private val whitelistRepository: WhitelistRepository
-) : Runnable {
- var resolverReceiver: LocalServerSocket? = null
- var stopped = false
- private var eBrowserAppUid = -1
-
- companion object {
- private const val SOCKET_NAME = "foundation.e.advancedprivacy"
- private const val E_BROWSER_DOT_SERVER = "chrome.cloudflare-dns.com"
- private const val TAG = "DNSBlockerRunnable"
- }
-
- init {
- initEBrowserDoTFix(ct)
- }
-
- @Synchronized
- fun stop() {
- stopped = true
- closeSocket()
- }
-
- private fun closeSocket() {
- // Known bug and workaround that LocalServerSocket::close is not working well
- // https://issuetracker.google.com/issues/36945762
- if (resolverReceiver != null) {
- try {
- Os.shutdown(resolverReceiver!!.fileDescriptor, OsConstants.SHUT_RDWR)
- resolverReceiver!!.close()
- resolverReceiver = null
- } catch (e: ErrnoException) {
- if (e.errno != OsConstants.EBADF) {
- Log.w(TAG, "Socket already closed")
- } else {
- Log.e(TAG, "Exception: cannot close DNS port on stop $SOCKET_NAME !", e)
- }
- } catch (e: Exception) {
- Log.e(TAG, "Exception: cannot close DNS port on stop $SOCKET_NAME !", e)
- }
- }
- }
-
- override fun run() {
- val resolverReceiver = try {
- LocalServerSocket(SOCKET_NAME)
- } catch (eio: IOException) {
- Log.e(TAG, "Exception:Cannot open DNS port $SOCKET_NAME !", eio)
- return
- }
-
- this.resolverReceiver = resolverReceiver
- Log.d(TAG, "DNSFilterProxy running on port $SOCKET_NAME !")
-
- while (!stopped) {
- try {
- val socket = resolverReceiver.accept()
- val reader = BufferedReader(InputStreamReader(socket.inputStream))
- val line = reader.readLine()
- val params = line.split(",").toTypedArray()
- val output = socket.outputStream
- val writer = PrintWriter(output, true)
- val domainName = params[0]
- val appUid = params[1].toInt()
- var isBlocked = false
- if (isEBrowserDoTBlockFix(appUid, domainName)) {
- isBlocked = true
- } else if (trackersRepository.isTracker(domainName)) {
- val trackerId = trackersRepository.getTrackerId(domainName)
- if (shouldBlock(appUid, trackerId)) {
- writer.println("block")
- isBlocked = true
- }
- trackersLogger.logAccess(trackerId, appUid, isBlocked)
- }
- if (!isBlocked) {
- writer.println("pass")
- }
- socket.close()
- // Printing bufferedreader data
- } catch (e: IOException) {
- Log.w(TAG, "Exception while listening DNS resolver", e)
- }
- }
- }
-
- private fun initEBrowserDoTFix(context: Context) {
- try {
- eBrowserAppUid =
- context.packageManager.getApplicationInfo("foundation.e.browser", 0).uid
- } catch (e: PackageManager.NameNotFoundException) {
- Log.i(TAG, "no E Browser package found.")
- }
- }
-
- private fun isEBrowserDoTBlockFix(appUid: Int, hostname: String): Boolean {
- return appUid == eBrowserAppUid && E_BROWSER_DOT_SERVER == hostname
- }
-
- private fun shouldBlock(appUid: Int, trackerId: String?): Boolean {
- return whitelistRepository.isBlockingEnabled &&
- !whitelistRepository.isAppWhiteListed(appUid) &&
- !whitelistRepository.isTrackerWhiteListedForApp(trackerId, appUid)
- }
-
-
-} \ No newline at end of file
+/*
+ * 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
+
+import android.content.Context
+import android.content.pm.PackageManager
+import android.net.LocalServerSocket
+import android.system.ErrnoException
+import android.system.Os
+import android.system.OsConstants
+import android.util.Log
+import foundation.e.privacymodules.trackers.data.TrackersRepository
+import foundation.e.privacymodules.trackers.data.WhitelistRepository
+import java.io.BufferedReader
+import java.io.IOException
+import java.io.InputStreamReader
+import java.io.PrintWriter
+
+class DNSBlockerRunnable(
+ ct: Context,
+ private val trackersLogger: TrackersLogger,
+ private val trackersRepository: TrackersRepository,
+ private val whitelistRepository: WhitelistRepository
+) : Runnable {
+ var resolverReceiver: LocalServerSocket? = null
+ var stopped = false
+ private var eBrowserAppUid = -1
+
+ companion object {
+ private const val SOCKET_NAME = "foundation.e.advancedprivacy"
+ private const val E_BROWSER_DOT_SERVER = "chrome.cloudflare-dns.com"
+ private const val TAG = "DNSBlockerRunnable"
+ }
+
+ init {
+ initEBrowserDoTFix(ct)
+ }
+
+ @Synchronized
+ fun stop() {
+ stopped = true
+ closeSocket()
+ }
+
+ private fun closeSocket() {
+ // Known bug and workaround that LocalServerSocket::close is not working well
+ // https://issuetracker.google.com/issues/36945762
+ if (resolverReceiver != null) {
+ try {
+ Os.shutdown(resolverReceiver!!.fileDescriptor, OsConstants.SHUT_RDWR)
+ resolverReceiver!!.close()
+ resolverReceiver = null
+ } catch (e: ErrnoException) {
+ if (e.errno != OsConstants.EBADF) {
+ Log.w(TAG, "Socket already closed")
+ } else {
+ Log.e(TAG, "Exception: cannot close DNS port on stop $SOCKET_NAME !", e)
+ }
+ } catch (e: Exception) {
+ Log.e(TAG, "Exception: cannot close DNS port on stop $SOCKET_NAME !", e)
+ }
+ }
+ }
+
+ override fun run() {
+ val resolverReceiver = try {
+ LocalServerSocket(SOCKET_NAME)
+ } catch (eio: IOException) {
+ Log.e(TAG, "Exception:Cannot open DNS port $SOCKET_NAME !", eio)
+ return
+ }
+
+ this.resolverReceiver = resolverReceiver
+ Log.d(TAG, "DNSFilterProxy running on port $SOCKET_NAME !")
+
+ while (!stopped) {
+ try {
+ val socket = resolverReceiver.accept()
+ val reader = BufferedReader(InputStreamReader(socket.inputStream))
+ val line = reader.readLine()
+ val params = line.split(",").toTypedArray()
+ val output = socket.outputStream
+ val writer = PrintWriter(output, true)
+ val domainName = params[0]
+ val appUid = params[1].toInt()
+ var isBlocked = false
+ if (isEBrowserDoTBlockFix(appUid, domainName)) {
+ isBlocked = true
+ } else if (trackersRepository.isTracker(domainName)) {
+ val trackerId = trackersRepository.getTrackerId(domainName)
+ if (shouldBlock(appUid, trackerId)) {
+ writer.println("block")
+ isBlocked = true
+ }
+ trackersLogger.logAccess(trackerId, appUid, isBlocked)
+ }
+ if (!isBlocked) {
+ writer.println("pass")
+ }
+ socket.close()
+ // Printing bufferedreader data
+ } catch (e: IOException) {
+ Log.w(TAG, "Exception while listening DNS resolver", e)
+ }
+ }
+ }
+
+ private fun initEBrowserDoTFix(context: Context) {
+ try {
+ eBrowserAppUid =
+ context.packageManager.getApplicationInfo("foundation.e.browser", 0).uid
+ } catch (e: PackageManager.NameNotFoundException) {
+ Log.i(TAG, "no E Browser package found.")
+ }
+ }
+
+ private fun isEBrowserDoTBlockFix(appUid: Int, hostname: String): Boolean {
+ return appUid == eBrowserAppUid && E_BROWSER_DOT_SERVER == hostname
+ }
+
+ private fun shouldBlock(appUid: Int, trackerId: String?): Boolean {
+ return whitelistRepository.isBlockingEnabled &&
+ !whitelistRepository.isAppWhiteListed(appUid) &&
+ !whitelistRepository.isTrackerWhiteListedForApp(trackerId, appUid)
+ }
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt
index 3162422..97a0fda 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2021 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * Copyright (C) 2021 E FOUNDATION
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+
package foundation.e.privacymodules.trackers
import android.app.Service
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/ForegroundStarter.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/ForegroundStarter.kt
index 30bba7b..69b4f28 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/ForegroundStarter.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/ForegroundStarter.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2021 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * Copyright (C) 2021 E FOUNDATION
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+
package foundation.e.privacymodules.trackers
import android.app.Notification
@@ -43,4 +42,4 @@ object ForegroundStarter {
service.startForeground(1337, notification)
}
}
-} \ No newline at end of file
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/TrackersLogger.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/TrackersLogger.kt
index 6d2abec..99e2148 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/TrackersLogger.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/TrackersLogger.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * 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
import android.content.Context
@@ -66,4 +65,4 @@ class TrackersLogger(context: Context) {
}
inner class DetectedTracker(var trackerId: String?, var appUid: Int, var wasBlocked: Boolean)
-} \ No newline at end of file
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/BlockTrackersPrivacyModule.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/BlockTrackersPrivacyModule.kt
index 46729fd..25f0f2a 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/BlockTrackersPrivacyModule.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/BlockTrackersPrivacyModule.kt
@@ -1,26 +1,25 @@
/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * 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.api
-import foundation.e.privacymodules.trackers.data.WhitelistRepository
import android.content.Context
import foundation.e.privacymodules.trackers.data.TrackersRepository
+import foundation.e.privacymodules.trackers.data.WhitelistRepository
class BlockTrackersPrivacyModule(context: Context) : IBlockTrackersPrivacyModule {
private val mListeners = mutableListOf<IBlockTrackersPrivacyModule.Listener>()
@@ -31,7 +30,7 @@ class BlockTrackersPrivacyModule(context: Context) : IBlockTrackersPrivacyModule
private var instance: BlockTrackersPrivacyModule? = null
fun getInstance(context: Context): BlockTrackersPrivacyModule {
- return instance?: BlockTrackersPrivacyModule(context).apply { instance = this }
+ return instance ?: BlockTrackersPrivacyModule(context).apply { instance = this }
}
}
@@ -86,6 +85,4 @@ class BlockTrackersPrivacyModule(context: Context) : IBlockTrackersPrivacyModule
override fun setWhiteListed(appUid: Int, isWhiteListed: Boolean) {
whitelistRepository.setWhiteListed(appUid, isWhiteListed)
}
-
-
-} \ No newline at end of file
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/IBlockTrackersPrivacyModule.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/IBlockTrackersPrivacyModule.kt
index b07e210..9e1a041 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/IBlockTrackersPrivacyModule.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/IBlockTrackersPrivacyModule.kt
@@ -22,7 +22,6 @@ package foundation.e.privacymodules.trackers.api
*/
interface IBlockTrackersPrivacyModule {
-
/**
* Get the state of the blockin module
* @return true when blocking is enabled, false otherwise.
@@ -69,7 +68,6 @@ interface IBlockTrackersPrivacyModule {
*/
fun isWhitelisted(appUid: Int): Boolean
-
/**
* List the white listed trackers for an App specified by it uid
*/
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt
index 5f1fa92..264f247 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt
@@ -61,7 +61,6 @@ interface ITrackTrackersPrivacyModule {
*/
fun getPastYearTrackersCount(): Int
-
/**
* Return number of trackers calls by hours, for the last 24hours.
* @return list of 24 numbers of trackers calls by hours
@@ -100,4 +99,4 @@ interface ITrackTrackersPrivacyModule {
fun removeListener(listener: Listener)
fun clearListeners()
-} \ No newline at end of file
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt
index d8f75aa..18c56c9 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2021 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * Copyright (C) 2021 E FOUNDATION
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+
package foundation.e.privacymodules.trackers.api
import android.content.Context
@@ -33,7 +32,7 @@ class TrackTrackersPrivacyModule(private val context: Context) : ITrackTrackersP
private var instance: TrackTrackersPrivacyModule? = null
fun getInstance(context: Context): TrackTrackersPrivacyModule {
- return instance?: TrackTrackersPrivacyModule(context).apply { instance = this }
+ return instance ?: TrackTrackersPrivacyModule(context).apply { instance = this }
}
}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt
index c93fe90..21edb56 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * 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.data
import android.content.ContentValues
@@ -97,10 +96,12 @@ class StatsDatabase(context: Context) :
val selection = "$COLUMN_NAME_TIMESTAMP >= ?"
val selectionArg = arrayOf("" + minTimestamp)
- val projection = ("$COLUMN_NAME_TIMESTAMP, " +
- "STRFTIME('${sqlitePeriodFormat}', DATETIME($COLUMN_NAME_TIMESTAMP, 'unixepoch', 'localtime')) $PROJECTION_NAME_PERIOD," +
- "SUM($COLUMN_NAME_NUMBER_CONTACTED) $PROJECTION_NAME_CONTACTED_SUM, " +
- "SUM($COLUMN_NAME_NUMBER_BLOCKED) $PROJECTION_NAME_BLOCKED_SUM")
+ val projection = (
+ "$COLUMN_NAME_TIMESTAMP, " +
+ "STRFTIME('$sqlitePeriodFormat', DATETIME($COLUMN_NAME_TIMESTAMP, 'unixepoch', 'localtime')) $PROJECTION_NAME_PERIOD," +
+ "SUM($COLUMN_NAME_NUMBER_CONTACTED) $PROJECTION_NAME_CONTACTED_SUM, " +
+ "SUM($COLUMN_NAME_NUMBER_BLOCKED) $PROJECTION_NAME_BLOCKED_SUM"
+ )
val cursor = db.rawQuery(
"SELECT $projection FROM $TABLE_NAME WHERE $selection" +
@@ -208,7 +209,7 @@ class StatsDatabase(context: Context) :
val db = readableDatabase
val projection = "$COLUMN_NAME_APP_UID, $COLUMN_NAME_TRACKER"
val cursor = db.rawQuery(
- "SELECT DISTINCT $projection FROM $TABLE_NAME", //+
+ "SELECT DISTINCT $projection FROM $TABLE_NAME", // +
arrayOf()
)
val countByApp = mutableMapOf<Int, Int>()
@@ -260,7 +261,7 @@ class StatsDatabase(context: Context) :
val selectionArg = arrayOf("" + appUid, "" + minTimestamp)
val projection =
"SUM($COLUMN_NAME_NUMBER_CONTACTED) $PROJECTION_NAME_CONTACTED_SUM," +
- "SUM($COLUMN_NAME_NUMBER_BLOCKED) $PROJECTION_NAME_BLOCKED_SUM"
+ "SUM($COLUMN_NAME_NUMBER_BLOCKED) $PROJECTION_NAME_BLOCKED_SUM"
val cursor = db.rawQuery(
"SELECT $projection FROM $TABLE_NAME WHERE $selection",
selectionArg
@@ -363,7 +364,6 @@ class StatsDatabase(context: Context) :
return entry
}
-
fun getTrackers(appUids: List<Int>?): List<Tracker> {
synchronized(lock) {
val columns = arrayOf(COLUMN_NAME_TRACKER, COLUMN_NAME_APP_UID)
@@ -444,5 +444,4 @@ class StatsDatabase(context: Context) :
val columnIndex = getColumnIndex(columnName)
return if (columnIndex >= 0) getString(columnIndex) else ""
}
-
-} \ No newline at end of file
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt
index f5d217a..16d8ec6 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * 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.data
import android.content.Context
@@ -80,4 +79,4 @@ class StatsRepository private constructor(context: Context) {
fun getMostLeakedApp(periodCount: Int, periodUnit: TemporalUnit): Int {
return database.getMostLeakedApp(periodCount, periodUnit)
}
-} \ No newline at end of file
+}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/TrackersRepository.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/TrackersRepository.kt
index bc4d50b..994bccf 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/TrackersRepository.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/TrackersRepository.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * 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.data
import foundation.e.privacymodules.trackers.api.Tracker
@@ -27,7 +26,7 @@ class TrackersRepository private constructor() {
companion object {
private var instance: TrackersRepository? = null
fun getInstance(): TrackersRepository {
- return instance?: TrackersRepository().apply { instance = this }
+ return instance ?: TrackersRepository().apply { instance = this }
}
}
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/WhitelistRepository.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/WhitelistRepository.kt
index 65a8c39..e9f049d 100644
--- a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/WhitelistRepository.kt
+++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/WhitelistRepository.kt
@@ -1,21 +1,20 @@
/*
- Copyright (C) 2022 ECORP
-
- 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 2
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
+ * 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.data
import android.content.Context
@@ -34,7 +33,7 @@ class WhitelistRepository private constructor(context: Context) {
private const val KEY_APP_TRACKERS_WHITELIST_PREFIX = "app_trackers_whitelist_"
private var instance: WhitelistRepository? = null
fun getInstance(context: Context): WhitelistRepository {
- return instance?: WhitelistRepository(context).apply { instance = this }
+ return instance ?: WhitelistRepository(context).apply { instance = this }
}
}
@@ -51,13 +50,13 @@ class WhitelistRepository private constructor(context: Context) {
private fun reloadAppsWhiteList() {
appsWhitelist = prefs.getStringSet(KEY_APPS_WHITELIST, HashSet())?.mapNotNull {
- try { it.toInt() } catch(e: Exception) { null }
- }?.toHashSet()?: HashSet()
+ try { it.toInt() } catch (e: Exception) { null }
+ }?.toHashSet() ?: HashSet()
}
private fun reloadAppTrackersWhiteList(appUid: Int) {
val key = buildAppTrackersKey(appUid)
- trackersWhitelistByApp[appUid] = prefs.getStringSet(key, HashSet())?: HashSet()
+ trackersWhitelistByApp[appUid] = prefs.getStringSet(key, HashSet()) ?: HashSet()
}
private fun reloadAllAppTrackersWhiteList() {
@@ -70,8 +69,6 @@ class WhitelistRepository private constructor(context: Context) {
}
}
-
-
var isBlockingEnabled: Boolean = false
get() = field
set(enabled) {
@@ -79,9 +76,8 @@ class WhitelistRepository private constructor(context: Context) {
field = enabled
}
-
fun setWhiteListed(appUid: Int, isWhiteListed: Boolean) {
- val current = prefs.getStringSet(KEY_APPS_WHITELIST, HashSet())?.toHashSet()?: HashSet()
+ val current = prefs.getStringSet(KEY_APPS_WHITELIST, HashSet())?.toHashSet() ?: HashSet()
if (isWhiteListed) {
current.add("" + appUid)
@@ -123,6 +119,6 @@ class WhitelistRepository private constructor(context: Context) {
val whiteListedApp: List<Int> get() = appsWhitelist.toList()
fun getWhiteListForApp(appUid: Int): List<String> {
- return trackersWhitelistByApp[appUid]?.toList()?: emptyList()
+ return trackersWhitelistByApp[appUid]?.toList() ?: emptyList()
}
-} \ No newline at end of file
+}