<commit_before>import {Cordova, Plugin} from './plugin';

declare var window;

export interface BackgroundGeolocationResponse {

  /**
   * ID of location as stored in DB (or null)
   */
  locationId: number;

  /**
   * Service provider
   */
  serviceProvider: string;

  /**
   * true if location recorded as part of debug
   */
  debug: boolean;

  /**
   * UTC time of this fix, in milliseconds since January 1, 1970.
   */
  time: number;

  /**
   * latitude, in degrees.
   */
  latitude: number;

  /**
   * longitude, in degrees.
   */
  longitude: number;

  /**
   * estimated accuracy of this location, in meters.
   */
  accuracy: number;

  /**
   * speed if it is available, in meters/second over ground.
   */
  speed: number;

  /**
   * altitude if available, in meters above the WGS 84 reference ellipsoid.
   */
  altitude: number;

  /**
    * accuracy of the altitude if available.
    */
  altitudeAccuracy: number;

  /**
   * bearing, in degrees.
   */
  bearing: number;

  /**
   * A Coordinates object defining the current location
   */
  coords: Coordinates;

  /**
   * A timestamp representing the time at which the location was retrieved.
   */
  timestamp: number;
}

export interface BackgroundGeolocationConfig {

  /**
   * Desired accuracy in meters. Possible values [0, 10, 100, 1000]. The lower
   * the number, the more power devoted to GeoLocation resulting in higher
   * accuracy readings. 1000 results in lowest power drain and least accurate
   * readings. @see Apple docs (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy)
   */
  desiredAccuracy: number;

  /**
   * Stationary radius in meters. When stopped, the minimum distance the device
   * must move beyond the stationary location for aggressive background-tracking
   * to engage.
   */
  stationaryRadius: number;

  /**
   * When enabled, the plugin will emit sounds for life-cycle events of
   * background-geolocation! See debugging sounds table.
   */
  debug?: boolean;

  /**
   * The minimum distance (measured in meters) a device must move horizontally
   * before an update event is generated. @see Apple docs. (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/distanceFilter)
   */
  distanceFilter: number;

  /**
   * IOS, ANDROID ONLY
   * Enable this in order to force a stop() when the application terminated
   * (e.g. on iOS, double-tap home button, swipe away the app).o
   *
   * Defaults to true
   */
  stopOnTerminate?: boolean;

  /**

   * ANDROID ONLY

   * Start background service on device boot.

   *
   * Defaults to false

   */
  startOnBoot?: boolean;

  /**

   * ANDROID ONLY

   * If false location service will not be started in foreground and no notification will be shown.
   *
   * Defaults to true

   */
  startForeground?: boolean;

  /**
   * ANDROID, WP8 ONLY
   * When using BackgroundGeolocation.LocationProvider.ANDROID_DISTANCE_FILTER_PROVIDER:
   * The minimum time interval between location updates in milliseconds.
   * @see Android docs (http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent))
   * and the MS doc (http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.reportinterval)
   * for more information
   * When using BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER:
   * Rate in milliseconds at which your app prefers to receive location updates.
   * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getInterval())
   */
  interval?: number;

  /**
   * ANDROID ONLY
   * Custom notification title in the drawer.
   */
  notificationTitle?: string;

  /**
   * ANDROID ONLY
   * Custom notification text in the drawer.
   */
  notificationText?: string;

  /**
   * ANDROID ONLY
   * The accent color to use for notification. Eg. #4CAF50.
   */
  notificationIconColor?: string;

  /**

   * ANDROID ONLY

   * The filename of a custom notification icon. See android quirks.

   * NOTE: Only available for API Level >=21.

   */
  notificationIconLarge?: string;

  /**

   * ANDROID ONLY

   * The filename of a custom notification icon. See android quirks.

   * NOTE: Only available for API Level >=21.

   */
  notificationIconSmall?: string;

  /**
   * ANDROID ONLY
   * Set location service provider @see wiki (https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers)
   */
  locationProvider?: number;

