Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 1 | // Copyright 2022, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! Client library for VirtualizationService. |
| 16 | |
| 17 | mod death_reason; |
Alan Stokes | 2bead0d | 2022-09-05 16:58:34 +0100 | [diff] [blame] | 18 | mod error_code; |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 19 | mod errors; |
| 20 | mod sync; |
| 21 | |
| 22 | pub use crate::death_reason::DeathReason; |
Alan Stokes | 2bead0d | 2022-09-05 16:58:34 +0100 | [diff] [blame] | 23 | pub use crate::error_code::ErrorCode; |
Andrew Walbran | c944fae | 2022-08-02 16:16:28 +0000 | [diff] [blame] | 24 | pub use crate::errors::VmWaitError; |
| 25 | use crate::sync::Monitor; |
David Brazdil | 49f96f5 | 2022-12-16 21:29:13 +0000 | [diff] [blame] | 26 | use android_system_virtualizationcommon::aidl::android::system::virtualizationcommon::{ |
| 27 | DeathReason::DeathReason as AidlDeathReason, ErrorCode::ErrorCode as AidlErrorCode, |
| 28 | }; |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 29 | use android_system_virtualizationservice::{ |
| 30 | aidl::android::system::virtualizationservice::{ |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 31 | IVirtualMachine::IVirtualMachine, |
| 32 | IVirtualMachineCallback::{BnVirtualMachineCallback, IVirtualMachineCallback}, |
| 33 | IVirtualizationService::IVirtualizationService, |
| 34 | VirtualMachineConfig::VirtualMachineConfig, |
| 35 | VirtualMachineState::VirtualMachineState, |
| 36 | }, |
| 37 | binder::{ |
Seungjae Yoo | 81821f6 | 2023-09-13 14:30:11 +0900 | [diff] [blame] | 38 | BinderFeatures, DeathRecipient, FromIBinder, IBinder, Interface, ParcelFileDescriptor, |
| 39 | Result as BinderResult, StatusCode, Strong, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 40 | }, |
| 41 | }; |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 42 | use command_fds::CommandFdExt; |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 43 | use log::warn; |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 44 | use rpcbinder::{FileDescriptorTransportMode, RpcSession}; |
| 45 | use shared_child::SharedChild; |
| 46 | use std::io::{self, Read}; |
| 47 | use std::process::Command; |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 48 | use std::{ |
| 49 | fmt::{self, Debug, Formatter}, |
| 50 | fs::File, |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 51 | os::unix::io::{AsFd, AsRawFd, FromRawFd, IntoRawFd, OwnedFd}, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 52 | sync::Arc, |
| 53 | time::Duration, |
| 54 | }; |
| 55 | |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 56 | const VIRTMGR_PATH: &str = "/apex/com.android.virt/bin/virtmgr"; |
Alan Stokes | eab0cdf | 2023-03-01 12:13:23 +0000 | [diff] [blame] | 57 | const VIRTMGR_THREADS: usize = 2; |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 58 | |
| 59 | fn posix_pipe() -> Result<(OwnedFd, OwnedFd), io::Error> { |
| 60 | use nix::fcntl::OFlag; |
| 61 | use nix::unistd::pipe2; |
| 62 | |
| 63 | // Create new POSIX pipe. Make it O_CLOEXEC to align with how Rust creates |
| 64 | // file descriptors (expected by SharedChild). |
| 65 | let (raw1, raw2) = pipe2(OFlag::O_CLOEXEC)?; |
| 66 | |
Andrew Walbran | b58d1b4 | 2023-07-07 13:54:49 +0100 | [diff] [blame] | 67 | // SAFETY: Taking ownership of brand new FDs. |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 68 | unsafe { Ok((OwnedFd::from_raw_fd(raw1), OwnedFd::from_raw_fd(raw2))) } |
| 69 | } |
| 70 | |
| 71 | fn posix_socketpair() -> Result<(OwnedFd, OwnedFd), io::Error> { |
| 72 | use nix::sys::socket::{socketpair, AddressFamily, SockFlag, SockType}; |
| 73 | |
| 74 | // Create new POSIX socketpair, suitable for use with RpcBinder UDS bootstrap |
| 75 | // transport. Make it O_CLOEXEC to align with how Rust creates file |
| 76 | // descriptors (expected by SharedChild). |
Ludovic Barman | 696dd7e | 2023-11-30 14:21:52 +0000 | [diff] [blame^] | 77 | Ok(socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::SOCK_CLOEXEC)?) |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /// A running instance of virtmgr which is hosting a VirtualizationService |
| 81 | /// RpcBinder server. |
| 82 | pub struct VirtualizationService { |
| 83 | /// Client FD for UDS connection to virtmgr's RpcBinder server. Closing it |
| 84 | /// will make virtmgr shut down. |
| 85 | client_fd: OwnedFd, |
| 86 | } |
| 87 | |
| 88 | impl VirtualizationService { |
| 89 | /// Spawns a new instance of virtmgr, a child process that will host |
| 90 | /// the VirtualizationService AIDL service. |
| 91 | pub fn new() -> Result<VirtualizationService, io::Error> { |
| 92 | let (wait_fd, ready_fd) = posix_pipe()?; |
| 93 | let (client_fd, server_fd) = posix_socketpair()?; |
| 94 | |
| 95 | let mut command = Command::new(VIRTMGR_PATH); |
| 96 | command.arg("--rpc-server-fd").arg(format!("{}", server_fd.as_raw_fd())); |
| 97 | command.arg("--ready-fd").arg(format!("{}", ready_fd.as_raw_fd())); |
| 98 | command.preserved_fds(vec![server_fd.as_raw_fd(), ready_fd.as_raw_fd()]); |
| 99 | |
| 100 | SharedChild::spawn(&mut command)?; |
| 101 | |
| 102 | // Drop FDs that belong to virtmgr. |
| 103 | drop(server_fd); |
| 104 | drop(ready_fd); |
| 105 | |
| 106 | // Wait for the child to signal that the RpcBinder server is ready |
| 107 | // by closing its end of the pipe. |
Dan Albert | 04e5dbd | 2023-05-08 22:49:40 +0000 | [diff] [blame] | 108 | let _ignored = File::from(wait_fd).read(&mut [0]); |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 109 | |
| 110 | Ok(VirtualizationService { client_fd }) |
| 111 | } |
| 112 | |
| 113 | /// Connects to the VirtualizationService AIDL service. |
| 114 | pub fn connect(&self) -> Result<Strong<dyn IVirtualizationService>, io::Error> { |
| 115 | let session = RpcSession::new(); |
| 116 | session.set_file_descriptor_transport_mode(FileDescriptorTransportMode::Unix); |
| 117 | session.set_max_incoming_threads(VIRTMGR_THREADS); |
David Brazdil | 4644606 | 2022-10-25 13:18:18 +0100 | [diff] [blame] | 118 | session |
| 119 | .setup_unix_domain_bootstrap_client(self.client_fd.as_fd()) |
| 120 | .map_err(|_| io::Error::from(io::ErrorKind::ConnectionRefused)) |
| 121 | } |
| 122 | } |
| 123 | |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 124 | /// A virtual machine which has been started by the VirtualizationService. |
| 125 | pub struct VmInstance { |
| 126 | /// The `IVirtualMachine` Binder object representing the VM. |
| 127 | pub vm: Strong<dyn IVirtualMachine>, |
| 128 | cid: i32, |
| 129 | state: Arc<Monitor<VmState>>, |
| 130 | // Ensure that the DeathRecipient isn't dropped while someone might call wait_for_death, as it |
| 131 | // is removed from the Binder when it's dropped. |
| 132 | _death_recipient: DeathRecipient, |
| 133 | } |
| 134 | |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 135 | /// A trait to be implemented by clients to handle notification of significant changes to the VM |
| 136 | /// state. Default implementations of all functions are provided so clients only need to handle the |
| 137 | /// notifications they are interested in. |
| 138 | #[allow(unused_variables)] |
| 139 | pub trait VmCallback { |
| 140 | /// Called when the payload has been started within the VM. If present, `stream` is connected |
| 141 | /// to the stdin/stdout of the payload. |
David Brazdil | 451cc96 | 2022-10-14 14:08:12 +0100 | [diff] [blame] | 142 | fn on_payload_started(&self, cid: i32) {} |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 143 | |
| 144 | /// Callend when the payload has notified Virtualization Service that it is ready to serve |
| 145 | /// clients. |
| 146 | fn on_payload_ready(&self, cid: i32) {} |
| 147 | |
| 148 | /// Called when the payload has exited in the VM. `exit_code` is the exit code of the payload |
| 149 | /// process. |
| 150 | fn on_payload_finished(&self, cid: i32, exit_code: i32) {} |
| 151 | |
| 152 | /// Called when an error has occurred in the VM. The `error_code` and `message` may give |
| 153 | /// further details. |
Alan Stokes | 2bead0d | 2022-09-05 16:58:34 +0100 | [diff] [blame] | 154 | fn on_error(&self, cid: i32, error_code: ErrorCode, message: &str) {} |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 155 | |
| 156 | /// Called when the VM has exited, all resources have been freed, and any logs have been |
| 157 | /// written. `death_reason` gives an indication why the VM exited. |
| 158 | fn on_died(&self, cid: i32, death_reason: DeathReason) {} |
| 159 | } |
| 160 | |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 161 | impl VmInstance { |
| 162 | /// Creates (but doesn't start) a new VM with the given configuration. |
| 163 | pub fn create( |
| 164 | service: &dyn IVirtualizationService, |
| 165 | config: &VirtualMachineConfig, |
Jiyong Park | e6fb167 | 2023-06-26 16:45:55 +0900 | [diff] [blame] | 166 | console_out: Option<File>, |
| 167 | console_in: Option<File>, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 168 | log: Option<File>, |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 169 | callback: Option<Box<dyn VmCallback + Send + Sync>>, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 170 | ) -> BinderResult<Self> { |
Jiyong Park | e6fb167 | 2023-06-26 16:45:55 +0900 | [diff] [blame] | 171 | let console_out = console_out.map(ParcelFileDescriptor::new); |
| 172 | let console_in = console_in.map(ParcelFileDescriptor::new); |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 173 | let log = log.map(ParcelFileDescriptor::new); |
| 174 | |
Jiyong Park | e6fb167 | 2023-06-26 16:45:55 +0900 | [diff] [blame] | 175 | let vm = |
| 176 | service.createVm(config, console_out.as_ref(), console_in.as_ref(), log.as_ref())?; |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 177 | |
| 178 | let cid = vm.getCid()?; |
| 179 | |
| 180 | // Register callback before starting VM, in case it dies immediately. |
| 181 | let state = Arc::new(Monitor::new(VmState::default())); |
| 182 | let callback = BnVirtualMachineCallback::new_binder( |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 183 | VirtualMachineCallback { state: state.clone(), client_callback: callback }, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 184 | BinderFeatures::default(), |
| 185 | ); |
| 186 | vm.registerCallback(&callback)?; |
| 187 | let death_recipient = wait_for_binder_death(&mut vm.as_binder(), state.clone())?; |
| 188 | |
| 189 | Ok(Self { vm, cid, state, _death_recipient: death_recipient }) |
| 190 | } |
| 191 | |
| 192 | /// Starts the VM. |
| 193 | pub fn start(&self) -> BinderResult<()> { |
| 194 | self.vm.start() |
| 195 | } |
| 196 | |
| 197 | /// Returns the CID used for vsock connections to the VM. |
| 198 | pub fn cid(&self) -> i32 { |
| 199 | self.cid |
| 200 | } |
| 201 | |
| 202 | /// Returns the current lifecycle state of the VM. |
| 203 | pub fn state(&self) -> BinderResult<VirtualMachineState> { |
| 204 | self.vm.getState() |
| 205 | } |
| 206 | |
| 207 | /// Blocks until the VM or the VirtualizationService itself dies, and then returns the reason |
| 208 | /// why it died. |
| 209 | pub fn wait_for_death(&self) -> DeathReason { |
| 210 | self.state.wait_while(|state| state.death_reason.is_none()).unwrap().death_reason.unwrap() |
| 211 | } |
| 212 | |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 213 | /// Blocks until the VM or the VirtualizationService itself dies, or the given timeout expires. |
| 214 | /// Returns the reason why it died if it did so. |
| 215 | pub fn wait_for_death_with_timeout(&self, timeout: Duration) -> Option<DeathReason> { |
| 216 | let (state, _timeout_result) = |
| 217 | self.state.wait_timeout_while(timeout, |state| state.death_reason.is_none()).unwrap(); |
| 218 | // We don't care if it timed out - we just return the reason if there now is one |
| 219 | state.death_reason |
| 220 | } |
| 221 | |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 222 | /// Waits until the VM reports that it is ready. |
| 223 | /// |
| 224 | /// Returns an error if the VM dies first, or the `timeout` elapses before the VM is ready. |
| 225 | pub fn wait_until_ready(&self, timeout: Duration) -> Result<(), VmWaitError> { |
| 226 | let (state, timeout_result) = self |
| 227 | .state |
| 228 | .wait_timeout_while(timeout, |state| { |
| 229 | state.reported_state < VirtualMachineState::READY && state.death_reason.is_none() |
| 230 | }) |
| 231 | .unwrap(); |
| 232 | if timeout_result.timed_out() { |
| 233 | Err(VmWaitError::TimedOut) |
| 234 | } else if let Some(reason) = state.death_reason { |
| 235 | Err(VmWaitError::Died { reason }) |
| 236 | } else if state.reported_state != VirtualMachineState::READY { |
| 237 | Err(VmWaitError::Finished) |
| 238 | } else { |
| 239 | Ok(()) |
| 240 | } |
| 241 | } |
Andrew Walbran | 1072cc0 | 2022-05-23 14:47:58 +0000 | [diff] [blame] | 242 | |
| 243 | /// Tries to connect to an RPC Binder service provided by the VM on the given vsock port. |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 244 | pub fn connect_service<T: FromIBinder + ?Sized>( |
Andrew Walbran | 1072cc0 | 2022-05-23 14:47:58 +0000 | [diff] [blame] | 245 | &self, |
| 246 | port: u32, |
Andrew Walbran | c944fae | 2022-08-02 16:16:28 +0000 | [diff] [blame] | 247 | ) -> Result<Strong<T>, StatusCode> { |
David Brazdil | a2125dd | 2022-12-14 16:37:44 +0000 | [diff] [blame] | 248 | RpcSession::new().setup_preconnected_client(|| { |
Andrew Walbran | c944fae | 2022-08-02 16:16:28 +0000 | [diff] [blame] | 249 | match self.vm.connectVsock(port as i32) { |
| 250 | Ok(vsock) => { |
| 251 | // Ownership of the fd is transferred to binder |
| 252 | Some(vsock.into_raw_fd()) |
| 253 | } |
| 254 | Err(e) => { |
| 255 | warn!("Vsock connection failed: {}", e); |
| 256 | None |
| 257 | } |
| 258 | } |
| 259 | }) |
Andrew Walbran | 1072cc0 | 2022-05-23 14:47:58 +0000 | [diff] [blame] | 260 | } |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | impl Debug for VmInstance { |
| 264 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
| 265 | f.debug_struct("VmInstance").field("cid", &self.cid).field("state", &self.state).finish() |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /// Notify the VmState when the given Binder object dies. |
| 270 | /// |
| 271 | /// If the returned DeathRecipient is dropped then this will no longer do anything. |
| 272 | fn wait_for_binder_death( |
| 273 | binder: &mut impl IBinder, |
| 274 | state: Arc<Monitor<VmState>>, |
| 275 | ) -> BinderResult<DeathRecipient> { |
| 276 | let mut death_recipient = DeathRecipient::new(move || { |
| 277 | warn!("VirtualizationService unexpectedly died"); |
| 278 | state.notify_death(DeathReason::VirtualizationServiceDied); |
| 279 | }); |
| 280 | binder.link_to_death(&mut death_recipient)?; |
| 281 | Ok(death_recipient) |
| 282 | } |
| 283 | |
| 284 | #[derive(Debug, Default)] |
| 285 | struct VmState { |
| 286 | death_reason: Option<DeathReason>, |
| 287 | reported_state: VirtualMachineState, |
| 288 | } |
| 289 | |
| 290 | impl Monitor<VmState> { |
| 291 | fn notify_death(&self, reason: DeathReason) { |
| 292 | let state = &mut *self.state.lock().unwrap(); |
| 293 | // In case this method is called more than once, ignore subsequent calls. |
| 294 | if state.death_reason.is_none() { |
| 295 | state.death_reason.replace(reason); |
| 296 | self.cv.notify_all(); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | fn notify_state(&self, state: VirtualMachineState) { |
| 301 | self.state.lock().unwrap().reported_state = state; |
| 302 | self.cv.notify_all(); |
| 303 | } |
| 304 | } |
| 305 | |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 306 | struct VirtualMachineCallback { |
| 307 | state: Arc<Monitor<VmState>>, |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 308 | client_callback: Option<Box<dyn VmCallback + Send + Sync>>, |
| 309 | } |
| 310 | |
| 311 | impl Debug for VirtualMachineCallback { |
| 312 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
| 313 | fmt.debug_struct("VirtualMachineCallback") |
| 314 | .field("state", &self.state) |
| 315 | .field( |
| 316 | "client_callback", |
| 317 | &if self.client_callback.is_some() { "Some(...)" } else { "None" }, |
| 318 | ) |
| 319 | .finish() |
| 320 | } |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | impl Interface for VirtualMachineCallback {} |
| 324 | |
| 325 | impl IVirtualMachineCallback for VirtualMachineCallback { |
David Brazdil | 451cc96 | 2022-10-14 14:08:12 +0100 | [diff] [blame] | 326 | fn onPayloadStarted(&self, cid: i32) -> BinderResult<()> { |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 327 | self.state.notify_state(VirtualMachineState::STARTED); |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 328 | if let Some(ref callback) = self.client_callback { |
David Brazdil | 451cc96 | 2022-10-14 14:08:12 +0100 | [diff] [blame] | 329 | callback.on_payload_started(cid); |
| 330 | } |
| 331 | Ok(()) |
| 332 | } |
| 333 | |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 334 | fn onPayloadReady(&self, cid: i32) -> BinderResult<()> { |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 335 | self.state.notify_state(VirtualMachineState::READY); |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 336 | if let Some(ref callback) = self.client_callback { |
| 337 | callback.on_payload_ready(cid); |
| 338 | } |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 339 | Ok(()) |
| 340 | } |
| 341 | |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 342 | fn onPayloadFinished(&self, cid: i32, exit_code: i32) -> BinderResult<()> { |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 343 | self.state.notify_state(VirtualMachineState::FINISHED); |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 344 | if let Some(ref callback) = self.client_callback { |
| 345 | callback.on_payload_finished(cid, exit_code); |
| 346 | } |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 347 | Ok(()) |
| 348 | } |
| 349 | |
Alan Stokes | 2bead0d | 2022-09-05 16:58:34 +0100 | [diff] [blame] | 350 | fn onError(&self, cid: i32, error_code: AidlErrorCode, message: &str) -> BinderResult<()> { |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 351 | self.state.notify_state(VirtualMachineState::FINISHED); |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 352 | if let Some(ref callback) = self.client_callback { |
Alan Stokes | 2bead0d | 2022-09-05 16:58:34 +0100 | [diff] [blame] | 353 | let error_code = error_code.into(); |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 354 | callback.on_error(cid, error_code, message); |
| 355 | } |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 356 | Ok(()) |
| 357 | } |
| 358 | |
Alan Stokes | 0e82b50 | 2022-08-08 14:44:48 +0100 | [diff] [blame] | 359 | fn onDied(&self, cid: i32, reason: AidlDeathReason) -> BinderResult<()> { |
| 360 | let reason = reason.into(); |
| 361 | self.state.notify_death(reason); |
| 362 | if let Some(ref callback) = self.client_callback { |
| 363 | callback.on_died(cid, reason); |
| 364 | } |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 365 | Ok(()) |
| 366 | } |
| 367 | } |