react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

invalid null provider error on start

Open andkom opened this issue 4 years ago • 1 comments

Your Environment

  • Plugin version: 0.6.3
  • Platform: Android
  • OS version: 10, 11
  • Device manufacturer and model: Galaxy A32, Galaxy A51, Honor 8X, Huawei P smart 2019, Galaxy J6, Galaxy A10s, Galaxy Note 9, Galaxy J6, Redmi Note 7, Galaxy A21s, Redmi Note 8 Pro, Galaxy A50, MI 9, Galaxy S21 Ultra 5G
  • Running in Simulator:
  • React Native version: 0.66.4
  • Plugin configuration options:
  • Link to your project:

Context

In firebase console I can see crash events with error:

Fatal Exception: java.lang.RuntimeException: Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@ee59593 with null: java.lang.IllegalArgumentException: invalid null provider
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4794)
       at android.app.ActivityThread.access$2000(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2196)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8595)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by java.lang.IllegalArgumentException: invalid null provider
       at com.android.internal.util.Preconditions.checkArgument(Preconditions.java:52)
       at android.location.LocationManager.requestLocationUpdates(LocationManager.java:927)
       at com.marianhello.bgloc.provider.RawLocationProvider.onStart(RawLocationProvider.java:49)
       at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:366)
       at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
       at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:363)
       at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4776)
       at android.app.ActivityThread.access$2000(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2196)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8595)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Expected Behavior

Exception can be handled properly

Actual Behavior

App crashes with error

Fatal Exception: java.lang.RuntimeException
Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@ee59593 with null: java.lang.IllegalArgumentException: invalid null provider

Possible Fix

Error happens in https://github.com/mauron85/background-geolocation-android/blob/58464febf6901f1e489817e4425418d48443929b/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java#L49 because system somehow can't find suitable location provider and locationManager.getBestProvider(criteria, true) returns null:

try {
    locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), mConfig.getInterval(), mConfig.getDistanceFilter(), this);
    isStarted = true;
} catch (SecurityException e) {
    logger.error("Security exception: {}", e.getMessage());
    this.handleSecurityException(e);
}

The try {} catch {} block only handles SecurityException but should also handle any exception . Also, there should be a check of getBestProvider function call result.

Steps to Reproduce

Context

Debug logs

andkom avatar Jan 08 '22 19:01 andkom

It's the same issue that happened to me. when I remove the location access from my app

nassimmiled avatar May 28 '23 10:05 nassimmiled