हमारा सुझाव है कि 27 मार्च, 2025 से AOSP को बनाने और उसमें योगदान देने के लिए, aosp-main के बजाय android-latest-release का इस्तेमाल करें. ज़्यादा जानकारी के लिए, AOSP में हुए बदलाव लेख पढ़ें.
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
किसी मौजूदा इंटरफ़ेस क्लास के लिए, नए ConfigStore आइटम (यानी, इंटरफ़ेस के तरीके) जोड़े जा सकते हैं. अगर इंटरफ़ेस क्लास तय नहीं की गई है, तो उस क्लास के लिए ConfigStore आइटम जोड़ने से पहले, आपको एक नई क्लास जोड़नी होगी. इस सेक्शन में, IChargerConfigs इंटरफ़ेस क्लास में जोड़े जा रहे healthd के लिए, disableInitBlank कॉन्फ़िगरेशन आइटम के उदाहरण का इस्तेमाल किया गया है.
इंटरफ़ेस क्लास जोड़ना
अगर आपको जो इंटरफ़ेस तरीका जोड़ना है उसके लिए कोई इंटरफ़ेस क्लास तय नहीं की गई है, तो उससे जुड़े ConfigStore आइटम जोड़ने से पहले, आपको इंटरफ़ेस क्लास जोड़नी होगी.
एचएएल इंटरफ़ेस फ़ाइल बनाएं. 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. यह फ़ंक्शन, HIDL पासथ्रू मोड के लिए ज़रूरी है. इसका इस्तेमाल ConfigStore नहीं करता.
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
}
LOCAL_SRC_FILES में लागू करने की फ़ाइल (modulenameConfigs.cpp) जोड़ने और मैक्रो डेफ़िनिशन में बिल्ड फ़्लैग को मैप करने के लिए, Android.mk फ़ाइल में बदलाव करें. उदाहरण के लिए, hardware/interfaces/configstore/1.0/default/Android.mk में:
(ज़रूरी नहीं) मेनिफ़ेस्ट एंट्री जोड़ें. अगर यह मौजूद नहीं है, तो डिफ़ॉल्ट रूप से ConfigStore के "default" इंस्टेंस का नाम इस्तेमाल किया जाता है. उदाहरण के लिए, device/google/marlin/manifest.xml में:
अगर ज़रूरी हो, तो sepolicy नियम जोड़ें. इसका मतलब है कि अगर क्लाइंट के पास hal_configstore को hwbinder कॉल करने की अनुमतियां नहीं हैं. उदाहरण के लिए, system/sepolicy/private/healthd.te में:
... // other rules
binder_call(healthd, hal_configstore)
नए ConfigStore आइटम जोड़ना
नया ConfigStore आइटम जोड़ने के लिए:
एचएएल फ़ाइल खोलें और आइटम के लिए ज़रूरी इंटरफ़ेस का तरीका जोड़ें. (ConfigStore के लिए .hal फ़ाइलें hardware/interfaces/configstore/1.0 में मौजूद होती हैं.) उदाहरण के लिए, hardware/interfaces/configstore/1.0/IChargerConfigs.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 सेवा से संपर्क किए बिना, कैश मेमोरी में सेव की गई वैल्यू को तुरंत वापस पाया जा सके.
ConfigStore और Android.mk या Android.bp में configstore-utils
लाइब्रेरी पर डिपेंडेंसी जोड़ें. उदाहरण के लिए, system/core/healthd/Android.mk में:
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, 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,["# 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 ```"]]