transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.63k stars 425 forks source link

On Android 14 app crashes with message: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts #2047

Closed jabiel closed 2 months ago

jabiel commented 4 months ago

Your Environment

Expected Behavior

App should work same way as for other android versions

Actual Behavior

On android 14 app crashes after selecting background location permission: com.transistorsoft.locationmanager.device.DeviceSettings.startMonitoringPowerSaveChanges java.lang.SecurityException: com.bostondigital.devicetrackerplus: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

Steps to Reproduce

1. 2. 3. 4.

Context

We updated react native to latest version Currect targetSdk for android is 34

Debug logs

Logs ``` 2024-06-06 14:20:59.537 6892-7013 AndroidRuntime com.bostondigital.devicetrackerplus E FATAL EXCEPTION: pool-17-thread-3 Process: com.bostondigital.devicetrackerplus, PID: 6892 java.lang.SecurityException: com.bostondigital.devicetrackerplus: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5765) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at com.transistorsoft.locationmanager.device.DeviceSettings.startMonitoringPowerSaveChanges(Unknown Source:61) at com.transistorsoft.locationmanager.service.TrackingService.start(Unknown Source:47) at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$z0.run(Unknown Source:159) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) 2024-06-06 14:20:59.538 6892-6980 AndroidRuntime com.bostondigital.devicetrackerplus E FATAL EXCEPTION: pool-17-thread-1 Process: com.bostondigital.devicetrackerplus, PID: 6892 java.lang.SecurityException: com.bostondigital.devicetrackerplus: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5765) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at com.transistorsoft.locationmanager.device.DeviceSettings.startMonitoringPowerSaveChanges(Unknown Source:61) at com.transistorsoft.locationmanager.service.TrackingService.start(Unknown Source:47) at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$z0.run(Unknown Source:159) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:14107) at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2607) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2789) at android.os.Binder.execTransactInternal(Binder.java:1339) at android.os.Binder.execTransact(Binder.java:1275) 2024-06-06 14:20:59.542 6892-6980 TSLocationManager com.bostondigital.devicetrackerplus E [c.t.l.a.BackgroundGeolocation$w0 uncaughtException] ‼️ Uncaught Exception: com.bostondigital.devicetrackerplus: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts {"activityRecognitionInterval":10000,"allowIdenticalLocations":false,"authorization":{},"autoSync":true,"autoSyncThreshold":3,"backgroundPermissionRationale":{"title":"Allow DTP to access to this device's location in the background","message":"DTP collects location data to enable recording your trips","positiveAction":"Change to \"{backgroundPermissionOptionLabel}\"","negativeAction":""},"batchSync":true,"configUrl":"","debug":false,"deferTime":0,"desiredAccuracy":-1,"desiredOdometerAccuracy":100,"disableAutoSyncOnCellular":false,"disableElasticity":false,"disableLocationAuthorizationAlert":false,"disableMotionActivityUpdates":false,"disableProviderChangeRecord":false,"disableStopDetection":false,"distanceFilter":50,"elasticityMultiplier":2,"enableHeadless":false,"enableTimestampMeta":false,"extras":{},"fastestLocationUpdateInterval":20000,"foregroundService":true,"geofenceInitialTriggerEntry":true,"geofenceModeHighAccuracy":false,"geofenceProximityRadius":1000,"geofenceTemplate":"","headers":{},"headlessJobService":"com.transistorsoft.rnbackgroundgeolocation.HeadlessTask","heartbeatInterval":-1,"httpRootProperty":"location","httpTimeout":60000,"isMoving":false,"locationAuthorizationRequest":"Always","locationTemplate":"","locationTimeout":60,"locationUpdateInterval":1000,"locationsOrderDirection":"ASC","logLevel":2,"logMaxDays":3,"maxBatchSize":20,"maxDaysToPersist":7,"maxRecordsToPersist":-1,"method":"POST","minimumActivityRecognitionConfidence":75,"motionTriggerDelay":0,"notification":{"layout":"","title":"Device Tracker Plus","text":"Location tracking is enabled","color":"","channelName":"DTP","channelId":"","smallIcon":"","largeIcon":"","priority":0,"sticky":false,"strings":{},"actions":[]},"params":{"deviceId":"42768f92-af91-46bc-911a-0381d71fee43","appVersion":"6.3.3","param1":"value1"},"persist":true,"persistMode":2,"schedule":[],"scheduleUseAlarmManager":false,"speedJumpFilter":300,"startOnBoot":true,"stationaryRadius":40,"stopAfterElapsedMinutes":0,"stopOnStationary":false,"stopOnTerminate":false,"stopTimeout":5,"triggerActivities":"in_vehicle, on_bicycle, on_foot, running, walking","url":"https:\/\/device.devicetrackerplus.com\/Device\/tslocation","useSignificantChangesOnly":false,"enabled":true,"schedulerEnabled":false,"trackingMode":1,"odometer":0,"isFirstBoot":false,"didLaunchInBackground":false,"didDeviceReboot":false} java.lang.SecurityException: com.bostondigital.devicetrackerplus: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5765) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at com.transistorsoft.locationmanager.device.DeviceSettings.startMonitoringPowerSaveChanges(Unknown Source:61) at com.transistorsoft.locationmanager.service.TrackingService.start(Unknown Source:47) at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$z0.run(Unknown Source:159) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) ```
christocracy commented 4 months ago

Plugin version: 4.16.2

There's no way you're getting that error from 4.16.2.

  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
  at com.transistorsoft.locationmanager.device.DeviceSettings.startMonitoringPowerSaveChanges(Unknown Source:61)

I've been using targetSdkVersion 34 for nearly a year. The source-code from the SDK for calling .registerReceiver has been supplying the param Context.RECEIVER_NOT_EXPORTED since July 2023.

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      context.registerReceiver(mPowerSaveChangeReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
  } else {
      context.registerReceiver(mPowerSaveChangeReceiver, filter);
 }
christocracy commented 4 months ago

This error was fixed in v4.13.1, published last August.

[Android] Android 14 (API 34) support: Fix error "One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified" in DeviceSettings.startMonitoringPowerSaveChanges.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.