blob: ff64aef8e1184798333282076b6bd5f30e946da8 [file] [log] [blame]
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_INCLUDE_HARDWARE_FUSED_LOCATION_H
18#define ANDROID_INCLUDE_HARDWARE_FUSED_LOCATION_H
19
20#include <hardware/hardware.h>
21
22
23/**
24 * This header file defines the interface of the Fused Location Provider.
25 * Fused Location Provider is designed to fuse data from various sources
26 * like GPS, Wifi, Cell, Sensors, Bluetooth etc to provide a fused location to the
27 * upper layers. The advantage of doing fusion in hardware is power savings.
28 * The goal is to do this without waking up the AP to get additional data.
29 * The software implementation of FLP will decide when to use
30 * the hardware fused location. Other location features like geofencing will
31 * also be implemented using fusion in hardware.
32 */
33__BEGIN_DECLS
34
35#define FLP_HEADER_VERSION 1
36#define FLP_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
37#define FLP_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, FLP_HEADER_VERSION)
38
39/**
40 * The id of this module
41 */
42#define FUSED_LOCATION_HARDWARE_MODULE_ID "flp"
43
44/**
45 * Name for the FLP location interface
46 */
47#define FLP_LOCATION_INTERFACE "flp_location"
48
49/**
50 * Name for the FLP location interface
51 */
Kevin Tangd2c966f2013-06-17 12:47:27 -070052#define FLP_DIAGNOSTIC_INTERFACE "flp_diagnostic"
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -070053
54/**
55 * Name for the FLP_Geofencing interface.
56 */
57#define FLP_GEOFENCING_INTERFACE "flp_geofencing"
58
59/**
Kevin Tangd2c966f2013-06-17 12:47:27 -070060 * Name for the FLP_device context interface.
61 */
62#define FLP_DEVICE_CONTEXT_INTERFACE "flp_device_context"
63
64/**
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -070065 * Constants to indicate the various subsystems
66 * that will be used.
67 */
68#define FLP_TECH_MASK_GNSS (1U<<0)
69#define FLP_TECH_MASK_WIFI (1U<<1)
70#define FLP_TECH_MASK_SENSORS (1U<<2)
71#define FLP_TECH_MASK_CELL (1U<<3)
72#define FLP_TECH_MASK_BLUETOOTH (1U<<4)
73
74/**
75 * This constant is used with the batched locations
76 * APIs. Batching is mandatory when FLP implementation
77 * is supported. If the flag is set, the hardware implementation
78 * will wake up the application processor when the FIFO is full,
79 * If the flag is not set, the hardware implementation will drop
80 * the oldest data when the FIFO is full.
81 */
82#define FLP_BATCH_WAKEUP_ON_FIFO_FULL 0x0000001
83
84/**
85 * While batching, the implementation should not call the
86 * flp_location_callback on every location fix. However,
87 * sometimes in high power mode, the system might need
88 * a location callback every single time the location
89 * fix has been obtained. This flag controls that option.
90 * Its the responsibility of the upper layers (caller) to switch
91 * it off, if it knows that the AP might go to sleep.
Kevin Tangd2c966f2013-06-17 12:47:27 -070092 * When this bit is on amidst a batching session, batching should
93 * continue while location fixes are reported in real time.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -070094 */
95#define FLP_BATCH_CALLBACK_ON_LOCATION_FIX 0x0000002
96
97/** Flags to indicate which values are valid in a FlpLocation. */
98typedef uint16_t FlpLocationFlags;
99
100// IMPORTANT: Note that the following values must match
101// constants in the corresponding java file.
102
103/** FlpLocation has valid latitude and longitude. */
104#define FLP_LOCATION_HAS_LAT_LONG (1U<<0)
105/** FlpLocation has valid altitude. */
106#define FLP_LOCATION_HAS_ALTITUDE (1U<<1)
107/** FlpLocation has valid speed. */
108#define FLP_LOCATION_HAS_SPEED (1U<<2)
109/** FlpLocation has valid bearing. */
110#define FLP_LOCATION_HAS_BEARING (1U<<4)
111/** FlpLocation has valid accuracy. */
112#define FLP_LOCATION_HAS_ACCURACY (1U<<8)
113
114
115typedef int64_t FlpUtcTime;
116
117/** Represents a location. */
118typedef struct {
119 /** set to sizeof(FlpLocation) */
120 size_t size;
121
122 /** Flags associated with the location object. */
123 FlpLocationFlags flags;
124
125 /** Represents latitude in degrees. */
126 double latitude;
127
128 /** Represents longitude in degrees. */
129 double longitude;
130
131 /**
132 * Represents altitude in meters above the WGS 84 reference
133 * ellipsoid. */
134 double altitude;
135
136 /** Represents speed in meters per second. */
137 float speed;
138
139 /** Represents heading in degrees. */
140 float bearing;
141
142 /** Represents expected accuracy in meters. */
143 float accuracy;
144
145 /** Timestamp for the location fix. */
146 FlpUtcTime timestamp;
147
148 /** Sources used, will be Bitwise OR of the FLP_TECH_MASK bits. */
149 uint32_t sources_used;
150} FlpLocation;
151
152typedef enum {
153 ASSOCIATE_JVM,
154 DISASSOCIATE_JVM,
155} ThreadEvent;
156
157/**
158 * Callback with location information.
destradaab8948792013-07-12 16:18:12 -0700159 * Can only be called from a thread associated to JVM using set_thread_event_cb.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700160 * Parameters:
161 * num_locations is the number of batched locations available.
162 * location is the pointer to an array of pointers to location objects.
163 */
164typedef void (*flp_location_callback)(int32_t num_locations, FlpLocation** location);
165
166/**
167 * Callback utility for acquiring a wakelock.
168 * This can be used to prevent the CPU from suspending while handling FLP events.
169 */
170typedef void (*flp_acquire_wakelock)();
171
172/**
173 * Callback utility for releasing the FLP wakelock.
174 */
175typedef void (*flp_release_wakelock)();
176
177/**
destradaab8948792013-07-12 16:18:12 -0700178 * Callback for associating a thread that can call into the Java framework code.
179 * This must be used to initialize any threads that report events up to the framework.
180 * Return value:
181 * FLP_RESULT_SUCCESS on success.
182 * FLP_RESULT_ERROR if the association failed in the current thread.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700183 */
destradaab8948792013-07-12 16:18:12 -0700184typedef int (*flp_set_thread_event)(ThreadEvent event);
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700185
186/** FLP callback structure. */
187typedef struct {
188 /** set to sizeof(FlpCallbacks) */
189 size_t size;
190 flp_location_callback location_cb;
191 flp_acquire_wakelock acquire_wakelock_cb;
192 flp_release_wakelock release_wakelock_cb;
destradaab8948792013-07-12 16:18:12 -0700193 flp_set_thread_event set_thread_event_cb;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700194} FlpCallbacks;
195
196
197/** Options with the batching FLP APIs */
198typedef struct {
199 /**
200 * Maximum power in mW that the underlying implementation
201 * can use for this batching call.
Kevin Tangd2c966f2013-06-17 12:47:27 -0700202 * If max_power_allocation_mW is 0, only fixes that are generated
203 * at no additional cost of power shall be reported.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700204 */
205 double max_power_allocation_mW;
206
207 /** Bitwise OR of the FLP_TECH_MASKS to use */
208 uint32_t sources_to_use;
209
210 /**
211 * FLP_BATCH_WAKEUP_ON_FIFO_FULL - If set the hardware
212 * will wake up the AP when the buffer is full. If not set, the
213 * hardware will drop the oldest location object.
214 *
215 * FLP_BATCH_CALLBACK_ON_LOCATION_FIX - If set the location
216 * callback will be called every time there is a location fix.
217 * Its the responsibility of the upper layers (caller) to switch
Kevin Tangd2c966f2013-06-17 12:47:27 -0700218 * it off, if it knows that the AP might go to sleep. When this
219 * bit is on amidst a batching session, batching should continue
220 * while location fixes are reported in real time.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700221 *
222 * Other flags to be bitwised ORed in the future.
223 */
224 uint32_t flags;
225
226 /**
227 * Frequency with which location needs to be batched in nano
228 * seconds.
229 */
230 int64_t period_ns;
David Christieb3a7d372015-04-08 15:30:55 -0700231
232 /**
233 * The smallest displacement between reported locations in meters.
234 *
235 * If set to 0, then you should report locations at the requested
236 * interval even if the device is stationary. If positive, you
237 * can use this parameter as a hint to save power (e.g. throttling
238 * location period if the user hasn't traveled close to the displacement
239 * threshold). Even small positive values can be interpreted to mean
240 * that you don't have to compute location when the device is stationary.
241 *
242 * There is no need to filter location delivery based on this parameter.
243 * Locations can be delivered even if they have a displacement smaller than
244 * requested. This parameter can safely be ignored at the cost of potential
245 * power savings.
246 */
247 float smallest_displacement_meters;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700248} FlpBatchOptions;
249
250#define FLP_RESULT_SUCCESS 0
251#define FLP_RESULT_ERROR -1
252#define FLP_RESULT_INSUFFICIENT_MEMORY -2
253#define FLP_RESULT_TOO_MANY_GEOFENCES -3
254#define FLP_RESULT_ID_EXISTS -4
255#define FLP_RESULT_ID_UNKNOWN -5
256#define FLP_RESULT_INVALID_GEOFENCE_TRANSITION -6
257
258/**
259 * Represents the standard FLP interface.
260 */
261typedef struct {
262 /**
263 * set to sizeof(FlpLocationInterface)
264 */
265 size_t size;
266
267 /**
268 * Opens the interface and provides the callback routines
269 * to the implemenation of this interface.
270 */
271 int (*init)(FlpCallbacks* callbacks );
272
273 /**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700274 * Return the batch size (in number of FlpLocation objects)
275 * available in the hardware. Note, different HW implementations
276 * may have different sample sizes. This shall return number
277 * of samples defined in the format of FlpLocation.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700278 * This will be used by the upper layer, to decide on the batching
279 * interval and whether the AP should be woken up or not.
280 */
281 int (*get_batch_size)();
282
283 /**
284 * Start batching locations. This API is primarily used when the AP is
285 * asleep and the device can batch locations in the hardware.
286 * flp_location_callback is used to return the locations. When the buffer
287 * is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is used, the AP is woken up.
288 * When the buffer is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is not set,
289 * the oldest location object is dropped. In this case the AP will not be
290 * woken up. The upper layer will use get_batched_location
291 * API to explicitly ask for the location.
292 * If FLP_BATCH_CALLBACK_ON_LOCATION_FIX is set, the implementation
293 * will call the flp_location_callback every single time there is a location
294 * fix. This overrides FLP_BATCH_WAKEUP_ON_FIFO_FULL flag setting.
295 * It's the responsibility of the upper layers (caller) to switch
296 * it off, if it knows that the AP might go to sleep. This is useful
297 * for nagivational applications when the system is in high power mode.
298 * Parameters:
299 * id - Id for the request.
300 * options - See FlpBatchOptions struct definition.
301 * Return value:
302 * FLP_RESULT_SUCCESS on success, FLP_RESULT_INSUFFICIENT_MEMORY,
303 * FLP_RESULT_ID_EXISTS, FLP_RESULT_ERROR on failure.
304 */
305 int (*start_batching)(int id, FlpBatchOptions* options);
306
307 /**
308 * Update FlpBatchOptions associated with a batching request.
309 * When a batching operation is in progress and a batching option
310 * such as FLP_BATCH_WAKEUP_ON_FIFO_FULL needs to be updated, this API
311 * will be used. For instance, this can happen when the AP is awake and
312 * the maps application is being used.
313 * Parameters:
314 * id - Id of an existing batch request.
315 * new_options - Updated FlpBatchOptions
316 * Return value:
317 * FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN,
318 * FLP_RESULT_ERROR on error.
319 */
320 int (*update_batching_options)(int id, FlpBatchOptions* new_options);
321
322 /**
323 * Stop batching.
324 * Parameters:
325 * id - Id for the request.
326 * Return Value:
327 * FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN or
328 * FLP_RESULT_ERROR on failure.
329 */
330 int (*stop_batching)(int id);
331
332 /**
333 * Closes the interface. If any batch operations are in progress,
334 * they should be stopped.
335 */
336 void (*cleanup)();
337
338 /**
339 * Get the fused location that was batched.
340 * flp_location_callback is used to return the location. The location object
341 * is dropped from the buffer only when the buffer is full. Do not remove it
342 * from the buffer just because it has been returned using the callback.
343 * In other words, when there is no new location object, two calls to
344 * get_batched_location(1) should return the same location object.
345 * Parameters:
346 * last_n_locations - Number of locations to get. This can be one or many.
347 * If the last_n_locations is 1, you get the latest location known to the
348 * hardware.
349 */
350 void (*get_batched_location)(int last_n_locations);
351
352 /**
353 * Injects current location from another location provider
354 * latitude and longitude are measured in degrees
355 * expected accuracy is measured in meters
356 * Parameters:
357 * location - The location object being injected.
358 * Return value: FLP_RESULT_SUCCESS or FLP_RESULT_ERROR.
359 */
360 int (*inject_location)(FlpLocation* location);
361
362 /**
363 * Get a pointer to extension information.
364 */
365 const void* (*get_extension)(const char* name);
366} FlpLocationInterface;
367
368struct flp_device_t {
369 struct hw_device_t common;
370
371 /**
372 * Get a handle to the FLP Interface.
373 */
374 const FlpLocationInterface* (*get_flp_interface)(struct flp_device_t* dev);
375};
376
377/**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700378 * Callback for reports diagnostic data into the Java framework code.
379*/
380typedef void (*report_data)(char* data, int length);
381
382/**
383 * FLP diagnostic callback structure.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700384 * Currently, not used - but this for future extension.
385 */
386typedef struct {
Kevin Tangd2c966f2013-06-17 12:47:27 -0700387 /** set to sizeof(FlpDiagnosticCallbacks) */
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700388 size_t size;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700389
destradaab8948792013-07-12 16:18:12 -0700390 flp_set_thread_event set_thread_event_cb;
Kevin Tangd2c966f2013-06-17 12:47:27 -0700391
392 /** reports diagnostic data into the Java framework code */
393 report_data data_cb;
394} FlpDiagnosticCallbacks;
395
396/** Extended interface for diagnostic support. */
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700397typedef struct {
Kevin Tangd2c966f2013-06-17 12:47:27 -0700398 /** set to sizeof(FlpDiagnosticInterface) */
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700399 size_t size;
400
401 /**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700402 * Opens the diagnostic interface and provides the callback routines
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700403 * to the implemenation of this interface.
404 */
Kevin Tangd2c966f2013-06-17 12:47:27 -0700405 void (*init)(FlpDiagnosticCallbacks* callbacks);
406
407 /**
408 * Injects diagnostic data into the FLP subsystem.
409 * Return 0 on success, -1 on error.
410 **/
411 int (*inject_data)(char* data, int length );
412} FlpDiagnosticInterface;
413
414/**
415 * Context setting information.
416 * All these settings shall be injected to FLP HAL at FLP init time.
417 * Following that, only the changed setting need to be re-injected
418 * upon changes.
419 */
420
421#define FLP_DEVICE_CONTEXT_GPS_ENABLED (1U<<0)
422#define FLP_DEVICE_CONTEXT_AGPS_ENABLED (1U<<1)
423#define FLP_DEVICE_CONTEXT_NETWORK_POSITIONING_ENABLED (1U<<2)
424#define FLP_DEVICE_CONTEXT_WIFI_CONNECTIVITY_ENABLED (1U<<3)
425#define FLP_DEVICE_CONTEXT_WIFI_POSITIONING_ENABLED (1U<<4)
destradaa06b77aa2013-08-21 12:41:19 -0700426#define FLP_DEVICE_CONTEXT_HW_NETWORK_POSITIONING_ENABLED (1U<<5)
Kevin Tangd2c966f2013-06-17 12:47:27 -0700427#define FLP_DEVICE_CONTEXT_AIRPLANE_MODE_ON (1U<<6)
428#define FLP_DEVICE_CONTEXT_DATA_ENABLED (1U<<7)
429#define FLP_DEVICE_CONTEXT_ROAMING_ENABLED (1U<<8)
430#define FLP_DEVICE_CONTEXT_CURRENTLY_ROAMING (1U<<9)
431#define FLP_DEVICE_CONTEXT_SENSOR_ENABLED (1U<<10)
432#define FLP_DEVICE_CONTEXT_BLUETOOTH_ENABLED (1U<<11)
433#define FLP_DEVICE_CONTEXT_CHARGER_ON (1U<<12)
434
435/** Extended interface for device context support. */
436typedef struct {
437 /** set to sizeof(FlpDeviceContextInterface) */
438 size_t size;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700439
440 /**
441 * Injects debug data into the FLP subsystem.
442 * Return 0 on success, -1 on error.
443 **/
Kevin Tangd2c966f2013-06-17 12:47:27 -0700444 int (*inject_device_context)(uint32_t enabledMask);
445} FlpDeviceContextInterface;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700446
447
448/**
449 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
450 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
451 *
452 * An example state diagram with confidence level: 95% and Unknown time limit
453 * set as 30 secs is shown below. (confidence level and Unknown time limit are
454 * explained latter)
455 * ____________________________
456 * | Unknown (30 secs) |
457 * """"""""""""""""""""""""""""
458 * ^ | | ^
459 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
460 * | v v |
461 * ________ EXITED _________
462 * | Inside | -----------> | Outside |
463 * | | <----------- | |
464 * """""""" ENTERED """""""""
465 *
466 * Inside state: We are 95% confident that the user is inside the geofence.
467 * Outside state: We are 95% confident that the user is outside the geofence
468 * Unknown state: Rest of the time.
469 *
470 * The Unknown state is better explained with an example:
471 *
472 * __________
473 * | c|
474 * | ___ | _______
475 * | |a| | | b |
476 * | """ | """""""
477 * | |
478 * """"""""""
479 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
480 * circle reported by the FLP subsystem. Now with regard to "b", the system is
481 * confident that the user is outside. But with regard to "a" is not confident
482 * whether it is inside or outside the geofence. If the accuracy remains the
483 * same for a sufficient period of time, the UNCERTAIN transition would be
484 * triggered with the state set to Unknown. If the accuracy improves later, an
485 * appropriate transition should be triggered. This "sufficient period of time"
486 * is defined by the parameter in the add_geofence_area API.
487 * In other words, Unknown state can be interpreted as a state in which the
488 * FLP subsystem isn't confident enough that the user is either inside or
489 * outside the Geofence. It moves to Unknown state only after the expiry of the
490 * timeout.
491 *
492 * The geofence callback needs to be triggered for the ENTERED and EXITED
493 * transitions, when the FLP system is confident that the user has entered
494 * (Inside state) or exited (Outside state) the Geofence. An implementation
495 * which uses a value of 95% as the confidence is recommended. The callback
496 * should be triggered only for the transitions requested by the
497 * add_geofence_area call.
498 *
499 * Even though the diagram and explanation talks about states and transitions,
500 * the callee is only interested in the transistions. The states are mentioned
501 * here for illustrative purposes.
502 *
503 * Startup Scenario: When the device boots up, if an application adds geofences,
504 * and then we get an accurate FLP location fix, it needs to trigger the
505 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
506 * By default, all the Geofences will be in the Unknown state.
507 *
508 * When the FLP system is unavailable, flp_geofence_status_callback should be
509 * called to inform the upper layers of the same. Similarly, when it becomes
510 * available the callback should be called. This is a global state while the
511 * UNKNOWN transition described above is per geofence.
512 *
513 */
514#define FLP_GEOFENCE_TRANSITION_ENTERED (1L<<0)
515#define FLP_GEOFENCE_TRANSITION_EXITED (1L<<1)
516#define FLP_GEOFENCE_TRANSITION_UNCERTAIN (1L<<2)
517
518#define FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE (1L<<0)
519#define FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE (1L<<1)
520
521/**
522 * The callback associated with the geofence.
523 * Parameters:
524 * geofence_id - The id associated with the add_geofence_area.
525 * location - The current location as determined by the FLP subsystem.
526 * transition - Can be one of FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED,
527 * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
Kevin Tangd2c966f2013-06-17 12:47:27 -0700528 * timestamp - Timestamp when the transition was detected; -1 if not available.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700529 * sources_used - Bitwise OR of FLP_TECH_MASK flags indicating which
530 * subsystems were used.
531 *
532 * The callback should only be called when the caller is interested in that
533 * particular transition. For instance, if the caller is interested only in
534 * ENTERED transition, then the callback should NOT be called with the EXITED
535 * transition.
536 *
537 * IMPORTANT: If a transition is triggered resulting in this callback, the
538 * subsystem will wake up the application processor, if its in suspend state.
539 */
540typedef void (*flp_geofence_transition_callback) (int32_t geofence_id, FlpLocation* location,
541 int32_t transition, FlpUtcTime timestamp, uint32_t sources_used);
542
543/**
544 * The callback associated with the availablity of one the sources used for geofence
545 * monitoring by the FLP sub-system For example, if the GPS system determines that it cannot
546 * monitor geofences because of lack of reliability or unavailability of the GPS signals,
547 * it will call this callback with FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE parameter and the
548 * source set to FLP_TECH_MASK_GNSS.
549 *
550 * Parameters:
551 * status - FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE or FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE.
552 * source - One of the FLP_TECH_MASKS
553 * last_location - Last known location.
554 */
555typedef void (*flp_geofence_monitor_status_callback) (int32_t status, uint32_t source,
556 FlpLocation* last_location);
557
558/**
559 * The callback associated with the add_geofence call.
560 *
561 * Parameter:
562 * geofence_id - Id of the geofence.
563 * result - FLP_RESULT_SUCCESS
564 * FLP_RESULT_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
565 * FLP_RESULT_ID_EXISTS - geofence with id already exists
566 * FLP_RESULT_INVALID_GEOFENCE_TRANSITION - the monitorTransition contains an
567 * invalid transition
568 * FLP_RESULT_ERROR - for other errors.
569 */
570typedef void (*flp_geofence_add_callback) (int32_t geofence_id, int32_t result);
571
572/**
573 * The callback associated with the remove_geofence call.
574 *
575 * Parameter:
576 * geofence_id - Id of the geofence.
577 * result - FLP_RESULT_SUCCESS
578 * FLP_RESULT_ID_UNKNOWN - for invalid id
579 * FLP_RESULT_ERROR for others.
580 */
581typedef void (*flp_geofence_remove_callback) (int32_t geofence_id, int32_t result);
582
583
584/**
585 * The callback associated with the pause_geofence call.
586 *
587 * Parameter:
588 * geofence_id - Id of the geofence.
589 * result - FLP_RESULT_SUCCESS
590 * FLP_RESULT__ID_UNKNOWN - for invalid id
591 * FLP_RESULT_INVALID_TRANSITION -
592 * when monitor_transitions is invalid
593 * FLP_RESULT_ERROR for others.
594 */
595typedef void (*flp_geofence_pause_callback) (int32_t geofence_id, int32_t result);
596
597/**
598 * The callback associated with the resume_geofence call.
599 *
600 * Parameter:
601 * geofence_id - Id of the geofence.
602 * result - FLP_RESULT_SUCCESS
603 * FLP_RESULT_ID_UNKNOWN - for invalid id
604 * FLP_RESULT_ERROR for others.
605 */
606typedef void (*flp_geofence_resume_callback) (int32_t geofence_id, int32_t result);
607
608typedef struct {
destradaab8948792013-07-12 16:18:12 -0700609 /** set to sizeof(FlpGeofenceCallbacks) */
610 size_t size;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700611 flp_geofence_transition_callback geofence_transition_callback;
612 flp_geofence_monitor_status_callback geofence_status_callback;
613 flp_geofence_add_callback geofence_add_callback;
614 flp_geofence_remove_callback geofence_remove_callback;
615 flp_geofence_pause_callback geofence_pause_callback;
616 flp_geofence_resume_callback geofence_resume_callback;
destradaab8948792013-07-12 16:18:12 -0700617 flp_set_thread_event set_thread_event_cb;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700618} FlpGeofenceCallbacks;
619
620
621/** Type of geofence */
622typedef enum {
623 TYPE_CIRCLE = 0,
624} GeofenceType;
625
626/** Circular geofence is represented by lat / long / radius */
627typedef struct {
628 double latitude;
629 double longitude;
630 double radius_m;
631} GeofenceCircle;
632
633/** Represents the type of geofence and data */
634typedef struct {
635 GeofenceType type;
636 union {
637 GeofenceCircle circle;
638 } geofence;
639} GeofenceData;
640
641/** Geofence Options */
642typedef struct {
643 /**
644 * The current state of the geofence. For example, if
645 * the system already knows that the user is inside the geofence,
646 * this will be set to FLP_GEOFENCE_TRANSITION_ENTERED. In most cases, it
647 * will be FLP_GEOFENCE_TRANSITION_UNCERTAIN. */
648 int last_transition;
649
650 /**
651 * Transitions to monitor. Bitwise OR of
652 * FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
653 * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
654 */
655 int monitor_transitions;
656
657 /**
658 * Defines the best-effort description
659 * of how soon should the callback be called when the transition
660 * associated with the Geofence is triggered. For instance, if set
661 * to 1000 millseconds with FLP_GEOFENCE_TRANSITION_ENTERED, the callback
662 * should be called 1000 milliseconds within entering the geofence.
663 * This parameter is defined in milliseconds.
664 * NOTE: This is not to be confused with the rate that the GPS is
665 * polled at. It is acceptable to dynamically vary the rate of
666 * sampling the GPS for power-saving reasons; thus the rate of
667 * sampling may be faster or slower than this.
668 */
669 int notification_responsivenes_ms;
670
671 /**
672 * The time limit after which the UNCERTAIN transition
673 * should be triggered. This paramter is defined in milliseconds.
674 */
675 int unknown_timer_ms;
676
677 /**
678 * The sources to use for monitoring geofences. Its a BITWISE-OR
679 * of FLP_TECH_MASK flags.
680 */
681 uint32_t sources_to_use;
682} GeofenceOptions;
683
684/** Geofence struct */
685typedef struct {
686 int32_t geofence_id;
687 GeofenceData* data;
688 GeofenceOptions* options;
689} Geofence;
690
691/** Extended interface for FLP_Geofencing support */
692typedef struct {
693 /** set to sizeof(FlpGeofencingInterface) */
694 size_t size;
695
696 /**
697 * Opens the geofence interface and provides the callback routines
698 * to the implemenation of this interface.
699 */
700 void (*init)( FlpGeofenceCallbacks* callbacks );
701
702 /**
703 * Add a list of geofences.
704 * Parameters:
705 * number_of_geofences - The number of geofences that needed to be added.
706 * geofences - Pointer to array of pointers to Geofence structure.
707 */
708 void (*add_geofences) (int32_t number_of_geofences, Geofence** geofences);
709
710 /**
711 * Pause monitoring a particular geofence.
712 * Parameters:
713 * geofence_id - The id for the geofence.
714 */
715 void (*pause_geofence) (int32_t geofence_id);
716
717 /**
718 * Resume monitoring a particular geofence.
719 * Parameters:
720 * geofence_id - The id for the geofence.
721 * monitor_transitions - Which transitions to monitor. Bitwise OR of
722 * FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
723 * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
724 * This supersedes the value associated provided in the
725 * add_geofence_area call.
726 */
727 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
728
729 /**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700730 * Modify a particular geofence option.
731 * Parameters:
732 * geofence_id - The id for the geofence.
733 * options - Various options associated with the geofence. See
734 * GeofenceOptions structure for details.
735 */
736 void (*modify_geofence_option) (int32_t geofence_id, GeofenceOptions* options);
737
738 /**
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700739 * Remove a list of geofences. After the function returns, no notifications
740 * should be sent.
741 * Parameter:
742 * number_of_geofences - The number of geofences that needed to be added.
743 * geofence_id - Pointer to array of geofence_ids to be removed.
744 */
745 void (*remove_geofences) (int32_t number_of_geofences, int32_t* geofence_id);
746} FlpGeofencingInterface;
747
748__END_DECLS
749
750#endif /* ANDROID_INCLUDE_HARDWARE_FLP_H */
751