• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 //! A daemon that can be launched on bootup that runs microfuchsia in AVF.
18 //! An on-demand binder service is also prepared in case we want to communicate with the daemon in
19 //! the future.
20 
21 mod instance_manager;
22 mod instance_starter;
23 mod service;
24 
25 use crate::instance_manager::InstanceManager;
26 use anyhow::{Context, Result};
27 use binder::{register_lazy_service, ProcessState};
28 use log::{error, info};
29 
30 #[allow(clippy::eq_op)]
try_main() -> Result<()>31 fn try_main() -> Result<()> {
32     let debuggable = env!("TARGET_BUILD_VARIANT") != "user";
33     let log_level = if debuggable { log::LevelFilter::Debug } else { log::LevelFilter::Info };
34     android_logger::init_once(
35         android_logger::Config::default().with_tag("microfuchsiad").with_max_level(log_level),
36     );
37 
38     ProcessState::start_thread_pool();
39 
40     let virtmgr =
41         vmclient::VirtualizationService::new().context("Failed to spawn VirtualizationService")?;
42     let virtualization_service =
43         virtmgr.connect().context("Failed to connect to VirtualizationService")?;
44 
45     let instance_manager = InstanceManager::new(virtualization_service);
46     let service = service::new_binder(instance_manager);
47     register_lazy_service("android.system.microfuchsiad", service.as_binder())
48         .context("Registering microfuchsiad service")?;
49 
50     info!("Registered services, joining threadpool");
51     ProcessState::join_thread_pool();
52 
53     info!("Exiting");
54     Ok(())
55 }
56 
main()57 fn main() {
58     if let Err(e) = try_main() {
59         error!("{:?}", e);
60         std::process::exit(1)
61     }
62 }
63