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

Commit 2848e9a0 authored by Gitsaibot's avatar Gitsaibot Committed by Jochen Sprickerhof
Browse files

Start service as "foreground service" (#509)

Closes: #439 #445 #497
parent 3268a129
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -128,12 +128,17 @@ public class AlertReceiver extends BroadcastReceiver {
                PowerManager pm =
                    (PowerManager)context.getSystemService(Context.POWER_SERVICE);
                mStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                        "StartingAlertService");
                        "Etar:StartingAlertService");
                mStartingService.setReferenceCounted(false);
            }
            mStartingService.acquire();
            if (Utils.isOreoOrLater()) {
                context.startForegroundService(intent);
            } else {
                context.startService(intent);
            }

        }
    }

    /**
+12 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.os.Process;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.CalendarAlerts;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.text.format.DateUtils;
@@ -172,7 +173,7 @@ public class AlertService extends Service {
        }


        if (!prefs.getBoolean(GeneralPreferences.KEY_ALERTS, true)) {
        if (!prefs.getBoolean(GeneralPreferences.KEY_ALERTS, true) && !Utils.isOreoOrLater()) {
            if (DEBUG) {
                Log.d(TAG, "alert preference is OFF");
            }
@@ -980,6 +981,16 @@ public class AlertService extends Service {
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null) {

            if (Utils.isOreoOrLater()) {
                Notification notification = new NotificationCompat.Builder(this, ALERT_CHANNEL_ID)
                        .setContentTitle("Event notifications")
                        .setSmallIcon(R.drawable.stat_notify_calendar)
                        .setShowWhen(false)
                        .build();
                startForeground(1337, notification);
            }

            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = intent.getExtras();