Implementing the Service

Stay organized with collections Save and categorize content based on your preferences.

To prepare for the HAL implementation, you can generate basic ConfigStore interface code, then modify it to meet your needs.

Generating interface code

To generate boilerplate code for the interface, run hidl-gen. For example, to generate code for surfaceflinger:

hidl-gen -o hardware/interfaces/configstore/1.0/default \
    -Lc++-impl \
    -randroid.hardware:hardware/interfaces \
    -randroid.hidl:system/libhidl/transport \


Next, modify the file to add the implementation file (<modulename>Configs.cpp) to LOCAL_SRC_FILES and to map build flags into macro definitions. For example, you can modify surfaceflinger in hardware/interface/configstore/1.0/default/

LOCAL_SRC_FILES += SurfaceFlingerConfigs.cpp


If includes several ifeq-endif blocks, consider moving your code into a new file (that is, then include that file from

Implementing functions

To fill the functions to implement the HAL, call back the _hidl_cb function with different values (conditioned on build flags). For example, you can fill the functions for surfaceflinger in hardware/interfaces/configstore/1.0/default/SurfaceFlingerConfigs.cpp:

Return<void> SurfaceFlingerConfigs::numFramebufferSurfaceBuffers(
        numFramebufferSurfaceBuffers_cb _hidl_cb) {

Return<void> SurfaceFlingerConfigs::runWithoutSyncFramework(
        runWithoutSyncFramework_cb _hidl_cb) {
    _hidl_cb({true /* specified */, true /* value */});
    // when macro not defined, we can give any value to the second argument.
    // It will simply be ignored in the framework side.
    _hidl_cb({false /* specified */, false /* value */});

Ensure that the implementation doesn't contain a function named HIDL_FETCH_interface-name (for example, HIDL_FETCH_ISurfaceFlingerConfigs). This function is needed for HIDL passthrough mode, which is unused (and prohibited) by configstore. ConfigStore must always run in binderized mode.

Registering as a service

Finally, register all interface implementations to the configstore service. For example, you can register surfaceflinger implementations in hardware/interfaces/configstore/1.0/default/service.cpp:

configureRpcThreadpool(maxThreads, true);
sp<ISurfaceFlingerConfigs> surfaceFlingerConfigs = new SurfaceFlingerConfigs;
status_t status = surfaceFlingerConfigs->registerAsService();

sp<IBluetoothConfigs> bluetoothConfigs = new BluetoothConfigs;
status = bluetoothConfigs->registerAsService();

// register more interfaces here

Ensuring early access

To ensure that a framework module can get early access the HAL service, the config HAL service should start as early as possible, just after hwservicemanager is ready. As the config HAL service doesn't read external files, it's expected to be ready quickly after it's launched.