اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release بدلاً من aosp-main لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يمكنك إعادة صياغة الرمز المُجمَّع بشكل مشروط لقراءة القيم ديناميكيًا من
واجهة HAL. مثلاً:
#ifdef TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS
// some code fragment
#endif
يمكن بعد ذلك لرمز الإطار أن يستدعي دالة مساعدة مناسبة محدّدة في
<configstore/Utils.h> استنادًا إلى نوعها.
مثال على ConfigStore
يعرض هذا المثال قراءة
TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS، المحدّدة في واجهة HAL لـ ConfigStore
بصفتها forceHwcForVirtualDisplays() مع نوع الإرجاع
OptionalBool:
#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 قيمة لعنصر الضبط. تأخذ كل دالة سمتَين
للنموذج:
I هو اسم فئة الواجهة.
Func هو مؤشر الدالة العضو ل retrieving the configuration item.
بما أنّ قيمة الإعدادات للقراءة فقط ولا تتغيّر، تخزِّن الدالة
utility قيمة الإعدادات داخليًا في ذاكرة التخزين المؤقت. تتم معالجة المكالمات اللاحقة
بكفاءة أكبر باستخدام القيمة المخزّنة مؤقتًا في وحدة الربط نفسها.
استخدام حزمة configstore-utils
تم تصميم HAL لـ ConfigStore ليكون متوافقًا مع الإصدارات اللاحقة عند ترقية الإصدارات الثانوية، ما يعني أنّه عند مراجعة HAL واستخدام بعض رموز إطار العمل في العناصر التي تم تقديمها حديثًا، سيظل بإمكانك استخدام خدمة ConfigStore مع إصدار قديم من الإصدارات الثانوية في /vendor.
لضمان التوافق مع الإصدارات المستقبلية، تأكَّد من أنّ عملية التنفيذ تلتزم بال
الإرشادات التالية:
تستخدِم العناصر الجديدة القيمة التلقائية عندما تكون خدمة الإصدار القديم متوفرة فقط. مثال:
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 كلما أمكن.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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."]]