Device & AVD Management
Relevant source files
The following files were used as context for generating this wiki page:
The Device & AVD Management system in Keynobi provides a comprehensive interface for interacting with physical Android devices and Android Virtual Devices (AVDs). It serves as a bridge between the user interface and the underlying Android development tools (ADB, avdmanager, sdkmanager), allowing developers to monitor device status, launch emulators, and manage virtual device lifecycles directly within the application.
This module is responsible for real-time device polling, AVD creation and deletion, system image management, and facilitating the connection between the companion app and the target Android environment. It works in conjunction with the Build System to ensure applications are deployed to the correct target.
System Architecture
The architecture follows a multi-layered approach typical of Tauri applications, separating state management in the frontend from hardware-level execution in the Rust backend.
Component Overview
- Rust Backend (
src-tauri): Executes low-level shell commands to ADB and AVD tools. It handles asynchronous polling and event emission when device lists change. - Tauri API Bridge (
src/lib/tauri-api.ts): Provides typed TypeScript wrappers for invoking Rust commands. - SolidJS Store (
src/stores/device.store.ts): Maintains the global reactive state for all discovered devices and emulators. - UI Layers: Includes the
DeviceSidebar,DevicePanel, and various dialogs for creation and downloads.
The following diagram illustrates the data flow when a device is connected or an emulator is launched:
Device State & Selection
Keynobi tracks two distinct categories of devices:
- Connected Devices: Real-time physical devices or running emulators detected via
adb devices. - Virtual Devices (AVDs): Configured emulators available on the system, regardless of whether they are currently running.
State Data Structure
The DeviceStoreState interface defines the core data tracked by the application:
| Field | Type | Description |
|---|---|---|
devices | Device[] | Array of online/offline devices from ADB. |
avds | AvdInfo[] | List of installed AVDs from avdmanager. |
selectedSerial | string | null | The serial of the device targeted for builds/logs. |
launchingAvd | string | null | Name of an AVD currently in the boot process. |
systemImages | SystemImageInfo[] | Cached list of installed system images. |
Sources: src/stores/device.store.ts:13-22, src/lib/tauri-api.ts:203-204
Selection Logic
The store automatically selects the first online device if no selection exists. Manual selection via pickDevice notifies other services, such as the project.service, to persist target preferences per project.
Sources: src/stores/device.store.ts:80-97
AVD Lifecycle Management
Keynobi provides a full suite of management tools for virtual devices, wrapping complex CLI interactions into user-friendly dialogs and context menus.
Creation Workflow
The CreateDeviceDialog facilitates the creation of new emulators. It requires selecting a hardware Device Profile and a System Image.
- Suggested Naming: Automatically generates names like
Pixel_5_API_35based on selection. - Validation: Prevents spaces and duplicate names.
Sources: src/components/device/CreateDeviceDialog.tsx:38-55
Maintenance Operations
Users can perform the following actions on AVDs via the DevicePanel or DeviceSidebar context menus:
- Launch: Executes the emulator and waits for it to appear in ADB.
- Stop: Terminates the process associated with a specific serial.
- Wipe Data: Erases user data by relaunching with the
-wipe-dataflag. - Delete: Permanently removes the AVD configuration from the disk.
Sources: src/components/device/DevicePanel.tsx:64-106, src-tauri/src/commands/device.rs:239-244
System Image Management
To support AVD creation, Keynobi manages both installed and available system images through sdkmanager.
Downloading Images
The DownloadSystemImageDialog provides a searchable list of remote images.
- Progress Tracking: Uses a Tauri
Channelto stream download percentages and messages from Rust to the UI. - Filter Support: Allows filtering by API level, ABI (e.g.,
arm64-v8a), or display name.
Sources: src/components/device/DownloadSystemImageDialog.tsx:60-84, src-tauri/src/commands/device.rs:260-285
Image Data Model
| Field | Source | Description |
|---|---|---|
sdkId | AvailableSystemImage | The internal identifier (e.g., system-images;android-35;google_apis;arm64-v8a). |
apiLevel | SystemImageInfo | The Android API version. |
abi | SystemImageInfo | CPU architecture (arm64, x86_64). |
installed | AvailableSystemImage | Boolean indicating if the image is available locally. |
Sources: src/lib/tauri-api.ts:251-252, src/components/device/DownloadSystemImageDialog.tsx:18-24
Backend Polling and Synchronization
The backend maintains a background task to ensure the frontend remains synchronized with physical hardware changes (e.g., unplugging a USB cable).
- Polling Interval: The Rust service polls ADB every 3 seconds.
- Differential Updates: It only emits a
device:list_changedevent if the list of serial numbers has changed. - Property Enrichment: Upon discovering a new online device, the backend performs additional ADB calls to retrieve property metadata like
ro.build.version.releaseandro.product.model.
Sources: src-tauri/src/commands/device.rs:141-186
Technical Summary
The Device & AVD Management system centralizes Android hardware control by combining proactive backend monitoring with a reactive frontend store. By wrapping CLI tools like adb, avdmanager, and sdkmanager, Keynobi provides a GUI for complex developer workflows, ensuring that device availability and system images are always current and accessible for deployment tasks.