blob: 54b745e5d5934d219fafafaabe828c1b65a01cad [file] [log] [blame]
Jooyung Han634e2d72021-06-10 16:27:38 +09001// 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
17use serde::{Deserialize, Serialize};
18
19/// VM payload config
20#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
21pub 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 Han5dc42172021-10-05 16:43:47 +090033
Inseob Kima5a262f2021-11-17 19:41:03 +090034 /// Extra APKs to be passed to a VM
35 #[serde(default)]
36 pub extra_apks: Vec<ApkConfig>,
37
Jooyung Han5dc42172021-10-05 16:43:47 +090038 /// Tells VirtualizationService to use staged APEXes if possible
39 #[serde(default)]
40 pub prefer_staged: bool,
Shikha Panwar6f03c942022-04-13 20:26:50 +000041
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,
Alan Stokes01b3ef02022-09-22 17:43:24 +010045
46 /// Whether the authfs service should be started in the VM. This enables read or write of host
47 /// files with integrity checking, but not confidentiality.
48 #[serde(default)]
49 pub enable_authfs: bool,
Jooyung Han634e2d72021-06-10 16:27:38 +090050}
51
52/// OS config
53#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
54pub struct OsConfig {
55 /// The name of OS to use
56 pub name: String,
57}
58
59impl Default for OsConfig {
60 fn default() -> Self {
61 Self { name: "microdroid".to_owned() }
62 }
63}
64
65/// Payload's task can be one of plain executable
66/// or an .so library which can be started via /system/bin/microdroid_launcher
67#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
68pub enum TaskType {
69 /// Task's command indicates the path to the executable binary.
70 #[serde(rename = "executable")]
71 Executable,
72 /// Task's command indicates the .so library in /mnt/apk/lib/{arch}
73 #[serde(rename = "microdroid_launcher")]
74 MicrodroidLauncher,
75}
76
77/// Task to run in a VM
78#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
79pub struct Task {
80 /// Decides how to execute the command: executable(default) | microdroid_launcher
81 #[serde(default, rename = "type")]
82 pub type_: TaskType,
83
84 /// Command to run
85 /// - For executable task, this is the path to the executable.
86 /// - For microdroid_launcher task, this is the name of .so
87 pub command: String,
88
89 /// Args to the command
90 #[serde(default)]
91 pub args: Vec<String>,
92}
93
94impl Default for TaskType {
95 fn default() -> TaskType {
96 TaskType::Executable
97 }
98}
99
100/// APEX config
101/// For now, we only pass the name of APEX.
102#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
103pub struct ApexConfig {
104 /// The name of APEX
105 pub name: String,
106}
Inseob Kima5a262f2021-11-17 19:41:03 +0900107
108/// APK config
109#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
110pub struct ApkConfig {
111 /// The path of APK
112 pub path: String,
113}