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

Commit 7191e830 authored by Alexandre Roux's avatar Alexandre Roux
Browse files

foreground notification for trackers

parent 0886be2b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -58,9 +58,11 @@ public class DNSBlockerService extends Service {
            sDnsFilter = null;
            e.printStackTrace();
        }
        ForegroundStarter.startForeground(this);


        return START_STICKY;

    }
    
}
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
package foundation.e.trackerfilter;

import static android.content.Context.NOTIFICATION_SERVICE;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.Build;

import dnsfilter.android.R;

public class ForegroundStarter {
    private static final String NOTIFICATION_CHANNEL_ID = "blocker_service";
    public static void startForeground(Service service){
        NotificationManager mNotificationManager = (NotificationManager) service.getSystemService(NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= 26) {
            mNotificationManager.createNotificationChannel(new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_ID, NotificationManager.IMPORTANCE_LOW));
            Notification notification = new Notification.Builder(service, NOTIFICATION_CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(service.getString(R.string.app_name)).build();
            service.startForeground(1337, notification);
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public class StatsIntentService extends Service {
                handleActionLog(domaineName, appUid, intent.getBooleanExtra(EXTRA_BLOCKED, false));
            }
        }
        ForegroundStarter.startForeground(this);
        return start;
    }