android/emulator/mod.rs
1//! Client for the emulator's gRPC controller: the emulator fast path (design
2//! D7, android-driver requirement "Emulator fast path").
3//!
4//! An emulator started with `-grpc <port> -grpc-use-token` serves the
5//! `EmulatorController` service and writes the port and a bearer token into its
6//! discovery file. [`resolve`] finds them for an adb serial, and
7//! [`Controller::connect`] opens the connections and reads the hardware. When
8//! the endpoint cannot be used the error is [`Unavailable`], whose warning says
9//! how to enable it: the launch flag, or the console command that needs no
10//! restart.
11//!
12//! The client handles the protocol quirks spike S7 found:
13//!
14//! - scaling needs both width and height ([`scaled_size`]);
15//! - raw rows arrive top-down although the proto says bottom-up ([`Frame`]);
16//! - the display size is only in the deprecated `hardwareConfig`
17//! ([`Hardware::from_status`]);
18//! - every call needs a deadline, because some emulator ports accept TCP and
19//! never answer ([`Options`]);
20//! - `sendKey` accepts and drops keys when the AVD has no keyboard, so the
21//! client sends none and reports [`Hardware::keyboard`] instead;
22//! - the stream repeats unchanged frames and the status bar clock changes on
23//! its own, so changes are detected on hashes without the status bar
24//! ([`ChangeDetector`]).
25
26mod controller;
27mod discovery;
28mod endpoint;
29mod frame;
30mod hardware;
31pub mod proto;
32
33pub use controller::{
34 Controller, DOWN_PRESSURE, Error, FrameStream, MAX_MESSAGE, Options, TouchPoint,
35};
36pub use discovery::{
37 Discovery, DiscoveryError, Found, candidate_dirs, console_port_from_serial, find_for_serial,
38 pid_from_file_name, scan_dir,
39};
40pub use endpoint::{Endpoint, Unavailable, resolve, resolve_in};
41pub use frame::{
42 BYTES_PER_PIXEL, ChangeDetector, Frame, FrameError, FrameHasher, FrameKey, Observation,
43};
44pub use hardware::{DisplaySize, Hardware, scaled_size};
45
46/// The proto file the client was generated from, as `build.rs` found it.
47pub const PROTO_SOURCE: &str = env!("MOBILE_AGENT_EMULATOR_PROTO_SOURCE");