ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
Cuttlefish: การควบคุมสภาพแวดล้อม
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หน้านี้อธิบายวิธีควบคุมสภาพแวดล้อมในอุปกรณ์ Cuttlefish โดยใช้ REST API หรืออินเทอร์เฟซบรรทัดคำสั่ง เช่น คุณอาจแก้ไขสัญญาณ Wi-Fi หรืออัปเดตตำแหน่ง GPS ของอุปกรณ์ Cuttlefish ได้
บริการ
คำสั่ง cvd env
มีบริการต่อไปนี้สำหรับควบคุมสภาพแวดล้อม Cuttlefish
บริการ |
คำอธิบาย |
GnssGrpcProxy
|
ควบคุม GNSS สําหรับฟีเจอร์ระบุตําแหน่งทางภูมิศาสตร์ของ Cuttlefish |
OpenwrtControlService
|
ควบคุม Openwrt ซึ่งเป็นผู้ให้บริการ AP Wi-Fi เสมือนจริงสำหรับฟีเจอร์ Wi-Fi ของ Cuttlefish |
WmediumdService
|
ควบคุม Wmediumd ซึ่งเป็นเครื่องจำลองสื่อไร้สายสำหรับฟีเจอร์ Wi-Fi ของ Cuttlefish |
CasimirControlService
|
ควบคุม Casimir ซึ่งเป็นเครื่องจำลองสำหรับอุปกรณ์ NFC ภายนอก |
ควบคุมสภาพแวดล้อมโดยใช้ REST API
ส่วนนี้จะอธิบายวิธีควบคุมสภาพแวดล้อมโดยใช้ 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 เพื่อเรียกใช้เมธอดของบริการที่มีโปรโตคอลรูปแบบ JSON ให้ส่งคําขอ POST
ไปยัง URL ต่อไปนี้พร้อมรหัสอุปกรณ์ ชื่อบริการ และชื่อเมธอด ต้องใส่โปรโตคอลรูปแบบ JSON ไว้ในเนื้อหา
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
ตัวอย่างกรณีการใช้งาน
ต่อไปนี้คือตัวอย่าง Use Case ของ 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}
นี่คือตัวอย่างการตอบกลับ
{}
ควบคุมสภาพแวดล้อมโดยใช้บรรทัดคำสั่ง
ส่วนนี้จะอธิบายคำสั่งย่อยที่ใช้ได้กับคำสั่ง CLI 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 เพื่อเรียกใช้เมธอดของบริการที่มีโปรโตคอลรูปแบบ JSON ให้ใช้คําสั่ง cvd enc call
เมื่อคําขอ RPC สิ้นสุดลง อินเทอร์เฟซจะพิมพ์ข้อความ Rpc succeeded with OK status
และข้อความตอบกลับพร้อมค่า (หากมี)
cvd env call SERVICE_NAME METHOD_NAME JSON_FORMATTED_PROTO
ตัวอย่างกรณีการใช้งาน
ต่อไปนี้คือตัวอย่าง Use Case ของคําสั่ง CLI 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
คำขอประเภทข้อความ
cvd env type WmediumdService wmediumdserver.SetTxpowerRequest
(Omitted)
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
ส่งคําขอ RPC ไปยังบริการ 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 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-27 UTC"],[],[],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 {}"]]