transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
659 stars 276 forks source link

Android: `providerchange` event not always firing #604

Closed gmkohler closed 6 years ago

gmkohler commented 6 years ago

Your Environment

Nexus 5X (7.1.2) and Pixel (8.1.0)

6.4.1

        {
          elasticityMultiplier: 0.5,
          distanceFilter: 50,

          startOnBoot: true,
          preventSuspend: true,

          url,
          autoSync: true,
          headers: {
            "Authorization": `Token token="${token}"`
          }

Expected Behavior

I should receive a 'providerchange' event when I change the location permission from disabled to enabled while the app is closed, which is the behavior when I change the location permission from enabled to disabled while the app is closed.

Actual Behavior

I do not receive 'providerchange' event

Steps to Reproduce

  1. disable location permission (default
  2. open app
  3. close app
  4. enable location permission
  5. open app

Context

Know whether my location is authorized on boot. My setup (in Ember):

app/pods/application/route.js

// app/pods/application/route.js
import Ember from 'ember';

export default Ember.Route.extend({
  backgroundGeolocation: Ember.inject.service(),

  beforeModel() {
    return this.get('backgroundGeolocation').boot();
  }
});
import Ember from 'ember';

export default Ember.Service.extend({
  currentProvider: null,

  providerLocationAuthorized: Ember.computed('currentProvider', function() {
    return this.get('currentProvider.status') == BackgroundGeolocation.AUTHORIZATION_STATUS_ALWAYS
  }),

  boot() {
    BackgroundGeolocation.on('providerchange', (provider) => {
console.info('[backgroundGeolocation]', 'provider', provider)
      this.set('currentProvider', provider);
    });
  },

 // ...
});

Debug logs

christocracy commented 6 years ago

Try latest version, 2.10.1 I implemented permissions completely within the plugin using a 3rd party library, rather than from within the Cordova Activity. See if that changes the behaviour for you.

gmkohler commented 6 years ago

@christocracy That did not seem to change this behavior

christocracy commented 6 years ago

I will attempt to reproduce

gmkohler commented 6 years ago

Okay. Is there a reason that the provider is only accessible on change?

christocracy commented 6 years ago

Yes, I didn't feel like it.

gmkohler commented 6 years ago

Any way to expose it in the state object?

christocracy commented 6 years ago

It’s not necessary to place it in state object. The plugin fires the providerchange event as soon as #configure is called.

gmkohler commented 6 years ago

Configuring also fires a permission request right away, non? We do not want the permission dialog to show up until we actually need location permission from the user.

christocracy commented 6 years ago

In 2.10.1, the plugin doesn't request permission until you #start the plugin, just like iOS.

gmkohler commented 6 years ago

Hopefully that will render this issue a moot point. Thanks for the heads up.

gmkohler commented 6 years ago

@christocracy:

2.10.1 indeed does not request permission on Android 7.x, which makes configuring nice. I am noticing that I do not receive a provider change event when I "allow location access" via the dialog that pops up while configuring for the first time with the app, however.

Additionally, although I know this plugin does not yet support Android 8.0, the #configure function still seems to ask for permissions immediately for the 8.0 OS.

christocracy commented 6 years ago

The plugin isn’t going to ask permission until the plugin’s #start or #getCurrrntPosition method is executed.

Version of Cordova / Android does not affect when the plugin asks for permission.

gmkohler commented 6 years ago

@christocracy Okay, I'll go through the process again on Android 8 later to make sure I had the updated plugin in the manifest.

Is a providerchange event supposed to come through after explicitly granting the device location permission via the dialog that pops up during BackgroundGeolocation.start() (i.e., after explicitly changing the provider status)? I do not see one coming through, even on 7.x.x.

christocracy commented 6 years ago

providerchange is not involved with user location authorization. providerchange is fired only when you change Settings -> Location

gmkohler commented 6 years ago

I have location services on globally, but turned off for my app, and I receive provider status 2 when booting my app. When I then turn location permission on for my app via apps>my app>permissions, and reboot the app, I receive status 3. I also receive status 3 when granting permission via the dialog, then rebooting my app.

I don't understand how providerchange would be related only to the global location services, and not related to app-specific permissions, based on these observations. Can you shed some light or point me in the direction of where to learn more?

gmkohler commented 6 years ago

I suppose that doesn't invalidate that the providerchange event is only related to the device-level location permission, but the provider status changed--I would expect a change in a property of the provider to be considered a "change of provider". If that is not the case, is there a way to listen to the provider status via this plugin?

christocracy commented 6 years ago

It’s not easy to capture user authorization events. Android provides no such Broadcast of this event.

On Tue, Feb 13, 2018 at 3:00 PM Gregory M Kohler notifications@github.com wrote:

I suppose that doesn't invalidate that the providerchange event is only related to the device-level location permission, but the provider status changed--I would expect a change in a property of the provider to be considered a "change of provider". If that is not the case, is there a way to listen to the provider status via this plugin?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/604#issuecomment-365385928, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA6l0Og6PJxxf4_z-BzBQbDFiWjzh_Kks5tUenCgaJpZM4SAo_e .

-- Snet form Gmail Mobile

christocracy commented 6 years ago

I should receive a 'providerchange' event when I change the location permission from disabled to enabled while the app is closed

Are we talking about Device Location Permission or Application Location Permission. The two are different: