Skip to content

Commit

Permalink
feat: add run_activity method and default impl for ADBDeviceExt
Browse files Browse the repository at this point in the history
  • Loading branch information
lavafroth committed Nov 6, 2024
1 parent b3a1fcb commit 3ad5be0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
6 changes: 4 additions & 2 deletions adb_cli/src/commands/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ pub enum LocalCommand {
Shell { commands: Vec<String> },
/// Run an activity on device specified by the intent
Run {
/// The activity intent to be invoked, it is most commonly packagename/packagename.MainActivity
intent: String,
/// The package whose activity is to be invoked
package: String,
/// The activity to be invoked itself, Usually it is MainActivity
activity: String,
},
/// Reboot the device
Reboot {
Expand Down
6 changes: 4 additions & 2 deletions adb_cli/src/commands/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ pub enum UsbCommands {
Stat { path: String },
/// Run an activity on device specified by the intent
Run {
/// The activity intent to be invoked, it is most commonly packagename/packagename.MainActivity
intent: String,
/// The package whose activity is to be invoked
package: String,
/// The activity to be invoked itself, Usually it is MainActivity
activity: String,
},
/// Reboot the device
Reboot {
Expand Down
8 changes: 4 additions & 4 deletions adb_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fn main() -> Result<()> {
device.shell_command(commands, std::io::stdout())?;
}
}
LocalCommand::Run { intent } => {
device.shell_command(["am", "start", &intent], std::io::stdout())?;
LocalCommand::Run { package, activity } => {
device.run_activity(&package, &activity)?;
}
LocalCommand::HostFeatures => {
let features = device
Expand Down Expand Up @@ -218,8 +218,8 @@ fn main() -> Result<()> {
device.push(&mut input, &path)?;
log::info!("Uploaded {filename} to {path}");
}
UsbCommands::Run { intent } => {
device.shell_command(["am", "start", &intent], std::io::stdout())?;
UsbCommands::Run { package, activity } => {
device.run_activity(&package, &activity)?;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions adb_client/src/adb_device_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ 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<()> {
self.shell_command(
["am", "start", &format!("{package}/{package}.{activity}")],
std::io::stdout(),
)
}
}

0 comments on commit 3ad5be0

Please sign in to comment.