blob: 351eae921f79351d39fc30c5cf85772938e09cfa [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//! Implementation of IIsolatedCompilationService, called from system server when compilation is
18//! desired.
19
Alan Stokes9ca14ca2021-10-20 14:25:57 +010020use crate::compilation_task::CompilationTask;
Alan Stokesa2869d22021-09-22 09:06:41 +010021use crate::instance_manager::InstanceManager;
Alan Stokes9ca14ca2021-10-20 14:25:57 +010022use crate::util::to_binder_result;
23use android_system_composd::aidl::android::system::composd::{
24 ICompilationTask::{BnCompilationTask, ICompilationTask},
25 ICompilationTaskCallback::ICompilationTaskCallback,
26 IIsolatedCompilationService::{BnIsolatedCompilationService, IIsolatedCompilationService},
Alan Stokes3ef78d92021-09-08 11:51:06 +010027};
Alan Stokes3189af02021-09-30 17:51:19 +010028use android_system_composd::binder::{self, BinderFeatures, Interface, Strong};
Alan Stokes9ca14ca2021-10-20 14:25:57 +010029use anyhow::{Context, Result};
Alan Stokes3189af02021-09-30 17:51:19 +010030use binder_common::new_binder_service_specific_error;
Alan Stokesa2869d22021-09-22 09:06:41 +010031use compos_aidl_interface::aidl::com::android::compos::{
32 CompilationResult::CompilationResult, FdAnnotation::FdAnnotation,
33};
Alan Stokes3ef78d92021-09-08 11:51:06 +010034
Alan Stokesa2869d22021-09-22 09:06:41 +010035pub struct IsolatedCompilationService {
36 instance_manager: InstanceManager,
37}
Alan Stokes3ef78d92021-09-08 11:51:06 +010038
Alan Stokes69c610f2021-09-27 14:03:31 +010039pub fn new_binder(instance_manager: InstanceManager) -> Strong<dyn IIsolatedCompilationService> {
40 let service = IsolatedCompilationService { instance_manager };
Alan Stokes3ef78d92021-09-08 11:51:06 +010041 BnIsolatedCompilationService::new_binder(service, BinderFeatures::default())
42}
43
Alan Stokes3ef78d92021-09-08 11:51:06 +010044impl Interface for IsolatedCompilationService {}
45
46impl IIsolatedCompilationService for IsolatedCompilationService {
Alan Stokes9ca14ca2021-10-20 14:25:57 +010047 fn startTestCompile(
48 &self,
49 callback: &Strong<dyn ICompilationTaskCallback>,
50 ) -> binder::Result<Strong<dyn ICompilationTask>> {
Alan Stokesa2869d22021-09-22 09:06:41 +010051 // TODO - check caller is system or shell/root?
Alan Stokes9ca14ca2021-10-20 14:25:57 +010052 to_binder_result(self.do_start_test_compile(callback))
Alan Stokesb2cc79e2021-09-14 14:08:46 +010053 }
Alan Stokesa2869d22021-09-22 09:06:41 +010054
Victor Hsieh3c044c42021-10-01 17:17:10 -070055 fn compile_cmd(
Alan Stokesa2869d22021-09-22 09:06:41 +010056 &self,
57 args: &[String],
58 fd_annotation: &FdAnnotation,
59 ) -> binder::Result<CompilationResult> {
60 // TODO - check caller is odrefresh
Alan Stokes9ca14ca2021-10-20 14:25:57 +010061 to_binder_result(self.do_compile_cmd(args, fd_annotation))
Alan Stokesa2869d22021-09-22 09:06:41 +010062 }
Victor Hsieh3c044c42021-10-01 17:17:10 -070063
64 fn compile(&self, _marshaled: &[u8], _fd_annotation: &FdAnnotation) -> binder::Result<i8> {
65 Err(new_binder_service_specific_error(-1, "Not yet implemented"))
66 }
Alan Stokesb2cc79e2021-09-14 14:08:46 +010067}
68
Alan Stokesb2cc79e2021-09-14 14:08:46 +010069impl IsolatedCompilationService {
Alan Stokes9ca14ca2021-10-20 14:25:57 +010070 fn do_start_test_compile(
71 &self,
72 callback: &Strong<dyn ICompilationTaskCallback>,
73 ) -> Result<Strong<dyn ICompilationTask>> {
Alan Stokes388b88a2021-10-13 16:03:17 +010074 let comp_os = self.instance_manager.start_test_instance().context("Starting CompOS")?;
Alan Stokesb2cc79e2021-09-14 14:08:46 +010075
Alan Stokes9ca14ca2021-10-20 14:25:57 +010076 let task = CompilationTask::start_test_compile(comp_os, callback)?;
Alan Stokesb2cc79e2021-09-14 14:08:46 +010077
Alan Stokes9ca14ca2021-10-20 14:25:57 +010078 Ok(BnCompilationTask::new_binder(task, BinderFeatures::default()))
Alan Stokes3ef78d92021-09-08 11:51:06 +010079 }
Alan Stokesa2869d22021-09-22 09:06:41 +010080
Alan Stokes9ca14ca2021-10-20 14:25:57 +010081 fn do_compile_cmd(
Alan Stokesa2869d22021-09-22 09:06:41 +010082 &self,
83 args: &[String],
84 fd_annotation: &FdAnnotation,
85 ) -> Result<CompilationResult> {
86 let compos = self.instance_manager.get_running_service()?;
Victor Hsieh3c044c42021-10-01 17:17:10 -070087 compos.compile_cmd(args, fd_annotation).context("Compiling")
Alan Stokesa2869d22021-09-22 09:06:41 +010088 }
Alan Stokes3ef78d92021-09-08 11:51:06 +010089}