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

Android devices collect data sporadically

Open yonkahlon opened this issue 1 year ago • 5 comments

Your Environment

  • Plugin version: 4.14.4
  • Platform: Android
  • OS version: 12.1
  • Device manufacturer / model: Oppo A17K
  • React Native version (react-native -v): 0.72.3
  • Plugin config
  const initBackgroundGeolocation = useCallback(async () => {
    // Ready the SDK and fetch the current state.
    await BackgroundGeolocation.ready({
      httpRootProperty: '.',
      // Debug
      reset: true,
      debug: false,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      // transistorAuthorizationToken: token,
      // Geolocation
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
      distanceFilter: 5,
      // stopTimeout: 5,
      // Permissions
      locationAuthorizationRequest: 'Always',
      // HTTP & Persistence
      autoSync: true,
      maxDaysToPersist: 14,
      // Application
      // stopOnTerminate: false,
      // startOnBoot: true,
      enableHeadless: true,
      disableLocationAuthorizationAlert: true,
      disableElasticity: true,
      // disableStopDetection: true,
      pausesLocationUpdatesAutomatically: false,
      disableMotionActivityUpdates: true,
      heartbeatInterval: 60,
      stopOnTerminate: true,
      showsBackgroundLocationIndicator: true,
      stopOnStationary: false,
      backgroundPermissionRationale: {
        title: "Allow access to this device's location in the background",
        message:
          'In order to track your golf activity in the background, please enable "Allow all the time" location permission',
      },
    });

    setReady(true);
  }, []);
    const startTracking = async () => {
      if (
        config.config?.tracking?.serverUrl !== '' &&
        config.config?.tracking?.serverUrl !== undefined &&
        config.config?.tracking?.serverUrl !== null
      ) {
        await BackgroundGeolocation.setConfig({
          url: config.config?.tracking?.serverUrl,
          authorization: {
            strategy: 'JWT',
            accessToken: accessToken!,
          },
          params: { roundId: roundQuery.data?.id! },
        });
      }

      BackgroundGeolocation.start();
      BackgroundGeolocation.changePace(true);
    };

Expected Behavior

We tested iOS (iPhone 15) and Android side by side on a golf course. On both devices the app was in the background. We would bring it to the foreground a few times over 4 hours.

Here is what iOS data looks like: image

battery-level-ios

Data was consistently collected over the 4 hours, and battery level drops as expected over that time.

Here is a csv of all the datapoints we received. ios.csv

Actual Behavior

Here is what Android looks like: image (1)

Here is a graph of battery level over time: battery-level-android

Another graph on the age of the datapoint over time age-android

You can see that there were 2 periods when it did collect data for +/- 30 minutes each.

The battery level looks a bit strange as it's jumping up and down. It's also correlated to the 'age' of the data point.

I've attached a csv of all the datapoints android.csv

Steps to Reproduce

Context

Trying to track location over a period of about 4 hours while the app is in the background.

Debug logs

Logs
We didn't capture any logs.

yonkahlon avatar Jan 19 '24 09:01 yonkahlon

Oppo A17K

Oppo tends to be one of the worst performing devices. See https://dontkillmyapp.com

christocracy avatar Jan 19 '24 13:01 christocracy

BackgroundGeolocation.start(); >BackgroundGeolocation.changePace(true);

Also, use await

christocracy avatar Jan 19 '24 13:01 christocracy

@christocracy thanks for this! arg... this makes so hard to manage Android!

There is another issue though around having 2 coordinate that are exactly the same, but the one's age is 3M (i.e. 50mins). There seems to be quite a lot of that

yonkahlon avatar Jan 19 '24 14:01 yonkahlon

See wiki "Debugging" and search api docs "Logger". Learn to fetch and analyze the plug-in logs using the .emailLog method.

As for battery level jumping, the I will check to see if the level is being updated when an "old" location is returned.

I suggest you test Android on a Google pixel device, where the Android APIs are guaranteed to work as documented, as your baseline device.

christocracy avatar Jan 19 '24 14:01 christocracy

Yeah, for the next test we will make sure we can get the logs :-)

yonkahlon avatar Jan 19 '24 15:01 yonkahlon

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

github-actions[bot] avatar Apr 17 '24 01:04 github-actions[bot]

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

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