Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e043734f authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

feat:8998: automatically hide tracker service notification.

parent e97564f3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
    <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />

    <application
        android:allowBackup="true"
+27 −8
Original line number Diff line number Diff line
@@ -47,14 +47,17 @@ import foundation.e.advancedprivacy.domain.usecases.WeeklyReportUseCase
import foundation.e.advancedprivacy.externalinterfaces.permissions.IPermissionsPrivacyModule
import foundation.e.advancedprivacy.features.weeklyreport.WeeklyReportViewFactory
import foundation.e.advancedprivacy.main.MainActivity
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.ZoneId
import java.time.format.DateTimeFormatter


// @SuppressLint("MissingPermission")
class NotificationsPresenter(
@@ -67,6 +70,9 @@ class NotificationsPresenter(
    private val notificationTrackerFlag: NotificationContent,
    private val appScope: CoroutineScope
) {
    companion object {
        private const val HIDE_CHANNEL_DELAY = 30000L
    }

    private val notificationManager = NotificationManagerCompat.from(context)

@@ -109,12 +115,7 @@ class NotificationsPresenter(
            channelDescription = R.string.notifications_ipscrambling_channel_description
        )

        createNotificationFlagChannel(
            channelId = CHANNEL_TRACKER_FLAG,
            channelName = R.string.notifications_tracker_channel_name,
            channelDescription = R.string.notifications_tracker_channel_description,
            importance = NotificationManager.IMPORTANCE_MIN
        )
        createTrackerForegroundserviceChannel()

        createWeeklyReportChannel()

@@ -174,6 +175,24 @@ class NotificationsPresenter(
        NotificationManagerCompat.from(context).createNotificationChannel(channel)
    }

    private fun createTrackerForegroundserviceChannel() {
        val channel = NotificationChannel(
            CHANNEL_TRACKER_FLAG,
            context.getString(R.string.notifications_tracker_channel_name),
            NotificationManager.IMPORTANCE_LOW
        )

        channel.description = context.getString(R.string.notifications_tracker_channel_description)
        permissionsPrivacyModule.setBlockable(channel)

        notificationManager.createNotificationChannel(channel)

        appScope.launch {
            delay(HIDE_CHANNEL_DELAY)
            permissionsPrivacyModule.hideNotificationsChannel(CHANNEL_TRACKER_FLAG)
        }
    }

    private fun createWeeklyReportChannel() {
        val channel = NotificationChannel(
            CHANNEL_WEEKLYREPORT,
+5 −0
Original line number Diff line number Diff line
@@ -134,4 +134,9 @@ interface IPermissionsPrivacyModule {
     * unblockable.
     */
    fun setBlockable(notificationChannel: NotificationChannel)

    /**
     * Hide a notification channel. Works as if the user did toggle of the channel in settings.
     */
    fun hideNotificationsChannel(channelId: String)
}
+5 −0
Original line number Diff line number Diff line
@@ -34,4 +34,9 @@ public class NotificationChannel {
    @TargetApi(30)
    public void setBlockable(boolean blockable) {}

    // Public
    public int getImportance() { return 0; }

    // Public
    public void setImportance(int importance) {}
}
+24 −0
Original line number Diff line number Diff line
package android.app;

import androidx.annotation.DeprecatedSinceApi;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

/* Stub based on:
   https://gitlab.e.foundation/e/os/android_frameworks_base/-/blob/[SDK_VERSION]/core/java/
   android/app/NotificationManager.java */
public class NotificationManager {

    // Public
    public static final int IMPORTANCE_NONE = 0;

    // Public
    public NotificationChannel getNotificationChannel(String channelId) {
        return null;
    }

    @RequiresApi(31)
    @DeprecatedSinceApi(api = 37, message = "Check availability in SDK37")
    public void updateNotificationChannel(@NonNull String pkg, int uid, @NonNull NotificationChannel channel) {
    }
}
Loading