  /**
   * IOS ONLY
   * [AutomotiveNavigation, OtherNavigation, Fitness, Other] Presumably,
   * this affects iOS GPS algorithm. @see Apple docs for more information
   * (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType)
   */
  activityType?: string;

  /**

   * IOS ONLY

   * Pauses location updates when app is paused

   *
   * Defaults to true

   */
  pauseLocationUpdates?: boolean;

  /**

   * Server url where to send HTTP POST with recorded locations

   * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting

   */
  url?: string;

  /**

   * Server url where to send fail to post locations

   * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting

   */
  syncUrl?: string;

  /**
   * Specifies how many previously failed locations will be sent to server at once

   *
   * Defaults to 100

   */
  syncThreshold?: number;

  /**

   * Optional HTTP headers sent along in HTTP request

   */
  httpHeaders?: any;

  /**
   * IOS ONLY

   * Switch to less accurate significant changes and region monitory when in background (default)
   *
   * Defaults to 100

   */
  saveBatteryOnBackground?: boolean;

  /**

   * Limit maximum number of locations stored into db

   *
   * Defaults to 10000

   */
  maxLocations?: number;

  /**
   * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
   *
   * Fastest rate in milliseconds at which your app can handle location updates.
   * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getFastestInterval())
   */
  fastestInterval?: number;

  /**
   * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
   *
   * Rate in milliseconds at which activity recognition occurs. Larger values will result in fewer activity detections while improving battery life.
   */
  activitiesInterval?: number;

  /**
   * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
   *
   * stop() is forced, when the STILL activity is detected (default is true)
   */
  stopOnStillActivity?: boolean;
}

/**
 * @name BackgroundGeolocation
 * @description
 * This plugin provides foreground and background geolocation with battery-saving "circular region monitoring" and "stop detection". For
 * more detail, please see https://github.com/mauron85/cordova-plugin-background-geolocation
 *
 * @usage
 *
 * ```typescript
 * import { BackgroundGeolocation } from 'ionic-native';
 *
 *
 * // When device is ready :
 * platform.ready().then(() => {
 *     // IMPORTANT: BackgroundGeolocation must be called within app.ts and or before Geolocation. Otherwise the platform will not ask you for background tracking permission.
 *
 *     // BackgroundGeolocation is highly configurable. See platform specific configuration options
 *     let config = {
 *             desiredAccuracy: 10,
 *             stationaryRadius: 20,
 *             distanceFilter: 30,
 *             debug: true, //  enable this hear sounds for background-geolocation life-cycle.
 *             stopOnTerminate: false, // enable this to clear background location settings when the app terminates
 *     };
 *
 *     BackgroundGeolocation.configure((location) => {
         console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);

          // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
          // and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
          // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
          BackgroundGeolocation.finish(); // FOR IOS ONLY

 *      }, (error) => {
 *        console.log('BackgroundGeolocation error');
 *      }, config);
 *
 *     // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
 *     BackgroundGeolocation.start();
 * })
 *
 * // If you wish to turn OFF background-tracking, call the #stop method.
 * BackgroundGeolocation.stop();
 *
 * ```
 * @interfaces
 * BackgroundGeolocationResponse
 * BackgroundGeolocationConfig
 */
@Plugin({
  pluginName: 'BackgroundGeolocation',
  plugin: 'cordova-plugin-mauron85-background-geolocation',
  pluginRef: 'backgroundGeolocation',
  repo: 'https://github.com/mauron85/cordova-plugin-background-geolocation',
  platforms: ['iOS', 'Android', 'Windows Phone 8']
})
export class BackgroundGeolocation {

  /**

   * Set location service provider @see https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers

   *
   * Possible values:
   *  ANDROID_DISTANCE_FILTER_PROVIDER: 0,

   *  ANDROID_ACTIVITY_PROVIDER: 1

   *
   * @enum {number}

   */
  static LocationProvider: any = {
    ANDROID_DISTANCE_FILTER_PROVIDER: 0,
    ANDROID_ACTIVITY_PROVIDER: 1
  };

