Skip to content

Commit

Permalink
LocationService.java: Fix #4 for SecurityException crash on Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
eladnava committed Sep 5, 2024
1 parent 1f038ea commit 2101f2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void startAppServices(Context context) {

public static void startLocationService(Context context) {
// API level 34 support
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !LocationLogic.isLocationPermissionGranted(context)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !LocationLogic.isLocationAccessGranted(context)) {
// Don't try to start a foreground service
// as it will throw a SecurityException
return;
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/red/alert/receivers/BootReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.legacy.content.WakefulBroadcastReceiver;

import com.red.alert.logic.services.ServiceManager;
import com.red.alert.logic.settings.AppPreferences;

public class BootReceiver extends WakefulBroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Got boot completed event?
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
// Run all other services
ServiceManager.startAppServices(context);
// Start the Pushy push service
ServiceManager.startPushyService(context);

// Location alerts enabled?
if (AppPreferences.getLocationAlertsEnabled(context)) {
// Unfortunately, we can't start a foreground location service via boot receiver on API level 34+
// Wait for users to manually open the app to restart the foreground service
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// Start the location service
ServiceManager.startLocationService(context);
}
}
}
}
}

0 comments on commit 2101f2b

Please sign in to comment.