그런 다음 Android.mk 파일을 수정하여 LOCAL_SRC_FILES에 구현 파일(<modulename>Configs.cpp)을 추가하고 매크로 정의에 빌드 플래그를 매핑합니다. 예를 들어 hardware/interface/configstore/1.0/default/Android.mk에서 surfaceflinger를 수정할 수 있습니다.
Android.mk에 여러 ifeq-endif 블록이 포함되어 있으면 코드를 새 파일(surfaceflinger.mk)로 이동하고 Android.mk에서 이 파일을 포함하는 것이 좋습니다.
함수 구현
함수를 채워 HAL을 구현하려면 빌드 플래그에서 조건이 정의된 다른 값으로 _hidl_cb 함수를 다시 호출합니다. 예를 들어 hardware/interfaces/configstore/1.0/default/SurfaceFlingerConfigs.cpp에서 surfaceflinger 함수를 채울 수 있습니다.
Return<void> SurfaceFlingerConfigs::numFramebufferSurfaceBuffers(
numFramebufferSurfaceBuffers_cb _hidl_cb) {
#if NUM_FRAMEBUFFER_SURFACE_BUFFERS 2
_hidl_cb(NumBuffers.TWO);
#else if NUM_FRAMEBUFFER_SURFACE_BUFFERS 3
_hidl_cb(NumBuffers.THREE);
#else
_hidl_cb(NumBuffers.USE_DEFAULT);
#endif
}
Return<void> SurfaceFlingerConfigs::runWithoutSyncFramework(
runWithoutSyncFramework_cb _hidl_cb) {
#ifdef RUNNING_WITHOUT_SYNC_FRAMEWORK
_hidl_cb({true /* specified */, true /* value */});
#else
// 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 */});
#endif
}
구현에 HIDL_FETCH_interface-name이라는 함수(예: HIDL_FETCH_ISurfaceFlingerConfigs)가 포함되어 있지 않은지 확인합니다. 이 함수는 configstore에서 사용하지 않고 금지하는 HIDL 패스 스루 모드에 필요합니다. ConfigStore는 항상 바인더화 모드에서 사용해야 합니다.
서비스로 등록
마지막으로 모든 인터페이스 구현을 configstore 서비스에 등록합니다. 예를 들어 hardware/interfaces/configstore/1.0/default/service.cpp에서 surfaceflinger 구현을 등록할 수 있습니다.
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
joinRpcThreadpool();
사전 체험판 제공
프레임워크 모듈이 HAL 서비스에 사전에 액세스할 수 있도록 하려면 hwservicemanager가 준비된 직후에 config HAL 서비스가 최대한 일찍 시작되어야 합니다. config HAL 서비스는 외부 파일을 읽지 않으므로 실행 후에 빠르게 준비됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Implement the service\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\nTo prepare for the HAL implementation, you can generate basic ConfigStore\ninterface code, then modify it to meet your needs.\n\nGenerate interface code\n-----------------------\n\nTo generate boilerplate code for the interface, run `hidl-gen`.\nFor example, to generate code for `surfaceflinger`: \n\n```\nhidl-gen -o hardware/interfaces/configstore/1.0/default \\\n -Lc++-impl \\\n -randroid.hardware:hardware/interfaces \\\n -randroid.hidl:system/libhidl/transport \\\n android.hardware.config@1.0::ISurfaceFlingerConfigs\n```\n| **Note:** Don't run `hidl-gen` with `-Landroidbp-impl` as this generates `Android.bp`. The module must be built with `Android.mk` to access build flags.\n\nModify Android.mk\n-----------------\n\nNext, modify the `Android.mk` file to add the implementation file\n(`\u003cmodulename\u003eConfigs.cpp`) to `LOCAL_SRC_FILES` and\nto map build flags into macro definitions. For example, you can modify\n`surfaceflinger` in\n`hardware/interface/configstore/1.0/default/Android.mk`: \n\n```\nLOCAL_SRC_FILES += SurfaceFlingerConfigs.cpp\nifneq ($(NUM_FRAMEBUFFER_SURFACE_BUFFERS),)\n LOCAL_CFLAGS += -DNUM_FRAMEBUFFER_SURFACE_BUFFERS=$(NUM_FRAMEBUFFER_SURFACE_BUFFERS)\nendif\n\nifeq ($(TARGET_RUNNING_WITHOUT_SYNC_FRAMEWORK),true)\n LOCAL_CFLAGS += -DRUNNING_WITHOUT_SYNC_FRAMEWORK\nendif\n```\n\nIf `Android.mk` includes several `ifeq-endif` blocks,\nconsider moving your code into a new file (that is,\n`surfaceflinger.mk`) then include that file from\n`Android.mk`.\n\nImplement functions\n-------------------\n\nTo fill the functions to implement the HAL, call back the\n`_hidl_cb` function with different values (conditioned on build\nflags). For example, you can fill the functions for `surfaceflinger`\nin\n`hardware/interfaces/configstore/1.0/default/SurfaceFlingerConfigs.cpp`: \n\n```\nReturn\u003cvoid\u003e SurfaceFlingerConfigs::numFramebufferSurfaceBuffers(\n numFramebufferSurfaceBuffers_cb _hidl_cb) {\n #if NUM_FRAMEBUFFER_SURFACE_BUFFERS 2\n _hidl_cb(NumBuffers.TWO);\n #else if NUM_FRAMEBUFFER_SURFACE_BUFFERS 3\n _hidl_cb(NumBuffers.THREE);\n #else\n _hidl_cb(NumBuffers.USE_DEFAULT);\n #endif\n}\n\nReturn\u003cvoid\u003e SurfaceFlingerConfigs::runWithoutSyncFramework(\n runWithoutSyncFramework_cb _hidl_cb) {\n #ifdef RUNNING_WITHOUT_SYNC_FRAMEWORK\n _hidl_cb({true /* specified */, true /* value */});\n #else\n // when macro not defined, we can give any value to the second argument.\n // It will simply be ignored in the framework side.\n _hidl_cb({false /* specified */, false /* value */});\n #endif\n}\n```\n\nEnsure that the implementation doesn't contain a function named\n`HIDL_FETCH_`\u003cvar translate=\"no\"\u003einterface-name\u003c/var\u003e (for example,\n`HIDL_FETCH_ISurfaceFlingerConfigs`). This function is needed for\nHIDL passthrough mode, which is unused (and prohibited) by\n`configstore`. ConfigStore must always run in binderized mode.\n\nRegister as a service\n---------------------\n\nFinally, register all interface implementations to the\n`configstore` service. For example, you can register\n`surfaceflinger` implementations in\n`hardware/interfaces/configstore/1.0/default/service.cpp`: \n\n```\nconfigureRpcThreadpool(maxThreads, true);\nsp\u003cISurfaceFlingerConfigs\u003e surfaceFlingerConfigs = new SurfaceFlingerConfigs;\nstatus_t status = surfaceFlingerConfigs-\u003eregisterAsService();\n\nsp\u003cIBluetoothConfigs\u003e bluetoothConfigs = new BluetoothConfigs;\nstatus = bluetoothConfigs-\u003eregisterAsService();\n\n// register more interfaces here\njoinRpcThreadpool();\n```\n\nEnsure early access\n-------------------\n\nTo ensure that a framework module can get early access the HAL service, the\nconfig HAL service should start as early as possible, just after\n`hwservicemanager` is ready. As the config HAL service doesn't read\nexternal files, it's expected to be ready quickly after it's launched."]]