You can add new ConfigStore items (i.e., interface methods) for an
existing interface class. If the interface class is not defined, you must add a
new class before you can add a ConfigStore item for that class. This section
uses the example of a disableInitBlank
configuration item for
healthd
being added to the IChargerConfigs
interface
class.
Note: Before continuing, ensure you are familiar with general HIDL concepts, HIDL C++ development workflow, HIDL Code Style, and ConfigStore design.
If no interface class is defined for the interface method you want to add, you must first add the interface class before you can add the associated ConfigStore items.
hardware/interfaces/configstore/1.0
. For
example, in
hardware/interfaces/configstore/1.0/IChargerConfigs.hal
:
package android.hardware.configstore@1.0; interface IChargerConfigs { // TO-BE-FILLED-BELOW };
Android.bp
and Android.mk
for ConfigStore
shared library and header files to include the new interface HAL. For example:
These commands updatehidl-gen -o hardware/interfaces/configstore/1.0/default -Lmakefile -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.configstore@1.0::IChargerConfigs
hidl-gen -o hardware/interfaces/configstore/1.0/default -Landroidbp -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.configstore@1.0::IChargerConfigs
Android.bp
and Android.mk
in
hardware/interfaces/configstore/1.0
.hidl-gen -o hardware/interfaces/configstore/1.0/default -Lc++-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.configstore@1.0::IChargerConfigsThis command creates two files,
ChargerConfigs.h
and
ChargerConfigs.cpp
, in
hardware/interfaces/configstore/1.0/default
.HIDL_FETCH_name
(e.g.,
HIDL_FETCH_IChargerConfigs
). This function is needed for HIDL
passthrough mode, which is unused by ConfigStore.hardware/interfaces/configstore/1.0/default/service.cpp
:
#include <android/hardware/configstore/1.0/IChargerConfigs.h> #include "ChargerConfigs.h" using android::hardware::configstore::V1_0::IChargerConfigs; using android::hardware::configstore::V1_0::implementation::ChargerConfigs; int main() { ... // other code sp<IChargerConfigs> chargerConfigs = new ChargerConfigs; status = chargerConfigs->registerAsService(); LOG_ALWAYS_FATAL_IF(status != OK, "Could not register IChargerConfigs"); ... // other code }
Android.mk
file to add implementation file
(modulenameConfigs.cpp) to LOCAL_SRC_FILES and to map build flags into
macro definitions. For example, in
hardware/interfaces/configstore/1.0/default/Android.mk
:
LOCAL_SRC_FILES += ChargerConfigs.cpp ifeq ($(strip $(BOARD_CHARGER_DISABLE_INIT_BLANK)),true) LOCAL_CFLAGS += -DCHARGER_DISABLE_INIT_BLANK endif
device/google/marlin/manifest.xml
:
<hal format="hidl"> <name>android.hardware.configstore</name> ... <interface> <name>IChargerConfigs</name> <instance>default</instance> </interface> </hal>
hal_configstore
). For
example, in system/sepolicy/private/healthd.te
:
... // other rules binder_call(healthd, hal_configstore)
To add a new ConfigStore item:
hardware/interfaces/configstore/1.0
.) For example, in
hardware/interfaces/configstore/1.0/IChargerConfigs.hal
:
package android.hardware.configstore@1.0; interface IChargerConfigs { ... // Other interfaces disableInitBlank() generates(OptionalBool value); };
hardware/interfaces/configstore/1.0/default
.
Note: Running hidl-gen
with
-Lc++-impl
generates skeleton code for the newly added interface
method. However, as it also overwrites implementations for all existing
interface methods, use the -o
option appropriately.
hardware/interfaces/configstore/1.0/default/ChargerConfigs.h
:
struct ChargerConfigs : public IChargerConfigs { ... // Other interfaces Return<void> disableInitBlank(disableInitBlank_cb _hidl_cb) override; };And in
hardware/interfaces/configstore/1.0/default/ChargerConfigs.cpp
:
Return<void> ChargerConfigs::disableInitBlank(disableInitBlank_cb _hidl_cb) { bool value = false; #ifdef CHARGER_DISABLE_INIT_BLANK value = true; #endif _hidl_cb({true, value}); return Void(); }
To use a ConfigStore item:
system/core/healthd/healthd.cpp
:
#include <android/hardware/configstore/1.0/IChargerConfigs.h> #include <configstore/Utils.h>
android.hardware.configstore-utils
. For example, in
system/core/healthd/healthd.cpp
:
using namespace android::hardware::configstore; using namespace android::hardware::configstore::V1_0; static int64_t disableInitBlank = getBool< IChargerConfigs, &IChargerConfigs::disableInitBlank>(false);In this example, the ConfigStore item
disableInitBlank
is retrieved
and stored to a variable (useful when the variable needs to be accessed multiple
times). The value retrieved from the ConfigStore is cached inside the
instantiated template function so it can be retrieved quickly from the cached
value without contacting the ConfigStore service for later calls to the
instantiated template function.
configstore-utils
library
in Android.mk
or Android.bp
. For example, in
system/core/healthd/Android.mk
:
LOCAL_SHARED_LIBRARIES := \ android.hardware.configstore@1.0 \ android.hardware.configstore-utils \ ... (other libraries) \