  /**
   * Desired accuracy in meters. Possible values [0, 10, 100, 1000].

   * The lower the number, the more power devoted to GeoLocation resulting in higher accuracy readings.

   * 1000 results in lowest power drain and least accurate readings.

   *
   * Possible values:
   *  HIGH: 0

   *  MEDIUM: 10

   *  LOW: 100

   *  PASSIVE: 1000
   *
   * enum {number}

   */
  static Accuracy: any = {
    HIGH: 0,
    MEDIUM: 10,
    LOW: 100,
    PASSIVE: 1000
  };

  /**

   * Used in the switchMode function

   *
   * Possible values:
   *  BACKGROUND: 0
   *  FOREGROUND: 1

   *
   * @enum {number}

   */
  static Mode: any = {
    BACKGROUND: 0,
    FOREGROUND: 1
  };

  /**
   * Configure the plugin.
   *
   * @param {Function} callback callback will be called when background location is determined.
   * @param {Function} errorCallback callback to be executed every time a geolocation error occurs.
   * @param {Config} options An object of type Config
   * @return Location object, which tries to mimic w3c Coordinates interface.
   * See http://dev.w3.org/geo/api/spec-source.html#coordinates_interface
   * Callback to be executed every time a geolocation is recorded in the background.
   */
  @Cordova({
    sync: true
  })
  static configure(callback: Function, errorCallback: Function, options: BackgroundGeolocationConfig): any { return; }

  /**
   * Turn ON the background-geolocation system.
   * The user will be tracked whenever they suspend the app.
   * @returns {Promise<any>}
   */
  @Cordova()
  static start(): Promise<any> { return; }

  /**
   * Turn OFF background-tracking
   * @returns {Promise<any>}
   */
  @Cordova()
  static stop(): Promise<any> { return; }

  /**
   * Inform the native plugin that you're finished, the background-task may be completed
   * NOTE: IOS, WP only
   */
  @Cordova()
  static finish() { }

  /**
   * Force the plugin to enter "moving" or "stationary" state
   * NOTE: IOS, WP only
   */<commit_msg>fix(background-geolocation): configure returns a promise<commit_after>import {Cordova, Plugin} from './plugin';

declare var window;

export interface BackgroundGeolocationResponse {

  /**
   * ID of location as stored in DB (or null)
   */
  locationId: number;

  /**
   * Service provider
   */
  serviceProvider: string;

  /**
   * true if location recorded as part of debug
   */
  debug: boolean;

  /**
   * UTC time of this fix, in milliseconds since January 1, 1970.
   */
  time: number;

  /**
   * latitude, in degrees.
   */
  latitude: number;

  /**
   * longitude, in degrees.
   */
  longitude: number;

  /**
   * estimated accuracy of this location, in meters.
   */
  accuracy: number;

  /**
   * speed if it is available, in meters/second over ground.
   */
  speed: number;

  /**
   * altitude if available, in meters above the WGS 84 reference ellipsoid.
   */
  altitude: number;

  /**
    * accuracy of the altitude if available.
    */
  altitudeAccuracy: number;

  /**
   * bearing, in degrees.
   */
  bearing: number;

  /**
   * A Coordinates object defining the current location
   */
  coords: Coordinates;

  /**
   * A timestamp representing the time at which the location was retrieved.
   */
  timestamp: number;
}

export interface BackgroundGeolocationConfig {

  /**
   * Desired accuracy in meters. Possible values [0, 10, 100, 1000]. The lower
   * the number, the more power devoted to GeoLocation resulting in higher
   * accuracy readings. 1000 results in lowest power drain and least accurate
   * readings. @see Apple docs (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy)
   */
  desiredAccuracy: number;

  /**
   * Stationary radius in meters. When stopped, the minimum distance the device
   * must move beyond the stationary location for aggressive background-tracking
   * to engage.
   */
  stationaryRadius: number;

  /**
   * When enabled, the plugin will emit sounds for life-cycle events of
   * background-geolocation! See debugging sounds table.
   */
  debug?: boolean;

  /**
   * The minimum distance (measured in meters) a device must move horizontally
   * before an update event is generated. @see Apple docs. (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/distanceFilter)
   */
  distanceFilter: number;

  /**
   * IOS, ANDROID ONLY
   * Enable this in order to force a stop() when the application terminated
   * (e.g. on iOS, double-tap home button, swipe away the app).o
   *
   * Defaults to true
   */
  stopOnTerminate?: boolean;

  /**

   * ANDROID ONLY

   * Start background service on device boot.

   *
   * Defaults to false

   */
  startOnBoot?: boolean;

  /**

   * ANDROID ONLY

   * If false location service will not be started in foreground and no notification will be shown.
   *
   * Defaults to true

   */
  startForeground?: boolean;

  /**
   * ANDROID, WP8 ONLY
   * When using BackgroundGeolocation.LocationProvider.ANDROID_DISTANCE_FILTER_PROVIDER:
   * The minimum time interval between location updates in milliseconds.
   * @see Android docs (http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent))
   * and the MS doc (http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.reportinterval)
   * for more information
   * When using BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER:
   * Rate in milliseconds at which your app prefers to receive location updates.
   * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getInterval())
   */
  interval?: number;

  /**
   * ANDROID ONLY
   * Custom notification title in the drawer.
   */
  notificationTitle?: string;

  /**
   * ANDROID ONLY
   * Custom notification text in the drawer.
   */
  notificationText?: string;

  /**
   * ANDROID ONLY
   * The accent color to use for notification. Eg. #4CAF50.
   */
  notificationIconColor?: string;

  /**

   * ANDROID ONLY

   * The filename of a custom notification icon. See android quirks.

   * NOTE: Only available for API Level >=21.

   */
  notificationIconLarge?: string;

  /**

   * ANDROID ONLY

   * The filename of a custom notification icon. See android quirks.

   * NOTE: Only available for API Level >=21.

   */
  notificationIconSmall?: string;

  /**
   * ANDROID ONLY
   * Set location service provider @see wiki (https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers)
   */
  locationProvider?: number;

  /**
   * IOS ONLY
   * [AutomotiveNavigation, OtherNavigation, Fitness, Other] Presumably,
   * this affects iOS GPS algorithm. @see Apple docs for more information
   * (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType)
   */
  activityType?: string;

  /**

   * IOS ONLY

   * Pauses location updates when app is paused

   *
   * Defaults to true

   */
  pauseLocationUpdates?: boolean;

  /**

   * Server url where to send HTTP POST with recorded locations

   * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting

   */
  url?: string;

  /**

   * Server url where to send fail to post locations

   * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting

   */
  syncUrl?: string;

  /**
   * Specifies how many previously failed locations will be sent to server at once

   *
   * Defaults to 100

   */
  syncThreshold?: number;

  /**

   * Optional HTTP headers sent along in HTTP request

   */
  httpHeaders?: any;

  /**
   * IOS ONLY

   * Switch to less accurate significant changes and region monitory when in background (default)
   *
   * Defaults to 100

   */
  saveBatteryOnBackground?: boolean;

  /**

   * Limit maximum number of locations stored into db

   *
   * Defaults to 10000

   */
  maxLocations?: number;

  /**
   * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
   *
   * Fastest rate in milliseconds at which your app can handle location updates.
   * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getFastestInterval())
   */
  fastestInterval?: number;

  /**
   * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
   *
   * Rate in milliseconds at which activity recognition occurs. Larger values will result in fewer activity detections while improving battery life.
   */
  activitiesInterval?: number;

