• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _CHRE_EVENT_H_
18 #define _CHRE_EVENT_H_
19 
20 /**
21  * @file
22  * Context Hub Runtime Environment API dealing with events and messages.
23  */
24 
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 
29 #include <chre/toolchain.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * The CHRE implementation is required to provide the following preprocessor
37  * defines via the build system.
38  *
39  * CHRE_MESSAGE_TO_HOST_MAX_SIZE: The maximum size, in bytes, allowed for
40  *     a message sent to chreSendMessageToHostEndpoint().  This must be at least
41  *     CHRE_MESSAGE_TO_HOST_MINIMUM_MAX_SIZE.
42  */
43 
44 #ifndef CHRE_MESSAGE_TO_HOST_MAX_SIZE
45 #error CHRE_MESSAGE_TO_HOST_MAX_SIZE must be defined by the CHRE implementation
46 #endif
47 
48 /**
49  * The minimum size, in bytes, any CHRE implementation will use for
50  * CHRE_MESSAGE_TO_HOST_MAX_SIZE is set to 1000 for v1.5+ CHRE implementations,
51  * and 128 for v1.0-v1.4 implementations (previously kept in
52  * CHRE_MESSAGE_TO_HOST_MINIMUM_MAX_SIZE, which has been removed).
53  *
54  * All CHRE implementations supporting v1.5+ must support the raised limit of
55  * 1000 bytes, however a nanoapp compiled against v1.5 cannot assume this
56  * limit if there is a possibility their binary will run on a v1.4 or earlier
57  * implementation that had a lower limit. To allow for nanoapp compilation in
58  * these situations, CHRE_MESSAGE_TO_HOST_MAX_SIZE must be set to the minimum
59  * value the nanoapp may encounter, and CHRE_NANOAPP_SUPPORTS_PRE_V1_5 can be
60  * defined to skip the compile-time check.
61  */
62 #if (!defined(CHRE_NANOAPP_SUPPORTS_PRE_V1_5) && \
63      CHRE_MESSAGE_TO_HOST_MAX_SIZE < 1000) ||    \
64     (defined(CHRE_NANOAPP_SUPPORTS_PRE_V1_5) &&  \
65      CHRE_MESSAGE_TO_HOST_MAX_SIZE < 128)
66 #error CHRE_MESSAGE_TO_HOST_MAX_SIZE is too small.
67 #endif
68 
69 /**
70  * The lowest numerical value legal for a user-defined event.
71  *
72  * The system reserves all event values from 0 to 0x7FFF, inclusive.
73  * User events may use any value in the range 0x8000 to 0xFFFF, inclusive.
74  *
75  * Note that the same event values might be used by different nanoapps
76  * for different meanings.  This is not a concern, as these values only
77  * have meaning when paired with the originating nanoapp.
78  */
79 #define CHRE_EVENT_FIRST_USER_VALUE  UINT16_C(0x8000)
80 
81 /**
82  * nanoappHandleEvent argument: struct chreMessageFromHostData
83  *
84  * The format of the 'message' part of this structure is left undefined,
85  * and it's up to the nanoapp and host to have an established protocol
86  * beforehand.
87  */
88 #define CHRE_EVENT_MESSAGE_FROM_HOST  UINT16_C(0x0001)
89 
90 /**
91  * nanoappHandleEvent argument: 'cookie' given to chreTimerSet() method.
92  *
93  * Indicates that a timer has elapsed, in accordance with how chreTimerSet() was
94  * invoked.
95  */
96 #define CHRE_EVENT_TIMER  UINT16_C(0x0002)
97 
98 /**
99  * nanoappHandleEvent argument: struct chreNanoappInfo
100  *
101  * Indicates that a nanoapp has successfully started (its nanoappStart()
102  * function has been called, and it returned true) and is able to receive events
103  * sent via chreSendEvent().  Note that this event is not sent for nanoapps that
104  * were started prior to the current nanoapp - use chreGetNanoappInfo() to
105  * determine if another nanoapp is already running.
106  *
107  * @see chreConfigureNanoappInfoEvents
108  * @since v1.1
109  */
110 #define CHRE_EVENT_NANOAPP_STARTED  UINT16_C(0x0003)
111 
112 /**
113  * nanoappHandleEvent argument: struct chreNanoappInfo
114  *
115  * Indicates that a nanoapp has stopped executing and is no longer able to
116  * receive events sent via chreSendEvent().  Any events sent prior to receiving
117  * this event are not guaranteed to have been delivered.
118  *
119  * @see chreConfigureNanoappInfoEvents
120  * @since v1.1
121  */
122 #define CHRE_EVENT_NANOAPP_STOPPED  UINT16_C(0x0004)
123 
124 /**
125  * nanoappHandleEvent argument: NULL
126  *
127  * Indicates that CHRE has observed the host wake from low-power sleep state.
128  *
129  * @see chreConfigureHostSleepStateEvents
130  * @since v1.2
131  */
132 #define CHRE_EVENT_HOST_AWAKE  UINT16_C(0x0005)
133 
134 /**
135  * nanoappHandleEvent argument: NULL
136  *
137  * Indicates that CHRE has observed the host enter low-power sleep state.
138  *
139  * @see chreConfigureHostSleepStateEvents
140  * @since v1.2
141  */
142 #define CHRE_EVENT_HOST_ASLEEP  UINT16_C(0x0006)
143 
144 /**
145  * nanoappHandleEvent argument: NULL
146  *
147  * Indicates that CHRE is collecting debug dumps. Nanoapps can call
148  * chreDebugDumpLog() to log their debug data while handling this event.
149  *
150  * @see chreConfigureDebugDumpEvent
151  * @see chreDebugDumpLog
152  * @since v1.4
153  */
154 #define CHRE_EVENT_DEBUG_DUMP  UINT16_C(0x0007)
155 
156 /**
157  * First possible value for CHRE_EVENT_SENSOR events.
158  *
159  * This allows us to separately define our CHRE_EVENT_SENSOR_* events in
160  * chre/sensor.h, without fear of collision with other event values.
161  */
162 #define CHRE_EVENT_SENSOR_FIRST_EVENT  UINT16_C(0x0100)
163 
164 /**
165  * Last possible value for CHRE_EVENT_SENSOR events.
166  *
167  * This allows us to separately define our CHRE_EVENT_SENSOR_* events in
168  * chre/sensor.h, without fear of collision with other event values.
169  */
170 #define CHRE_EVENT_SENSOR_LAST_EVENT  UINT16_C(0x02FF)
171 
172 /**
173  * First event in the block reserved for GNSS. These events are defined in
174  * chre/gnss.h.
175  */
176 #define CHRE_EVENT_GNSS_FIRST_EVENT  UINT16_C(0x0300)
177 #define CHRE_EVENT_GNSS_LAST_EVENT   UINT16_C(0x030F)
178 
179 /**
180  * First event in the block reserved for WiFi. These events are defined in
181  * chre/wifi.h.
182  */
183 #define CHRE_EVENT_WIFI_FIRST_EVENT  UINT16_C(0x0310)
184 #define CHRE_EVENT_WIFI_LAST_EVENT   UINT16_C(0x031F)
185 
186 /**
187  * First event in the block reserved for WWAN. These events are defined in
188  * chre/wwan.h.
189  */
190 #define CHRE_EVENT_WWAN_FIRST_EVENT  UINT16_C(0x0320)
191 #define CHRE_EVENT_WWAN_LAST_EVENT   UINT16_C(0x032F)
192 
193 /**
194  * First event in the block reserved for audio. These events are defined in
195  * chre/audio.h.
196  */
197 
198 #define CHRE_EVENT_AUDIO_FIRST_EVENT UINT16_C(0x0330)
199 #define CHRE_EVENT_AUDIO_LAST_EVENT  UINT16_C(0x033F)
200 
201 /**
202  * First event in the block reserved for settings changed notifications.
203  * These events are defined in chre/user_settings.h
204  *
205  * @since v1.5
206  */
207 #define CHRE_EVENT_SETTING_CHANGED_FIRST_EVENT UINT16_C(0x340)
208 #define CHRE_EVENT_SETTING_CHANGED_LAST_EVENT  UINT16_C(0x34F)
209 
210 /**
211  * First in the extended range of values dedicated for internal CHRE
212  * implementation usage.
213  *
214  * This range is semantically the same as the internal event range defined
215  * below, but has been extended to allow for more implementation-specific events
216  * to be used.
217  *
218  * @since v1.1
219  */
220 #define CHRE_EVENT_INTERNAL_EXTENDED_FIRST_EVENT  UINT16_C(0x7000)
221 
222 /**
223  * First in a range of values dedicated for internal CHRE implementation usage.
224  *
225  * If a CHRE wishes to use events internally, any values within this range
226  * are assured not to be taken by future CHRE API additions.
227  */
228 #define CHRE_EVENT_INTERNAL_FIRST_EVENT  UINT16_C(0x7E00)
229 
230 /**
231  * Last in a range of values dedicated for internal CHRE implementation usage.
232  *
233  * If a CHRE wishes to use events internally, any values within this range
234  * are assured not to be taken by future CHRE API additions.
235  */
236 #define CHRE_EVENT_INTERNAL_LAST_EVENT  UINT16_C(0x7FFF)
237 
238 /**
239  * A special value for the hostEndpoint argument in
240  * chreSendMessageToHostEndpoint() that indicates that the message should be
241  * delivered to all host endpoints.  This value will not be used in the
242  * hostEndpoint field of struct chreMessageFromHostData supplied with
243  * CHRE_EVENT_MESSAGE_FROM_HOST.
244  *
245  * @since v1.1
246  */
247 #define CHRE_HOST_ENDPOINT_BROADCAST  UINT16_C(0xFFFF)
248 
249 /**
250  * A special value for hostEndpoint in struct chreMessageFromHostData that
251  * indicates that a host endpoint is unknown or otherwise unspecified.  This
252  * value may be received in CHRE_EVENT_MESSAGE_FROM_HOST, but it is not valid to
253  * provide it to chreSendMessageToHostEndpoint().
254  *
255  * @since v1.1
256  */
257 #define CHRE_HOST_ENDPOINT_UNSPECIFIED  UINT16_C(0xFFFE)
258 
259 /**
260  * Bitmask values that can be given as input to the messagePermissions parameter
261  * of chreSendMessageWithPermissions(). These values are typically used by
262  * nanoapps when they used data from the corresponding CHRE APIs to produce the
263  * message contents being sent and is used to attribute permissions usage on
264  * the Android side. See chreSendMessageWithPermissions() for more details on
265  * how these values are used when sending a message.
266  *
267  * Values in the range
268  * [CHRE_MESSAGE_PERMISSION_VENDOR_START, CHRE_MESSAGE_PERMISSION_VENDOR_END]
269  * are reserved for vendors to use when adding support for permission-gated APIs
270  * in their implementations.
271  *
272  * On the Android side, CHRE permissions are mapped as follows:
273  * - CHRE_MESSAGE_PERMISSION_AUDIO: android.permission.RECORD_AUDIO
274  * - CHRE_MESSAGE_PERMISSION_GNSS, CHRE_MESSAGE_PERMISSION_WIFI, and
275  *   CHRE_MESSAGE_PERMISSION_WWAN: android.permission.ACCESS_FINE_LOCATION, and
276  *   android.permissions.ACCESS_BACKGROUND_LOCATION
277  *
278  * @since v1.5
279  *
280  * @defgroup CHRE_MESSAGE_PERMISSION
281  * @{
282  */
283 
284 #define CHRE_MESSAGE_PERMISSION_NONE UINT32_C(0)
285 #define CHRE_MESSAGE_PERMISSION_AUDIO UINT32_C(1)
286 #define CHRE_MESSAGE_PERMISSION_GNSS (UINT32_C(1) << 1)
287 #define CHRE_MESSAGE_PERMISSION_WIFI (UINT32_C(1) << 2)
288 #define CHRE_MESSAGE_PERMISSION_WWAN (UINT32_C(1) << 3)
289 #define CHRE_MESSAGE_PERMISSION_VENDOR_START (UINT32_C(1) << 24)
290 #define CHRE_MESSAGE_PERMISSION_VENDOR_END (UINT32_C(1) << 31)
291 
292 /** @} */
293 
294 /**
295  * Data provided with CHRE_EVENT_MESSAGE_FROM_HOST.
296  */
297 struct chreMessageFromHostData {
298     /**
299      * Message type supplied by the host.
300      *
301      * @note In CHRE API v1.0, support for forwarding this field from the host
302      * was not strictly required, and some implementations did not support it.
303      * However, its support is mandatory as of v1.1.
304      */
305     union {
306         /**
307          * The preferred name to use when referencing this field.
308          *
309          * @since v1.1
310          */
311         uint32_t messageType;
312 
313         /**
314          * @deprecated This is the name for the messageType field used in v1.0.
315          * Left to allow code to compile against both v1.0 and v1.1 of the API
316          * definition without needing to use #ifdefs. This will be removed in a
317          * future API update - use messageType instead.
318          */
319         uint32_t reservedMessageType;
320     };
321 
322     /**
323      * The size, in bytes of the following 'message'.
324      *
325      * This can be 0.
326      */
327     uint32_t messageSize;
328 
329     /**
330      * The message from the host.
331      *
332      * These contents are of a format that the host and nanoapp must have
333      * established beforehand.
334      *
335      * This data is 'messageSize' bytes in length.  Note that if 'messageSize'
336      * is 0, this might be NULL.
337      */
338     const void *message;
339 
340     /**
341      * An identifier for the host-side entity that sent this message.  Unless
342      * this is set to CHRE_HOST_ENDPOINT_UNSPECIFIED, it can be used in
343      * chreSendMessageToHostEndpoint() to send a directed reply that will only
344      * be received by the given entity on the host.  Endpoint identifiers are
345      * opaque values assigned at runtime, so they cannot be assumed to always
346      * describe a specific entity across restarts.
347      *
348      * If running on a CHRE API v1.0 implementation, this field will always be
349      * set to CHRE_HOST_ENDPOINT_UNSPECIFIED.
350      *
351      * @since v1.1
352      */
353     uint16_t hostEndpoint;
354 };
355 
356 /**
357  * Provides metadata for a nanoapp in the system.
358  */
359 struct chreNanoappInfo {
360     /**
361      * Nanoapp identifier. The convention for populating this value is to set
362      * the most significant 5 bytes to a value that uniquely identifies the
363      * vendor, and the lower 3 bytes identify the nanoapp.
364      */
365     uint64_t appId;
366 
367     /**
368      * Nanoapp version.  The semantics of this field are defined by the nanoapp,
369      * however nanoapps are recommended to follow the same scheme used for the
370      * CHRE version exposed in chreGetVersion().  That is, the most significant
371      * byte represents the major version, the next byte the minor version, and
372      * the lower two bytes the patch version.
373      */
374     uint32_t version;
375 
376     /**
377      * The instance ID of this nanoapp, which can be used in chreSendEvent() to
378      * address an event specifically to this nanoapp.  This identifier is
379      * guaranteed to be unique among all nanoapps in the system.
380      */
381     uint32_t instanceId;
382 };
383 
384 /**
385  * Callback which frees data associated with an event.
386  *
387  * This callback is (optionally) provided to the chreSendEvent() method as
388  * a means for freeing the event data and performing any other cleanup
389  * necessary when the event is completed.  When this callback is invoked,
390  * 'eventData' is no longer needed and can be released.
391  *
392  * @param eventType  The 'eventType' argument from chreSendEvent().
393  * @param eventData  The 'eventData' argument from chreSendEvent().
394  *
395  * @see chreSendEvent
396  */
397 typedef void (chreEventCompleteFunction)(uint16_t eventType, void *eventData);
398 
399 /**
400  * Callback which frees a message.
401  *
402  * This callback is (optionally) provided to the chreSendMessageToHostEndpoint()
403  * method as a means for freeing the message.  When this callback is invoked,
404  * 'message' is no longer needed and can be released.  Note that this in
405  * no way assures that said message did or did not make it to the host, simply
406  * that this memory is no longer needed.
407  *
408  * @param message  The 'message' argument from chreSendMessageToHostEndpoint().
409  * @param messageSize  The 'messageSize' argument from
410  *     chreSendMessageToHostEndpoint().
411  *
412  * @see chreSendMessageToHostEndpoint
413  */
414 typedef void (chreMessageFreeFunction)(void *message, size_t messageSize);
415 
416 
417 /**
418  * Enqueue an event to be sent to another nanoapp.
419  *
420  * @param eventType  This is a user-defined event type, of at least the
421  *     value CHRE_EVENT_FIRST_USER_VALUE.  It is illegal to attempt to use any
422  *     of the CHRE_EVENT_* values reserved for the CHRE.
423  * @param eventData  A pointer value that will be understood by the receiving
424  *     app.  Note that NULL is perfectly acceptable.  It also is not required
425  *     that this be a valid pointer, although if this nanoapp is intended to
426  *     work on arbitrary CHRE implementations, then the size of a
427  *     pointer cannot be assumed to be a certain size.  Note that the caller
428  *     no longer owns this memory after the call.
429  * @param freeCallback  A pointer to a callback function.  After the lifetime
430  *     of 'eventData' is over (either through successful delivery or the event
431  *     being dropped), this callback will be invoked.  This argument is allowed
432  *     to be NULL, in which case no callback will be invoked.
433  * @param targetInstanceId  The ID of the instance we're delivering this event
434  *     to.  Note that this is allowed to be our own instance.  The instance ID
435  *     of a nanoapp can be retrieved by using chreGetNanoappInfoByInstanceId().
436  * @return true if the event was enqueued, false otherwise.  Note that even
437  *     if this method returns 'false', the 'freeCallback' will be invoked,
438  *     if non-NULL.  Note in the 'false' case, the 'freeCallback' may be
439  *     invoked directly from within chreSendEvent(), so it's necessary
440  *     for nanoapp authors to avoid possible recursion with this.
441  *
442  * @see chreEventDataFreeFunction
443  */
444 bool chreSendEvent(uint16_t eventType, void *eventData,
445                    chreEventCompleteFunction *freeCallback,
446                    uint32_t targetInstanceId);
447 
448 /**
449  * Send a message to the host, using the broadcast endpoint
450  * CHRE_HOST_ENDPOINT_BROADCAST.  Refer to chreSendMessageToHostEndpoint() for
451  * further details.
452  *
453  * @see chreSendMessageToHostEndpoint
454  *
455  * @deprecated New code should use chreSendMessageToHostEndpoint() instead of
456  * this function.  A future update to the API may cause references to this
457  * function to produce a compiler warning.
458  */
459 bool chreSendMessageToHost(void *message, uint32_t messageSize,
460                            uint32_t messageType,
461                            chreMessageFreeFunction *freeCallback)
462     CHRE_DEPRECATED("Use chreSendMessageToHostEndpoint instead");
463 
464 /**
465  * Send a message to the host, using CHRE_MESSAGE_PERMISSION_NONE for the
466  * associated message permissions. This method must only be used if no data
467  * provided by CHRE's audio, GNSS, WiFi, and WWAN APIs was used to produce the
468  * contents of the message being sent. Refer to chreSendMessageWithPermissions()
469  * for further details.
470  *
471  * @see chreSendMessageWithPermissions
472  *
473  * @since v1.1
474  */
475 bool chreSendMessageToHostEndpoint(void *message, size_t messageSize,
476                                    uint32_t messageType, uint16_t hostEndpoint,
477                                    chreMessageFreeFunction *freeCallback);
478 
479 /**
480  * Send a message to the host, waking it up if it is currently asleep.
481  *
482  * This message is by definition arbitrarily defined.  Since we're not
483  * just a passing a pointer to memory around the system, but need to copy
484  * this into various buffers to send it to the host, the CHRE
485  * implementation cannot be asked to support an arbitrarily large message
486  * size.  As a result, we have the CHRE implementation define
487  * CHRE_MESSAGE_TO_HOST_MAX_SIZE.
488  *
489  * CHRE_MESSAGE_TO_HOST_MAX_SIZE is not given a value by the Platform API.  The
490  * Platform API does define CHRE_MESSAGE_TO_HOST_MINIMUM_MAX_SIZE, and requires
491  * that CHRE_MESSAGE_TO_HOST_MAX_SIZE is at least that value.
492  *
493  * As a result, if your message sizes are all less than
494  * CHRE_MESSAGE_TO_HOST_MINIMUM_MAX_SIZE, then you have no concerns on any
495  * CHRE implementation.  If your message sizes are larger, you'll need to
496  * come up with a strategy for splitting your message across several calls
497  * to this method.  As long as that strategy works for
498  * CHRE_MESSAGE_TO_HOST_MINIMUM_MAX_SIZE, it will work across all CHRE
499  * implementations (although on some implementations less calls to this
500  * method may be necessary).
501  *
502  * When sending a message to the host, the ContextHub service will enforce
503  * the host client has been granted Android-level permissions corresponding to
504  * the ones the nanoapp declares it uses through CHRE_NANOAPP_USES_AUDIO, etc.
505  * In addition to this, the permissions bitmask provided as input to this method
506  * results in the Android framework using app-ops to verify and log access upon
507  * message delivery to an application. This is primarily useful for ensuring
508  * accurate attribution for messages generated using permission-controlled data.
509  * The bitmask declared by the nanoapp for this message must be a
510  * subset of the permissions it declared it would use at build time or the
511  * message will be rejected.
512  *
513  * Nanoapps must use this method if the data they are sending contains or was
514  * derived from any data sampled through CHRE's audio, GNSS, WiFi, or WWAN APIs.
515  * Additionally, if vendors add APIs to expose data that would be guarded by a
516  * permission in Android, vendors must support declaring a message permission
517  * through this method.
518  *
519  * @param message  Pointer to a block of memory to send to the host.
520  *     NULL is acceptable only if messageSize is 0.  If non-NULL, this
521  *     must be a legitimate pointer (that is, unlike chreSendEvent(), a small
522  *     integral value cannot be cast to a pointer for this).  Note that the
523  *     caller no longer owns this memory after the call.
524  * @param messageSize  The size, in bytes, of the given message. If this exceeds
525  *     CHRE_MESSAGE_TO_HOST_MAX_SIZE, the message will be rejected.
526  * @param messageType  Message type sent to the app on the host.
527  *     NOTE: In CHRE API v1.0, support for forwarding this field to the host was
528  *     not strictly required, and some implementations did not support it.
529  *     However, its support is mandatory as of v1.1.
530  * @param hostEndpoint  An identifier for the intended recipient of the message,
531  *     or CHRE_HOST_ENDPOINT_BROADCAST if all registered endpoints on the host
532  *     should receive the message.  Endpoint identifiers are assigned on the
533  *     host side, and nanoapps may learn of the host endpoint ID of an intended
534  *     recipient via an initial message sent by the host.  This parameter is
535  *     always treated as CHRE_HOST_ENDPOINT_BROADCAST if running on a CHRE API
536  *     v1.0 implementation. CHRE_HOST_ENDPOINT_BROADCAST isn't allowed to be
537  *     specified if anything other than CHRE_MESSAGE_PERMISSION_NONE is given
538  *     as messagePermissions since doing so would potentially attribute
539  *     permissions usage to host clients that don't intend to consume the data.
540  * @param messagePermissions Bitmasked CHRE_MESSAGE_PERMISSION_ values that will
541  *     be converted to corresponding Android-level permissions and attributed
542  *     the host endpoint upon consumption of the message.
543  * @param freeCallback  A pointer to a callback function.  After the lifetime
544  *     of 'message' is over (which does not assure that 'message' made it to
545  *     the host, just that the transport layer no longer needs this memory),
546  *     this callback will be invoked.  This argument is allowed
547  *     to be NULL, in which case no callback will be invoked.
548  * @return true if the message was accepted for transmission, false otherwise.
549  *     Note that even if this method returns 'false', the 'freeCallback' will
550  *     be invoked, if non-NULL.  In either case, the 'freeCallback' may be
551  *     invoked directly from within chreSendMessageToHostEndpoint(), so it's
552  *     necessary for nanoapp authors to avoid possible recursion with this.
553  *
554  * @see chreMessageFreeFunction
555  *
556  * @since v1.5
557  */
558 bool chreSendMessageWithPermissions(void *message, size_t messageSize,
559                                     uint32_t messageType, uint16_t hostEndpoint,
560                                     uint32_t messagePermissions,
561                                     chreMessageFreeFunction *freeCallback);
562 
563 /**
564  * Queries for information about a nanoapp running in the system.
565  *
566  * In the current API, appId is required to be unique, i.e. there cannot be two
567  * nanoapps running concurrently with the same appId.  If this restriction is
568  * removed in a future API version and multiple instances of the same appId are
569  * present, this function must always return the first app to start.
570  *
571  * @param appId Identifier for the nanoapp that the caller is requesting
572  *     information about.
573  * @param info Output parameter.  If this function returns true, this structure
574  *     will be populated with details of the specified nanoapp.
575  * @return true if a nanoapp with the given ID is currently running, and the
576  *     supplied info parameter was populated with its information.
577  *
578  * @since v1.1
579  */
580 bool chreGetNanoappInfoByAppId(uint64_t appId, struct chreNanoappInfo *info);
581 
582 /**
583  * Queries for information about a nanoapp running in the system, using the
584  * runtime unique identifier.  This method can be used to get information about
585  * the sender of an event.
586  *
587  * @param instanceId
588  * @param info Output parameter.  If this function returns true, this structure
589  *     will be populated with details of the specified nanoapp.
590  * @return true if a nanoapp with the given instance ID is currently running,
591  *     and the supplied info parameter was populated with its information.
592  *
593  * @since v1.1
594  */
595 bool chreGetNanoappInfoByInstanceId(uint32_t instanceId,
596                                     struct chreNanoappInfo *info);
597 
598 /**
599  * Configures whether this nanoapp will be notified when other nanoapps in the
600  * system start and stop, via CHRE_EVENT_NANOAPP_STARTED and
601  * CHRE_EVENT_NANOAPP_STOPPED.  These events are disabled by default, and if a
602  * nanoapp is not interested in interacting with other nanoapps, then it does
603  * not need to register for them.  However, if inter-nanoapp communication is
604  * desired, nanoapps are recommended to call this function from nanoappStart().
605  *
606  * If running on a CHRE platform that only supports v1.0 of the CHRE API, this
607  * function has no effect.
608  *
609  * @param enable true to enable these events, false to disable
610  *
611  * @see CHRE_EVENT_NANOAPP_STARTED
612  * @see CHRE_EVENT_NANOAPP_STOPPED
613  *
614  * @since v1.1
615  */
616 void chreConfigureNanoappInfoEvents(bool enable);
617 
618 /**
619  * Configures whether this nanoapp will be notified when the host (applications
620  * processor) transitions between wake and sleep, via CHRE_EVENT_HOST_AWAKE and
621  * CHRE_EVENT_HOST_ASLEEP.  As chreSendMessageToHostEndpoint() wakes the host if
622  * it is asleep, these events can be used to opportunistically send data to the
623  * host only when it wakes up for some other reason.  Note that this event is
624  * not instantaneous - there is an inherent delay in CHRE observing power state
625  * changes of the host processor, which may be significant depending on the
626  * implementation, especially in the wake to sleep direction.  Therefore,
627  * nanoapps are not guaranteed that messages sent to the host between AWAKE and
628  * ASLEEP events will not trigger a host wakeup.  However, implementations must
629  * ensure that the nominal wake-up notification latency is strictly less than
630  * the minimum wake-sleep time of the host processor.  Implementations are also
631  * encouraged to minimize this and related latencies where possible, to avoid
632  * unnecessary host wake-ups.
633  *
634  * These events are only sent on transitions, so the initial state will not be
635  * sent to the nanoapp as an event - use chreIsHostAwake().
636  *
637  * @param enable true to enable these events, false to disable
638  *
639  * @see CHRE_EVENT_HOST_AWAKE
640  * @see CHRE_EVENT_HOST_ASLEEP
641  *
642  * @since v1.2
643  */
644 void chreConfigureHostSleepStateEvents(bool enable);
645 
646 /**
647  * Retrieves the current sleep/wake state of the host (applications processor).
648  * Note that, as with the CHRE_EVENT_HOST_AWAKE and CHRE_EVENT_HOST_ASLEEP
649  * events, there is no guarantee that CHRE's view of the host processor's sleep
650  * state is instantaneous, and it may also change between querying the state and
651  * performing a host-waking action like sending a message to the host.
652  *
653  * @return true if by CHRE's own estimation the host is currently awake,
654  *     false otherwise
655  *
656  * @since v1.2
657  */
658 bool chreIsHostAwake(void);
659 
660 /**
661  * Configures whether this nanoapp will be notified when CHRE is collecting
662  * debug dumps, via CHRE_EVENT_DEBUG_DUMP. This event is disabled by default,
663  * and if a nanoapp is not interested in logging its debug data, then it does
664  * not need to register for it.
665  *
666  * @param enable true to enable receipt of this event, false to disable.
667  *
668  * @see CHRE_EVENT_DEBUG_DUMP
669  * @see chreDebugDumpLog
670  *
671  * @since v1.4
672  */
673 void chreConfigureDebugDumpEvent(bool enable);
674 
675 #ifdef __cplusplus
676 }
677 #endif
678 
679 #endif  /* _CHRE_EVENT_H_ */
680 
681