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