Suspend the VM when it's not visible on the screen
... and resume it when it becomes visible again
Bug: 348552343
Bug: 348380730
Test: play a youtube video in a vm. go back to Android. take some time
and return to the vm. the video resumes at the point it was.
Change-Id: I517c8cf242866df99fe68396417f30bec28ff7dc
Change-Id: I462590eb1cc67b82ef0ef2283e4647f9163af4d0
diff --git a/virtualizationmanager/src/crosvm.rs b/virtualizationmanager/src/crosvm.rs
index 47ef91a..102ac51 100644
--- a/virtualizationmanager/src/crosvm.rs
+++ b/virtualizationmanager/src/crosvm.rs
@@ -682,6 +682,28 @@
conn.notify_completion()?;
Ok(())
}
+
+ /// Suspends the VM
+ pub fn suspend(&self) -> Result<(), Error> {
+ match vm_control::client::handle_request(
+ &VmRequest::SuspendVcpus,
+ &self.crosvm_control_socket_path,
+ ) {
+ Ok(VmResponse::Ok) => Ok(()),
+ e => bail!("Failed to suspend VM: {e:?}"),
+ }
+ }
+
+ /// Resumes the suspended VM
+ pub fn resume(&self) -> Result<(), Error> {
+ match vm_control::client::handle_request(
+ &VmRequest::ResumeVcpus,
+ &self.crosvm_control_socket_path,
+ ) {
+ Ok(VmResponse::Ok) => Ok(()),
+ e => bail!("Failed to resume: {e:?}"),
+ }
+ }
}
impl Rss {