Skip to main content

EmulatorConfig

Struct EmulatorConfig 

Source
pub struct EmulatorConfig { /* private fields */ }
Expand description

Configuration for starting an Android emulator

Implementations§

Source§

impl EmulatorConfig

Source

pub fn new(avd_name: impl Into<String>) -> Self

Create a new config with a specific AVD name

Source

pub fn avd_id(&self) -> &str

Get the AVD name that was specified

Source

pub fn with_grpc_auth(self, auth: GrpcAuthConfig) -> Self

Configure gRPC authentication

§Examples

No authentication:

use android_emulator::{EmulatorConfig, GrpcAuthConfig};

let config = EmulatorConfig::new("test")
    .with_grpc_auth(GrpcAuthConfig::None);

Basic authentication (console token as bearer):

use android_emulator::{EmulatorConfig, GrpcAuthConfig};

let config = EmulatorConfig::new("test")
    .with_grpc_auth(GrpcAuthConfig::Basic)
    .with_grpc_port(8554);

JWT mode with custom issuer:

use android_emulator::{EmulatorConfig, GrpcAuthConfig};

let config = EmulatorConfig::new("test")
    .with_grpc_auth(GrpcAuthConfig::Jwt {
        issuer: Some("mytool".to_string()),
    })
    .with_grpc_port(8555);

JWT mode with auto-derived issuer and auto-selected port:

use android_emulator::{EmulatorConfig, GrpcAuthConfig};

let config = EmulatorConfig::new("test")
    .with_grpc_auth(GrpcAuthConfig::Jwt {
        issuer: None,  // Will be "emulator-{port}"
    });
Source

pub fn with_grpc_port(self, port: u16) -> Self

Set the gRPC port

If not specified, a free port will be automatically selected.

§Example
use android_emulator::EmulatorConfig;

let config = EmulatorConfig::new("test")
    .with_grpc_port(8554);
Source

pub fn with_window(self, show: bool) -> Self

Configure whether to show the emulator window

Default is false (headless). Set to true to show the window.

Source

pub fn with_snapshot_load(self, load: bool) -> Self

Configure whether to load snapshots

Default is true (load snapshots). Set to false to disable snapshot loading on startup.

Source

pub fn with_snapshot_save(self, save: bool) -> Self

Configure whether to save snapshots on exit

Default is true (save snapshots). Set to false to disable snapshot saving on exit.

Source

pub fn with_boot_animation(self, show: bool) -> Self

Configure whether to show the boot animation

Default is true (show boot animation). Set to false to disable the boot animation for faster startup.

Source

pub fn with_acceleration(self, enable: bool) -> Self

Configure whether to disable hardware acceleration (e.g., for running in CI without KVM)

Default is false (use hardware acceleration if available). Set to true to disable hardware acceleration

Source

pub fn with_dalvik_vm_check_jni(self, enable: bool) -> Self

Configure whether to pass -dalvik-vm-checkjni flag to the emulator

This can be useful for testing JNI-related functionality and catching errors early. Default is false (don’t check JNI). Set to true to enable JNI checking.

Source

pub fn with_read_only(self, read_only: bool) -> Self

Configure whether to allow running multiple instances of the same AVD (without support for snapshots)

Default is false (don’t allow multiple instances). Set to true to allow multiple instances of the same AVD, but note that snapshots will not work in this mode.

Source

pub fn with_quit_after_boot(self, duration: Option<Duration>) -> Self

Configure the emulator to automatically quit after it has booted and been idle for the specified duration (for testing purposes)

This can be useful for testing emulator startup and shutdown in CI environments.

Default is None (don’t quit automatically). Set to Some(duration) to enable this behavior.

Source

pub fn with_extra_args(self, args: Vec<String>) -> Self

Source

pub fn with_grpc_allowlist(self, allowlist: GrpcAllowlist) -> Self

Set a custom gRPC allowlist configuration for JWT authentication

This allows fine-grained control over which gRPC methods are accessible and under what conditions when using JWT authentication. The allowlist defines three categories of methods:

  • Unprotected: Methods that can be invoked without any authentication token
  • Allowed: Methods that can be called with a valid JWT token, even without an aud claim
  • Protected: Methods that require the specific method to be present in the JWT token’s aud claim

If you don’t specify a custom allowlist, a default one will be generated using GrpcAllowlist::default_for_issuer.

§Arguments
§Example
use android_emulator::{EmulatorConfig, GrpcAuthConfig, auth::{GrpcAllowlist, AllowlistEntry}};

let allowlist = GrpcAllowlist {
    unprotected: vec![],  // No methods accessible without auth
    allowlist: vec![
        AllowlistEntry {
            iss: "mytool".to_string(),
            allowed: vec![
                "/android.emulation.control.EmulatorController/.*".to_string(),
            ],
            protected: vec![
                "/android.emulation.control.SnapshotService/.*".to_string(),
            ],
        },
    ],
};

let config = EmulatorConfig::new("test")
    .with_grpc_auth(GrpcAuthConfig::Jwt {
        issuer: Some("mytool".to_string()),
    })
    .with_grpc_allowlist(allowlist);
§See Also
Source

pub fn stdout<T: Into<Stdio>>(self, cfg: T) -> Self

Configure stdout for the emulator process

Source

pub fn stderr<T: Into<Stdio>>(self, cfg: T) -> Self

Configure stderr for the emulator process

Source

pub async fn spawn(self) -> Result<Emulator>

Start an Android emulator with the given configuration

Trait Implementations§

Source§

impl Debug for EmulatorConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more