blob: e5d6c75f5c14cda0197f3cfdd866f4e7bbf967b3 [file] [log] [blame]
Alan Stokes3ef78d92021-09-08 11:51:06 +01001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! Exposes an on-demand binder service to perform system compilation tasks using CompOS. It is
18//! responsible for managing the lifecycle of the CompOS VM instances, providing key management for
19//! them, and orchestrating trusted compilation.
20
Victor Hsieh23bcbfe2021-11-18 10:32:50 -080021mod fd_server_helper;
Alan Stokesa2869d22021-09-22 09:06:41 +010022mod instance_manager;
Alan Stokes6b2d0a82021-09-29 11:30:39 +010023mod instance_starter;
Alan Stokes8c840442021-11-26 15:54:30 +000024mod odrefresh_task;
Alan Stokes3ef78d92021-09-08 11:51:06 +010025mod service;
26
Alan Stokes69c610f2021-09-27 14:03:31 +010027use crate::instance_manager::InstanceManager;
Alan Stokes3ef78d92021-09-08 11:51:06 +010028use anyhow::{Context, Result};
Alan Stokes0e82b502022-08-08 14:44:48 +010029use binder::{register_lazy_service, ProcessState};
Alan Stokes3ef78d92021-09-08 11:51:06 +010030use log::{error, info};
Alan Stokes7e8c9fc2022-02-02 18:02:41 +000031use std::panic;
Alan Stokese5e1d8d2021-11-19 16:31:14 +000032use std::sync::Arc;
Alan Stokes3ef78d92021-09-08 11:51:06 +010033
Charisee484cead2023-11-30 04:24:10 +000034#[allow(clippy::eq_op)]
Alan Stokes3ef78d92021-09-08 11:51:06 +010035fn try_main() -> Result<()> {
Victor Hsieh72c774c2021-11-18 15:52:28 -080036 let debuggable = env!("TARGET_BUILD_VARIANT") != "user";
Jeff Vander Stoep57da1572024-01-31 10:52:16 +010037 let log_level = if debuggable { log::LevelFilter::Debug } else { log::LevelFilter::Info };
Alan Stokes3ef78d92021-09-08 11:51:06 +010038 android_logger::init_once(
Jeff Vander Stoep57da1572024-01-31 10:52:16 +010039 android_logger::Config::default().with_tag("composd").with_max_level(log_level),
Alan Stokes3ef78d92021-09-08 11:51:06 +010040 );
41
Alan Stokes7e8c9fc2022-02-02 18:02:41 +000042 // Redirect panic messages to logcat.
43 panic::set_hook(Box::new(|panic_info| {
44 log::error!("{}", panic_info);
45 }));
46
Alan Stokesb2cc79e2021-09-14 14:08:46 +010047 ProcessState::start_thread_pool();
48
David Brazdil4b4c5102022-12-19 22:56:20 +000049 let virtmgr =
50 vmclient::VirtualizationService::new().context("Failed to spawn VirtualizationService")?;
Andrew Walbrand0ef4002022-05-16 16:14:10 +000051 let virtualization_service =
David Brazdil4b4c5102022-12-19 22:56:20 +000052 virtmgr.connect().context("Failed to connect to VirtualizationService")?;
53
Alan Stokese5e1d8d2021-11-19 16:31:14 +000054 let instance_manager = Arc::new(InstanceManager::new(virtualization_service));
Victor Hsieh616f8222022-01-14 13:06:32 -080055 let composd_service = service::new_binder(instance_manager);
Alan Stokes69c610f2021-09-27 14:03:31 +010056 register_lazy_service("android.system.composd", composd_service.as_binder())
Alan Stokese5e1d8d2021-11-19 16:31:14 +000057 .context("Registering composd service")?;
Alan Stokes3ef78d92021-09-08 11:51:06 +010058
Alan Stokese5e1d8d2021-11-19 16:31:14 +000059 info!("Registered services, joining threadpool");
Alan Stokes3ef78d92021-09-08 11:51:06 +010060 ProcessState::join_thread_pool();
61
62 info!("Exiting");
63 Ok(())
64}
65
66fn main() {
67 if let Err(e) = try_main() {
Alan Stokes6018a8c2021-10-01 10:54:38 +010068 error!("{:?}", e);
Alan Stokes3ef78d92021-09-08 11:51:06 +010069 std::process::exit(1)
70 }
71}