blob: a60280ce92a54f07c1e730befb0a14cb025ce0c4 [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/**
David Christie6e4b5042015-04-09 14:53:37 -070075 * Set when your implementation can produce GNNS-derived locations,
76 * for use with flp_capabilities_callback.
77 *
78 * GNNS is a required capability for a particular feature to be used
79 * (batching or geofencing). If not supported that particular feature
80 * won't be used by the upper layer.
81 */
82#define CAPABILITY_GNSS (1U<<0)
83/**
84 * Set when your implementation can produce WiFi-derived locations, for
85 * use with flp_capabilities_callback.
86 */
87#define CAPABILITY_WIFI (1U<<1)
88/**
89 * Set when your implementation can produce cell-derived locations, for
90 * use with flp_capabilities_callback.
91 */
92#define CAPABILITY_CELL (1U<<3)
93
94/**
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -070095 * This constant is used with the batched locations
96 * APIs. Batching is mandatory when FLP implementation
97 * is supported. If the flag is set, the hardware implementation
98 * will wake up the application processor when the FIFO is full,
99 * If the flag is not set, the hardware implementation will drop
100 * the oldest data when the FIFO is full.
101 */
102#define FLP_BATCH_WAKEUP_ON_FIFO_FULL 0x0000001
103
104/**
105 * While batching, the implementation should not call the
106 * flp_location_callback on every location fix. However,
107 * sometimes in high power mode, the system might need
108 * a location callback every single time the location
109 * fix has been obtained. This flag controls that option.
110 * Its the responsibility of the upper layers (caller) to switch
111 * it off, if it knows that the AP might go to sleep.
Kevin Tangd2c966f2013-06-17 12:47:27 -0700112 * When this bit is on amidst a batching session, batching should
113 * continue while location fixes are reported in real time.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700114 */
115#define FLP_BATCH_CALLBACK_ON_LOCATION_FIX 0x0000002
116
117/** Flags to indicate which values are valid in a FlpLocation. */
118typedef uint16_t FlpLocationFlags;
119
120// IMPORTANT: Note that the following values must match
121// constants in the corresponding java file.
122
123/** FlpLocation has valid latitude and longitude. */
124#define FLP_LOCATION_HAS_LAT_LONG (1U<<0)
125/** FlpLocation has valid altitude. */
126#define FLP_LOCATION_HAS_ALTITUDE (1U<<1)
127/** FlpLocation has valid speed. */
128#define FLP_LOCATION_HAS_SPEED (1U<<2)
129/** FlpLocation has valid bearing. */
130#define FLP_LOCATION_HAS_BEARING (1U<<4)
131/** FlpLocation has valid accuracy. */
132#define FLP_LOCATION_HAS_ACCURACY (1U<<8)
133
134
135typedef int64_t FlpUtcTime;
136
137/** Represents a location. */
138typedef struct {
139 /** set to sizeof(FlpLocation) */
140 size_t size;
141
142 /** Flags associated with the location object. */
143 FlpLocationFlags flags;
144
145 /** Represents latitude in degrees. */
146 double latitude;
147
148 /** Represents longitude in degrees. */
149 double longitude;
150
151 /**
152 * Represents altitude in meters above the WGS 84 reference
153 * ellipsoid. */
154 double altitude;
155
156 /** Represents speed in meters per second. */
157 float speed;
158
159 /** Represents heading in degrees. */
160 float bearing;
161
162 /** Represents expected accuracy in meters. */
163 float accuracy;
164
165 /** Timestamp for the location fix. */
166 FlpUtcTime timestamp;
167
168 /** Sources used, will be Bitwise OR of the FLP_TECH_MASK bits. */
169 uint32_t sources_used;
170} FlpLocation;
171
172typedef enum {
173 ASSOCIATE_JVM,
174 DISASSOCIATE_JVM,
175} ThreadEvent;
176
177/**
178 * Callback with location information.
destradaab8948792013-07-12 16:18:12 -0700179 * Can only be called from a thread associated to JVM using set_thread_event_cb.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700180 * Parameters:
181 * num_locations is the number of batched locations available.
182 * location is the pointer to an array of pointers to location objects.
183 */
184typedef void (*flp_location_callback)(int32_t num_locations, FlpLocation** location);
185
186/**
187 * Callback utility for acquiring a wakelock.
188 * This can be used to prevent the CPU from suspending while handling FLP events.
189 */
190typedef void (*flp_acquire_wakelock)();
191
192/**
193 * Callback utility for releasing the FLP wakelock.
194 */
195typedef void (*flp_release_wakelock)();
196
197/**
destradaab8948792013-07-12 16:18:12 -0700198 * Callback for associating a thread that can call into the Java framework code.
199 * This must be used to initialize any threads that report events up to the framework.
200 * Return value:
201 * FLP_RESULT_SUCCESS on success.
202 * FLP_RESULT_ERROR if the association failed in the current thread.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700203 */
destradaab8948792013-07-12 16:18:12 -0700204typedef int (*flp_set_thread_event)(ThreadEvent event);
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700205
David Christie6e4b5042015-04-09 14:53:37 -0700206/**
207 * Callback for technologies supported by this implementation.
208 *
209 * Parameters: capabilities is a bitmask of FLP_CAPABILITY_* values describing
210 * which features your implementation supports. You should support
211 * CAPABILITY_GNSS at a minimum for your implementation to be utilized. You can
212 * return 0 in FlpGeofenceCallbacks to indicate you don't support geofencing,
213 * or 0 in FlpCallbacks to indicate you don't support location batching.
214 */
215typedef void (*flp_capabilities_callback)(int capabilities);
216
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700217/** FLP callback structure. */
218typedef struct {
219 /** set to sizeof(FlpCallbacks) */
220 size_t size;
221 flp_location_callback location_cb;
222 flp_acquire_wakelock acquire_wakelock_cb;
223 flp_release_wakelock release_wakelock_cb;
destradaab8948792013-07-12 16:18:12 -0700224 flp_set_thread_event set_thread_event_cb;
David Christie6e4b5042015-04-09 14:53:37 -0700225 flp_capabilities_callback flp_capabilities_cb;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700226} FlpCallbacks;
227
228
229/** Options with the batching FLP APIs */
230typedef struct {
231 /**
232 * Maximum power in mW that the underlying implementation
233 * can use for this batching call.
Kevin Tangd2c966f2013-06-17 12:47:27 -0700234 * If max_power_allocation_mW is 0, only fixes that are generated
235 * at no additional cost of power shall be reported.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700236 */
237 double max_power_allocation_mW;
238
239 /** Bitwise OR of the FLP_TECH_MASKS to use */
240 uint32_t sources_to_use;
241
242 /**
243 * FLP_BATCH_WAKEUP_ON_FIFO_FULL - If set the hardware
244 * will wake up the AP when the buffer is full. If not set, the
245 * hardware will drop the oldest location object.
246 *
247 * FLP_BATCH_CALLBACK_ON_LOCATION_FIX - If set the location
248 * callback will be called every time there is a location fix.
249 * Its the responsibility of the upper layers (caller) to switch
Kevin Tangd2c966f2013-06-17 12:47:27 -0700250 * it off, if it knows that the AP might go to sleep. When this
251 * bit is on amidst a batching session, batching should continue
252 * while location fixes are reported in real time.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700253 *
254 * Other flags to be bitwised ORed in the future.
255 */
256 uint32_t flags;
257
258 /**
259 * Frequency with which location needs to be batched in nano
260 * seconds.
261 */
262 int64_t period_ns;
David Christieb3a7d372015-04-08 15:30:55 -0700263
264 /**
265 * The smallest displacement between reported locations in meters.
266 *
267 * If set to 0, then you should report locations at the requested
268 * interval even if the device is stationary. If positive, you
269 * can use this parameter as a hint to save power (e.g. throttling
270 * location period if the user hasn't traveled close to the displacement
271 * threshold). Even small positive values can be interpreted to mean
272 * that you don't have to compute location when the device is stationary.
273 *
274 * There is no need to filter location delivery based on this parameter.
275 * Locations can be delivered even if they have a displacement smaller than
276 * requested. This parameter can safely be ignored at the cost of potential
277 * power savings.
278 */
279 float smallest_displacement_meters;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700280} FlpBatchOptions;
281
282#define FLP_RESULT_SUCCESS 0
283#define FLP_RESULT_ERROR -1
284#define FLP_RESULT_INSUFFICIENT_MEMORY -2
285#define FLP_RESULT_TOO_MANY_GEOFENCES -3
286#define FLP_RESULT_ID_EXISTS -4
287#define FLP_RESULT_ID_UNKNOWN -5
288#define FLP_RESULT_INVALID_GEOFENCE_TRANSITION -6
289
290/**
291 * Represents the standard FLP interface.
292 */
293typedef struct {
294 /**
295 * set to sizeof(FlpLocationInterface)
296 */
297 size_t size;
298
299 /**
300 * Opens the interface and provides the callback routines
David Christie6e4b5042015-04-09 14:53:37 -0700301 * to the implementation of this interface. Once called you should respond
302 * by calling the flp_capabilities_callback in FlpCallbacks to
303 * specify the capabilities that your implementation supports.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700304 */
305 int (*init)(FlpCallbacks* callbacks );
306
307 /**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700308 * Return the batch size (in number of FlpLocation objects)
309 * available in the hardware. Note, different HW implementations
310 * may have different sample sizes. This shall return number
311 * of samples defined in the format of FlpLocation.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700312 * This will be used by the upper layer, to decide on the batching
313 * interval and whether the AP should be woken up or not.
314 */
315 int (*get_batch_size)();
316
317 /**
318 * Start batching locations. This API is primarily used when the AP is
319 * asleep and the device can batch locations in the hardware.
320 * flp_location_callback is used to return the locations. When the buffer
321 * is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is used, the AP is woken up.
322 * When the buffer is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is not set,
323 * the oldest location object is dropped. In this case the AP will not be
324 * woken up. The upper layer will use get_batched_location
325 * API to explicitly ask for the location.
326 * If FLP_BATCH_CALLBACK_ON_LOCATION_FIX is set, the implementation
327 * will call the flp_location_callback every single time there is a location
328 * fix. This overrides FLP_BATCH_WAKEUP_ON_FIFO_FULL flag setting.
329 * It's the responsibility of the upper layers (caller) to switch
330 * it off, if it knows that the AP might go to sleep. This is useful
331 * for nagivational applications when the system is in high power mode.
332 * Parameters:
333 * id - Id for the request.
334 * options - See FlpBatchOptions struct definition.
335 * Return value:
336 * FLP_RESULT_SUCCESS on success, FLP_RESULT_INSUFFICIENT_MEMORY,
337 * FLP_RESULT_ID_EXISTS, FLP_RESULT_ERROR on failure.
338 */
339 int (*start_batching)(int id, FlpBatchOptions* options);
340
341 /**
342 * Update FlpBatchOptions associated with a batching request.
343 * When a batching operation is in progress and a batching option
344 * such as FLP_BATCH_WAKEUP_ON_FIFO_FULL needs to be updated, this API
345 * will be used. For instance, this can happen when the AP is awake and
346 * the maps application is being used.
347 * Parameters:
348 * id - Id of an existing batch request.
349 * new_options - Updated FlpBatchOptions
350 * Return value:
351 * FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN,
352 * FLP_RESULT_ERROR on error.
353 */
354 int (*update_batching_options)(int id, FlpBatchOptions* new_options);
355
356 /**
357 * Stop batching.
358 * Parameters:
359 * id - Id for the request.
360 * Return Value:
361 * FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN or
362 * FLP_RESULT_ERROR on failure.
363 */
364 int (*stop_batching)(int id);
365
366 /**
367 * Closes the interface. If any batch operations are in progress,
368 * they should be stopped.
369 */
370 void (*cleanup)();
371
372 /**
373 * Get the fused location that was batched.
374 * flp_location_callback is used to return the location. The location object
375 * is dropped from the buffer only when the buffer is full. Do not remove it
376 * from the buffer just because it has been returned using the callback.
377 * In other words, when there is no new location object, two calls to
378 * get_batched_location(1) should return the same location object.
379 * Parameters:
380 * last_n_locations - Number of locations to get. This can be one or many.
381 * If the last_n_locations is 1, you get the latest location known to the
382 * hardware.
383 */
384 void (*get_batched_location)(int last_n_locations);
385
386 /**
387 * Injects current location from another location provider
388 * latitude and longitude are measured in degrees
389 * expected accuracy is measured in meters
390 * Parameters:
391 * location - The location object being injected.
392 * Return value: FLP_RESULT_SUCCESS or FLP_RESULT_ERROR.
393 */
394 int (*inject_location)(FlpLocation* location);
395
396 /**
397 * Get a pointer to extension information.
398 */
399 const void* (*get_extension)(const char* name);
400} FlpLocationInterface;
401
402struct flp_device_t {
403 struct hw_device_t common;
404
405 /**
406 * Get a handle to the FLP Interface.
407 */
408 const FlpLocationInterface* (*get_flp_interface)(struct flp_device_t* dev);
409};
410
411/**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700412 * Callback for reports diagnostic data into the Java framework code.
413*/
414typedef void (*report_data)(char* data, int length);
415
416/**
417 * FLP diagnostic callback structure.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700418 * Currently, not used - but this for future extension.
419 */
420typedef struct {
Kevin Tangd2c966f2013-06-17 12:47:27 -0700421 /** set to sizeof(FlpDiagnosticCallbacks) */
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700422 size_t size;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700423
destradaab8948792013-07-12 16:18:12 -0700424 flp_set_thread_event set_thread_event_cb;
Kevin Tangd2c966f2013-06-17 12:47:27 -0700425
426 /** reports diagnostic data into the Java framework code */
427 report_data data_cb;
428} FlpDiagnosticCallbacks;
429
430/** Extended interface for diagnostic support. */
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700431typedef struct {
Kevin Tangd2c966f2013-06-17 12:47:27 -0700432 /** set to sizeof(FlpDiagnosticInterface) */
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700433 size_t size;
434
435 /**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700436 * Opens the diagnostic interface and provides the callback routines
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700437 * to the implemenation of this interface.
438 */
Kevin Tangd2c966f2013-06-17 12:47:27 -0700439 void (*init)(FlpDiagnosticCallbacks* callbacks);
440
441 /**
442 * Injects diagnostic data into the FLP subsystem.
443 * Return 0 on success, -1 on error.
444 **/
445 int (*inject_data)(char* data, int length );
446} FlpDiagnosticInterface;
447
448/**
449 * Context setting information.
450 * All these settings shall be injected to FLP HAL at FLP init time.
451 * Following that, only the changed setting need to be re-injected
452 * upon changes.
453 */
454
455#define FLP_DEVICE_CONTEXT_GPS_ENABLED (1U<<0)
456#define FLP_DEVICE_CONTEXT_AGPS_ENABLED (1U<<1)
457#define FLP_DEVICE_CONTEXT_NETWORK_POSITIONING_ENABLED (1U<<2)
458#define FLP_DEVICE_CONTEXT_WIFI_CONNECTIVITY_ENABLED (1U<<3)
459#define FLP_DEVICE_CONTEXT_WIFI_POSITIONING_ENABLED (1U<<4)
destradaa06b77aa2013-08-21 12:41:19 -0700460#define FLP_DEVICE_CONTEXT_HW_NETWORK_POSITIONING_ENABLED (1U<<5)
Kevin Tangd2c966f2013-06-17 12:47:27 -0700461#define FLP_DEVICE_CONTEXT_AIRPLANE_MODE_ON (1U<<6)
462#define FLP_DEVICE_CONTEXT_DATA_ENABLED (1U<<7)
463#define FLP_DEVICE_CONTEXT_ROAMING_ENABLED (1U<<8)
464#define FLP_DEVICE_CONTEXT_CURRENTLY_ROAMING (1U<<9)
465#define FLP_DEVICE_CONTEXT_SENSOR_ENABLED (1U<<10)
466#define FLP_DEVICE_CONTEXT_BLUETOOTH_ENABLED (1U<<11)
467#define FLP_DEVICE_CONTEXT_CHARGER_ON (1U<<12)
468
469/** Extended interface for device context support. */
470typedef struct {
471 /** set to sizeof(FlpDeviceContextInterface) */
472 size_t size;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700473
474 /**
475 * Injects debug data into the FLP subsystem.
476 * Return 0 on success, -1 on error.
477 **/
Kevin Tangd2c966f2013-06-17 12:47:27 -0700478 int (*inject_device_context)(uint32_t enabledMask);
479} FlpDeviceContextInterface;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700480
481
482/**
483 * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
484 * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
485 *
486 * An example state diagram with confidence level: 95% and Unknown time limit
487 * set as 30 secs is shown below. (confidence level and Unknown time limit are
488 * explained latter)
489 * ____________________________
490 * | Unknown (30 secs) |
491 * """"""""""""""""""""""""""""
492 * ^ | | ^
493 * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
494 * | v v |
495 * ________ EXITED _________
496 * | Inside | -----------> | Outside |
497 * | | <----------- | |
498 * """""""" ENTERED """""""""
499 *
500 * Inside state: We are 95% confident that the user is inside the geofence.
501 * Outside state: We are 95% confident that the user is outside the geofence
502 * Unknown state: Rest of the time.
503 *
504 * The Unknown state is better explained with an example:
505 *
506 * __________
507 * | c|
508 * | ___ | _______
509 * | |a| | | b |
510 * | """ | """""""
511 * | |
512 * """"""""""
513 * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
514 * circle reported by the FLP subsystem. Now with regard to "b", the system is
515 * confident that the user is outside. But with regard to "a" is not confident
516 * whether it is inside or outside the geofence. If the accuracy remains the
517 * same for a sufficient period of time, the UNCERTAIN transition would be
518 * triggered with the state set to Unknown. If the accuracy improves later, an
519 * appropriate transition should be triggered. This "sufficient period of time"
520 * is defined by the parameter in the add_geofence_area API.
521 * In other words, Unknown state can be interpreted as a state in which the
522 * FLP subsystem isn't confident enough that the user is either inside or
523 * outside the Geofence. It moves to Unknown state only after the expiry of the
524 * timeout.
525 *
526 * The geofence callback needs to be triggered for the ENTERED and EXITED
527 * transitions, when the FLP system is confident that the user has entered
528 * (Inside state) or exited (Outside state) the Geofence. An implementation
529 * which uses a value of 95% as the confidence is recommended. The callback
530 * should be triggered only for the transitions requested by the
531 * add_geofence_area call.
532 *
533 * Even though the diagram and explanation talks about states and transitions,
534 * the callee is only interested in the transistions. The states are mentioned
535 * here for illustrative purposes.
536 *
537 * Startup Scenario: When the device boots up, if an application adds geofences,
538 * and then we get an accurate FLP location fix, it needs to trigger the
539 * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
540 * By default, all the Geofences will be in the Unknown state.
541 *
542 * When the FLP system is unavailable, flp_geofence_status_callback should be
543 * called to inform the upper layers of the same. Similarly, when it becomes
544 * available the callback should be called. This is a global state while the
545 * UNKNOWN transition described above is per geofence.
546 *
547 */
548#define FLP_GEOFENCE_TRANSITION_ENTERED (1L<<0)
549#define FLP_GEOFENCE_TRANSITION_EXITED (1L<<1)
550#define FLP_GEOFENCE_TRANSITION_UNCERTAIN (1L<<2)
551
552#define FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE (1L<<0)
553#define FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE (1L<<1)
554
555/**
556 * The callback associated with the geofence.
557 * Parameters:
558 * geofence_id - The id associated with the add_geofence_area.
559 * location - The current location as determined by the FLP subsystem.
560 * transition - Can be one of FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED,
561 * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
Kevin Tangd2c966f2013-06-17 12:47:27 -0700562 * timestamp - Timestamp when the transition was detected; -1 if not available.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700563 * sources_used - Bitwise OR of FLP_TECH_MASK flags indicating which
564 * subsystems were used.
565 *
566 * The callback should only be called when the caller is interested in that
567 * particular transition. For instance, if the caller is interested only in
568 * ENTERED transition, then the callback should NOT be called with the EXITED
569 * transition.
570 *
571 * IMPORTANT: If a transition is triggered resulting in this callback, the
572 * subsystem will wake up the application processor, if its in suspend state.
573 */
574typedef void (*flp_geofence_transition_callback) (int32_t geofence_id, FlpLocation* location,
575 int32_t transition, FlpUtcTime timestamp, uint32_t sources_used);
576
577/**
578 * The callback associated with the availablity of one the sources used for geofence
579 * monitoring by the FLP sub-system For example, if the GPS system determines that it cannot
580 * monitor geofences because of lack of reliability or unavailability of the GPS signals,
581 * it will call this callback with FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE parameter and the
582 * source set to FLP_TECH_MASK_GNSS.
583 *
584 * Parameters:
585 * status - FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE or FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE.
586 * source - One of the FLP_TECH_MASKS
587 * last_location - Last known location.
588 */
589typedef void (*flp_geofence_monitor_status_callback) (int32_t status, uint32_t source,
590 FlpLocation* last_location);
591
592/**
593 * The callback associated with the add_geofence call.
594 *
595 * Parameter:
596 * geofence_id - Id of the geofence.
597 * result - FLP_RESULT_SUCCESS
598 * FLP_RESULT_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
599 * FLP_RESULT_ID_EXISTS - geofence with id already exists
600 * FLP_RESULT_INVALID_GEOFENCE_TRANSITION - the monitorTransition contains an
601 * invalid transition
602 * FLP_RESULT_ERROR - for other errors.
603 */
604typedef void (*flp_geofence_add_callback) (int32_t geofence_id, int32_t result);
605
606/**
607 * The callback associated with the remove_geofence call.
608 *
609 * Parameter:
610 * geofence_id - Id of the geofence.
611 * result - FLP_RESULT_SUCCESS
612 * FLP_RESULT_ID_UNKNOWN - for invalid id
613 * FLP_RESULT_ERROR for others.
614 */
615typedef void (*flp_geofence_remove_callback) (int32_t geofence_id, int32_t result);
616
617
618/**
619 * The callback associated with the pause_geofence call.
620 *
621 * Parameter:
622 * geofence_id - Id of the geofence.
623 * result - FLP_RESULT_SUCCESS
624 * FLP_RESULT__ID_UNKNOWN - for invalid id
625 * FLP_RESULT_INVALID_TRANSITION -
626 * when monitor_transitions is invalid
627 * FLP_RESULT_ERROR for others.
628 */
629typedef void (*flp_geofence_pause_callback) (int32_t geofence_id, int32_t result);
630
631/**
632 * The callback associated with the resume_geofence call.
633 *
634 * Parameter:
635 * geofence_id - Id of the geofence.
636 * result - FLP_RESULT_SUCCESS
637 * FLP_RESULT_ID_UNKNOWN - for invalid id
638 * FLP_RESULT_ERROR for others.
639 */
640typedef void (*flp_geofence_resume_callback) (int32_t geofence_id, int32_t result);
641
642typedef struct {
destradaab8948792013-07-12 16:18:12 -0700643 /** set to sizeof(FlpGeofenceCallbacks) */
644 size_t size;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700645 flp_geofence_transition_callback geofence_transition_callback;
646 flp_geofence_monitor_status_callback geofence_status_callback;
647 flp_geofence_add_callback geofence_add_callback;
648 flp_geofence_remove_callback geofence_remove_callback;
649 flp_geofence_pause_callback geofence_pause_callback;
650 flp_geofence_resume_callback geofence_resume_callback;
destradaab8948792013-07-12 16:18:12 -0700651 flp_set_thread_event set_thread_event_cb;
David Christie6e4b5042015-04-09 14:53:37 -0700652 flp_capabilities_callback flp_capabilities_cb;
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700653} FlpGeofenceCallbacks;
654
655
656/** Type of geofence */
657typedef enum {
658 TYPE_CIRCLE = 0,
659} GeofenceType;
660
661/** Circular geofence is represented by lat / long / radius */
662typedef struct {
663 double latitude;
664 double longitude;
665 double radius_m;
666} GeofenceCircle;
667
668/** Represents the type of geofence and data */
669typedef struct {
670 GeofenceType type;
671 union {
672 GeofenceCircle circle;
673 } geofence;
674} GeofenceData;
675
676/** Geofence Options */
677typedef struct {
678 /**
679 * The current state of the geofence. For example, if
680 * the system already knows that the user is inside the geofence,
681 * this will be set to FLP_GEOFENCE_TRANSITION_ENTERED. In most cases, it
682 * will be FLP_GEOFENCE_TRANSITION_UNCERTAIN. */
683 int last_transition;
684
685 /**
686 * Transitions to monitor. Bitwise OR of
687 * FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
688 * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
689 */
690 int monitor_transitions;
691
692 /**
693 * Defines the best-effort description
694 * of how soon should the callback be called when the transition
695 * associated with the Geofence is triggered. For instance, if set
696 * to 1000 millseconds with FLP_GEOFENCE_TRANSITION_ENTERED, the callback
697 * should be called 1000 milliseconds within entering the geofence.
698 * This parameter is defined in milliseconds.
699 * NOTE: This is not to be confused with the rate that the GPS is
700 * polled at. It is acceptable to dynamically vary the rate of
701 * sampling the GPS for power-saving reasons; thus the rate of
702 * sampling may be faster or slower than this.
703 */
704 int notification_responsivenes_ms;
705
706 /**
707 * The time limit after which the UNCERTAIN transition
708 * should be triggered. This paramter is defined in milliseconds.
709 */
710 int unknown_timer_ms;
711
712 /**
713 * The sources to use for monitoring geofences. Its a BITWISE-OR
714 * of FLP_TECH_MASK flags.
715 */
716 uint32_t sources_to_use;
717} GeofenceOptions;
718
719/** Geofence struct */
720typedef struct {
721 int32_t geofence_id;
722 GeofenceData* data;
723 GeofenceOptions* options;
724} Geofence;
725
726/** Extended interface for FLP_Geofencing support */
727typedef struct {
728 /** set to sizeof(FlpGeofencingInterface) */
729 size_t size;
730
731 /**
732 * Opens the geofence interface and provides the callback routines
David Christie6e4b5042015-04-09 14:53:37 -0700733 * to the implemenation of this interface. Once called you should respond
734 * by calling the flp_capabilities_callback in FlpGeofenceCallbacks to
735 * specify the capabilities that your implementation supports.
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700736 */
737 void (*init)( FlpGeofenceCallbacks* callbacks );
738
739 /**
740 * Add a list of geofences.
741 * Parameters:
742 * number_of_geofences - The number of geofences that needed to be added.
743 * geofences - Pointer to array of pointers to Geofence structure.
744 */
745 void (*add_geofences) (int32_t number_of_geofences, Geofence** geofences);
746
747 /**
748 * Pause monitoring a particular geofence.
749 * Parameters:
750 * geofence_id - The id for the geofence.
751 */
752 void (*pause_geofence) (int32_t geofence_id);
753
754 /**
755 * Resume monitoring a particular geofence.
756 * Parameters:
757 * geofence_id - The id for the geofence.
758 * monitor_transitions - Which transitions to monitor. Bitwise OR of
759 * FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
760 * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
761 * This supersedes the value associated provided in the
762 * add_geofence_area call.
763 */
764 void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
765
766 /**
Kevin Tangd2c966f2013-06-17 12:47:27 -0700767 * Modify a particular geofence option.
768 * Parameters:
769 * geofence_id - The id for the geofence.
770 * options - Various options associated with the geofence. See
771 * GeofenceOptions structure for details.
772 */
773 void (*modify_geofence_option) (int32_t geofence_id, GeofenceOptions* options);
774
775 /**
Jaikumar Ganeshb951dee2013-06-04 15:43:07 -0700776 * Remove a list of geofences. After the function returns, no notifications
777 * should be sent.
778 * Parameter:
779 * number_of_geofences - The number of geofences that needed to be added.
780 * geofence_id - Pointer to array of geofence_ids to be removed.
781 */
782 void (*remove_geofences) (int32_t number_of_geofences, int32_t* geofence_id);
783} FlpGeofencingInterface;
784
785__END_DECLS
786
787#endif /* ANDROID_INCLUDE_HARDWARE_FLP_H */
788