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::{serialize_task_info, RequestServiceStub};
19 
20 impl RequestServiceStub {
touch(&self, data: &mut MsgParcel, reply: &mut MsgParcel) -> IpcResult<()>21     pub(crate) fn touch(&self, data: &mut MsgParcel, reply: &mut MsgParcel) -> IpcResult<()> {
22         let task_id: String = data.read()?;
23         info!("Service touch tid {}", task_id);
24 
25         let Ok(task_id) = task_id.parse::<u32>() else {
26             error!("End Service touch, failed: task_id or token not valid");
27             reply.write(&(ErrorCode::TaskNotFound as i32))?;
28             return Err(IpcStatusCode::Failed);
29         };
30 
31         let token: String = data.read()?;
32         let uid = ipc::Skeleton::calling_uid();
33 
34         if !self.check_task_uid(task_id, uid) {
35             reply.write(&(ErrorCode::TaskNotFound as i32))?;
36             return Err(IpcStatusCode::Failed);
37         }
38         let info = self.task_manager.lock().unwrap().touch(uid, task_id, token);
39 
40         match info {
41             Some(info) => {
42                 reply.write(&(ErrorCode::ErrOk as i32))?;
43                 serialize_task_info(info, reply)?;
44                 Ok(())
45             }
46             None => {
47                 error!(
48                     "End Service touch, tid: {}, failed: task_id or token not found",
49                     task_id
50                 );
51                 reply.write(&(ErrorCode::TaskNotFound as i32))?;
52                 Err(IpcStatusCode::Failed)
53             }
54         }
55     }
56 }
57