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

Crash on TSProviderManager.handleProviderChangeEvent with IllegalArgumentException

Open Sfirleaalex opened this issue 2 years ago • 5 comments

Your Environment

  • Plugin version: 4.10
  • Platform: Android
  • OS version: All android versions > 6.0
  • Device manufacturer / model: All Samsung devices
  • React Native version (react-native -v): "0.68.5"
  • Plugin config
const locationConfig: Config = {
    distanceFilter: 10,
    desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
    disableMotionActivityUpdates: true,
    stopOnTerminate: true,
    startOnBoot: false,
    enableHeadless: false,
    locationAuthorizationRequest: 'WhenInUse',
};

export function* locationServiceConfigureSaga() {
    BackgroundGeolocation.onLocation(EMPTY_OBJECT_FROM_FUNCTION, error => {
        LocationConfigureChannel.put({ error });
    });

    BackgroundGeolocation.onProviderChange(event => {
        LocationConfigureChannel.put({ event });
    });

    try {
        yield BackgroundGeolocation.ready(locationConfig);
        yield put(setServiceConfigured(true));
    } catch (error) {
        yield put(setErrorAction(LocationErrorCode.NETWORK_ERROR));
    }
}

Expected Behavior

No crash regarding provider change event should be seen.

Actual Behavior

Started to see the crashes after update from 4.7 to 4.8 . From 4.8 we updated the library directly to 4.10.

Steps to Reproduce

I have not managed to reproduce the issue locally but GooglePlay is reporting that about 2000 users are experiencing the crash.

Context

Debug logs

Logs
com.transistorsoft.locationmanager.provider.TSProviderManager.handleProviderChangeEvent Exception java.lang.IllegalArgumentException:
  at android.app.LoadedApk.forgetReceiverDispatcher (LoadedApk.java:1221)
  at android.app.ContextImpl.unregisterReceiver (ContextImpl.java:1437)
  at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:639)
  at com.transistorsoft.locationmanager.provider.TSProviderManager.handleProviderChangeEvent
  at com.transistorsoft.locationmanager.provider.TSProviderManager.access$100
  at com.transistorsoft.locationmanager.provider.TSProviderManager$b$a.run
  at android.os.Handler.handleCallback (Handler.java:789)
  at android.os.Handler.dispatchMessage (Handler.java:98)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6710)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:770)

Sfirleaalex avatar Mar 14 '23 14:03 Sfirleaalex

Are you sure that error came from 4.10.0?

Your error seems related to "unregistering a broadcast receiver".

at android.app.ContextImpl.unregisterReceiver (ContextImpl.java:1437) at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:639)

The method referenced in your stacktrace does execute a method to unregister broadcast receivers (stopMonitoring). However, that method is correctly set up to catch (IllegalArgumentException):

private void handleProviderChangeEvent(Context context, @Nullable Intent intent) {

        // Android Q fires PROVIDERS_CHANGED_ACTION multiple times and for each provider.  Throttle these events.
        // Arbitrarily, if we receive 2 providerchange events within 250ms, ignore: it's a duplicate event.
        synchronized (mLastEvent) {
            if (mLastEvent.elapsed() < 250) return;
        }
        // Good to go...
        TSConfig config = TSConfig.getInstance(context);
        if (LifecycleManager.getInstance().isHeadless() && !config.getEnabled()) {
            TSLog.logger.info(TSLog.off("Stop monitoring location-provider changes"));
            stopMonitoring(context);       // <-------------- Unregister Broadcast Receiver here
        }
        .
        .
        .
}

public void stopMonitoring(Context context) {
        if (mProviderChangeReceiver != null) {
            try {
                context.getApplicationContext().unregisterReceiver(mProviderChangeReceiver);
                mProviderChangeReceiver = null;
                TSLog.logger.info(TSLog.off("Stop monitoring location-provider changes"));
            } catch (IllegalArgumentException e) {   // <------------ catching IllegalArgumentException
                TSLog.logger.error(TSLog.error(e.getMessage()));
            }
        }
    }

christocracy avatar Mar 14 '23 15:03 christocracy

The application is not using background location at all. Crashes appeared after we upgraded to 4.8 but we have not time to investigate the issue until now. A new version of the app using 4.10 lib version was released 2 weeks ago, the number of crashes decreased but it is still 5% of our total crashes count reported by GooglePlay console.

Sfirleaalex avatar Mar 15 '23 08:03 Sfirleaalex

The application is not using background location at all.

Then why are you using this plugin?

christocracy avatar Mar 15 '23 14:03 christocracy

The application is not using background location at all.

Then why are you using this plugin?

Because is stable, well maintained and offers nice interface to aquire location when the app is in use.

Sfirleaalex avatar Mar 19 '23 19:03 Sfirleaalex

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

github-actions[bot] avatar May 23 '24 01:05 github-actions[bot]

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

github-actions[bot] avatar Jun 06 '24 01:06 github-actions[bot]