diff options
| author | Romain Hunault <romain.hunault@e.email> | 2021-08-13 10:14:03 +0000 |
|---|---|---|
| committer | Romain Hunault <romain.hunault@e.email> | 2021-08-13 10:14:03 +0000 |
| commit | daea2f9510ac1af22a4e2e2f3db7c2d6d314008b (patch) | |
| tree | 2dfcd606e8693a79520f9931e566c237547e7cd1 /app/src/main/java/foundation/e/privacycentralapp/dummy | |
| parent | 97b51f18dcc2f87a9cdd7f482033e30a6282d853 (diff) | |
| parent | f522c4615503120b5e62e45405e8c6c3b18e5e4a (diff) | |
| download | advanced-privacy-daea2f9510ac1af22a4e2e2f3db7c2d6d314008b.tar.gz | |
Merge branch 'features/blocker' into 'master'
Add blocker feature
See merge request e/privacy-central/privacycentralapp!6
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/dummy')
| -rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt new file mode 100644 index 0000000..b6f319c --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt @@ -0,0 +1,105 @@ +/* + * 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.privacycentralapp.dummy + +import foundation.e.privacycentralapp.R +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import lineageos.blockers.BlockerInterface + +data class TrackedApp(val appName: String, val isEnabled: Boolean, val iconId: Int) + +data class Tracker( + val name: String, + val domain: String? = null, + val ipAddress: String? = null, + val trackedApps: List<TrackedApp> +) + +object TrackersDataSource { + + private lateinit var blockerService: BlockerInterface + + val facebook = TrackedApp("Facebook", true, R.drawable.ic_facebook) + val firefox = TrackedApp("Firefox", true, R.drawable.ic_facebook) + val google = TrackedApp("Google", true, R.drawable.ic_facebook) + val whatsapp = TrackedApp("Whatsapp", true, R.drawable.ic_facebook) + val blisslauncher = TrackedApp("BlissLauncher", true, R.drawable.ic_facebook) + val youtube = TrackedApp("Youtube", true, R.drawable.ic_facebook) + + val crashlytics = Tracker( + "Google Crashlytics", + domain = "|0b|crashlytics|03|com", + trackedApps = listOf(facebook, firefox) + ) + + val facebookAds = Tracker( + "Facebook Analytics", + domain = "|08|facebook|03|com", + trackedApps = listOf(facebook, whatsapp) + ) + val rubiconTracker = Tracker( + "Rubicon Projects", + domain = "|03|ads|0e|rubiconproject|03|com", + trackedApps = listOf(google, blisslauncher, youtube) + ) + val googleAnalytics = Tracker( + "Google Analytics", + domain = "|10|google-analytics|03|com", + trackedApps = listOf(facebook, firefox) + ) + + val _trackers = + MutableStateFlow(listOf(crashlytics, facebookAds, rubiconTracker, googleAnalytics)) + val trackers = _trackers.asStateFlow() + + fun injectBlockerService(blockerInterface: BlockerInterface) { + this.blockerService = blockerInterface + } + + fun getTracker(name: String): Tracker? { + try { + return _trackers.value.first { + it.name == name + } + } catch (e: NoSuchElementException) { + return null + } + } + + fun toggleTracker(tracker: Tracker, enable: Boolean): Boolean { + val result = if (!enable) { + blockerService.blockDomain(tracker.domain) + } else { + blockerService.unblockDomain(tracker.domain) + } + + if (result) { + _trackers.value = _trackers.value.map { + if (it.name == tracker.name) { + it.copy( + trackedApps = it.trackedApps.map { app -> + app.copy(isEnabled = enable) + } + ) + } else it + } + } + return result + } +} |
