Android’s Context Hub Runtime Environment (CHRE)

Android’s context hub enables the use of nanoapps. A single nanoapp has 3 entry points seen in chre_api/chre/nanoapp.h:

  • A nanoappStart function used to notify the nanoapp that it is now active.

  • A nanoappHandleEvent function used to notify the nanoapp tha an event of interest took place.

  • A nanoappEnd function used to notify the nanoapp that it is now deactivated.

The CHRE connects to several frameworks called Platform Abstraction Layers (PAL)s. Note that currently, none of these are implemented for Zephyr, but they are scheduled to be added. These frameworks include:

  1. Audio - a framework allowing nanoapps to get audio events. See pal/audio.h for API details.

  2. GNSS - a framework allowing nanoapps to manage location and measurement sessions. See pal/gnss.h for API details.

  3. Sensor - a framework allowing nanoapps to request changes to sensors configuration get data/bias events. See pal/sensor.h for API details.

  4. System - a framework allowing nanoapps to make common system requests such as logging, clock, and some basic memory allocation/deallocation. See pal/system.h for API details.

  5. WiFi - a framework allowing nanoapps to interact with the on board WiFi. See pal/wifi.h for API details.

  6. WWAN - a framework allowing nanoapps to interact with the WWAN module such as getting the current capabilities and info. See pal/wwan.h for API details.

Building and expectations

To build the sample use the following west command:

# From the root of the zephyr repository
west build -b native_posix samples/modules/chre

Once built and run, the sample application should:

  1. Print a hello message

  2. Notify that the event loop started via an inf level log

  3. Notify that a nanoapp was started and assigned an instance/app ID of 1 via a dbg level log

  4. Print a message saying that the nanoapp’s start callback was called

  5. Send an event of type 1 and no data to the nanoapp

  6. Notify that the event was processed

  7. Call the nanoappEnd function of the nanoapp

  8. Print a message notifying that it’s not possible to remove a system level nanoapp

  9. Exit the event loop


  1. Add an implementation of the pal/sensor.h and pal/system.h to Zephyr. These will be standalone modules that can be used independently of CHRE, but when CONFIG_CHRE is enabled will also provide an implementation of chrePalSensorGetApi() and struct chrePalSystemApi.

  2. Add a directory chre/nanoapps which will host various nanoapps to be used by the Zephyr community. These should each have their own Kconfig to enable them and set the appropriate dependencies. The first nanoapp will be a lid angle calculator which will use 2 accelerometers.

  3. Update the overlay.dts of this sample application to include 2 emulated accelerometers and configure them to return scripted data.

  4. Run this sample application and watch the nanoapp provide lid angle calculations based on 2 accelerometers provided by the sensors PAL framework.