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 | //! Implementation of IIsolatedCompilationService, called from system server when compilation is |
| 18 | //! desired. |
| 19 | |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 20 | use crate::compilation_task::CompilationTask; |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 21 | use crate::instance_manager::InstanceManager; |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 22 | use crate::util::to_binder_result; |
| 23 | use android_system_composd::aidl::android::system::composd::{ |
| 24 | ICompilationTask::{BnCompilationTask, ICompilationTask}, |
| 25 | ICompilationTaskCallback::ICompilationTaskCallback, |
| 26 | IIsolatedCompilationService::{BnIsolatedCompilationService, IIsolatedCompilationService}, |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 27 | }; |
Alan Stokes | 3189af0 | 2021-09-30 17:51:19 +0100 | [diff] [blame] | 28 | use android_system_composd::binder::{self, BinderFeatures, Interface, Strong}; |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 29 | use anyhow::{Context, Result}; |
Alan Stokes | 3189af0 | 2021-09-30 17:51:19 +0100 | [diff] [blame] | 30 | use binder_common::new_binder_service_specific_error; |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 31 | use compos_aidl_interface::aidl::com::android::compos::{ |
| 32 | CompilationResult::CompilationResult, FdAnnotation::FdAnnotation, |
| 33 | }; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 34 | |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 35 | pub struct IsolatedCompilationService { |
| 36 | instance_manager: InstanceManager, |
| 37 | } |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 38 | |
Alan Stokes | 69c610f | 2021-09-27 14:03:31 +0100 | [diff] [blame] | 39 | pub fn new_binder(instance_manager: InstanceManager) -> Strong<dyn IIsolatedCompilationService> { |
| 40 | let service = IsolatedCompilationService { instance_manager }; |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 41 | BnIsolatedCompilationService::new_binder(service, BinderFeatures::default()) |
| 42 | } |
| 43 | |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 44 | impl Interface for IsolatedCompilationService {} |
| 45 | |
| 46 | impl IIsolatedCompilationService for IsolatedCompilationService { |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 47 | fn startTestCompile( |
| 48 | &self, |
| 49 | callback: &Strong<dyn ICompilationTaskCallback>, |
| 50 | ) -> binder::Result<Strong<dyn ICompilationTask>> { |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 51 | // TODO - check caller is system or shell/root? |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 52 | to_binder_result(self.do_start_test_compile(callback)) |
Alan Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 53 | } |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 54 | |
Victor Hsieh | 3c044c4 | 2021-10-01 17:17:10 -0700 | [diff] [blame] | 55 | fn compile_cmd( |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 56 | &self, |
| 57 | args: &[String], |
| 58 | fd_annotation: &FdAnnotation, |
| 59 | ) -> binder::Result<CompilationResult> { |
| 60 | // TODO - check caller is odrefresh |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 61 | to_binder_result(self.do_compile_cmd(args, fd_annotation)) |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 62 | } |
Victor Hsieh | 3c044c4 | 2021-10-01 17:17:10 -0700 | [diff] [blame] | 63 | |
| 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 Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Alan Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 69 | impl IsolatedCompilationService { |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 70 | fn do_start_test_compile( |
| 71 | &self, |
| 72 | callback: &Strong<dyn ICompilationTaskCallback>, |
| 73 | ) -> Result<Strong<dyn ICompilationTask>> { |
Alan Stokes | 388b88a | 2021-10-13 16:03:17 +0100 | [diff] [blame] | 74 | let comp_os = self.instance_manager.start_test_instance().context("Starting CompOS")?; |
Alan Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 75 | |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 76 | let task = CompilationTask::start_test_compile(comp_os, callback)?; |
Alan Stokes | b2cc79e | 2021-09-14 14:08:46 +0100 | [diff] [blame] | 77 | |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 78 | Ok(BnCompilationTask::new_binder(task, BinderFeatures::default())) |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 79 | } |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 80 | |
Alan Stokes | 9ca14ca | 2021-10-20 14:25:57 +0100 | [diff] [blame^] | 81 | fn do_compile_cmd( |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 82 | &self, |
| 83 | args: &[String], |
| 84 | fd_annotation: &FdAnnotation, |
| 85 | ) -> Result<CompilationResult> { |
| 86 | let compos = self.instance_manager.get_running_service()?; |
Victor Hsieh | 3c044c4 | 2021-10-01 17:17:10 -0700 | [diff] [blame] | 87 | compos.compile_cmd(args, fd_annotation).context("Compiling") |
Alan Stokes | a2869d2 | 2021-09-22 09:06:41 +0100 | [diff] [blame] | 88 | } |
Alan Stokes | 3ef78d9 | 2021-09-08 11:51:06 +0100 | [diff] [blame] | 89 | } |