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 | |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 15 | use android_system_virtualizationservice::{ |
| 16 | aidl::android::system::virtualizationservice::{ |
| 17 | DeathReason::DeathReason as AidlDeathReason}}; |
| 18 | |
| 19 | /// The reason why a VM died. |
| 20 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 21 | pub enum DeathReason { |
| 22 | /// VirtualizationService died. |
| 23 | VirtualizationServiceDied, |
| 24 | /// There was an error waiting for the VM. |
| 25 | InfrastructureError, |
| 26 | /// The VM was killed. |
| 27 | Killed, |
| 28 | /// The VM died for an unknown reason. |
| 29 | Unknown, |
| 30 | /// The VM requested to shut down. |
| 31 | Shutdown, |
| 32 | /// crosvm had an error starting the VM. |
Alan Stokes | 7c459e8 | 2022-12-06 12:21:49 +0000 | [diff] [blame] | 33 | StartFailed, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 34 | /// The VM requested to reboot, possibly as the result of a kernel panic. |
| 35 | Reboot, |
| 36 | /// The VM or crosvm crashed. |
| 37 | Crash, |
| 38 | /// The pVM firmware failed to verify the VM because the public key doesn't match. |
| 39 | PvmFirmwarePublicKeyMismatch, |
| 40 | /// The pVM firmware failed to verify the VM because the instance image changed. |
| 41 | PvmFirmwareInstanceImageChanged, |
| 42 | /// The bootloader failed to verify the VM because the public key doesn't match. |
| 43 | BootloaderPublicKeyMismatch, |
| 44 | /// The bootloader failed to verify the VM because the instance image changed. |
| 45 | BootloaderInstanceImageChanged, |
Jiyong Park | e6ed0f9 | 2022-06-22 00:13:00 +0900 | [diff] [blame] | 46 | /// The microdroid failed to connect to VirtualizationService's RPC server. |
| 47 | MicrodroidFailedToConnectToVirtualizationService, |
| 48 | /// The payload for microdroid is changed. |
| 49 | MicrodroidPayloadHasChanged, |
| 50 | /// The microdroid failed to verify given payload APK. |
| 51 | MicrodroidPayloadVerificationFailed, |
| 52 | /// The VM config for microdroid is invalid (e.g. missing tasks). |
| 53 | MicrodroidInvalidPayloadConfig, |
| 54 | /// There was a runtime error while running microdroid manager. |
| 55 | MicrodroidUnknownRuntimeError, |
| 56 | /// The VM was killed due to hangup. |
| 57 | Hangup, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 58 | /// VirtualizationService sent a death reason which was not recognised by the client library. |
| 59 | Unrecognised(AidlDeathReason), |
| 60 | } |
| 61 | |
| 62 | impl From<AidlDeathReason> for DeathReason { |
| 63 | fn from(reason: AidlDeathReason) -> Self { |
| 64 | match reason { |
| 65 | AidlDeathReason::INFRASTRUCTURE_ERROR => Self::InfrastructureError, |
| 66 | AidlDeathReason::KILLED => Self::Killed, |
| 67 | AidlDeathReason::UNKNOWN => Self::Unknown, |
| 68 | AidlDeathReason::SHUTDOWN => Self::Shutdown, |
Alan Stokes | 7c459e8 | 2022-12-06 12:21:49 +0000 | [diff] [blame] | 69 | AidlDeathReason::START_FAILED => Self::StartFailed, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 70 | AidlDeathReason::REBOOT => Self::Reboot, |
| 71 | AidlDeathReason::CRASH => Self::Crash, |
| 72 | AidlDeathReason::PVM_FIRMWARE_PUBLIC_KEY_MISMATCH => Self::PvmFirmwarePublicKeyMismatch, |
| 73 | AidlDeathReason::PVM_FIRMWARE_INSTANCE_IMAGE_CHANGED => { |
| 74 | Self::PvmFirmwareInstanceImageChanged |
| 75 | } |
| 76 | AidlDeathReason::BOOTLOADER_PUBLIC_KEY_MISMATCH => Self::BootloaderPublicKeyMismatch, |
| 77 | AidlDeathReason::BOOTLOADER_INSTANCE_IMAGE_CHANGED => { |
| 78 | Self::BootloaderInstanceImageChanged |
| 79 | } |
Jiyong Park | e6ed0f9 | 2022-06-22 00:13:00 +0900 | [diff] [blame] | 80 | AidlDeathReason::MICRODROID_FAILED_TO_CONNECT_TO_VIRTUALIZATION_SERVICE => { |
| 81 | Self::MicrodroidFailedToConnectToVirtualizationService |
| 82 | } |
| 83 | AidlDeathReason::MICRODROID_PAYLOAD_HAS_CHANGED => Self::MicrodroidPayloadHasChanged, |
| 84 | AidlDeathReason::MICRODROID_PAYLOAD_VERIFICATION_FAILED => { |
| 85 | Self::MicrodroidPayloadVerificationFailed |
| 86 | } |
| 87 | AidlDeathReason::MICRODROID_INVALID_PAYLOAD_CONFIG => { |
| 88 | Self::MicrodroidInvalidPayloadConfig |
| 89 | } |
| 90 | AidlDeathReason::MICRODROID_UNKNOWN_RUNTIME_ERROR => { |
| 91 | Self::MicrodroidUnknownRuntimeError |
| 92 | } |
| 93 | AidlDeathReason::HANGUP => Self::Hangup, |
Andrew Walbran | d0ef400 | 2022-05-16 16:14:10 +0000 | [diff] [blame] | 94 | _ => Self::Unrecognised(reason), |
| 95 | } |
| 96 | } |
| 97 | } |