transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
650 stars 241 forks source link

[Bug] onProviderChange Event Reports Incorrect GPS Status After Enabling/Disabling GPS #1350

Open eulerchavez opened 3 months ago

eulerchavez commented 3 months ago

Your Environment

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/eulerchavez/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio 2.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio 2.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.92.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0

[✓] Connected device (6 available) • SM G973F (mobile) • R28M20WVE1N • android-arm64 • Android 12 (API 31) • iPad mini (mobile) • 00008020-001B14C10105002E • ios • iOS 17.5.1 21F90 • YBS (mobile) • 025D64B4-AFDF-4AC4-92E4-C8ED9CF82D7F • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 127.0.6533.120 ! Error: Browsing on the local area network for iPhone de Melisa. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources • All expected network resources are available.

* Plugin config:
```dart <-- Syntax highlighting: DO NOT REMOVE -->
/*
   * 1.  Listen to events (See docs for all 12 available events).
   */

  // Fired whenever a location is recorded
  bg.BackgroundGeolocation.onLocation((bg.Location location) {
    print('[location] - $location');
  }, (bg.LocationError error) {
    print('[onLocation] ERROR: ${error}');
  });

  // Fired whenever the plugin changes motion-state (stationary->moving and vice-versa)
  bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
    print('[motionchange] - $location');
  });

  // Subscribe to changes in device's location-services configuration / authorization.
  // Fired whenever the state of location-services changes.  Always fired at boot
  bg.BackgroundGeolocation.onProviderChange((bg.ProviderChangeEvent event) {
    print('[providerchange] - $event');
  });

  /*
   *  2.  Configure the plugin
   */
  var config = bg.Config(
    backgroundPermissionRationale: bg.PermissionRationale(
        title:
            "Permita que {applicationName} acceda a la ubicación de este dispositivo incluso cuando la aplicación esté cerrada o no esté en uso.",
        message:
            "Esta aplicación recopila datos de ubicación para permitir registrar sus viajes y calcular la distancia recorrida.",
        positiveAction: 'Cambiar a "{backgroundPermissionOptionLabel}"',
        negativeAction: 'Cancelar'),
    // HTTP / SQLite config
    url: "https://my-url",
    // Application config
    stopOnTerminate: // <-- Controls whether to continue location-tracking after application is terminated.
        false,
    startOnBoot: // <-- Controls whether to resume location-tracking after device is rebooted.
        true,
    enableHeadless: false,
    reset: // <-- Forces [BackgroundGeolocation.ready] to apply supplied [Config] with each application launch.
        true,
    debug: // <-- Enable this hear sounds for background-geolocation life-cycle.
        true,
    logLevel: bg.Config.LOG_LEVEL_VERBOSE,
    desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    distanceFilter: 10.0,
  );

  if (!isWeb) {
    /*
     * Signal to the plugin that your app is launched and ready, proving the default [Config].
     * 
     * The supplied [Config] will be applied only at first install of your app — 
     * for every launch thereafter, the plugin will automatically load its last-known configuration from persistent storage.
     * 
     * The plugin always remembers the configuration you apply to it.
     * 
     * ⚠️ Warning: You must call .ready(config) once and only once, each time your app is launched.
     */
    var backgroundGeolocationState =
        await bg.BackgroundGeolocation.ready(config);

    print('[ready] - ${backgroundGeolocationState}');
  }

Expected Behavior

It is expected that when the GPS is enabled, the onProviderChange event should return true in the GPS field, and when it is disabled, it should return false.

Actual Behavior

When the GPS is disabled on the device and then re-enabled, the onProviderChange event should indicate that the GPS is active (GPS: true). However, instead of receiving true, the event incorrectly reports GPS: false. This incorrect behavior continues until the GPS provider is toggled on and off several times, after which the event finally reflects the correct GPS status.

Steps to Reproduce

https://github.com/user-attachments/assets/02cffed2-0cb7-483e-97f1-bf823d9cf87a

Context

Debug logs

Logs ``` I/InputMethodManager(13941): startInputInner - mService.startInputOrWindowGainedFocus I/ViewRootImpl@3cc4475[MainActivity](13941): MSG_WINDOW_FOCUS_CHANGED 0 1 W/Settings(13941): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value. I/TSLocationManager(13941): [c.t.l.p.TSProviderManager a] I/TSLocationManager(13941): ╔═════════════════════════════════════════════ I/TSLocationManager(13941): ║ Location-provider change: false I/TSLocationManager(13941): ╠═════════════════════════════════════════════ I/TSLocationManager(13941): ╟─ GPS: false I/TSLocationManager(13941): ╟─ Network: false I/TSLocationManager(13941): ╟─ AP Mode: false I/flutter (13941): [providerchange] - [ProviderChangeEvent enabled:false, status: 3, network: false, gps: false, accuracyAuthorization: 0] W/Settings(13941): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value. I/TSLocationManager(13941): [c.t.l.p.TSProviderManager a] I/TSLocationManager(13941): ╔═════════════════════════════════════════════ I/TSLocationManager(13941): ║ Location-provider change: true I/TSLocationManager(13941): ╠═════════════════════════════════════════════ I/TSLocationManager(13941): ╟─ GPS: false I/TSLocationManager(13941): ╟─ Network: true I/TSLocationManager(13941): ╟─ AP Mode: false I/flutter (13941): [providerchange] - [ProviderChangeEvent enabled:true, status: 3, network: true, gps: false, accuracyAuthorization: 0] I/TRuntime.CctTransportBackend(13941): Making request to: https://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog I/TRuntime.CctTransportBackend(13941): Status Code: 200 W/Settings(13941): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value. I/TSLocationManager(13941): [c.t.l.p.TSProviderManager a] I/TSLocationManager(13941): ╔═════════════════════════════════════════════ I/TSLocationManager(13941): ║ Location-provider change: false I/TSLocationManager(13941): ╠═════════════════════════════════════════════ I/TSLocationManager(13941): ╟─ GPS: false I/TSLocationManager(13941): ╟─ Network: false I/TSLocationManager(13941): ╟─ AP Mode: false I/flutter (13941): [providerchange] - [ProviderChangeEvent enabled:false, status: 3, network: false, gps: false, accuracyAuthorization: 0] W/Settings(13941): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value. I/TSLocationManager(13941): [c.t.l.p.TSProviderManager a] I/TSLocationManager(13941): ╔═════════════════════════════════════════════ I/TSLocationManager(13941): ║ Location-provider change: true I/TSLocationManager(13941): ╠═════════════════════════════════════════════ I/TSLocationManager(13941): ╟─ GPS: true I/TSLocationManager(13941): ╟─ Network: true I/TSLocationManager(13941): ╟─ AP Mode: false I/flutter (13941): [providerchange] - [ProviderChangeEvent enabled:true, status: 3, network: true, gps: true, accuracyAuthorization: 0] ```
eulerchavez commented 2 months ago

Any status?

christocracy commented 2 months ago

Forgot about this one. Never had a look yet. I’ll try and have a look next week.

github-actions[bot] commented 1 month ago

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

eulerchavez commented 1 month ago

Just a friendly reminder :) Do you have any updates on the status?

github-actions[bot] commented 1 day ago

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