조건부로 컴파일된 코드를 리팩터링하면 HAL 인터페이스에서 값을 동적으로 읽을 수 있습니다. 예:
#ifdef TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS
// some code fragment
#endif
그러면 프레임워크 코드는 유형에 따라 <configstore/Utils.h>에서 정의된 적절한 유틸리티 함수를 호출할 수 있습니다.
ConfigStore 예
이 예에서는 ConfigStore HAL에서 반환 유형 OptionalBool이 있는 forceHwcForVirtualDisplays()로 정의된 TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS 읽기를 보여줍니다.
#include <configstore/Utils.h>
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
static bool vsyncPhaseOffsetNs = getBool<ISurfaceFlingerConfigs,
ISurfaceFlingerConfigs::forceHwcForVirtualDisplays>(false);
유틸리티 함수(위 예에서 getBool)가 configstore 서비스에 접속하여 인터페이스 함수의 프록시 핸들을 가져온 다음 핸들을 HIDL/hwbinder를 통해 호출하여 값을 검색합니다.
유틸리티 함수
<configstore/Utils.h>(configstore/1.0/include/configstore/Utils.h)는 아래 나열된 Optional[Bool|String|Int32|UInt32|Int64|UInt64]를 비롯하여 각 프리미티브 반환 유형의 유틸리티 함수를 제공합니다.
defValue는 HAL 구현에서 구성 항목의 값을 지정하지 않을 때 반환되는 기본값입니다. 각 함수는 2개의 템플릿 매개변수를 취합니다.
I는 인터페이스 클래스 이름입니다.
Func는 구성 항목을 가져오기 위한 멤버 함수 포인터입니다.
구성 값은 읽기 전용이고 변경되지 않으므로 유틸리티 함수가 내부적으로 구성 값을 캐시합니다. 후속 호출은 같은 연결 단위의 캐싱된 값을 사용하여 더욱 효율적으로 제공됩니다.
configstore-utils 사용
ConfigStore HAL은 부 버전 업그레이드를 위해 향후 버전과 호환되도록 설계되었으므로 HAL이 수정되고 일부 프레임워크 코드가 새로 도입된 항목을 사용하면 /vendor의 이전 부 버전이 있는 ConfigStore 서비스를 계속 사용할 수 있습니다.
향후 버전과의 호환성의 경우 구현이 다음 가이드라인을 준수하는지 확인합니다.
이전 버전의 서비스가 제공되는 경우에만 새 항목에서 기본값을 사용해야 합니다. 예를 들어 다음과 같습니다.
service = V1_1::IConfig::getService(); // null if V1_0 is installed
value = DEFAULT_VALUE;
if(service) {
value = service->v1_1API(DEFAULT_VALUE);
}
클라이언트가 ConfigStore 항목에 포함된 첫 번째 인터페이스를 사용해야 합니다.
예를 들어 다음과 같습니다.
V1_1::IConfig::getService()->v1_0API(); // NOT ALLOWED
V1_0::IConfig::getService()->v1_0API(); // OK
기존 버전의 인터페이스에 새 버전의 서비스를 가져올 수 있어야 합니다. 다음 예에서 설치된 버전이 v1_1이면 v1_1 서비스를 getService()에 반환해야 합니다.
V1_0::IConfig::getService()->v1_0API();
configstore-utils 라이브러리의 액세스 함수가 ConfigStore 항목에 액세스하는 데 사용되면 #1이 구현에서 보장되고 #2가 컴파일러 오류에서 보장됩니다. 따라서 가능한 경우 항상 configstore-utils를 사용하는 것이 좋습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 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,["# Client-side use\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 refactor conditionally compiled code to read values dynamically from\nthe HAL interface. For example: \n\n```\n#ifdef TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS\n// some code fragment\n#endif\n```\n\nFramework code can then call an appropriate utility function defined in\n`\u003cconfigstore/Utils.h\u003e` depending on its type.\n\nConfigStore example\n-------------------\n\nThis example shows reading\n`TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS`, defined in ConfigStore HAL\nas `forceHwcForVirtualDisplays()` with return type\n`OptionalBool`: \n\n```\n#include \u003cconfigstore/Utils.h\u003e\nusing namespace android::hardware::configstore;\nusing namespace android::hardware::configstore::V1_0;\n\nstatic bool vsyncPhaseOffsetNs = getBool\u003cISurfaceFlingerConfigs,\n ISurfaceFlingerConfigs::forceHwcForVirtualDisplays\u003e(false);\n```\n\nThe utility function (`getBool` in the example above) contacts the\n`configstore` service to get the handle for the proxy of the\ninterface function, then retrieves the value by invoking the handle via\nHIDL/hwbinder.\n\nUtility functions\n-----------------\n\n`\u003cconfigstore/Utils.h\u003e`\n(`configstore/1.0/include/configstore/Utils.h`) provides utility\nfunctions for each primitive return type, including\n`Optional[Bool|String|Int32|UInt32|Int64|UInt64]`, as listed\nbelow:\n\n| Type | Function *(template parameters omitted)* |\n|------------------|------------------------------------------------------|\n| `OptionalBool` | `bool getBool(const bool defValue)` |\n| `OptionalInt32` | `int32_t getInt32(const int32_t defValue)` |\n| `OptionalUInt32` | `uint32_t getUInt32(const uint32_t defValue)` |\n| `OptionalInt64` | `int64_t getInt64(const int64_t defValue)` |\n| `OptionalUInt64` | `uint64_t getUInt64(const uint64_t defValue)` |\n| `OptionalString` | `std::string getString(const std::string &defValue)` |\n\n`defValue` is a default value returned when the HAL implementation\ndoesn't specify a value for the configuration item. Each function takes two\ntemplate parameters:\n\n- **I** is the interface class name.\n- **Func** is the member function pointer for getting the configuration item.\n\nBecause the configuration value is read-only and doesn't change, the utility\nfunction internally caches the configuration value. Subsequent calls are\nserviced more efficiently using the cached value in the same linking unit.\n\nUse configstore-utils\n---------------------\n\nThe ConfigStore HAL is designed to be forward compatible for minor version\nupgrades, meaning that when the HAL is revised and some framework code\nuses the newly introduced items, the ConfigStore service with an older minor\nversion in `/vendor` can still be used.\n\nFor forward compatibility, ensure that your implementation adheres to the\nfollowing guidelines:\n\n1. New items use the default value when *only* the old version's service is available. Example: \n\n ```\n service = V1_1::IConfig::getService(); // null if V1_0 is installed\n value = DEFAULT_VALUE;\n if(service) {\n value = service-\u003ev1_1API(DEFAULT_VALUE);\n }\n ```\n2. The client uses the first interface that included the ConfigStore item. Example: \n\n ```\n V1_1::IConfig::getService()-\u003ev1_0API(); // NOT ALLOWED\n\n V1_0::IConfig::getService()-\u003ev1_0API(); // OK\n ```\n3. The new version's service can be retrieved for old version's interface. In the following example, if the installed version is v1_1, the v1_1 service must be returned for `getService()`: \n\n ```\n V1_0::IConfig::getService()-\u003ev1_0API();\n ```\n | **Note:** The [current\n | AOSP implementation](https://android-review.googlesource.com/c/393736/) satisfies this requirement.\n\nWhen the access functions in the `configstore-utils` library are\nused for accessing the ConfigStore item, #1 is guaranteed by the implementation\nand #2 is guaranteed by compiler errors. For these reasons, we strongly\nrecommend using `configstore-utils` wherever possible."]]