diff options
| author | jacquarg <guillaume.jacquart@hoodbrains.com> | 2021-11-14 19:26:10 +0100 |
|---|---|---|
| committer | jacquarg <guillaume.jacquart@hoodbrains.com> | 2021-11-14 19:26:10 +0100 |
| commit | 30ef837288e3a5df823b31d0ecee20276de157c5 (patch) | |
| tree | 57fb2800212cd63072e931aa804cd3e47b5f883d /app/src/main/java/foundation/e/privacycentralapp/dummy | |
| parent | eeeab1f5b6f2314b408fd9d935192a4a095bcaf8 (diff) | |
| download | advanced-privacy-30ef837288e3a5df823b31d0ecee20276de157c5.tar.gz | |
Remove unused code.
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/dummy')
4 files changed, 0 insertions, 496 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 deleted file mode 100644 index 38daeab..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/DummyDataSource.kt +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode -import foundation.e.privacycentralapp.domain.entities.LocationMode -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlin.random.Random - -// ======================================================// -// -// ================ ==== ==== =============== -// ================ ====== ====== ================ -// ==== ======== ======== ==== ==== -// ==== ========= ========= ==== ==== -// ==== ==================== ================ -// ==== ==== ======== ==== =============== -// ==== ==== ==== ==== ==== -// ================ ==== == ==== ==== -// ================ ==== ==== ==== -// -// ======================================================// - -/** - * This whole file acts as a dummy source. All data classes and method implementations - * are not proper ones and are subject to change anytime. - */ - -/** - * Dummmy permission data class. - */ -data class Permission( - val id: Int, - val name: String, - val iconId: Int, - val packagesRequested: Set<String> = emptySet(), - val packagesAllowed: Set<String> = emptySet() -) - -data class Location(val mode: LocationMode, val latitude: Double, val longitude: Double) - -object DummyDataSource { - - const val trackersCount = 77 - private val _activeTrackersCount = MutableStateFlow(10) - val activeTrackersCount = _activeTrackersCount.asStateFlow() - - private val _location = MutableStateFlow(Location(LocationMode.REAL_LOCATION, 0.0, 0.0)) - val location = _location.asStateFlow() - - private val _internetActivityMode = MutableStateFlow(InternetPrivacyMode.REAL_IP) - val internetActivityMode = _internetActivityMode.asStateFlow() - - /** - * Declare dummy permissions with following ids - * - * [0] -> Body sensor - * [1] -> Calendar - * [2] -> Call Logs - * [3] -> Location - */ - val permissions = arrayOf("Body Sensor", "Calendar", "Call Logs", "Location") - - private val permissionIcons = arrayOf( - R.drawable.ic_body_monitor, - R.drawable.ic_calendar, - R.drawable.ic_call, - R.drawable.ic_location - ) - - val packages = arrayOf( - "facebook", - "uber", - "instagram", - "openstreetmap", - "truecaller", - "netflix", - "firefox", - "pubg", - "amazon", - "calendar", - "zohomail", - "privacycentral" - ) - - val _populatedPermissions = MutableStateFlow(fetchPermissions()) - val populatedPermission = _populatedPermissions.asStateFlow() - - private val _appsUsingLocationPerm = - MutableStateFlow(_populatedPermissions.value[3].packagesAllowed) - val appsUsingLocationPerm = _appsUsingLocationPerm.asStateFlow() - - private fun fetchPermissions(): List<Permission> { - val result = mutableListOf<Permission>() - permissions.forEachIndexed { index, permission -> - when (index) { - 0 -> result.add(Permission(index, permission, permissionIcons[index])) - 1 -> { - val randomPackages = getRandomItems(packages, 8) - val grantedPackages = getRandomItems(randomPackages, 3) - result.add( - Permission( - index, - permission, - permissionIcons[index], - randomPackages, - grantedPackages - ) - ) - } - 2 -> { - val randomPackages = getRandomItems(packages, 10) - val grantedPackages = getRandomItems(randomPackages, 9) - result.add( - Permission( - index, - permission, - permissionIcons[index], - randomPackages, - grantedPackages - ) - ) - } - 3 -> { - val randomPackages = getRandomItems(packages, 5) - val grantedPackages = getRandomItems(randomPackages, 3) - result.add( - Permission( - index, - permission, - permissionIcons[index], - randomPackages, - grantedPackages - ) - ) - } - } - } - return result - } - - private fun <T> getRandomItems(data: Array<T>, limit: Int): Set<T> = - getRandomItems(data.toSet(), limit) - - private fun <T> getRandomItems(data: Set<T>, limit: Int): Set<T> { - val randomItems = mutableSetOf<T>() - val localData = data.toMutableList() - repeat(limit) { - val generated = localData.random() - randomItems.add(generated) - localData.remove(generated) - } - return randomItems - } - - fun getPermission(permissionId: Int): Permission = populatedPermission.value[permissionId] - - fun getLocationPermissionApps(): Permission = getPermission(3) - - fun setLocationMode(locationMode: LocationMode, location: Location? = null): Boolean { - when (locationMode) { - LocationMode.REAL_LOCATION -> - _location.value = - Location(LocationMode.REAL_LOCATION, 24.39, 71.80) - LocationMode.RANDOM_LOCATION -> { - requireNotNull(location) { "Custom location should be null" } - _location.value = location - } - LocationMode.SPECIFIC_LOCATION -> { - requireNotNull(location) { "Custom location should be null" } - _location.value = location.copy(mode = LocationMode.SPECIFIC_LOCATION) - } - } - return true - } - - private fun randomLocation(): Location = Location( - LocationMode.RANDOM_LOCATION, - Random.nextDouble(-90.0, 90.0), - Random.nextDouble(-180.0, 180.0) - ) - - fun setInternetPrivacyMode(mode: InternetPrivacyMode): Boolean { - _internetActivityMode.value = mode - return true - } - - fun togglePermission(permissionId: Int, packageName: String, grant: Boolean) { - val allPermissions = _populatedPermissions.value.toMutableList() - val permission: Permission = allPermissions[permissionId].let { permission -> - - val packagesAllowed = permission.packagesAllowed.toMutableSet() - - if (grant) packagesAllowed.add(packageName) - else packagesAllowed.remove(packageName) - - permission.copy(packagesAllowed = packagesAllowed) - } - allPermissions[permissionId] = permission - _populatedPermissions.value = allPermissions - - // Update when permission is toggled for Location - if (permissionId == 3) { - _appsUsingLocationPerm.value = _populatedPermissions.value[permissionId].packagesAllowed - } - } -} diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/Extensions.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/Extensions.kt deleted file mode 100644 index ab4ba72..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/Extensions.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 android.content.Context -import foundation.e.privacycentralapp.R -import foundation.e.privacycentralapp.domain.entities.LocationMode - -fun LocationMode.mapToString(context: Context): String = when (this) { - LocationMode.REAL_LOCATION -> context.getString(R.string.real_location_mode) - LocationMode.RANDOM_LOCATION -> context.getString(R.string.random_location_mode) - LocationMode.SPECIFIC_LOCATION -> context.getString(R.string.fake_location_mode) -} diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackTrackersPrivacyMock.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackTrackersPrivacyMock.kt deleted file mode 100644 index 5b1eb9e..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackTrackersPrivacyMock.kt +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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.privacymodules.trackers.IBlockTrackersPrivacyModule -import foundation.e.privacymodules.trackers.ITrackTrackersPrivacyModule -import foundation.e.privacymodules.trackers.Tracker - -class TrackTrackersPrivacyMock : - ITrackTrackersPrivacyModule, - IBlockTrackersPrivacyModule { - - private val trackers = listOf( - Tracker(1, "Crashlytics", null), - Tracker(2, label = "Facebook", null) - ) - - override fun getPastDayTrackersCalls(): List<Int> { - return listOf( - 2000, 2300, 130, 2500, 1000, 2000, - 2000, 2300, 130, 2500, 1000, 2000, - 2000, 2300, 130, 2500, 1000, 2000, - 2000, 2300, 130, 2500, 1000, 2000 - ) - } - - override fun getPastDayTrackersCount(): Int { - return 30 - } - - override fun getPastMonthTrackersCalls(): List<Int> { - return listOf( - 20000, 23000, 24130, 12500, 31000, 22000, - 20000, 23000, 24130, 12500, 31000, 22000, - 20000, 23000, 24130, 12500, 31000, 22000, - 20000, 23000, 24130, 12500, 31000, 22000, - 20000, 23000, 24130, 12500, 31000, 22000 - ) - } - - override fun getPastMonthTrackersCount(): Int { - return 43 - } - - override fun getPastYearTrackersCalls(): List<Int> { - return listOf( - 620000, 823000, 424130, 712500, 831000, 922000, - 620000, 823000, 424130, 712500, 831000, 922000 - ) - } - - override fun getPastYearTrackersCount(): Int { - return 46 - } - - override fun getTrackersCount(): Int { - return 72 - } - - override fun getTrackersForApp(appUid: Int): List<Tracker> { - return trackers - } - - private var isBlockingEnabled = false - private val appWhitelist = mutableSetOf<Int>() - private val trackersWhitelist = mutableMapOf<Int, MutableSet<Tracker>>() - - override fun addListener(listener: IBlockTrackersPrivacyModule.Listener) { - TODO("Not yet implemented") - } - - override fun removeListener(listener: IBlockTrackersPrivacyModule.Listener) { - TODO("Not yet implemented") - } - - override fun clearListeners() { - TODO("Not yet implemented") - } - - override fun disableBlocking() {} - - override fun enableBlocking() {} - - override fun getWhiteList(appUid: Int): List<Tracker> { - return trackersWhitelist[appUid]?.toList() ?: emptyList() - } - - override fun getWhiteListedApp(): List<Int> { - return appWhitelist.toList() - } - - override fun isBlockingEnabled(): Boolean { - return isBlockingEnabled - } - - override fun isWhiteListEmpty(): Boolean { - return appWhitelist.isEmpty() && - (trackersWhitelist.isEmpty() || trackersWhitelist.values.all { it.isEmpty() }) - } - - override fun isWhitelisted(appUid: Int): Boolean { - return appUid in appWhitelist - } - - override fun setWhiteListed(tracker: Tracker, appUid: Int, isWhiteListed: Boolean) { - if (appUid !in trackersWhitelist) { - trackersWhitelist[appUid] = mutableSetOf<Tracker>() - } - - if (isWhiteListed) { - trackersWhitelist[appUid]?.add(tracker) - } else { - trackersWhitelist[appUid]?.remove(tracker) - } - } - - override fun setWhiteListed(appUid: Int, isWhiteListed: Boolean) { - if (isWhiteListed) { - appWhitelist.add(appUid) - } else { - appWhitelist.remove(appUid) - } - } -} diff --git a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt b/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt deleted file mode 100644 index b6f319c..0000000 --- a/app/src/main/java/foundation/e/privacycentralapp/dummy/TrackersDataSource.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 - } -} |
