feat: add run_activity method and default impl for ADBDeviceExt

This commit is contained in:
Himadri Bhattacharjee
2024-11-06 13:46:42 +05:30
committed by cocool97
parent b51965f5af
commit c835f20263
4 changed files with 20 additions and 8 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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
@@ -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)?;
}
}
}

View File

@@ -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(),
)
}
}