summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-10-11 16:36:02 +0000
committerGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-10-11 16:36:02 +0000
commit95e68cbbe748f81af1113753c5b99929e3db9ea2 (patch)
tree776b2e1fb3d5c16a48beb1c947eef887b2475db8 /app/src/main
parent41c0e48498979ec8310961e40c89aa6b3c0d8e0f (diff)
epic18: Trackers control on standalone app (without Ipscrambling).
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt9
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt0
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt27
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/Notifications.kt48
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/common/BuildFlavor.kt22
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt2
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt2
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt3
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt6
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt4
-rw-r--r--app/src/main/res/values/strings.xml5
11 files changed, 81 insertions, 47 deletions
diff --git a/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt b/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt
index 0af2a0e..71fef00 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/AdvancedPrivacyApplication.kt
@@ -18,7 +18,6 @@
package foundation.e.advancedprivacy
import android.app.Application
-import android.content.Intent
import foundation.e.advancedprivacy.common.WarningDialog
import foundation.e.advancedprivacy.domain.usecases.FakeLocationStateUseCase
import foundation.e.advancedprivacy.domain.usecases.GetQuickPrivacyStateUseCase
@@ -27,7 +26,6 @@ import foundation.e.advancedprivacy.domain.usecases.ShowFeaturesWarningUseCase
import foundation.e.advancedprivacy.domain.usecases.TrackersStateUseCase
import foundation.e.advancedprivacy.domain.usecases.TrackersStatisticsUseCase
import foundation.e.advancedprivacy.externalinterfaces.permissions.IPermissionsPrivacyModule
-import foundation.e.advancedprivacy.trackers.services.DNSBlockerService
import foundation.e.advancedprivacy.trackers.services.UpdateTrackersWorker
import foundation.e.lib.telemetry.Telemetry
import kotlinx.coroutines.CoroutineScope
@@ -70,12 +68,7 @@ class AdvancedPrivacyApplication : Application() {
)
get<IpScramblingStateUseCase>(IpScramblingStateUseCase::class.java)
- get<FakeLocationStateUseCase>(FakeLocationStateUseCase::class.java)
get<TrackersStateUseCase>(TrackersStateUseCase::class.java)
-
- val intent = Intent(this, DNSBlockerService::class.java)
- intent.action = DNSBlockerService.ACTION_START
- intent.putExtra(DNSBlockerService.EXTRA_ENABLE_NOTIFICATION, false)
- startService(intent)
+ get<FakeLocationStateUseCase>(FakeLocationStateUseCase::class.java)
}
}
diff --git a/app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt b/app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/src/main/java/foundation/e/advancedprivacy/DependencyContainer.kt
diff --git a/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt b/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt
index 3fbb636..20cefd5 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/KoinModule.kt
@@ -22,6 +22,8 @@ import android.os.Process
import foundation.e.advancedprivacy.core.coreModule
import foundation.e.advancedprivacy.data.repositories.LocalStateRepository
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
+import foundation.e.advancedprivacy.domain.entities.CHANNEL_TRACKER_FLAG
+import foundation.e.advancedprivacy.domain.entities.NotificationContent
import foundation.e.advancedprivacy.domain.entities.ProfileType
import foundation.e.advancedprivacy.domain.usecases.AppListUseCase
import foundation.e.advancedprivacy.domain.usecases.FakeLocationStateUseCase
@@ -39,7 +41,10 @@ import foundation.e.advancedprivacy.features.location.FakeLocationViewModel
import foundation.e.advancedprivacy.features.trackers.TrackersViewModel
import foundation.e.advancedprivacy.features.trackers.apptrackers.AppTrackersViewModel
import foundation.e.advancedprivacy.ipscrambler.ipScramblerModule
-import foundation.e.advancedprivacy.permissions.externalinterfaces.PermissionsPrivacyModule
+import foundation.e.advancedprivacy.permissions.externalinterfaces.PermissionsPrivacyModuleImpl
+import foundation.e.advancedprivacy.trackers.domain.externalinterfaces.TrackersServiceSupervisor
+import foundation.e.advancedprivacy.trackers.service.TrackersServiceSupervisorImpl
+import foundation.e.advancedprivacy.trackers.service.trackerServiceModule
import foundation.e.advancedprivacy.trackers.trackersModule
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
@@ -49,7 +54,7 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module
val appModule = module {
- includes(coreModule, trackersModule, fakelocationModule, ipScramblerModule)
+ includes(coreModule, trackersModule, fakelocationModule, ipScramblerModule, trackerServiceModule)
factory<Resources> { androidContext().resources }
single {
@@ -89,6 +94,16 @@ val appModule = module {
)
}
+ single<NotificationContent>(named("notificationTrackerFlag")) {
+ NotificationContent(
+ channelId = CHANNEL_TRACKER_FLAG,
+ icon = R.drawable.ic_e_app_logo,
+ title = R.string.notifications_tracker_title,
+ description = R.string.notifications_tracker_content,
+ pendingIntent = null
+ )
+ }
+
single { CityDataSource }
singleOf(::AppListUseCase)
@@ -120,7 +135,13 @@ val appModule = module {
singleOf(::TrackersStatisticsUseCase)
single<IPermissionsPrivacyModule> {
- PermissionsPrivacyModule(context = androidContext())
+ PermissionsPrivacyModuleImpl(context = androidContext())
+ }
+
+ single<TrackersServiceSupervisor> {
+ TrackersServiceSupervisorImpl(
+ context = androidContext(),
+ )
}
viewModel { parameters ->
diff --git a/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt b/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt
index cd85e9a..455b1a7 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/Notifications.kt
@@ -20,13 +20,21 @@ package foundation.e.advancedprivacy
import android.app.NotificationChannel
import android.app.NotificationManager
-import android.app.PendingIntent
import android.content.Context
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
+import foundation.e.advancedprivacy.core.utils.notificationBuilder
+import foundation.e.advancedprivacy.domain.entities.CHANNEL_FAKE_LOCATION_FLAG
+import foundation.e.advancedprivacy.domain.entities.CHANNEL_FIRST_BOOT
+import foundation.e.advancedprivacy.domain.entities.CHANNEL_IPSCRAMBLING_FLAG
+import foundation.e.advancedprivacy.domain.entities.CHANNEL_TRACKER_FLAG
import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode
import foundation.e.advancedprivacy.domain.entities.MainFeatures
+import foundation.e.advancedprivacy.domain.entities.NOTIFICATION_FAKE_LOCATION_FLAG
+import foundation.e.advancedprivacy.domain.entities.NOTIFICATION_FIRST_BOOT
+import foundation.e.advancedprivacy.domain.entities.NOTIFICATION_IPSCRAMBLING_FLAG
+import foundation.e.advancedprivacy.domain.entities.NotificationContent
import foundation.e.advancedprivacy.domain.usecases.GetQuickPrivacyStateUseCase
import foundation.e.advancedprivacy.externalinterfaces.permissions.IPermissionsPrivacyModule
import foundation.e.advancedprivacy.main.MainActivity
@@ -37,14 +45,6 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
object Notifications {
- const val CHANNEL_FIRST_BOOT = "first_boot_notification"
- const val CHANNEL_FAKE_LOCATION_FLAG = "fake_location_flag"
- const val CHANNEL_IPSCRAMBLING_FLAG = "ipscrambling_flag"
-
- const val NOTIFICATION_FIRST_BOOT = 1000
- const val NOTIFICATION_FAKE_LOCATION_FLAG = NOTIFICATION_FIRST_BOOT + 1
- const val NOTIFICATION_IPSCRAMBLING_FLAG = NOTIFICATION_FAKE_LOCATION_FLAG + 1
-
fun showFirstBootNotification(context: Context) {
createNotificationFirstBootChannel(context)
val notificationBuilder: NotificationCompat.Builder = notificationBuilder(
@@ -88,6 +88,14 @@ object Notifications {
channelDescription = R.string.notifications_ipscrambling_channel_description
)
+ createNotificationFlagChannel(
+ context = appContext,
+ permissionsPrivacyModule = permissionsPrivacyModule,
+ channelId = CHANNEL_TRACKER_FLAG,
+ channelName = R.string.notifications_tracker_channel_name,
+ channelDescription = R.string.notifications_ipscrambling_channel_description
+ )
+
getQuickPrivacyStateUseCase.isLocationHidden.onEach {
if (it) {
showFlagNotification(appContext, MainFeatures.FAKE_LOCATION)
@@ -183,26 +191,4 @@ object Notifications {
}
NotificationManagerCompat.from(context).cancel(id)
}
-
- private data class NotificationContent(
- val channelId: String,
- val icon: Int,
- val title: Int,
- val description: Int,
- val pendingIntent: PendingIntent?
- )
-
- private fun notificationBuilder(
- context: Context,
- content: NotificationContent
- ): NotificationCompat.Builder {
- val builder = NotificationCompat.Builder(context, content.channelId)
- .setSmallIcon(content.icon)
- .setPriority(NotificationCompat.PRIORITY_LOW)
- .setContentTitle(context.getString(content.title))
- .setStyle(NotificationCompat.BigTextStyle().bigText(context.getString(content.description)))
- content.pendingIntent?.let { builder.setContentIntent(it) }
-
- return builder
- }
}
diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/BuildFlavor.kt b/app/src/main/java/foundation/e/advancedprivacy/common/BuildFlavor.kt
new file mode 100644
index 0000000..ecb24ce
--- /dev/null
+++ b/app/src/main/java/foundation/e/advancedprivacy/common/BuildFlavor.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 MURENA SAS
+ *
+ * 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.advancedprivacy.common
+
+import foundation.e.advancedprivacy.BuildConfig
+
+const val isStandaloneBuild: Boolean = BuildConfig.FLAVOR == "standalone"
diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt b/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt
index 80fc760..589aa74 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/common/WarningDialog.kt
@@ -75,7 +75,7 @@ class WarningDialog : AppCompatActivity() {
val feature = try {
intent.getParcelableExtra<ShowFeaturesWarning>(PARAM_FEATURE)!!
} catch (e: Exception) {
- Timber.e("Missing mandatory activity parameter", e)
+ Timber.e(e, "Missing mandatory activity parameter")
finish()
return
}
diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt
index 30c8e6b..983ba71 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/FakeLocationStateUseCase.kt
@@ -202,7 +202,7 @@ class FakeLocationStateUseCase(
lastKnownLocation?.let { localListener.onLocationChanged(it) }
} catch (se: SecurityException) {
- Timber.e("Missing permission", se)
+ Timber.e(se, "Missing permission")
}
}
}
diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt
index 27e7fe4..9c89329 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt
@@ -19,6 +19,7 @@
package foundation.e.advancedprivacy.domain.usecases
import android.content.Intent
+import foundation.e.advancedprivacy.common.isStandaloneBuild
import foundation.e.advancedprivacy.data.repositories.AppListsRepository
import foundation.e.advancedprivacy.data.repositories.LocalStateRepository
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
@@ -190,7 +191,7 @@ class IpScramblingStateUseCase(
fun startIpScrambling() {
localStateRepository.internetPrivacyMode.value = HIDE_IP_LOADING
- ipScramblerModule.start(enableNotification = false) // change the false ?
+ ipScramblerModule.start(enableNotification = isStandaloneBuild)
}
private fun map(status: IpScramblerModule.Status): InternetPrivacyMode {
diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt
index ed15a41..9b79dcc 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStateUseCase.kt
@@ -22,6 +22,7 @@ import foundation.e.advancedprivacy.data.repositories.LocalStateRepository
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
import foundation.e.advancedprivacy.trackers.data.WhitelistRepository
import foundation.e.advancedprivacy.trackers.domain.entities.Tracker
+import foundation.e.advancedprivacy.trackers.domain.externalinterfaces.TrackersServiceSupervisor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@@ -29,7 +30,8 @@ class TrackersStateUseCase(
private val whitelistRepository: WhitelistRepository,
private val localStateRepository: LocalStateRepository,
private val appListsRepository: AppListsRepository,
- coroutineScope: CoroutineScope
+ private val trackersServiceSupervisor: TrackersServiceSupervisor,
+ coroutineScope: CoroutineScope,
) {
init {
coroutineScope.launch {
@@ -38,6 +40,8 @@ class TrackersStateUseCase(
updateAllTrackersBlockedState()
}
}
+
+ trackersServiceSupervisor.start()
}
private fun updateAllTrackersBlockedState() {
diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt
index b0c9f39..3d6ade0 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/TrackersStatisticsUseCase.kt
@@ -24,6 +24,7 @@ import foundation.e.advancedprivacy.data.repositories.AppListsRepository
import foundation.e.advancedprivacy.domain.entities.AppWithCounts
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
import foundation.e.advancedprivacy.domain.entities.TrackersPeriodicStatistics
+import foundation.e.advancedprivacy.trackers.data.StatsDatabase
import foundation.e.advancedprivacy.trackers.data.TrackersRepository
import foundation.e.advancedprivacy.trackers.data.WhitelistRepository
import foundation.e.advancedprivacy.trackers.domain.entities.Tracker
@@ -44,6 +45,7 @@ class TrackersStatisticsUseCase(
private val whitelistRepository: WhitelistRepository,
private val trackersRepository: TrackersRepository,
private val appListsRepository: AppListsRepository,
+ private val statsDatabase: StatsDatabase,
private val resources: Resources
) {
fun initAppList() {
@@ -52,7 +54,7 @@ class TrackersStatisticsUseCase(
@OptIn(FlowPreview::class)
fun listenUpdates(debounce: Duration = 1.seconds) =
- statisticsUseCase.newDataAvailable
+ statsDatabase.newDataAvailable
.throttleFirst(windowDuration = debounce)
.onStart { emit(Unit) }
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fac1f75..ba3ba03 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -144,4 +144,9 @@
<string name="notifications_ipscrambling_title">Real IP hidden</string>
<string name="notifications_ipscrambling_content">This could impact the functioning of some applications.</string>
+ <string name="notifications_tracker_channel_name">Tracker control flag</string>
+ <string name="notifications_tracker_channel_description">Highlight that the trackers are actually logged and blocked by Advanced Privacy</string>
+ <string name="notifications_tracker_title">Tracker control is on</string>
+ <string name="notifications_tracker_content">This could impact the functioning of some applications.</string>
+
</resources>