自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Cuttlefish:环境控制
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了如何使用 REST API 或命令行界面控制 Cuttlefish 设备中的环境。例如,您可以修改 Cuttlefish 设备的 Wi-Fi 信号或更新其 GPS 位置。
服务
cvd env
命令提供以下控制 Cuttlefish 环境的服务:
使用 REST API 控制环境
本部分介绍如何通过 <https://localhost:1443>
服务端点使用 REST API 控制环境。
列出可用的服务或方法
要获取所有服务的列表,请向以下网址发送 GET
请求(其中包含设备 ID)。
https://localhost:1443/devices/DEVICE_ID/services
要获取服务的所有方法的列表,请向以下网址发送 GET
请求(其中包含设备 ID 和服务名称)。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME
要获取方法的详细信息(例如请求或响应消息类型),请向以下网址发送 GET
请求(其中包含设备 ID、服务名称和方法名称)。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
详细了解请求和响应类型
如需获取请求或响应消息类型的详细信息,请向以下网址发送 GET
请求(其中包含设备 ID、服务名称,以及请求或响应消息类型)。这将输出消息中每个字段的所有名称和类型。然后,您可以根据此信息编写 JSON 格式的 proto 消息,用于发送 RPC 请求。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/REQUEST_OR_RESPONSE_TYPE_NAME/type
发送 RPC 请求以更改环境
如需使用 JSON 格式的 proto 发送 RPC 请求来调用某项服务的方法,请向以下网址发送 POST
请求(其中包含设备 ID、服务名称和方法名称)。JSON 格式的 proto 必须包含在正文中。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
示例用例
以下是 REST API 的一个示例用例,该命令通过调用 SetTxpower
修改 Wi-Fi 信号强度。
确定用于修改 Wi-Fi 信号强度的服务名称、方法名称和请求消息类型名称。
向以下网址发送 GET
请求,以获取所有可用服务的列表。
https://localhost:1443/devices/cvd-1/services
这是一个示例响应。
{"services":["OpenwrtControlService","EchoService","GnssGrpcProxy","WmediumdService"]}
向以下网址发送 GET
请求,以获取 WmediumdService
的方法列表。
https://localhost:1443/devices/cvd-1/services/WmediumdService
这是一个示例响应。
{"methods":["ListStations","LoadConfig","ReloadConfig","SetCivicloc","SetLci","SetPosition","SetSnr","SetTxpower","StartPcap","StopPcap"]}
向以下网址发送 GET
请求,获取 SetTxpower
方法的请求和响应消息类型的信息。
https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower
这是一个示例响应。
{"request_type_name":"wmediumdserver.SetTxpowerRequest","response_type_name":"google.protobuf.Empty"}
向以下网址发送 GET
请求,以获取 wmediumdserver.SetTxpowerRequest
请求消息类型的详细信息。
https://localhost:1443/devices/cvd-1/services/WmediumdService/wmediumdserver.SetTxpowerRequest/type
这是一个示例响应。
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
通过向此网址发送正文如下的 POST
请求来向 WmediumdService
服务发送 RPC 请求,以将 Wi-Fi 信号强度修改为所需的级别。
https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower
{"mac_address":"42:00:00:00:00:00", "tx_power":1}
这是一个示例响应。
{}
使用命令行控制环境
本部分介绍了 cvd env
CLI 命令可用的子命令。如需了解更多详情,请使用 cvd help env
输出帮助消息。
列出可用的服务或方法
要获取所有服务的列表,请使用不带任何参数的 cvd env ls
。
cvd env ls
要获取服务的所有方法的列表,请将服务的名称添加为参数。
cvd env ls SERVICE_NAME
要获取详细信息(例如某方法的请求或响应消息类型),请添加服务名称和方法名称。
cvd env ls SERVICE_NAME METHOD_NAME
详细了解请求和响应类型
如需获取请求或响应消息类型的详细信息,请使用 cvd env type
命令。此命令会输出消息中每个字段的所有名称和类型。然后,您可以根据此信息编写 JSON 格式的 proto 消息,用于发送 RPC 请求。
cvd env type SERVICE_NAME REQUEST_OR_RESPONSE_TYPE_NAME
发送 RPC 请求以更改环境
如需使用 JSON 格式的 proto 发送 RPC 请求来调用某项服务的方法,请使用 cvd enc call
命令。当 RPC 请求终止时,界面会输出消息 Rpc succeeded with OK status
和一条包含值的响应消息(如有)。
cvd env call SERVICE_NAME METHOD_NAME JSON_FORMATTED_PROTO
示例用例
以下是 cvd env
CLI 命令的一个示例用例,该命令通过调用 SetTxpower
修改 Wi-Fi 信号强度。
确定用于修改 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
请求消息类型的详细信息。
cvd env type WmediumdService wmediumdserver.SetTxpowerRequest
(Omitted)
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
向 WmediumdService
服务发送 RPC 请求,以将 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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],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 {}"]]