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