2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
Cuttlefish: 環境制御
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このページでは、REST API またはコマンドライン インターフェースを使用して、Cuttlefish デバイスの環境を制御する方法について説明します。たとえば、Cuttlefish デバイスの Wi-Fi の電波を変更したり、GPS 位置情報を更新したりできます。
サービス
cvd env
コマンドでは、Cuttlefish 環境を制御する次のサービスを実行できます。
REST API を使用して環境を制御する
このセクションでは、<https://localhost:1443>
サービス エンドポイントを介して REST API を使用して環境を制御する方法について説明します。
利用できるサービスまたはメソッドを一覧表示する
すべてのサービスのリストを取得するには、デバイス ID を指定した次の URL に GET
リクエストを送信します。
https://localhost:1443/devices/DEVICE_ID/services
サービスの全メソッドのリストを取得するには、デバイス ID とサービス名を指定した次の URL に GET
リクエストを送信します。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME
メソッドの詳細情報(リクエストやレスポンス メッセージのタイプなど)を取得するには、デバイス ID、サービス名、メソッド名を指定した次の URL に GET
リクエストを送信します。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
リクエストおよびレスポンス タイプに関する詳細情報を取得する
リクエストまたはレスポンス メッセージのタイプに関する詳細情報を取得するには、デバイス ID、サービス名、リクエストまたはレスポンス メッセージのタイプを指定した次の URL に GET
リクエストを送信します。これにより、メッセージの各フィールドの名前とタイプがすべて出力されます。この情報を利用して、リモート プロシージャ コール(RPC)リクエストを送信するための JSON 形式の proto メッセージを作成できます。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/REQUEST_OR_RESPONSE_TYPE_NAME/type
RPC リクエストを送信して環境を変更する
JSON 形式の proto で RPC リクエストを送信して、サービスのメソッドを呼び出すには、デバイス ID、サービス名、メソッド名を指定した次の URL に POST
リクエストを送信します。JSON 形式の proto を本文に含める必要があります。
https://localhost:1443/devices/DEVICE_ID/services/SERVICE_NAME/METHOD_NAME
ユースケースの例
以下は、SetTxpower
を呼び出して Wi-Fi 電波強度を調整する、REST API のユースケースの例です。
Wi-Fi 電波強度を調整するサービス名、メソッド名、リクエスト メッセージのタイプ名を決定します。
次の URL に GET
リクエストを送信して、利用可能なすべてのサービスのリストを取得します。
https://localhost:1443/devices/cvd-1/services
以下は、レスポンスの例です。
{"services":["OpenwrtControlService","EchoService","GnssGrpcProxy","WmediumdService"]}
次の URL に GET
リクエストを送信して、WmediumdService
のメソッドのリストを取得します。
https://localhost:1443/devices/cvd-1/services/WmediumdService
以下は、レスポンスの例です。
{"methods":["ListStations","LoadConfig","ReloadConfig","SetCivicloc","SetLci","SetPosition","SetSnr","SetTxpower","StartPcap","StopPcap"]}
次の URL に GET
リクエストを送信して、SetTxpower
メソッドのリクエストおよびレスポンス メッセージのタイプに関する情報を取得します。
https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower
以下は、レスポンスの例です。
{"request_type_name":"wmediumdserver.SetTxpowerRequest","response_type_name":"google.protobuf.Empty"}
次の URL に GET
リクエストを送信して、wmediumdserver.SetTxpowerRequest
リクエスト メッセージ タイプの詳細情報を取得します。
https://localhost:1443/devices/cvd-1/services/WmediumdService/wmediumdserver.SetTxpowerRequest/type
以下は、レスポンスの例です。
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
下記のリクエスト本文を使用して次の URL に POST
リクエストを送信し、Wi-Fi 電波強度を望ましいレベルに調整するよう WmediumdService
サービスに RPC リクエストを送信します。
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
コマンドを使用します。このコマンドでは、メッセージの各フィールドの名前とタイプがすべて出力されます。この情報を利用して、リモート プロシージャ コール(RPC)リクエストを送信するための JSON 形式の proto メッセージを作成できます。
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
ユースケースの例
以下は、SetTxpower
を呼び出して Wi-Fi 電波強度を調整する、cvd env
CLI コマンドのユースケースの例です。
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 および関連会社の商標または登録商標です。
最終更新日 2025-03-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-03-26 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 {}"]]