[[["เข้าใจง่าย","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."]]