1 // Copyright (C) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use ipc::parcel::MsgParcel; 15 use ipc::{IpcResult, IpcStatusCode}; 16 17 use crate::error::ErrorCode; 18 use crate::service::permission::PermissionChecker; 19 use crate::service::{serialize_task_info, RequestServiceStub}; 20 21 impl RequestServiceStub { show(&self, data: &mut MsgParcel, reply: &mut MsgParcel) -> IpcResult<()>22 pub(crate) fn show(&self, data: &mut MsgParcel, reply: &mut MsgParcel) -> IpcResult<()> { 23 if !PermissionChecker::check_internet() { 24 error!("Service show: no INTERNET permission"); 25 reply.write(&(ErrorCode::Permission as i32))?; 26 return Err(IpcStatusCode::Failed); 27 } 28 let task_id: String = data.read()?; 29 info!("Service show tid {}", task_id); 30 31 let Ok(task_id) = task_id.parse::<u32>() else { 32 error!("End Service show, failed: task_id not valid"); 33 reply.write(&(ErrorCode::TaskNotFound as i32))?; 34 return Err(IpcStatusCode::Failed); 35 }; 36 37 let uid = ipc::Skeleton::calling_uid(); 38 if !self.check_task_uid(task_id, uid) { 39 reply.write(&(ErrorCode::TaskNotFound as i32))?; 40 return Err(IpcStatusCode::Failed); 41 } 42 43 let info = self.task_manager.lock().unwrap().show(uid, task_id); 44 match info { 45 Some(info) => { 46 reply.write(&(ErrorCode::ErrOk as i32))?; 47 serialize_task_info(info, reply)?; 48 Ok(()) 49 } 50 None => { 51 error!( 52 "End Service show, failed: task_id not found, tid: {}", 53 task_id 54 ); 55 reply.write(&(ErrorCode::TaskNotFound as i32))?; 56 Err(IpcStatusCode::Failed) 57 } 58 } 59 } 60 } 61