Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 1 | // Copyright 2021, 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 | //! VM Payload Config |
| 16 | |
| 17 | use serde::{Deserialize, Serialize}; |
| 18 | |
| 19 | /// VM payload config |
| 20 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 21 | pub struct VmPayloadConfig { |
| 22 | /// OS config. Default: "microdroid" |
| 23 | #[serde(default)] |
| 24 | pub os: OsConfig, |
| 25 | |
| 26 | /// Task to run in a VM |
| 27 | #[serde(default)] |
| 28 | pub task: Option<Task>, |
| 29 | |
| 30 | /// APEXes to activate in a VM |
| 31 | #[serde(default)] |
| 32 | pub apexes: Vec<ApexConfig>, |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 33 | |
Inseob Kim | a5a262f | 2021-11-17 19:41:03 +0900 | [diff] [blame] | 34 | /// Extra APKs to be passed to a VM |
| 35 | #[serde(default)] |
| 36 | pub extra_apks: Vec<ApkConfig>, |
| 37 | |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 38 | /// Tells VirtualizationService to use staged APEXes if possible |
| 39 | #[serde(default)] |
| 40 | pub prefer_staged: bool, |
Shikha Panwar | 6f03c94 | 2022-04-13 20:26:50 +0000 | [diff] [blame^] | 41 | |
| 42 | /// Whether to export the tomsbtones (VM crashes) out of VM to host |
| 43 | /// This does not have a default & the value is expected to be in json for deserialization |
| 44 | pub export_tombstones: bool, |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /// OS config |
| 48 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 49 | pub struct OsConfig { |
| 50 | /// The name of OS to use |
| 51 | pub name: String, |
| 52 | } |
| 53 | |
| 54 | impl Default for OsConfig { |
| 55 | fn default() -> Self { |
| 56 | Self { name: "microdroid".to_owned() } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /// Payload's task can be one of plain executable |
| 61 | /// or an .so library which can be started via /system/bin/microdroid_launcher |
| 62 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 63 | pub enum TaskType { |
| 64 | /// Task's command indicates the path to the executable binary. |
| 65 | #[serde(rename = "executable")] |
| 66 | Executable, |
| 67 | /// Task's command indicates the .so library in /mnt/apk/lib/{arch} |
| 68 | #[serde(rename = "microdroid_launcher")] |
| 69 | MicrodroidLauncher, |
| 70 | } |
| 71 | |
| 72 | /// Task to run in a VM |
| 73 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 74 | pub struct Task { |
| 75 | /// Decides how to execute the command: executable(default) | microdroid_launcher |
| 76 | #[serde(default, rename = "type")] |
| 77 | pub type_: TaskType, |
| 78 | |
| 79 | /// Command to run |
| 80 | /// - For executable task, this is the path to the executable. |
| 81 | /// - For microdroid_launcher task, this is the name of .so |
| 82 | pub command: String, |
| 83 | |
| 84 | /// Args to the command |
| 85 | #[serde(default)] |
| 86 | pub args: Vec<String>, |
| 87 | } |
| 88 | |
| 89 | impl Default for TaskType { |
| 90 | fn default() -> TaskType { |
| 91 | TaskType::Executable |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /// APEX config |
| 96 | /// For now, we only pass the name of APEX. |
| 97 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 98 | pub struct ApexConfig { |
| 99 | /// The name of APEX |
| 100 | pub name: String, |
| 101 | } |
Inseob Kim | a5a262f | 2021-11-17 19:41:03 +0900 | [diff] [blame] | 102 | |
| 103 | /// APK config |
| 104 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 105 | pub struct ApkConfig { |
| 106 | /// The path of APK |
| 107 | pub path: String, |
| 108 | } |