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