<commit_before>import * as Linking from 'expo-linking';
import * as Location from 'expo-location';
import { Alert, Platform } from 'react-native';

// got this idea from: https://forums.expo.dev/t/how-to-setstate-from-within-taskmanager/26630/5?u=agrc
function BackgroundLocationService() {
  let subscriber;

  return {
    subscribe: (callback) => (subscriber = callback),
    unsubscribe: () => {
      subscriber = null;
    },
    notify: (location) => subscriber && subscriber(location),
    taskName: 'wvcr-vehicle-tracking-background-task',
  };
}

export default new BackgroundLocationService();

export async function verifyPermissions() {
  console.log('verifyPermissions');

  const existingPermissions = await Location.getBackgroundPermissionsAsync();
  console.log('existingPermissions', existingPermissions);

  if (!existingPermissions.granted) {
    await new Promise((resolve) => {
      let buttons = [{ text: 'OK', onPress: resolve }];
      if (!existingPermissions.canAskAgain) {
        buttons.push({ text: 'Go To Settings', onPress: () => Linking.openSettings() });
      }
      Alert.alert(
        'Background Location Permissions',
        [
          'This app collects location data to enable the tracking of vehicle routes even when the app is closed or',
          'not in use. Data is only collected when a tracking session is active. Data submitted to the server is only',<commit_msg>fix(front): make background task name specific to app version<commit_after>import { applicationId } from 'expo-application';
import * as Linking from 'expo-linking';
import * as Location from 'expo-location';
import { Alert, Platform } from 'react-native';

// got this idea from: https://forums.expo.dev/t/how-to-setstate-from-within-taskmanager/26630/5?u=agrc
function BackgroundLocationService() {
  let subscriber;

  return {
    subscribe: (callback) => (subscriber = callback),
    unsubscribe: () => {
      subscriber = null;
    },
    notify: (location) => subscriber && subscriber(location),
    taskName: `${applicationId}-vehicle-tracking-background-task`,
  };
}

export default new BackgroundLocationService();

export async function verifyPermissions() {
  console.log('verifyPermissions');

  const existingPermissions = await Location.getBackgroundPermissionsAsync();
  console.log('existingPermissions', existingPermissions);

  if (!existingPermissions.granted) {
    await new Promise((resolve) => {
      let buttons = [{ text: 'OK', onPress: resolve }];
      if (!existingPermissions.canAskAgain) {
        buttons.push({ text: 'Go To Settings', onPress: () => Linking.openSettings() });
      }
      Alert.alert(
        'Background Location Permissions',
        [
          'This app collects location data to enable the tracking of vehicle routes even when the app is closed or',
          'not in use. Data is only collected when a tracking session is active. Data submitted to the server is only',
{'fraction_non_alphanumeric': 0.11804613297150611, 'fraction_numerical': 0.004070556309362279, 'mean_word_length': 3.8344262295081966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7474199', 'n_tokens_mistral': 802, 'n_tokens_neox': 782, 'n_words': 243}