prebuilt_etc_host {
// Use any name you choose.
name: "my_custom_action_config.json",
src: "my_custom_action_config.json",
// Always use this sub_dir.
sub_dir: "cvd_custom_action_config",
}
# Set these variables exactly as shown here to enable the host package to see# your custom config module name.SOONG_CONFIG_NAMESPACES+=cvdSOONG_CONFIG_cvd+=custom_action_config# Set this value to the name of your JSON module.SOONG_CONFIG_cvd_custom_action_config:=my_custom_action_config.json
# Append to this variable exactly as shown here.SOONG_CONFIG_cvd+=custom_action_servers# Append the name of your action server(s) to this variable.SOONG_CONFIG_cvd_custom_action_servers+=cuttlefish_example_action_server
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["The default WebRTC browser interface for Cuttlefish includes a control panel\nthat enables more ways to interact with the virtual device.\n\nThe control panel features default buttons to simulate common physical device\nactions such as power button or volume buttons, as well as device rotation.\n\nCustom actions\n\nYou can customize the control panel to add more buttons that allow your virtual\ndevice to more closely emulate your physical device. This is useful for testing\nfeatures unique to your device, such as a hardware button or special gesture\nthat triggers a unique action in the OS. You can also use custom buttons to\nenable testing more QA-focused features such as the behavior of your OS when the\ndevice is low battery.\n\nThe default Cuttlefish control panel includes support to \"plug in\" custom\nactions *without needing to modify the main Cuttlefish AOSP project* . Your\nvirtual device needs to include only a minimal configuration file to start using\ncustom actions. See this\n[example custom action config file](https://cs.android.com/android/platform/superproject/+/android-latest-release:device/google/cuttlefish/host/example_custom_actions/custom_action_config.json).\n\n1. Create a JSON file that defines your device's custom actions. You can put\n this file in any directory you own. The structure of this file is described\n in the [ADB shell](#adb-shell) and [Action server](#action-server) sections.\n\n2. Create a `prebuilt_etc_host` module for your JSON config. Ensure that the\n `sub_dir` is equal to `cvd_custom_action_config`.\n\n prebuilt_etc_host {\n // Use any name you choose.\n name: \"my_custom_action_config.json\",\n src: \"my_custom_action_config.json\",\n // Always use this sub_dir.\n sub_dir: \"cvd_custom_action_config\",\n }\n\n3. Set Soong config build variables in your device's product makefile to\n configure the virtual device host package to include your custom action\n config file.\n\n # Set these variables exactly as shown here to enable the host package to see\n # your custom config module name.\n SOONG_CONFIG_NAMESPACES += cvd\n SOONG_CONFIG_cvd += custom_action_config\n\n # Set this value to the name of your JSON module.\n SOONG_CONFIG_cvd_custom_action_config := my_custom_action_config.json\n\n| **Note:** If you want to remove custom actions from a local build, or change the name of the custom action config module, remove your old config by deleting `${ANDROID_SOONG_HOST_OUT}/etc/cvd_custom_action_config`.\n\nThere are two supported methods to implement a custom action:\n\n- ADB shell command\n- Action server\n\nYour JSON config file can define multiple instances of each type of\nimplementation.\n\nADB shell command\n\nYou can define a single button that is implemented by executing a single `adb\nshell` command. For example, the following JSON snippet defines a single button\nthat launches a web page: \n\n {\n \"shell_command\":\"am start -a android.intent.action.VIEW -d https://www.android.com/\",\n \"button\":{\n \"command\":\"web\",\n \";title\":\"Web Page\",\n \"icon_name\":\"language\"\n }\n }\n\nThe fields are:\n\n- `shell_command`: The command to execute in `adb shell` when the button is pressed\n- `button`: A single button object with the following subfields:\n - `command`: A unique name for this button\n - `title`: An alt-text title for this button\n - `icon_name`: The name of an icon from \u003chttps://material.io/resources/icons\u003e\n\nAction server\n\nAction servers allow more control over the behavior of your actions. An action\nserver is a host binary that listens for button press events from WebRTC using a\nsocket pair. WebRTC forwards the events to the action server, and then the\naction server decides how to implement the action.\n\nAction servers allow more powerful control, such as maintaining state (such as\nfor a toggleable event) or even running \"meta-actions\" such as killing the\ncurrent device, launching more devices, or starting a screen-recording browser\nextension. The possibilities are limited only by what you decide to implement\ninside the host binary.\n\nThe following JSON snippet defines an action server that listens for events on\ntwo buttons: \n\n {\n \"server\":\"cuttlefish_example_action_server\",\n \"buttons\":[\n {\n \"command\":\"settings\",\n \"title\":\"Quick Settings\",\n \"icon_name\":\"settings\"\n },\n {\n \"command":\"alert\",\n \"title\":\"Do Not Disturb\",\n \"icon_name\":\"notifications_paused\"\n }\n ]\n }\n\nThe fields are:\n\n- `server`: The name of your host binary module\n- `buttons`: An array of buttons, with the same subfields as above\n\nAfter updating the JSON config, append the name of the action server module to\nthe Soong config build variable `cvd_custom_action_servers`. For example: \n\n # Append to this variable exactly as shown here.\n SOONG_CONFIG_cvd += custom_action_servers\n\n # Append the name of your action server(s) to this variable.\n SOONG_CONFIG_cvd_custom_action_servers += cuttlefish_example_action_server\n\nEach action server host binary should perform the following steps:\n\n1. Accept a socket file descriptor number as the first and only program\n argument.\n\n This socket is created by `launch_cvd` using `socketpair` with domain\n `AF_LOCAL`, type `SOCK_STREAM`, and protocol 0.\n2. In a loop, attempt to read 128 bytes from the socket. These bytes\n contain button press events sent by the WebRTC client in the format\n `command:state`. `command` is as provided in the JSON config, and `state` is\n the button press state (`down` or `up`).\n\n3. Act on the incoming events to simulate the custom action.\n\n| **Warning:** You should implement any action servers in projects that you own, **not** in the main AOSP Cuttlefish project. This prevents conflicts with future AOSP changes in that project."]]