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

Background service stopped with no logs available on Android device (VIVO V2205)

Open hadikhan-inserito opened this issue 2 years ago • 3 comments

Our app is currently showing a technical problem, that the background service has stopped and there are no logs available. The logs are not being generated, which is making it difficult to determine the cause of the issue with the background service.

Your Environment

Plugin version:

  • Platform: ANDROID
  • OS version: 12
  • Device manufacturer / model: VIVO V2205
  • React Native version (react-native -v): 9.3.2
  • Plugin config
// config
import BackgroundGeolocation from "react-native-background-geolocation";
import { API_URL } from "../utils";
export const config = {
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  debug: true,
  logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
  stopOnTerminate: false,
  batchSync: true,
  autoSyncThreshold: 0,
  startOnBoot: true,
  autoSync: true,
  geofenceModeHighAccuracy: true,
  preventSuspend: true,
  maxDaysToPersist: 90,
  backgroundPermissionRationale: {
    title: "Allow {applicationName} to access to this device's location in the background?",
    message: "In order to track your activity in the background, please enable {backgroundPermissionOptionLabel} location permission",
    positiveAction: "Change to {backgroundPermissionOptionLabel}",
    negativeAction: "Cancel",
  },
  locationAuthorizationRequest: 'Always',
  url: `${API_URL}/geofence-event`,
  method: "POST",
}

// Main DashboardScreen.js
React.useEffect(() => {

    const onLocation = BackgroundGeolocation.onLocation(location => {
      console.log('[onLocation]', location);
    });

    const onMotionChange = BackgroundGeolocation.onMotionChange(event => {
      console.log('[onMotionChange]', event);
    });

    const onActivityChange = BackgroundGeolocation.onActivityChange(event => {
      console.log('[onActivityChange]', event);
    });

    const onProviderChange = BackgroundGeolocation.onProviderChange(event => {
      console.log('[onProviderChange]', event);
    });

    const onGeofence = BackgroundGeolocation.onGeofence(geofence => {
      setGeofenceEventMessage(
        `You have ${geofence.action === 'ENTER' ? 'entered' : 'left'} ${geofence.identifier}`,
      );
      setShowGeofenceEvent(true);
    });

    const onHeartbeat = BackgroundGeolocation.onHeartbeat(event => {
      console.log('[onHeartbeat] ', event);
    });
    /// 2. ready the plugin.
    if (userData?._id) {
      BackgroundGeolocation.ready({
        ...config,
        extras: {
          userId: userData?._id
        },
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${userData?.accessToken}`
        },
      }).then(async (state) => {
        setEnabled(state.enabled)
        if (!state.enabled) {
          BackgroundGeolocation.startGeofences();
        } else {
          try {
            const permission = await BackgroundGeolocation.requestPermission();
          } catch (error) {
            console.warn('[requestPermission] FAILURE: ', error);
          }
        }
      });

      if (userData?.site?.siteName) {
        BackgroundGeolocation.removeGeofences().then(success => {
          console.log('[removeGeofences] all geofences have been destroyed');
          BackgroundGeolocation.addGeofence({
            identifier: userData?.site?.siteName,
            radius: userData?.site?.siteRadius,
            latitude: userData?.site?.siteCoordinates?.lat,
            longitude: userData?.site?.siteCoordinates?.lng,
            notifyOnEntry: true,
            notifyOnExit: true,
          })
            .then(success => {
              console.log(`[addGeofence] ${userData?.site?.siteName} added.`);
            })
            .catch(error => {
              console.log('[addGeofence] FAILURE: ', error);
            });
        });
      }
    }
    return () => {
      onLocation.remove();
      onMotionChange.remove();
      onActivityChange.remove();
      onProviderChange.remove();
      onGeofence.remove();
      onHeartbeat.remove();
    };
  }, [userData]);
  React.useEffect(() => {
    BackgroundGeolocation.getState().then(state => console.log("[state] ", state.enabled, state.trackingMode));
    if (enabled) {
      console.log('STARTED');
    } else {
      console.log('STOPPED');
    }
  }, [enabled]);

Expected Behavior

The expected behavior of the background service is to run continuously without any interruptions. It should store events in a log to provide a record of its activity and to allow for debugging purposes if any issues arise. If the background service has stopped unexpectedly,The lack of logs to diagnose the issue is adding to the problem and making it more difficult to resolve. The goal is to restore the background service to its expected behavior of running continuously and providing a record of its activity through stored logs.

Actual Behavior

The actual behavior of the background servics that it has stopped functioning unexpectedly and is not generating logs. This unexpected cessation of activity is causing problems for users who rely on the background service and its log records. You can find the log breaks on the following line number - 10935 - 10937 - 10823 - 10825

Context

This issue is recieved from an end user as his check in and check out were not updated while the application was in the background.

Test Case Device / Platform App State
CheckIn/CheckOut ANDROID 12 (vivo V2205) unknown

Steps to Reproduce

This issue is not reproduceable at our end as we cannot debug the situation.

Debug logs

Logs
PASTE_YOUR_LOGS_HERE

aqib-background-geolocation.log.gz

hadikhan-inserito avatar Feb 08 '23 10:02 hadikhan-inserito

It’s perfectly normal and expected to see “Service Stopped” messages in the logs.

have you read the api docs “Philosophy of Operation”. Also see my blog.

christocracy avatar Feb 08 '23 10:02 christocracy

If you’re having Android tracking problems on some particular device, first see https://dontkillmyapp.com

christocracy avatar Feb 08 '23 10:02 christocracy

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

github-actions[bot] avatar May 24 '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 07 '24 01:06 github-actions[bot]