새로운 ConfigStore 항목(인터페이스 메서드)을 기존 인터페이스 클래스에 추가할 수 있습니다. 인터페이스가 정의되지 않은 경우 먼저 새 클래스를 추가해야 ConfigStore 항목을 클래스에 추가할 수 있습니다. 이 섹션에서는 IChargerConfigs 인터페이스 클래스에 추가되는 healthd의 disableInitBlank 구성 항목에 관한 예시를 사용합니다.
인터페이스 클래스 추가
추가하고 싶은 인터페이스 메서드에 인터페이스 클래스가 정의되지 않은 경우 먼저 인터페이스 클래스부터 추가해야 관련 ConfigStore 항목을 추가할 수 있습니다.
HAL 인터페이스 파일을 생성합니다. ConfigStore 버전이 1.0이므로 hardware/interfaces/configstore/1.0에서 ConfigStore 인터페이스를 정의합니다. 예를 들어 hardware/interfaces/configstore/1.0/IChargerConfigs.hal에서 다음을 실행합니다.
이 명령어는 hardware/interfaces/configstore/1.0/default에 ChargerConfigs.h 및 ChargerConfigs.cpp의 두 파일을 만듭니다.
.h 및 .cpp 구현 파일을 열고 함수 HIDL_FETCH_name과 관련된 코드(예: HIDL_FETCH_IChargerConfigs)를 삭제합니다. 이 함수는 ConfigStore에서 사용하지 않는 HIDL 패스 스루 모드에 필요합니다.
구현을 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 파일을 수정하여 구현 파일(modulenameConfigs.cpp)을 LOCAL_SRC_FILES에 추가하고 빌드 플래그를 매크로 정의에 매핑합니다. 예를 들어 hardware/interfaces/configstore/1.0/default/Android.mk에서 다음을 실행합니다.
필요한 경우 sepolicy 규칙을 추가합니다(클라이언트에 hal_configstore에 관한 hwbinder 호출 권한이 없는 경우). 예를 들어 system/sepolicy/private/healthd.te에서 다음과 같습니다.
... // other rules
binder_call(healthd, hal_configstore)
새 ConfigStore 항목 추가
새 ConfigStore 항목을 추가하는 방법:
HAL 파일을 열고 항목의 필수 인터페이스 메서드를 추가합니다. (ConfigStore의 .hal 파일은 hardware/interfaces/configstore/1.0에 위치함) 예를 들어 hardware/interfaces/configstore/1.0/IChargerConfigs.hal에서 다음과 같습니다.
상응하는 인터페이스 HAL 구성 파일(.h 및 .cpp)에 메서드를 구현합니다. 기본 구현을 hardware/interfaces/configstore/1.0/default에 삽입합니다.
예를 들어 hardware/interfaces/configstore/1.0/default/ChargerConfigs.h에서 다음을 실행합니다.
struct ChargerConfigs : public IChargerConfigs {
... // Other interfaces
Return<void> disableInitBlank(disableInitBlank_cb _hidl_cb) override;
};
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();
}
ConfigStore 항목 사용
ConfigStore 항목을 사용하는 방법:
필수 헤더 파일을 포함합니다. 예를 들어 system/core/healthd/healthd.cpp에서 다음을 실행합니다.
android.hardware.configstore-utils에서 적절한 템플릿 함수를 사용하여 ConfigStore 항목에 액세스합니다. 예를 들어 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);
이 예에서는 ConfigStore 항목 disableInitBlank가 검색되어 변수에 저장됩니다 (변수에 여러 번 액세스해야 하는 경우에 유용). ConfigStore에서 검색된 값은 인스턴스화된 템플릿 함수 내에서 캐시됩니다. 이는 인스턴스화된 템플릿 함수에 관한 향후 호출을 위해 ConfigStore 서비스에 접속하지 않고도 값을 캐시된 값에서 빠르게 가져올 수 있도록 하기 위함입니다.
Android.mk 또는 Android.bp에서 ConfigStore 및 configstore-utils 라이브러리에 관한 종속 항목을 추가합니다. 예를 들어 system/core/healthd/Android.mk에서 다음을 실행합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Add ConfigStore classes and items\n\n| **Warning:** Android 10 deprecates the ConfigStore HAL and replaces the HAL with system properties. For details, refer to [Configuring](/docs/core/architecture/configuration).\n\nYou can add new ConfigStore items (that is, interface methods) for an\nexisting interface class. If the interface class isn't defined, you must add a\nnew class before you can add a ConfigStore item for that class. This section\nuses the example of a `disableInitBlank` configuration item for\n`healthd` being added to the `IChargerConfigs` interface\nclass.\n| **Note:** Before continuing, ensure that you're familiar with [general HIDL\n| concepts](/docs/core/architecture/hidl), [HIDL C++\n| development workflow](/docs/core/architecture/hidl-cpp), [HIDL Code Style](/docs/core/architecture/hidl/code-style), and [ConfigStore design](/docs/core/architecture/configstore).\n\nAdd interface classes\n---------------------\n\nIf no interface class is defined for the interface method that you want to\nadd, you must add the interface class before you can add the associated\nConfigStore items.\n\n1. Create a HAL interface file. The ConfigStore version is 1.0, so define ConfigStore interfaces in `hardware/interfaces/configstore/1.0`. For example, in `hardware/interfaces/configstore/1.0/IChargerConfigs.hal`: \n\n ```\n package android.hardware.configstore@1.0;\n\n interface IChargerConfigs {\n // TO-BE-FILLED-BELOW\n };\n ```\n2. Update `Android.bp` and `Android.mk` for the ConfigStore shared library and header files to include the new interface HAL. For example: \n\n hidl-gen -o hardware/interfaces/configstore/1.0/default -Lmakefile -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.configstore@1.0::IChargerConfigs\n 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\n\n These commands update `Android.bp` and `Android.mk` in `hardware/interfaces/configstore/1.0`.\n3. Generate the C++ stub for implementing the server code. For example: \n\n ```\n 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::IChargerConfigs\n ```\n This command creates two files, `ChargerConfigs.h` and `ChargerConfigs.cpp`, in `hardware/interfaces/configstore/1.0/default`.\n4. Open the `.h` and `.cpp` implementation files and remove code related to the function `HIDL_FETCH_`\u003cvar translate=\"no\"\u003ename\u003c/var\u003e (for example, `HIDL_FETCH_IChargerConfigs`). This function is needed for HIDL passthrough mode, which isn't used by ConfigStore.\n5. Register the implementation to the ConfigStore service. For example, in `hardware/interfaces/configstore/1.0/default/service.cpp`: \n\n ```\n #include \u003candroid/hardware/configstore/1.0/IChargerConfigs.h\u003e\n #include \"ChargerConfigs.h\"\n\n using android::hardware::configstore::V1_0::IChargerConfigs;\n using android::hardware::configstore::V1_0::implementation::ChargerConfigs;\n\n int main() {\n ... // other code\n sp\u003cIChargerConfigs\u003e chargerConfigs = new ChargerConfigs;\n status = chargerConfigs-\u003eregisterAsService();\n LOG_ALWAYS_FATAL_IF(status != OK, \"Could not register IChargerConfigs\");\n ... // other code\n }\n ```\n6. Modify the `Android.mk` file to add the implementation file (\u003cvar translate=\"no\"\u003emodulename\u003c/var\u003e`Configs.cpp`) to `LOCAL_SRC_FILES` and to map build flags into macro definitions. For example, in `hardware/interfaces/configstore/1.0/default/Android.mk`: \n\n ```\n LOCAL_SRC_FILES += ChargerConfigs.cpp\n\n ifeq ($(strip $(BOARD_CHARGER_DISABLE_INIT_BLANK)),true)\n LOCAL_CFLAGS += -DCHARGER_DISABLE_INIT_BLANK\n endif\n ```\n7. (Optional) Add a manifest entry. If it doesn't exist, default to the \"default\" instance name of ConfigStore. For example, in `device/google/marlin/manifest.xml`: \n\n ```\n \u003chal format=\"hidl\"\u003e\n \u003cname\u003eandroid.hardware.configstore\u003c/name\u003e\n ...\n \u003cinterface\u003e\n \u003cname\u003eIChargerConfigs\u003c/name\u003e\n \u003cinstance\u003edefault\u003c/instance\u003e\n \u003c/interface\u003e\n \u003c/hal\u003e\n ```\n8. Add the sepolicy rule if needed (that is, if the client doesn't have permissions for making hwbinder calls to `hal_configstore`). For example, in `system/sepolicy/private/healthd.te`: \n\n ```\n ... // other rules\n binder_call(healthd, hal_configstore)\n ```\n\nAdd new ConfigStore items\n-------------------------\n\nTo add a new ConfigStore item:\n\n1. Open the HAL file and add the required interface method for the item. (The `.hal` files for ConfigStore reside in `hardware/interfaces/configstore/1.0`.) For example, in `hardware/interfaces/configstore/1.0/IChargerConfigs.hal`: \n\n ```\n package android.hardware.configstore@1.0;\n\n interface IChargerConfigs {\n ... // Other interfaces\n disableInitBlank() generates(OptionalBool value);\n };\n ```\n2. Implement the method in the corresponding interface HAL implementation files (`.h` and `.cpp`). Place the default implementations in `hardware/interfaces/configstore/1.0/default`. **Note:** Running `hidl-gen` with `-Lc++-impl` generates skeleton code for the newly added interface method. However, it also overwrites implementations for all existing interface methods, so use the `-o` option appropriately.\n For example, in `hardware/interfaces/configstore/1.0/default/ChargerConfigs.h`: \n\n ```\n struct ChargerConfigs : public IChargerConfigs {\n ... // Other interfaces\n Return\u003cvoid\u003e disableInitBlank(disableInitBlank_cb _hidl_cb) override;\n };\n ```\n And in `hardware/interfaces/configstore/1.0/default/ChargerConfigs.cpp`: \n\n ```\n Return\u003cvoid\u003e ChargerConfigs::disableInitBlank(disableInitBlank_cb _hidl_cb) {\n bool value = false;\n #ifdef CHARGER_DISABLE_INIT_BLANK\n value = true;\n #endif\n _hidl_cb({true, value});\n return Void();\n }\n ```\n\nUse ConfigStore items\n---------------------\n\nTo use a ConfigStore item:\n\n1. Include the required header files. For example, in `system/core/healthd/healthd.cpp`: \n\n ```\n #include \u003candroid/hardware/configstore/1.0/IChargerConfigs.h\u003e\n #include \u003cconfigstore/Utils.h\u003e\n ```\n2. Access the ConfigStore item using the appropriate template function in `android.hardware.configstore-utils`. For example, in `system/core/healthd/healthd.cpp`: \n\n ```\n using namespace android::hardware::configstore;\n using namespace android::hardware::configstore::V1_0;\n\n static int64_t disableInitBlank = getBool\u003c\n IChargerConfigs,\n &IChargerConfigs::disableInitBlank\u003e(false);\n ```\n 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 that it can be retrieved quickly from the cached value without contacting the ConfigStore service for later calls to the instantiated template function.\n3. Add the dependency on ConfigStore and the `configstore-utils` library in `Android.mk` or `Android.bp`. For example, in `system/core/healthd/Android.mk`: \n\n ```\n LOCAL_SHARED_LIBRARIES := \\\n android.hardware.configstore@1.0 \\\n android.hardware.configstore-utils \\\n ... (other libraries) \\\n ```"]]