fix: minor improvments

This commit is contained in:
LIAUD Corentin
2024-11-09 13:58:28 +01:00
committed by cocool97
parent c835f20263
commit 61ba07ecf0
4 changed files with 15 additions and 6 deletions

View File

@@ -19,8 +19,10 @@ pub enum LocalCommand {
/// Run an activity on device specified by the intent
Run {
/// The package whose activity is to be invoked
#[clap(short = 'p', long = "package")]
package: String,
/// The activity to be invoked itself, Usually it is MainActivity
#[clap(short = 'a', long = "activity")]
activity: String,
},
/// Reboot the device

View File

@@ -37,8 +37,10 @@ pub enum UsbCommands {
/// Run an activity on device specified by the intent
Run {
/// The package whose activity is to be invoked
#[clap(short = 'p', long = "package")]
package: String,
/// The activity to be invoked itself, Usually it is MainActivity
#[clap(short = 'a', long = "activity")]
activity: String,
},
/// Reboot the device

View File

@@ -66,7 +66,8 @@ fn main() -> Result<()> {
}
}
LocalCommand::Run { package, activity } => {
device.run_activity(&package, &activity)?;
let output = device.run_activity(&package, &activity)?;
std::io::stdout().write_all(&output)?;
}
LocalCommand::HostFeatures => {
let features = device
@@ -219,7 +220,8 @@ fn main() -> Result<()> {
log::info!("Uploaded {filename} to {path}");
}
UsbCommands::Run { package, activity } => {
device.run_activity(&package, &activity)?;
let output = device.run_activity(&package, &activity)?;
std::io::stdout().write_all(&output)?;
}
}
}

View File

@@ -29,11 +29,14 @@ pub trait ADBDeviceExt {
/// Reboots the device using given reboot type
fn reboot(&mut self, reboot_type: RebootType) -> Result<()>;
/// Run an `activity` from a given `package` on device
fn run_activity(&mut self, package: &str, activity: &str) -> Result<()> {
/// Run `activity` from `package` on device. Return the command output.
fn run_activity(&mut self, package: &str, activity: &str) -> Result<Vec<u8>> {
let mut output = Vec::new();
self.shell_command(
["am", "start", &format!("{package}/{package}.{activity}")],
std::io::stdout(),
)
&mut output,
)?;
Ok(output)
}
}