Commit 3adef924 authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Fix: on API >= 34 starting location foreground service without permission throws security exception

parent 7bf53b8d
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -127,8 +127,16 @@ public class LoggerService extends Service {
            handlePrefsUpdated();
        } else {
            final Notification notification = notificationHelper.showNotification();
            boolean isForeground = false;
            try {
                startForeground(notificationHelper.getId(), notification);
            if (!initializeLocationUpdates()) {
                isForeground = true;
            } catch (SecurityException e) {
                if (Logger.DEBUG) { Log.d(TAG, "[SecurityException on startForeground: " + e.getMessage() + "]"); }
                BroadcastHelper.sendBroadcast(this, BROADCAST_LOCATION_PERMISSION_DENIED);
            }

            if (!isForeground || !initializeLocationUpdates()) {
                setRunning(false);
                stopSelf();
            }