-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking: make ADBDeviceExt dyn-compatible (#70)
* feat: make ADBDeviceExt dyn-compatible * feat: clean CLI code
- Loading branch information
Showing
29 changed files
with
453 additions
and
584 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use adb_client::ADBEmulatorDevice; | ||
|
||
use crate::models::{EmuCommand, EmulatorCommand}; | ||
|
||
pub fn handle_emulator_commands(emulator_command: EmulatorCommand) -> anyhow::Result<()> { | ||
let mut emulator = ADBEmulatorDevice::new(emulator_command.serial, None)?; | ||
|
||
match emulator_command.command { | ||
EmuCommand::Sms { | ||
phone_number, | ||
content, | ||
} => { | ||
emulator.send_sms(&phone_number, &content)?; | ||
log::info!("SMS sent to {phone_number}"); | ||
} | ||
EmuCommand::Rotate => emulator.rotate()?, | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use adb_client::{ADBServer, DeviceShort, MDNSBackend, Result}; | ||
|
||
use crate::models::{HostCommand, MdnsCommand, ServerCommand}; | ||
|
||
pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Result<()> { | ||
let mut adb_server = ADBServer::new(server_command.address); | ||
|
||
match server_command.command { | ||
HostCommand::Version => { | ||
let version = adb_server.version()?; | ||
log::info!("Android Debug Bridge version {}", version); | ||
log::info!("Package version {}-rust", std::env!("CARGO_PKG_VERSION")); | ||
} | ||
HostCommand::Kill => { | ||
adb_server.kill()?; | ||
} | ||
HostCommand::Devices { long } => { | ||
if long { | ||
log::info!("List of devices attached (extended)"); | ||
for device in adb_server.devices_long()? { | ||
log::info!("{}", device); | ||
} | ||
} else { | ||
log::info!("List of devices attached"); | ||
for device in adb_server.devices()? { | ||
log::info!("{}", device); | ||
} | ||
} | ||
} | ||
HostCommand::TrackDevices => { | ||
let callback = |device: DeviceShort| { | ||
log::info!("{}", device); | ||
Ok(()) | ||
}; | ||
log::info!("Live list of devices attached"); | ||
adb_server.track_devices(callback)?; | ||
} | ||
HostCommand::Pair { address, code } => { | ||
adb_server.pair(address, code)?; | ||
log::info!("Paired device {address}"); | ||
} | ||
HostCommand::Connect { address } => { | ||
adb_server.connect_device(address)?; | ||
log::info!("Connected to {address}"); | ||
} | ||
HostCommand::Disconnect { address } => { | ||
adb_server.disconnect_device(address)?; | ||
log::info!("Disconnected {address}"); | ||
} | ||
HostCommand::Mdns { subcommand } => match subcommand { | ||
MdnsCommand::Check => { | ||
let check = adb_server.mdns_check()?; | ||
let server_status = adb_server.server_status()?; | ||
match server_status.mdns_backend { | ||
MDNSBackend::Unknown => log::info!("unknown mdns backend..."), | ||
MDNSBackend::Bonjour => match check { | ||
true => log::info!("mdns daemon version [Bonjour]"), | ||
false => log::info!("ERROR: mdns daemon unavailable"), | ||
}, | ||
MDNSBackend::OpenScreen => { | ||
log::info!("mdns daemon version [Openscreen discovery 0.0.0]") | ||
} | ||
} | ||
} | ||
MdnsCommand::Services => { | ||
log::info!("List of discovered mdns services"); | ||
for service in adb_server.mdns_services()? { | ||
log::info!("{}", service); | ||
} | ||
} | ||
}, | ||
HostCommand::ServerStatus => { | ||
log::info!("{}", adb_server.server_status()?); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::{fs::File, io::Write}; | ||
|
||
use adb_client::ADBServerDevice; | ||
use anyhow::{anyhow, Result}; | ||
|
||
use crate::models::LocalDeviceCommand; | ||
|
||
pub fn handle_local_commands( | ||
mut device: ADBServerDevice, | ||
local_device_commands: LocalDeviceCommand, | ||
) -> Result<()> { | ||
match local_device_commands { | ||
LocalDeviceCommand::HostFeatures => { | ||
let features = device | ||
.host_features()? | ||
.iter() | ||
.map(|v| v.to_string()) | ||
.reduce(|a, b| format!("{a},{b}")) | ||
.ok_or(anyhow!("cannot list features"))?; | ||
log::info!("Available host features: {features}"); | ||
|
||
Ok(()) | ||
} | ||
LocalDeviceCommand::List { path } => Ok(device.list(path)?), | ||
LocalDeviceCommand::Logcat { path } => { | ||
let writer: Box<dyn Write> = if let Some(path) = path { | ||
let f = File::create(path)?; | ||
Box::new(f) | ||
} else { | ||
Box::new(std::io::stdout()) | ||
}; | ||
Ok(device.get_logs(writer)?) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod emulator_commands; | ||
mod host_commands; | ||
mod local_commands; | ||
|
||
pub use emulator_commands::handle_emulator_commands; | ||
pub use host_commands::handle_host_commands; | ||
pub use local_commands::handle_local_commands; |
Oops, something went wrong.