diff options
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/dummy')
| -rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt | 1 | ||||
| -rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt | 93 |
2 files changed, 94 insertions, 0 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt index fe61354..dd6112d 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt @@ -227,4 +227,5 @@ object DummyDataSource { _appsUsingLocationPerm.value = _populatedPermissions.value[permissionId].packagesAllowed } } + } 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..9485a26 --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt @@ -0,0 +1,93 @@ +/* + * 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 (Demo)", + domain = "google.com", + trackedApps = listOf(facebook, firefox) + ) + + val facebookAds = Tracker( + "Facebook (Demo)", + domain = "google.com", + trackedApps = listOf(facebook, whatsapp) + ) + val rubiconTracker = Tracker( + "Rubicon Projects", + domain = "google.com", + trackedApps = listOf(google, blisslauncher, youtube) + ) + val googleAnalytics = Tracker( + "Google Analytics", + domain = "google.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 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 + } +}
\ No newline at end of file |
