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