اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release
بدلاً من aosp-main
لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
الحبّار: التحكّم في البيئة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توضّح هذه الصفحة كيفية التحكّم في البيئة في جهاز Cuttlefish
باستخدام واجهة برمجة التطبيقات REST API أو واجهة سطر الأوامر. على سبيل المثال، يمكنك تعديل
إشارة Wi-Fi أو تعديل الموقع الجغرافي لجهاز Cuttlefish باستخدام نظام تحديد المواقع العالمي (GPS).
الخدمات
يقدّم الأمر cvd env
الخدمات التالية للتحكّم في
بيئة Cuttlefish:
الخدمات |
الوصف |
GnssGrpcProxy
|
تتحكّم هذه السياسة في نظام تحديد المواقع العالمي (GNSS) لميزة تحديد الموقع الجغرافي باستخدام Cuttlefish. |
OpenwrtControlService
|
تتحكّم هذه السياسة في Openwrt ، وهو مزوّد نقطة وصول Wi-Fi افتراضي
لميزة Wi-Fi في Cuttlefish. |
WmediumdService
|
التحكّم في Wmediumd ، وهو محاكي وسيط لاسلكي
لميزة Wi-Fi في Cuttlefish |
CasimirControlService
|
تتحكّم هذه السياسة في Casimir ، وهو محاكي لأجهزة NFC
الخارجية. |
التحكّم في البيئة باستخدام واجهة برمجة التطبيقات REST
يوضّح هذا القسم كيفية التحكّم في البيئة باستخدام واجهة برمجة التطبيقات Rest API
من خلال نقطة نهاية خدمة <https://localhost:1443>
.
إدراج الخدمات أو الطرق المتاحة
للحصول على قائمة بجميع الخدمات، أرسِل طلبًا من النوع GET
إلى عنوان URL التالي مع تحديد
رقم تعريف جهاز.
https://localhost:1443/devices/DEVICE_ID/services
للحصول على قائمة بجميع طرق خدمة معيّنة، أرسِل طلبًا من النوع GET
إلى عنوان URL التالي مع إدراج رقم تعريف الجهاز واسم الخدمة.
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME
للحصول على معلومات تفصيلية عن إحدى الطرق، مثل أنواع الرسائل المرسَلة أو المُستلَمة، أرسِل طلبًا من النوع GET
إلى عنوان URL التالي مع إدراج معرّف الجهاز
واسم الخدمة واسم الطريقة.
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
الحصول على معلومات تفصيلية حول أنواع الطلبات والردود
للحصول على معلومات تفصيلية عن نوع رسالة الطلب أو الاستجابة، أرسِل GET
طلبًا إلى عنوان URL التالي مع إدراج معرّف الجهاز واسم الخدمة و
نوع رسالة الطلب أو الاستجابة. يؤدي ذلك إلى طباعة جميع الأسماء وأنواع كل
حقل في الرسالة. يمكنك بعد ذلك استخدام هذه المعلومات لكتابة رسالة proto بتنسيق
JSON لإرسال طلب RPC.
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/REQUEST_OR_RESPONSE_TYPE_NAME/type
إرسال طلب RPC لإجراء تغييرات على البيئة
لإرسال طلب RPC لاستدعاء طريقة لخدمة باستخدام ملف proto بتنسيق JSON،
أرسِل طلب POST
إلى عنوان URL التالي مع رقم تعريف الجهاز واسم الخدمة
واسم الطريقة. يجب تضمين ملف proto بتنسيق JSON في
النص.
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
مثال على حالة الاستخدام
في ما يلي مثال على حالة استخدام واجهة برمجة التطبيقات Rest API لتعديل قوة إشارة Wi-Fi
من خلال الاتصال SetTxpower
.
حدِّد اسم الخدمة واسم الطريقة ونوع رسالة الطلب
اسمًا لتعديل قوة إشارة Wi-Fi.
يمكنك الحصول على قائمة بجميع الخدمات المتاحة من خلال إرسال طلب GET
إلى عنوان URL التالي:
https://localhost:1443/devices/cvd-1/services
هذا مثال على ردّ.
{"services":["OpenwrtControlService","EchoService","GnssGrpcProxy","WmediumdService"]}
يمكنك الحصول على قائمة بالطرق المتاحة لطلب WmediumdService
من خلال إرسال طلب GET
إلى عنوان URL التالي.
https://localhost:1443/devices/cvd-1/services/WmediumdService
هذا مثال على ردّ.
{"methods":["ListStations","LoadConfig","ReloadConfig","SetCivicloc","SetLci","SetPosition","SetSnr","SetTxpower","StartPcap","StopPcap"]}
يمكنك الحصول على معلومات عن أنواع رسائل الطلب والاستجابة لطريقة
SetTxpower
من خلال إرسال طلب GET
إلى عنوان URL التالي.
https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower
هذا مثال على ردّ.
{"request_type_name":"wmediumdserver.SetTxpowerRequest","response_type_name":"google.protobuf.Empty"}
يمكنك الحصول على معلومات تفصيلية لطلب wmediumdserver.SetTxpowerRequest
نوع الرسالة من خلال إرسال طلب GET
إلى عنوان URL التالي.
https://localhost:1443/devices/cvd-1/services/WmediumdService/wmediumdserver.SetTxpowerRequest/type
هذا مثال على ردّ.
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
أرسِل طلب RPC إلى خدمة WmediumdService
لتعديل قوة إشارة Wi-Fi
إلى المستوى المطلوب من خلال إرسال طلب POST
إلى عنوان URL التالي
مع نص الطلب التالي.
https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower
{"mac_address":"42:00:00:00:00:00", "tx_power":1}
هذا مثال على ردّ.
{}
التحكّم في البيئة باستخدام سطر الأوامر
يصف هذا القسم الأوامر الفرعية المتاحة لأمر سطر الأوامر cvd env
.
لمزيد من التفاصيل، اطبع رسالة المساعدة باستخدام cvd help env
.
إدراج الخدمات أو الطرق المتاحة
للحصول على قائمة بجميع الخدمات، استخدِم cvd env ls
بدون أي وسيطات.
cvd env ls
للحصول على قائمة بجميع طرق الخدمة، أدرِج اسم
الخدمة كوسيطة.
cvd env ls SERVICE_NAME
للحصول على معلومات تفصيلية، مثل أنواع رسائل الطلب أو الاستجابة لطريقة، يجب تضمين اسم الخدمة واسم الطريقة.
cvd env ls SERVICE_NAME METHOD_NAME
الحصول على معلومات تفصيلية حول أنواع الطلبات والردود
للحصول على معلومات تفصيلية عن نوع رسالة الطلب أو الردّ، استخدِم الأمر
cvd env type
. يطبع هذا الأمر جميع الأسماء وأنواع كل حقل
في الرسالة. يمكنك بعد ذلك استخدام هذه المعلومات لكتابة رسالة proto بتنسيق JSON لإرسال طلب RPC.
cvd env type SERVICE_NAME REQUEST_OR_RESPONSE_TYPE_NAME
إرسال طلب RPC لإجراء تغييرات على البيئة
لإرسال طلب RPC لاستدعاء طريقة لخدمة باستخدام ملف proto بتنسيق JSON،
استخدِم الأمر cvd enc call
. عند انتهاء طلب RPC، تُطبع الواجهة الرسالة Rpc succeeded with OK status
ورسالة استجابة، إن توفّرت، تتضمّن القيم.
cvd env call SERVICE_NAME METHOD_NAME JSON_FORMATTED_PROTO
مثال على حالة الاستخدام
في ما يلي مثال على حالة استخدام الأمر cvd env
من واجهة سطر الأوامر لتعديل
قوة إشارة Wi-Fi من خلال الاتصال بـ SetTxpower
.
حدِّد اسم الخدمة واسم الطريقة ونوع رسالة الطلب
اسمًا لتعديل قوة إشارة Wi-Fi.
الحصول على قائمة بجميع الخدمات المتاحة
cvd env ls
(Omitted)
{
"services" :
[
"OpenwrtControlService",
"EchoService",
"GnssGrpcProxy",
"WmediumdService"
]
}
الحصول على قائمة بالطرق المتاحة في WmediumdService
cvd env ls WmediumdService
(Omitted)
{
"methods" :
[
"ListStations",
"LoadConfig",
"ReloadConfig",
"SetCivicloc",
"SetLci",
"SetPosition",
"SetSnr",
"SetTxpower",
"StartPcap",
"StopPcap"
]
}
الحصول على معلومات عن أنواع رسائل الطلب والاستجابة لطريقة
SetTxpower
cvd env ls WmediumdService SetTxpower
(Omitted)
{
"request_type" : "wmediumdserver.SetTxpowerRequest",
"response_type" : "google.protobuf.Empty"
}
الحصول على معلومات تفصيلية لنوع wmediumdserver.SetTxpowerRequest
request
الرسالة
cvd env type WmediumdService wmediumdserver.SetTxpowerRequest
(Omitted)
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
أرسِل طلبًا لاستدعاء إجراء عن بُعد إلى خدمة WmediumdService
لتعديل قوة إشارة Wi-Fi
إلى المستوى المطلوب.
cvd env call WmediumdService SetTxpower "{mac_address:'42:00:00:00:00:00', tx_power:1}"
(Omitted)
Rpc succeeded with OK status
{}
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Cuttlefish: Environment control\n\nThis page describes how to control the environment in a Cuttlefish device\nusing the REST API or the command line interface. For example, you can modify the\nWi-Fi signal or update the GPS location of the Cuttlefish device.\n\nServices\n--------\n\nThe `cvd env` command provides the following services for controlling the\nCuttlefish environment:\n\n| Services | Description |\n|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|\n| `GnssGrpcProxy` | Controls GNSS for the Cuttlefish geolocation feature. |\n| [`OpenwrtControlService`](/docs/devices/cuttlefish/wifi#openwrt_control_service) | Controls `Openwrt`, a virtualized Wi-Fi AP provider for the Cuttlefish Wi-Fi feature. |\n| [`WmediumdService`](/docs/devices/cuttlefish/wifi#wmediumd_service) | Controls `Wmediumd`, a wireless medium simulator for the Cuttlefish Wi-Fi feature. |\n| [`CasimirControlService`](/docs/devices/cuttlefish/nfc#casimir_control_service) | Controls `Casimir`, a simulator for external NFC devices. |\n\nControl the environment using the REST API\n------------------------------------------\n\nThis section describes how to control the environment using the Rest API\nthrough the `\u003chttps://localhost:1443\u003e` service endpoint.\n\n### List available services or methods\n\nTo get a list of all services, send a `GET` request to the following URL with\na device ID. \n\n https://localhost:1443/devices/\u003cvar translate=\"no\"\u003eDEVICE_ID\u003c/var\u003e/services\n\nTo get a list of all the methods for a service, send a `GET` request to the\nfollowing URL with a device ID and the service name. \n\n https://localhost:1443/devices/\u003cvar translate=\"no\"\u003eDEVICE_ID\u003c/var\u003e/services/\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e\n\nTo get detailed information for a method, such as the request or response\nmessage types, send a `GET` request to the following URL with a device ID,\na service name, and the method name. \n\n https://localhost:1443/devices/\u003cvar translate=\"no\"\u003eDEVICE_ID\u003c/var\u003e/services/\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e/\u003cvar translate=\"no\"\u003eMETHOD_NAME\u003c/var\u003e\n\n### Get detailed information on request and response types\n\nTo get detailed information of a request or response message type, send a `GET`\nrequest to the following URL with a device ID, a service name, and the\nrequest or response message type. This prints all the names and types of each\nfield in the message. You can then use this information to write a\nJSON-formatted proto message for sending a RPC request. \n\n https://localhost:1443/devices/\u003cvar translate=\"no\"\u003eDEVICE_ID\u003c/var\u003e/services/\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e/\u003cvar translate=\"no\"\u003eREQUEST_OR_RESPONSE_TYPE_NAME\u003c/var\u003e/type\n\n### Send RPC request to make changes to the environment\n\nTo send a RPC request to call a method of a service with a JSON-formatted proto,\nsend a `POST` request to the following URL with a device ID, a service\nname, and the method name. The JSON-formatted proto must be included in the\nbody. \n\n https://localhost:1443/devices/\u003cvar translate=\"no\"\u003eDEVICE_ID\u003c/var\u003e/services/\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e/\u003cvar translate=\"no\"\u003eMETHOD_NAME\u003c/var\u003e\n\n### Example use case\n\nThe following is an example use case of the Rest API for modifying the Wi-Fi\nsignal strength by calling `SetTxpower`.\n\n1. Determine the service name, method name, and the request message type\n name for modifying the Wi-Fi signal strength.\n\n 1. Get a list of all available services by sending a `GET` request to the\n following URL.\n\n https://localhost:1443/devices/cvd-1/services\n\n This is an example response. \n\n {\"services\":[\"OpenwrtControlService\",\"EchoService\",\"GnssGrpcProxy\",\"WmediumdService\"]}\n\n 2. Get a list of methods for `WmediumdService` by sending a `GET` request\n to the following URL.\n\n https://localhost:1443/devices/cvd-1/services/WmediumdService\n\n This is an example response. \n\n {\"methods\":[\"ListStations\",\"LoadConfig\",\"ReloadConfig\",\"SetCivicloc\",\"SetLci\",\"SetPosition\",\"SetSnr\",\"SetTxpower\",\"StartPcap\",\"StopPcap\"]}\n\n 3. Get information on the request and response message types for the\n `SetTxpower` method by sending a `GET` request to the following URL.\n\n https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower\n\n This is an example response. \n\n {\"request_type_name\":\"wmediumdserver.SetTxpowerRequest\",\"response_type_name\":\"google.protobuf.Empty\"}\n\n2. Get detailed information for the `wmediumdserver.SetTxpowerRequest` request\n message type by sending a `GET` request to the following URL.\n\n https://localhost:1443/devices/cvd-1/services/WmediumdService/wmediumdserver.SetTxpowerRequest/type\n\n This is an example response. \n\n message SetTxpowerRequest {\n string mac_address = 1;\n int32 tx_power = 2;\n }\n\n3. Send a RPC request to the `WmediumdService` service to modify the Wi-Fi\n signal strength to the desired level by sending a `POST` request to this URL\n with the following request body.\n\n https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower\n\n {\"mac_address\":\"42:00:00:00:00:00\", \"tx_power\":1}\n\n This is an example response. \n\n {}\n\nControl the environment using the command line\n----------------------------------------------\n\nThis section describes the subcommands available for the `cvd env` CLI command.\nFor further details, print the help message using `cvd help env`.\n\n### List available services or methods\n\nTo get a list of all services, use `cvd env ls` without any arguments. \n\n cvd env ls\n\nTo get a list of all the methods for a service, include the name of the\nservice as an argument. \n\n cvd env ls \u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e\n\nTo get detailed information such as the request or response message types of a\nmethod, include the service name and method name. \n\n cvd env ls \u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eMETHOD_NAME\u003c/var\u003e\n\n### Get detailed information on request and response types\n\nTo get detailed information of a request or response message type, use the\n`cvd env type` command. This command prints all names and types of each field\nin the message. You can then use this information to write a JSON-formatted\nproto message for sending a RPC request. \n\n cvd env type \u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eREQUEST_OR_RESPONSE_TYPE_NAME\u003c/var\u003e\n\n### Send RPC request to make changes to the environment\n\nTo send a RPC request to call a method of a service with a JSON-formatted proto,\nuse the `cvd enc call` command. When the RPC request terminates, the interface\nprints the message `Rpc succeeded with OK status` and, if available, a response\nmessage including values. \n\n cvd env call \u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eMETHOD_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eJSON_FORMATTED_PROTO\u003c/var\u003e\n\n### Example use case\n\nThe following is an example use case of the `cvd env` CLI command for modifying\nthe Wi-Fi signal strength by calling `SetTxpower`.\n\n1. Determine the service name, method name, and the request message type\n name for modifying the Wi-Fi signal strength.\n\n Get a list of all available services. \n\n cvd env ls\n (Omitted)\n {\n \"services\" :\n [\n \"OpenwrtControlService\",\n \"EchoService\",\n \"GnssGrpcProxy\",\n \"WmediumdService\"\n ]\n }\n\n Get a list of methods for `WmediumdService`. \n\n cvd env ls WmediumdService\n (Omitted)\n {\n \"methods\" :\n [\n \"ListStations\",\n \"LoadConfig\",\n \"ReloadConfig\",\n \"SetCivicloc\",\n \"SetLci\",\n \"SetPosition\",\n \"SetSnr\",\n \"SetTxpower\",\n \"StartPcap\",\n \"StopPcap\"\n ]\n }\n\n Get information on the request and response message types for the\n `SetTxpower` method. \n\n cvd env ls WmediumdService SetTxpower\n (Omitted)\n {\n \"request_type\" : \"wmediumdserver.SetTxpowerRequest\",\n \"response_type\" : \"google.protobuf.Empty\"\n }\n\n2. Get detailed information for the `wmediumdserver.SetTxpowerRequest` request\n message type.\n\n cvd env type WmediumdService wmediumdserver.SetTxpowerRequest\n (Omitted)\n message SetTxpowerRequest {\n string mac_address = 1;\n int32 tx_power = 2;\n }\n\n3. Send RPC request to the `WmediumdService` service to modify the Wi-Fi\n signal strength to the desired level.\n\n cvd env call WmediumdService SetTxpower \"{mac_address:'42:00:00:00:00:00', tx_power:1}\"\n (Omitted)\n Rpc succeeded with OK status\n {}"]]