feat: add run_activity method and default impl for ADBDeviceExt
This commit is contained in:
committed by
cocool97
parent
b51965f5af
commit
c835f20263
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user