Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 1 | /* |
| 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 Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 21 | mod compilation_task; |
Victor Hsieh | 23bcbfe | 2021-11-18 10:32:50 -0800 | [diff] [blame] | 22 | mod fd_server_helper; |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 23 | mod instance_manager; |
Alan Stokes | 6b2d0a8 | 2021-09-29 11:30:39 +0100 | [diff] [blame] | 24 | mod instance_starter; |
Alan Stokes | e5e1d8d | 2021-11-19 16:31:14 +0000 | [diff] [blame] | 25 | mod internal_service; |
Alan Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 26 | mod odrefresh; |
Alan Stokes | 8c84044 | 2021-11-26 15:54:30 +0000 | [diff] [blame^] | 27 | mod odrefresh_task; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 28 | mod service; |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 29 | mod util; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 30 | |
Alan Stokes | 69c610f | 2021-09-27 14:03:31 +0100 | [diff] [blame] | 31 | use crate::instance_manager::InstanceManager; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 32 | use android_system_composd::binder::{register_lazy_service, ProcessState}; |
| 33 | use anyhow::{Context, Result}; |
Alan Stokes | 69c610f | 2021-09-27 14:03:31 +0100 | [diff] [blame] | 34 | use compos_common::compos_client::VmInstance; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 35 | use log::{error, info}; |
Alan Stokes | e5e1d8d | 2021-11-19 16:31:14 +0000 | [diff] [blame] | 36 | use std::sync::Arc; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 37 | |
| 38 | fn try_main() -> Result<()> { |
Victor Hsieh | 72c774c | 2021-11-18 15:52:28 -0800 | [diff] [blame] | 39 | let debuggable = env!("TARGET_BUILD_VARIANT") != "user"; |
| 40 | let log_level = if debuggable { log::Level::Debug } else { log::Level::Info }; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 41 | android_logger::init_once( |
Victor Hsieh | 72c774c | 2021-11-18 15:52:28 -0800 | [diff] [blame] | 42 | android_logger::Config::default().with_tag("composd").with_min_level(log_level), |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 43 | ); |
| 44 | |
Alan Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 45 | ProcessState::start_thread_pool(); |
| 46 | |
Alan Stokes | 69c610f | 2021-09-27 14:03:31 +0100 | [diff] [blame] | 47 | let virtualization_service = VmInstance::connect_to_virtualization_service()?; |
Alan Stokes | e5e1d8d | 2021-11-19 16:31:14 +0000 | [diff] [blame] | 48 | let instance_manager = Arc::new(InstanceManager::new(virtualization_service)); |
| 49 | let composd_service = service::new_binder(instance_manager.clone()); |
Alan Stokes | 69c610f | 2021-09-27 14:03:31 +0100 | [diff] [blame] | 50 | register_lazy_service("android.system.composd", composd_service.as_binder()) |
Alan Stokes | e5e1d8d | 2021-11-19 16:31:14 +0000 | [diff] [blame] | 51 | .context("Registering composd service")?; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 52 | |
Alan Stokes | e5e1d8d | 2021-11-19 16:31:14 +0000 | [diff] [blame] | 53 | let internal_service = internal_service::new_binder(instance_manager); |
| 54 | register_lazy_service("android.system.composd.internal", internal_service.as_binder()) |
| 55 | .context("Registering internal service")?; |
| 56 | |
| 57 | info!("Registered services, joining threadpool"); |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 58 | ProcessState::join_thread_pool(); |
| 59 | |
| 60 | info!("Exiting"); |
| 61 | Ok(()) |
| 62 | } |
| 63 | |
| 64 | fn main() { |
| 65 | if let Err(e) = try_main() { |
Alan Stokes | 6018a8c | 2021-10-01 10:54:38 +0100 | [diff] [blame] | 66 | error!("{:?}", e); |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 67 | std::process::exit(1) |
| 68 | } |
| 69 | } |