Skip to main content

Module emulator

Module emulator 

Source
Expand description

Client for the emulator’s gRPC controller: the emulator fast path (design D7, android-driver requirement “Emulator fast path”).

An emulator started with -grpc <port> -grpc-use-token serves the EmulatorController service and writes the port and a bearer token into its discovery file. resolve finds them for an adb serial, and Controller::connect opens the connections and reads the hardware. When the endpoint cannot be used the error is Unavailable, whose warning says how to enable it: the launch flag, or the console command that needs no restart.

The client handles the protocol quirks spike S7 found:

  • scaling needs both width and height (scaled_size);
  • raw rows arrive top-down although the proto says bottom-up (Frame);
  • the display size is only in the deprecated hardwareConfig (Hardware::from_status);
  • every call needs a deadline, because some emulator ports accept TCP and never answer (Options);
  • sendKey accepts and drops keys when the AVD has no keyboard, so the client sends none and reports Hardware::keyboard instead;
  • the stream repeats unchanged frames and the status bar clock changes on its own, so changes are detected on hashes without the status bar (ChangeDetector).

Modules§

proto
The android.emulation.control client, generated by build.rs from the installed emulator’s emulator_controller.proto.

Structs§

ChangeDetector
Detects content changes in a sequence of frames, such as a frame stream. Feeds the settle signal: frames keep arriving while nothing changes.
Controller
A connected emulator controller.
Discovery
Parsed contents of one discovery file.
DisplaySize
Size of the emulator’s display in pixels, in its natural orientation.
Endpoint
Where an emulator’s controller listens and how to authenticate to it.
Found
One discovery file found on disk.
Frame
A raw RGB888 frame.
FrameHasher
Hashes frame content without the status bar.
FrameKey
Identity of a frame’s content outside the status bar.
FrameStream
A subscription to the emulator’s frames.
Hardware
The virtual hardware the driver needs to know about.
Options
Deadlines of the client.
TouchPoint
One contact in a touch event.
Unavailable
The emulator’s control endpoint cannot be used, so taps and frames fall back to the agent. Unavailable::warning is the text for the target status.

Enums§

DiscoveryError
A discovery file that could not be parsed.
Error
Why a call on a connected controller failed.
FrameError
Why bytes do not make a frame.
Observation
What a frame means relative to the one before it.

Constants§

BYTES_PER_PIXEL
Bytes per pixel of the RGB888 frames the client requests.
DOWN_PRESSURE
Pressure of a finger on the glass; the touchscreen’s axis maximum is 1024.
MAX_MESSAGE
Largest message the client accepts: a native RGBA8888 frame of a 1080x2400 display is 10.4 MB, beyond tonic’s default of 4 MB.
PROTO_SOURCE
The proto file the client was generated from, as build.rs found it.

Functions§

candidate_dirs
Directories the emulator writes discovery files to, in search order: $XDG_RUNTIME_DIR/avd/running when set, then the per-OS default (~/Library/Caches/TemporaryItems/avd/running on macOS, /run/user/<uid>/avd/running on Linux, %LOCALAPPDATA%\Temp\avd\running on Windows), then avd/running under the temporary directory. For one emulator the authoritative answer is its console command avd discoverypath.
console_port_from_serial
The console port in an emulator serial: emulator-5554 gives 5554.
find_for_serial
The discovery whose console port matches serial. When several match, as when a crashed emulator left a stale file next to the live one, the last one in found wins; scan_dir orders files oldest first.
pid_from_file_name
The pid in a discovery file name: pid_59226.ini gives 59226.
resolve
Resolves serial through the discovery files in discovery::candidate_dirs.
resolve_in
Resolves serial through the discovery files in dirs; when several files name the serial, the newest wins.
scaled_size
The frame size to request for frames working_width pixels wide.
scan_dir
Reads every pid_*.ini in dir, oldest modification first. A file that cannot be read, such as one an exiting emulator just removed, is skipped.