blob: 2547f3d0df74f1749183096cc02397949868b981 [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
34 /// Tells VirtualizationService to use staged APEXes if possible
35 #[serde(default)]
36 pub prefer_staged: bool,
Jooyung Han634e2d72021-06-10 16:27:38 +090037}
38
39/// OS config
40#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
41pub struct OsConfig {
42 /// The name of OS to use
43 pub name: String,
44}
45
46impl Default for OsConfig {
47 fn default() -> Self {
48 Self { name: "microdroid".to_owned() }
49 }
50}
51
52/// Payload's task can be one of plain executable
53/// or an .so library which can be started via /system/bin/microdroid_launcher
54#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
55pub enum TaskType {
56 /// Task's command indicates the path to the executable binary.
57 #[serde(rename = "executable")]
58 Executable,
59 /// Task's command indicates the .so library in /mnt/apk/lib/{arch}
60 #[serde(rename = "microdroid_launcher")]
61 MicrodroidLauncher,
62}
63
64/// Task to run in a VM
65#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
66pub struct Task {
67 /// Decides how to execute the command: executable(default) | microdroid_launcher
68 #[serde(default, rename = "type")]
69 pub type_: TaskType,
70
71 /// Command to run
72 /// - For executable task, this is the path to the executable.
73 /// - For microdroid_launcher task, this is the name of .so
74 pub command: String,
75
76 /// Args to the command
77 #[serde(default)]
78 pub args: Vec<String>,
79}
80
81impl Default for TaskType {
82 fn default() -> TaskType {
83 TaskType::Executable
84 }
85}
86
87/// APEX config
88/// For now, we only pass the name of APEX.
89#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
90pub struct ApexConfig {
91 /// The name of APEX
92 pub name: String,
93}