1 /*
2  * Copyright (C) 2016 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 // IWYU pragma: private, include "chre_api/chre.h"
18 // IWYU pragma: friend chre/.*\.h
19 
20 #ifndef _CHRE_GNSS_H_
21 #define _CHRE_GNSS_H_
22 
23 /**
24  * @file
25  * Global Navigation Satellite System (GNSS) API.
26  *
27  * These structures and definitions are based on the Android N GPS HAL.
28  * Refer to that header file (located at this path as of the time of this
29  * comment: hardware/libhardware/include/hardware/gps.h) and associated
30  * documentation for further details and explanations for these fields.
31  * References in comments like "(ref: GnssAccumulatedDeltaRangeState)" map to
32  * the relevant element in the GPS HAL where additional information can be
33  * found.
34  *
35  * In general, the parts of this API that are taken from the GPS HAL follow the
36  * naming conventions established in that interface rather than the CHRE API
37  * conventions, in order to avoid confusion and enable code re-use where
38  * applicable.
39  */
40 
41 
42 #include <stdbool.h>
43 #include <stdint.h>
44 
45 #include <chre/common.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /**
52  * The set of flags that may be returned by chreGnssGetCapabilities()
53  * @defgroup CHRE_GNSS_CAPABILITIES
54  * @{
55  */
56 
57 //! A lack of flags indicates that GNSS is not supported in this CHRE
58 #define CHRE_GNSS_CAPABILITIES_NONE          UINT32_C(0)
59 
60 //! GNSS position fixes are supported via chreGnssLocationSessionStartAsync()
61 #define CHRE_GNSS_CAPABILITIES_LOCATION      UINT32_C(1 << 0)
62 
63 //! GNSS raw measurements are supported via
64 //! chreGnssMeasurementSessionStartAsync()
65 #define CHRE_GNSS_CAPABILITIES_MEASUREMENTS  UINT32_C(1 << 1)
66 
67 //! Location fixes supplied from chreGnssConfigurePassiveLocationListener()
68 //! are tapped in at the GNSS engine level, so they include additional fixes
69 //! such as those requested by the AP, and not just those requested by other
70 //! nanoapps within CHRE (which is the case when this flag is not set)
71 #define CHRE_GNSS_CAPABILITIES_GNSS_ENGINE_BASED_PASSIVE_LISTENER \
72                                              UINT32_C(1 << 2)
73 
74 /** @} */
75 
76 /**
77  * The current version of struct chreGnssDataEvent associated with this API
78  */
79 #define CHRE_GNSS_DATA_EVENT_VERSION  UINT8_C(0)
80 
81 /**
82  * The maximum time the CHRE implementation is allowed to elapse before sending
83  * an event with the result of an asynchronous request, unless specified
84  * otherwise
85  */
86 #define CHRE_GNSS_ASYNC_RESULT_TIMEOUT_NS  (5 * CHRE_NSEC_PER_SEC)
87 
88 /**
89  * Produce an event ID in the block of IDs reserved for GNSS
90  * @param offset  Index into GNSS event ID block; valid range [0,15]
91  */
92 #define CHRE_GNSS_EVENT_ID(offset)  (CHRE_EVENT_GNSS_FIRST_EVENT + (offset))
93 
94 /**
95  * nanoappHandleEvent argument: struct chreAsyncResult
96  *
97  * Communicates the asynchronous result of a request to the GNSS API, such as
98  * starting a location session via chreGnssLocationSessionStartAsync(). The
99  * requestType field in chreAsyncResult is set to a value from enum
100  * chreGnssRequestType.
101  */
102 #define CHRE_EVENT_GNSS_ASYNC_RESULT  CHRE_GNSS_EVENT_ID(0)
103 
104 /**
105  * nanoappHandleEvent argument: struct chreGnssLocationEvent
106  *
107  * Represents a location fix provided by the GNSS subsystem.
108  */
109 #define CHRE_EVENT_GNSS_LOCATION      CHRE_GNSS_EVENT_ID(1)
110 
111 /**
112  * nanoappHandleEvent argument: struct chreGnssDataEvent
113  *
114  * Represents a set of GNSS measurements with associated clock data.
115  */
116 #define CHRE_EVENT_GNSS_DATA          CHRE_GNSS_EVENT_ID(2)
117 
118 // NOTE: Do not add new events with ID > 15; only values 0-15 are reserved
119 // (see chre/event.h)
120 
121 // Flags indicating the Accumulated Delta Range's states
122 // (ref: GnssAccumulatedDeltaRangeState)
123 #define CHRE_GNSS_ADR_STATE_UNKNOWN     UINT16_C(0)
124 #define CHRE_GNSS_ADR_STATE_VALID       UINT16_C(1 << 0)
125 #define CHRE_GNSS_ADR_STATE_RESET       UINT16_C(1 << 1)
126 #define CHRE_GNSS_ADR_STATE_CYCLE_SLIP  UINT16_C(1 << 2)
127 
128 // Flags to indicate what fields in chreGnssClock are valid (ref: GnssClockFlags)
129 #define CHRE_GNSS_CLOCK_HAS_LEAP_SECOND        UINT16_C(1 << 0)
130 #define CHRE_GNSS_CLOCK_HAS_TIME_UNCERTAINTY   UINT16_C(1 << 1)
131 #define CHRE_GNSS_CLOCK_HAS_FULL_BIAS          UINT16_C(1 << 2)
132 #define CHRE_GNSS_CLOCK_HAS_BIAS               UINT16_C(1 << 3)
133 #define CHRE_GNSS_CLOCK_HAS_BIAS_UNCERTAINTY   UINT16_C(1 << 4)
134 #define CHRE_GNSS_CLOCK_HAS_DRIFT              UINT16_C(1 << 5)
135 #define CHRE_GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY  UINT16_C(1 << 6)
136 
137 // Flags to indicate which values are valid in a GpsLocation
138 // (ref: GpsLocationFlags)
139 #define CHRE_GPS_LOCATION_HAS_LAT_LONG           UINT16_C(1 << 0)
140 #define CHRE_GPS_LOCATION_HAS_ALTITUDE           UINT16_C(1 << 1)
141 #define CHRE_GPS_LOCATION_HAS_SPEED              UINT16_C(1 << 2)
142 #define CHRE_GPS_LOCATION_HAS_BEARING            UINT16_C(1 << 3)
143 #define CHRE_GPS_LOCATION_HAS_ACCURACY           UINT16_C(1 << 4)
144 
145 //! @since v1.3
146 #define CHRE_GPS_LOCATION_HAS_ALTITUDE_ACCURACY  UINT16_C(1 << 5)
147 //! @since v1.3
148 #define CHRE_GPS_LOCATION_HAS_SPEED_ACCURACY     UINT16_C(1 << 6)
149 //! @since v1.3
150 #define CHRE_GPS_LOCATION_HAS_BEARING_ACCURACY   UINT16_C(1 << 7)
151 
152 /**
153  * The maximum number of instances of struct chreGnssMeasurement that may be
154  * included in a single struct chreGnssDataEvent.
155  *
156  * The value of this struct was increased from 64 to 128 in CHRE v1.5. For
157  * nanoapps targeting CHRE v1.4 or lower, the measurement_count will be capped
158  * at 64.
159  */
160 #define CHRE_GNSS_MAX_MEASUREMENT  UINT8_C(128)
161 #define CHRE_GNSS_MAX_MEASUREMENT_PRE_1_5  UINT8_C(64)
162 
163 // Flags indicating the GNSS measurement state (ref: GnssMeasurementState)
164 #define CHRE_GNSS_MEASUREMENT_STATE_UNKNOWN                UINT16_C(0)
165 #define CHRE_GNSS_MEASUREMENT_STATE_CODE_LOCK              UINT16_C(1 << 0)
166 #define CHRE_GNSS_MEASUREMENT_STATE_BIT_SYNC               UINT16_C(1 << 1)
167 #define CHRE_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC          UINT16_C(1 << 2)
168 #define CHRE_GNSS_MEASUREMENT_STATE_TOW_DECODED            UINT16_C(1 << 3)
169 #define CHRE_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS         UINT16_C(1 << 4)
170 #define CHRE_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC            UINT16_C(1 << 5)
171 #define CHRE_GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC        UINT16_C(1 << 6)
172 #define CHRE_GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED        UINT16_C(1 << 7)
173 #define CHRE_GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC        UINT16_C(1 << 8)
174 #define CHRE_GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC   UINT16_C(1 << 9)
175 #define CHRE_GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK     UINT16_C(1 << 10)
176 #define CHRE_GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK  UINT16_C(1 << 11)
177 #define CHRE_GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC      UINT16_C(1 << 12)
178 #define CHRE_GNSS_MEASUREMENT_STATE_SBAS_SYNC              UINT16_C(1 << 13)
179 
180 #define CHRE_GNSS_MEASUREMENT_CARRIER_FREQUENCY_UNKNOWN    0.f
181 
182 /**
183  * Indicates a type of request made in this API. Used to populate the resultType
184  * field of struct chreAsyncResult sent with CHRE_EVENT_GNSS_ASYNC_RESULT.
185  */
186 enum chreGnssRequestType {
187     CHRE_GNSS_REQUEST_TYPE_LOCATION_SESSION_START    = 1,
188     CHRE_GNSS_REQUEST_TYPE_LOCATION_SESSION_STOP     = 2,
189     CHRE_GNSS_REQUEST_TYPE_MEASUREMENT_SESSION_START = 3,
190     CHRE_GNSS_REQUEST_TYPE_MEASUREMENT_SESSION_STOP  = 4,
191 };
192 
193 /**
194  * Constellation type associated with an SV
195  */
196 enum chreGnssConstellationType {
197     CHRE_GNSS_CONSTELLATION_UNKNOWN = 0,
198     CHRE_GNSS_CONSTELLATION_GPS     = 1,
199     CHRE_GNSS_CONSTELLATION_SBAS    = 2,
200     CHRE_GNSS_CONSTELLATION_GLONASS = 3,
201     CHRE_GNSS_CONSTELLATION_QZSS    = 4,
202     CHRE_GNSS_CONSTELLATION_BEIDOU  = 5,
203     CHRE_GNSS_CONSTELLATION_GALILEO = 6,
204 };
205 
206 /**
207  * Enumeration of available values for the chreGnssMeasurement multipath indicator
208  */
209 enum chreGnssMultipathIndicator {
210     //! The indicator is not available or unknown
211     CHRE_GNSS_MULTIPATH_INDICATOR_UNKNOWN     = 0,
212     //! The measurement is indicated to be affected by multipath
213     CHRE_GNSS_MULTIPATH_INDICATOR_PRESENT     = 1,
214     //! The measurement is indicated to be not affected by multipath
215     CHRE_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT = 2,
216 };
217 
218 /**
219  * Represents an estimate of the GNSS clock time (see the Android GPS HAL for
220  * more detailed information)
221  */
222 struct chreGnssClock {
223     //! The GNSS receiver hardware clock value in nanoseconds, including
224     //! uncertainty
225     int64_t time_ns;
226 
227     //! The difference between hardware clock inside GNSS receiver and the
228     //! estimated GNSS time in nanoseconds; contains bias uncertainty
229     int64_t full_bias_ns;
230 
231     //! Sub-nanosecond bias, adds to full_bias_ns
232     float bias_ns;
233 
234     //! The clock's drift in nanoseconds per second
235     float drift_nsps;
236 
237     //! 1-sigma uncertainty associated with the clock's bias in nanoseconds
238     float bias_uncertainty_ns;
239 
240     //! 1-sigma uncertainty associated with the clock's drift in nanoseconds
241     //! per second
242     float drift_uncertainty_nsps;
243 
244     //! While this number stays the same, timeNs should flow continuously
245     uint32_t hw_clock_discontinuity_count;
246 
247     //! A set of flags indicating the validity of the fields in this data
248     //! structure (see GNSS_CLOCK_HAS_*)
249     uint16_t flags;
250 
251     //! Reserved for future use; set to 0
252     uint8_t reserved[2];
253 };
254 
255 /**
256  * Represents a GNSS measurement; contains raw and computed information (see the
257  * Android GPS HAL for more detailed information)
258  */
259 struct chreGnssMeasurement {
260     //! Hardware time offset from time_ns for this measurement, in nanoseconds
261     int64_t time_offset_ns;
262 
263     //! Accumulated delta range since the last channel reset in micro-meters
264     int64_t accumulated_delta_range_um;
265 
266     //! Received GNSS satellite time at the time of measurement, in nanoseconds
267     int64_t received_sv_time_in_ns;
268 
269     //! 1-sigma uncertainty of received GNSS satellite time, in nanoseconds
270     int64_t received_sv_time_uncertainty_in_ns;
271 
272     //! Pseudorange rate at the timestamp in meters per second (uncorrected)
273     float pseudorange_rate_mps;
274 
275     //! 1-sigma uncertainty of pseudorange rate in meters per second
276     float pseudorange_rate_uncertainty_mps;
277 
278     //! 1-sigma uncertainty of the accumulated delta range in meters
279     float accumulated_delta_range_uncertainty_m;
280 
281     //! Carrier-to-noise density in dB-Hz, in the range of [0, 63]
282     float c_n0_dbhz;
283 
284     //! Signal to noise ratio (dB), power above observed noise at correlators
285     float snr_db;
286 
287     //! Satellite sync state flags (GNSS_MEASUREMENT_STATE_*) - sets modulus for
288     //! received_sv_time_in_ns
289     uint16_t state;
290 
291     //! Set of ADR state flags (GNSS_ADR_STATE_*)
292     uint16_t accumulated_delta_range_state;
293 
294     //! Satellite vehicle ID number
295     int16_t svid;
296 
297     //! Constellation of the given satellite vehicle
298     //! @see #chreGnssConstellationType
299     uint8_t constellation;
300 
301     //! @see #chreGnssMultipathIndicator
302     uint8_t multipath_indicator;
303 
304     //! Carrier frequency of the signal tracked in Hz.
305     //! For example, it can be the GPS central frequency for L1 = 1575.45 MHz,
306     //! or L2 = 1227.60 MHz, L5 = 1176.45 MHz, various GLO channels, etc.
307     //!
308     //! Set to CHRE_GNSS_MEASUREMENT_CARRIER_FREQUENCY_UNKNOWN if not reported.
309     //!
310     //! For an L1, L5 receiver tracking a satellite on L1 and L5 at the same
311     //! time, two chreGnssMeasurement structs must be reported for this same
312     //! satellite, in one of the measurement structs, all the values related to
313     //! L1 must be filled, and in the other all of the values related to L5
314     //! must be filled.
315     //! @since v1.4
316     float carrier_frequency_hz;
317 };
318 
319 /**
320  * Data structure sent with events associated with CHRE_EVENT_GNSS_DATA, enabled
321  * via chreGnssMeasurementSessionStartAsync()
322  */
323 struct chreGnssDataEvent {
324     //! Indicates the version of the structure, for compatibility purposes.
325     //! Clients do not normally need to worry about this field; the CHRE
326     //! implementation guarantees that it only sends the client the structure
327     //! version it expects.
328     uint8_t version;
329 
330     //! Number of chreGnssMeasurement entries included in this event. Must be in
331     //! the range [0, CHRE_GNSS_MAX_MEASUREMENT]
332     uint8_t measurement_count;
333 
334     //! Reserved for future use; set to 0
335     uint8_t reserved[6];
336 
337     struct chreGnssClock clock;
338 
339     //! Pointer to an array containing measurement_count measurements
340     const struct chreGnssMeasurement *measurements;
341 };
342 
343 /**
344  * Data structure sent with events of type CHRE_EVENT_GNSS_LOCATION, enabled via
345  * chreGnssLocationSessionStartAsync(). This is modeled after GpsLocation in the
346  * GPS HAL, but does not use the double data type.
347  */
348 struct chreGnssLocationEvent {
349     //! UTC timestamp for location fix in milliseconds since January 1, 1970
350     uint64_t timestamp;
351 
352     //! Fixed point latitude, degrees times 10^7 (roughly centimeter resolution)
353     int32_t latitude_deg_e7;
354 
355     //! Fixed point longitude, degrees times 10^7 (roughly centimeter
356     //! resolution)
357     int32_t longitude_deg_e7;
358 
359     //! Altitude in meters above the WGS 84 reference ellipsoid
360     float altitude;
361 
362     //! Horizontal speed in meters per second
363     float speed;
364 
365     //! Clockwise angle between north and current heading, in degrees; range
366     //! [0, 360)
367     float bearing;
368 
369     //! Expected horizontal accuracy in meters such that a circle with a radius
370     //! of length 'accuracy' from the latitude and longitude has a 68%
371     //! probability of including the true location.
372     float accuracy;
373 
374     //! A set of flags indicating which fields in this structure are valid.
375     //! If any fields are not available, the flag must not be set and the field
376     //! must be initialized to 0.
377     //! @see #GpsLocationFlags
378     uint16_t flags;
379 
380     //! Reserved for future use; set to 0
381     //! @since v1.3
382     uint8_t reserved[2];
383 
384     //! Expected vertical accuracy in meters such that a range of
385     //! 2 * altitude_accuracy centered around altitude has a 68% probability of
386     //! including the true altitude.
387     //! @since v1.3
388     float altitude_accuracy;
389 
390     //! Expected speed accuracy in meters per second such that a range of
391     //! 2 * speed_accuracy centered around speed has a 68% probability of
392     //! including the true speed.
393     //! @since v1.3
394     float speed_accuracy;
395 
396     //! Expected bearing accuracy in degrees such that a range of
397     //! 2 * bearing_accuracy centered around bearing has a 68% probability of
398     //! including the true bearing.
399     //! @since v1.3
400     float bearing_accuracy;
401 };
402 
403 
404 /**
405  * Retrieves a set of flags indicating the GNSS features supported by the
406  * current CHRE implementation. The value returned by this function must be
407  * consistent for the entire duration of the Nanoapp's execution.
408  *
409  * The client must allow for more flags to be set in this response than it knows
410  * about, for example if the implementation supports a newer version of the API
411  * than the client was compiled against.
412  *
413  * @return A bitmask with zero or more CHRE_GNSS_CAPABILITIES_* flags set
414  *
415  * @since v1.1
416  */
417 uint32_t chreGnssGetCapabilities(void);
418 
419 /**
420  * Nanoapps must define CHRE_NANOAPP_USES_GNSS somewhere in their build
421  * system (e.g. Makefile) if the nanoapp needs to use the following GNSS APIs.
422  * In addition to allowing access to these APIs, defining this macro will also
423  * ensure CHRE enforces that all host clients this nanoapp talks to have the
424  * required Android permissions needed to listen to GNSS data by adding metadata
425  * to the nanoapp.
426  */
427 #if defined(CHRE_NANOAPP_USES_GNSS) || !defined(CHRE_IS_NANOAPP_BUILD)
428 
429 /**
430  * Initiates a GNSS positioning session, or changes the requested interval of an
431  * existing session. If starting or modifying the session was successful, then
432  * the GNSS engine will work on determining the device's position.
433  *
434  * This result of this request is delivered asynchronously via an event of type
435  * CHRE_EVENT_GNSS_ASYNC_RESULT. Refer to the note in {@link #chreAsyncResult}
436  * for more details. If the "Location" setting is disabled at the Android level,
437  * the CHRE implementation is expected to return a result with
438  * CHRE_ERROR_FUNCTION_DISABLED.
439  *
440  * If chreGnssGetCapabilities() returns a value that does not have the
441  * CHRE_GNSS_CAPABILITIES_LOCATION flag set, then this method will return false.
442  *
443  * @param minIntervalMs The desired minimum interval between location fixes
444  *        delivered to the client via CHRE_EVENT_GNSS_LOCATION, in milliseconds.
445  *        The requesting client must allow for fixes to be delivered at shorter
446  *        or longer interval than requested. For example, adverse RF conditions
447  *        may result in fixes arriving at a longer interval, etc.
448  * @param minTimeToNextFixMs The desired minimum time to the next location fix.
449  *        If this is 0, the GNSS engine should start working on the next fix
450  *        immediately. If greater than 0, the GNSS engine should not spend
451  *        measurable power to produce a location fix until this amount of time
452  *        has elapsed.
453  * @param cookie An opaque value that will be included in the chreAsyncResult
454  *        sent in relation to this request.
455  *
456  * @return true if the request was accepted for processing, false otherwise
457  *
458  * @since v1.1
459  * @note Requires GNSS permission
460  */
461 bool chreGnssLocationSessionStartAsync(uint32_t minIntervalMs,
462                                        uint32_t minTimeToNextFixMs,
463                                        const void *cookie);
464 
465 /**
466  * Terminates an existing GNSS positioning session. If no positioning session
467  * is active at the time of this request, it is treated as if an active session
468  * was successfully ended.
469  *
470  * This result of this request is delivered asynchronously via an event of type
471  * CHRE_EVENT_GNSS_ASYNC_RESULT. Refer to the note in {@link #chreAsyncResult}
472  * for more details.
473  *
474  * After CHRE_EVENT_GNSS_ASYNC_RESULT is delivered to the client, no more
475  * CHRE_EVENT_GNSS_LOCATION events will be delievered until a new location
476  * session is started.
477  *
478  * If chreGnssGetCapabilities() returns a value that does not have the
479  * CHRE_GNSS_CAPABILITIES_LOCATION flag set, then this method will return false.
480  *
481  * @param cookie An opaque value that will be included in the chreAsyncResult
482  *        sent in relation to this request.
483  *
484  * @return true if the request was accepted for processing, false otherwise
485  *
486  * @since v1.1
487  * @note Requires GNSS permission
488  */
489 bool chreGnssLocationSessionStopAsync(const void *cookie);
490 
491 /**
492  * Initiates a request to receive raw GNSS measurements. A GNSS measurement
493  * session can exist independently of location sessions. In other words, a
494  * Nanoapp is able to receive measurements at its requested interval both with
495  * and without an active location session.
496  *
497  * This result of this request is delivered asynchronously via an event of type
498  * CHRE_EVENT_GNSS_ASYNC_RESULT. Refer to the note in {@link #chreAsyncResult}
499  * for more details. If the "Location" setting is disabled at the Android level,
500  * the CHRE implementation is expected to return a result with
501  * CHRE_ERROR_FUNCTION_DISABLED.
502  *
503  * If chreGnssGetCapabilities() returns a value that does not have the
504  * CHRE_GNSS_CAPABILITIES_MEASUREMENTS flag set, then this method will return
505  * false.
506  *
507  * @param minIntervalMs The desired minimum interval between measurement reports
508  *        delivered via CHRE_EVENT_GNSS_DATA. When requested at 1000ms or
509  *        faster, and GNSS measurements are tracked, device should report
510  *        measurements as fast as requested, and shall report no slower than
511  *        once every 1000ms, on average.
512  * @param cookie An opaque value that will be included in the chreAsyncResult
513  *        sent in relation to this request.
514  *
515  * @return true if the request was accepted for processing, false otherwise
516  *
517  * @since v1.1
518  * @note Requires GNSS permission
519  */
520 bool chreGnssMeasurementSessionStartAsync(uint32_t minIntervalMs,
521                                           const void *cookie);
522 
523 /**
524  * Terminates an existing raw GNSS measurement session. If no measurement
525  * session is active at the time of this request, it is treated as if an active
526  * session was successfully ended.
527  *
528  * This result of this request is delivered asynchronously via an event of type
529  * CHRE_EVENT_GNSS_ASYNC_RESULT. Refer to the note in {@link #chreAsyncResult}
530  * for more details.
531  *
532  * If chreGnssGetCapabilities() returns a value that does not have the
533  * CHRE_GNSS_CAPABILITIES_MEASUREMENTS flag set, then this method will return
534  * false.
535  *
536  * @param cookie An opaque value that will be included in the chreAsyncResult
537  *        sent in relation to this request.
538  *
539  * @return true if the request was accepted for processing, false otherwise
540  *
541  * @since v1.1
542  * @note Requires GNSS permission
543  */
544 bool chreGnssMeasurementSessionStopAsync(const void *cookie);
545 
546 /**
547  * Controls whether this nanoapp will passively receive GNSS-based location
548  * fixes produced as a result of location sessions initiated by other entities.
549  * This function allows a nanoapp to opportunistically receive location fixes
550  * via CHRE_EVENT_GNSS_LOCATION events without imposing additional power cost,
551  * though with no guarantees as to when or how often those events will arrive.
552  * There will be no duplication of events if a passive location listener and
553  * location session are enabled in parallel.
554  *
555  * Enabling passive location listening is not required to receive events for an
556  * active location session started via chreGnssLocationSessionStartAsync(). This
557  * setting is independent of the active location session, so modifying one does
558  * not have an effect on the other.
559  *
560  * If chreGnssGetCapabilities() returns a value that does not have the
561  * CHRE_GNSS_CAPABILITIES_LOCATION flag set or the value returned by
562  * chreGetApiVersion() is less than CHRE_API_VERSION_1_2, then this method will
563  * return false.
564  *
565  * If chreGnssGetCapabilities() includes
566  * CHRE_GNSS_CAPABILITIES_GNSS_ENGINE_BASED_PASSIVE_LISTENER, the passive
567  * registration is recorded at the GNSS engine level, so events include fixes
568  * requested by the applications processor and potentially other non-CHRE
569  * clients. If this flag is not set, then only fixes requested by other nanoapps
570  * within CHRE are provided.
571  *
572  * @param enable true to receive opportunistic location fixes, false to disable
573  *
574  * @return true if the configuration was processed successfully, false on error
575  *     or if this feature is not supported
576  *
577  * @since v1.2
578  * @note Requires GNSS permission
579  */
580 bool chreGnssConfigurePassiveLocationListener(bool enable);
581 
582 #else  /* defined(CHRE_NANOAPP_USES_GNSS) || !defined(CHRE_IS_NANOAPP_BUILD) */
583 #define CHRE_GNSS_PERM_ERROR_STRING \
584     "CHRE_NANOAPP_USES_GNSS must be defined when building this nanoapp in " \
585     "order to refer to "
586 #define chreGnssLocationSessionStartAsync(...) \
587     CHRE_BUILD_ERROR(CHRE_GNSS_PERM_ERROR_STRING \
588                      "chreGnssLocationSessionStartAsync")
589 #define chreGnssLocationSessionStopAsync(...) \
590     CHRE_BUILD_ERROR(CHRE_GNSS_PERM_ERROR_STRING \
591                      "chreGnssLocationSessionStopAsync")
592 #define chreGnssMeasurementSessionStartAsync(...) \
593     CHRE_BUILD_ERROR(CHRE_GNSS_PERM_ERROR_STRING \
594                      "chreGnssMeasurementSessionStartAsync")
595 #define chreGnssMeasurementSessionStopAsync(...) \
596     CHRE_BUILD_ERROR(CHRE_GNSS_PERM_ERROR_STRING \
597                      "chreGnssMeasurementSessionStopAsync")
598 #define chreGnssConfigurePassiveLocationListener(...) \
599     CHRE_BUILD_ERROR(CHRE_GNSS_PERM_ERROR_STRING \
600                      "chreGnssConfigurePassiveLocationListener")
601 #endif  /* defined(CHRE_NANOAPP_USES_GNSS) || !defined(CHRE_IS_NANOAPP_BUILD) */
602 
603 #ifdef __cplusplus
604 }
605 #endif
606 
607 #endif  /* _CHRE_GNSS_H_ */
608