Skip to content

Commit

Permalink
fix: minor improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
cocool97 committed Nov 9, 2024
1 parent c835f20 commit 61ba07e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions adb_cli/src/commands/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions adb_cli/src/commands/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions adb_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions adb_client/src/adb_device_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 61ba07e

Please sign in to comment.