A partire dal 27 marzo 2025, ti consigliamo di utilizzare android-latest-release anziché aosp-main per compilare e contribuire ad AOSP. Per ulteriori informazioni, vedi Modifiche ad AOSP.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Puoi aggiungere nuovi elementi ConfigStore (ovvero metodi di interfaccia) per una classe di interfaccia esistente. Se la classe di interfaccia non è definita, devi aggiungere una nuova classe prima di poter aggiungere un elemento ConfigStore per quella classe. Questa sezione
utilizza l'esempio di un elemento di configurazione disableInitBlank per
healthd da aggiungere alla classe di interfaccia
IChargerConfigs.
Aggiungere classi di interfaccia
Se non è definita una classe di interfaccia per il metodo di interfaccia che vuoi aggiungere, devi aggiungere la classe di interfaccia prima di poter aggiungere gli elementi ConfigStore associati.
Crea un file di interfaccia HAL. La versione di ConfigStore è 1.0, quindi definisci le interfacce ConfigStore in hardware/interfaces/configstore/1.0. Ad esempio, in hardware/interfaces/configstore/1.0/IChargerConfigs.hal:
Aggiorna Android.bp e Android.mk per la libreria condivisa e i file di intestazione ConfigStore in modo da includere la nuova interfaccia HAL.
Ad esempio:
Questo comando crea due file, ChargerConfigs.h e
ChargerConfigs.cpp, in
hardware/interfaces/configstore/1.0/default.
Apri i file di implementazione .h e .cpp e
rimuovi il codice relativo alla funzione HIDL_FETCH_name (ad es.HIDL_FETCH_IChargerConfigs). Questa funzione è necessaria per la modalità di passaggio HIDL, che non viene utilizzata da ConfigStore.
Registra l'implementazione nel servizio ConfigStore. Ad esempio, in
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
}
Modifica il file Android.mk per aggiungere il file di implementazione
(modulenameConfigs.cpp) a LOCAL_SRC_FILES
e per mappare i flag di compilazione alle definizioni di macro. Ad esempio, in
hardware/interfaces/configstore/1.0/default/Android.mk:
(Facoltativo) Aggiungi una voce manifest. Se non esiste, viene utilizzato per impostazione predefinita il nome dell'istanza "predefinita" di ConfigStore. Ad esempio, in
device/google/marlin/manifest.xml:
Aggiungi la regola sepolicy, se necessario (ovvero se il client non dispone delle autorizzazioni per effettuare chiamate hwbinder a hal_configstore). Ad esempio, in system/sepolicy/private/healthd.te:
... // other rules
binder_call(healthd, hal_configstore)
Aggiungere nuovi elementi ConfigStore
Per aggiungere un nuovo elemento ConfigStore:
Apri il file HAL e aggiungi il metodo di interfaccia richiesto per l'elemento. I file .hal per ConfigStore si trovano in hardware/interfaces/configstore/1.0. Ad esempio, in hardware/interfaces/configstore/1.0/IChargerConfigs.hal:
Implementa il metodo nei file di implementazione HAL dell'interfaccia corrispondente (.h e .cpp). Posiziona le implementazioni predefinite in hardware/interfaces/configstore/1.0/default.
Ad esempio, in
hardware/interfaces/configstore/1.0/default/ChargerConfigs.h:
struct ChargerConfigs : public IChargerConfigs {
... // Other interfaces
Return<void> disableInitBlank(disableInitBlank_cb _hidl_cb) override;
};
E in
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();
}
Utilizzare gli elementi ConfigStore
Per utilizzare un elemento ConfigStore:
Includi i file di intestazione richiesti. Ad esempio, in
system/core/healthd/healthd.cpp:
Accedi all'elemento ConfigStore utilizzando la funzione del modello appropriata in
android.hardware.configstore-utils. Ad esempio, in
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);
In questo esempio, l'elemento ConfigStore disableInitBlank viene recuperato
e memorizzato in una variabile (utile quando è necessario accedere alla variabile più volte). Il valore recuperato da ConfigStore viene memorizzato nella cache all'interno della funzione del modello creata in modo da poter essere recuperato rapidamente dal valore memorizzato nella cache senza contattare il servizio ConfigStore per le chiamate successive alla funzione del modello creata.
Aggiungi la dipendenza da ConfigStore e dalla libreria configstore-utils
in Android.mk o Android.bp. Ad esempio, in
system/core/healthd/Android.mk:
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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 ```"]]