  /**
   * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER
   *
   * stop() is forced, when the STILL activity is detected (default is true)
   */
  stopOnStillActivity?: boolean;
}

/**
 * @name BackgroundGeolocation
 * @description
 * This plugin provides foreground and background geolocation with battery-saving "circular region monitoring" and "stop detection". For
 * more detail, please see https://github.com/mauron85/cordova-plugin-background-geolocation
 *
 * @usage
 *
 * ```typescript
 * import { BackgroundGeolocation } from 'ionic-native';
 *
 *
 * // When device is ready :
 * platform.ready().then(() => {
 *     // IMPORTANT: BackgroundGeolocation must be called within app.ts and or before Geolocation. Otherwise the platform will not ask you for background tracking permission.
 *
 *     // BackgroundGeolocation is highly configurable. See platform specific configuration options
 *     let config = {
 *             desiredAccuracy: 10,
 *             stationaryRadius: 20,
 *             distanceFilter: 30,
 *             debug: true, //  enable this hear sounds for background-geolocation life-cycle.
 *             stopOnTerminate: false, // enable this to clear background location settings when the app terminates
 *     };
 *
 *     BackgroundGeolocation.configure((location) => {
         console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);

          // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
          // and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
          // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
          BackgroundGeolocation.finish(); // FOR IOS ONLY

 *      }, (error) => {
 *        console.log('BackgroundGeolocation error');
 *      }, config);
 *
 *     // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
 *     BackgroundGeolocation.start();
 * })
 *
 * // If you wish to turn OFF background-tracking, call the #stop method.
 * BackgroundGeolocation.stop();
 *
 * ```
 * @interfaces
 * BackgroundGeolocationResponse
 * BackgroundGeolocationConfig
 */
@Plugin({
  pluginName: 'BackgroundGeolocation',
  plugin: 'cordova-plugin-mauron85-background-geolocation',
  pluginRef: 'backgroundGeolocation',
  repo: 'https://github.com/mauron85/cordova-plugin-background-geolocation',
  platforms: ['iOS', 'Android', 'Windows Phone 8']
})
export class BackgroundGeolocation {

  /**

   * Set location service provider @see https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers

   *
   * Possible values:
   *  ANDROID_DISTANCE_FILTER_PROVIDER: 0,

   *  ANDROID_ACTIVITY_PROVIDER: 1

   *
   * @enum {number}

   */
  static LocationProvider: any = {
    ANDROID_DISTANCE_FILTER_PROVIDER: 0,
    ANDROID_ACTIVITY_PROVIDER: 1
  };

  /**
   * Desired accuracy in meters. Possible values [0, 10, 100, 1000].

   * The lower the number, the more power devoted to GeoLocation resulting in higher accuracy readings.

   * 1000 results in lowest power drain and least accurate readings.

   *
   * Possible values:
   *  HIGH: 0

   *  MEDIUM: 10

   *  LOW: 100

   *  PASSIVE: 1000
   *
   * enum {number}

   */
  static Accuracy: any = {
    HIGH: 0,
    MEDIUM: 10,
    LOW: 100,
    PASSIVE: 1000
  };

  /**

   * Used in the switchMode function

   *
   * Possible values:
   *  BACKGROUND: 0
   *  FOREGROUND: 1

   *
   * @enum {number}

   */
  static Mode: any = {
    BACKGROUND: 0,
    FOREGROUND: 1
  };

  /**
   * Configure the plugin.
   *
   * @param {Function} callback callback will be called when background location is determined.
   * @param {Function} errorCallback callback to be executed every time a geolocation error occurs.
   * @param {Config} options An object of type Config
   * @return {Promise<any>}
   */
  @Cordova({
    callbackOrder: 'reverse'
  })
  static configure(options: BackgroundGeolocationConfig): Promise<any> { return; }

  /**
   * Turn ON the background-geolocation system.
   * The user will be tracked whenever they suspend the app.
   * @returns {Promise<any>}
   */
  @Cordova()
  static start(): Promise<any> { return; }

  /**
   * Turn OFF background-tracking
   * @returns {Promise<any>}
   */
  @Cordova()
  static stop(): Promise<any> { return; }

  /**
   * Inform the native plugin that you're finished, the background-task may be completed
   * NOTE: IOS, WP only
   * @returns {Promise<any>}
   */
  @Cordova()
  static finish(): Promise<any> { }

  /**
   * Force the plugin to enter "moving" or "stationary" state
   * NOTE: IOS, WP only
   */
{'fraction_non_alphanumeric': 0.1010667453725176, 'fraction_numerical': 0.009276046717544378, 'mean_word_length': 3.127022794501479, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 22, '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': '3296369', 'n_tokens_mistral': 7334, 'n_tokens_neox': 6744, 'n_words': 2122}