blob: f9751c32260f484649bdfdd22c297db5ba2182d9 [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
Alan Stokes9ca14ca2021-10-20 14:25:57 +010021mod compilation_task;
Alan Stokesa2869d22021-09-22 09:06:41 +010022mod instance_manager;
Alan Stokes6b2d0a82021-09-29 11:30:39 +010023mod instance_starter;
Alan Stokese5e1d8d2021-11-19 16:31:14 +000024mod internal_service;
Alan Stokesb2cc79e2021-09-14 14:08:46 +010025mod odrefresh;
Alan Stokes3ef78d92021-09-08 11:51:06 +010026mod service;
Alan Stokes9ca14ca2021-10-20 14:25:57 +010027mod util;
Alan Stokes3ef78d92021-09-08 11:51:06 +010028
Alan Stokes69c610f2021-09-27 14:03:31 +010029use crate::instance_manager::InstanceManager;
Alan Stokes3ef78d92021-09-08 11:51:06 +010030use android_system_composd::binder::{register_lazy_service, ProcessState};
31use anyhow::{Context, Result};
Alan Stokes69c610f2021-09-27 14:03:31 +010032use compos_common::compos_client::VmInstance;
Alan Stokes3ef78d92021-09-08 11:51:06 +010033use log::{error, info};
Alan Stokese5e1d8d2021-11-19 16:31:14 +000034use std::sync::Arc;
Alan Stokes3ef78d92021-09-08 11:51:06 +010035
36fn try_main() -> Result<()> {
37 android_logger::init_once(
38 android_logger::Config::default().with_tag("composd").with_min_level(log::Level::Info),
39 );
40
Alan Stokesb2cc79e2021-09-14 14:08:46 +010041 ProcessState::start_thread_pool();
42
Alan Stokes69c610f2021-09-27 14:03:31 +010043 let virtualization_service = VmInstance::connect_to_virtualization_service()?;
Alan Stokese5e1d8d2021-11-19 16:31:14 +000044 let instance_manager = Arc::new(InstanceManager::new(virtualization_service));
45 let composd_service = service::new_binder(instance_manager.clone());
Alan Stokes69c610f2021-09-27 14:03:31 +010046 register_lazy_service("android.system.composd", composd_service.as_binder())
Alan Stokese5e1d8d2021-11-19 16:31:14 +000047 .context("Registering composd service")?;
Alan Stokes3ef78d92021-09-08 11:51:06 +010048
Alan Stokese5e1d8d2021-11-19 16:31:14 +000049 let internal_service = internal_service::new_binder(instance_manager);
50 register_lazy_service("android.system.composd.internal", internal_service.as_binder())
51 .context("Registering internal service")?;
52
53 info!("Registered services, joining threadpool");
Alan Stokes3ef78d92021-09-08 11:51:06 +010054 ProcessState::join_thread_pool();
55
56 info!("Exiting");
57 Ok(())
58}
59
60fn main() {
61 if let Err(e) = try_main() {
Alan Stokes6018a8c2021-10-01 10:54:38 +010062 error!("{:?}", e);
Alan Stokes3ef78d92021-09-08 11:51:06 +010063 std::process::exit(1)
64 }
65}