• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #define LOG_TAG "ProcessCallback"
16 #include "progress_callback.h"
17 
18 #include "error_code.h"
19 #include "ipc_skeleton.h"
20 #include "logger.h"
21 #include "udmf_async_client.h"
22 
23 
24 namespace OHOS {
25 namespace UDMF {
26 constexpr int BASE_DECIMAL = 10;
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t ProgressSignalStub::OnRemoteRequest(uint32_t code,
28     MessageParcel &data, MessageParcel &reply, MessageOption &option)
29 {
30     std::u16string myDescriptor = ProgressSignalStub::GetDescriptor();
31     std::u16string remoteDescriptor = data.ReadInterfaceToken();
32     if (myDescriptor != remoteDescriptor) {
33         LOG_ERROR(UDMF_SERVICE, "Descriptor checked fail");
34         return E_ERROR;
35     }
36     pid_t pid = IPCSkeleton::GetCallingPid();
37     LOG_INFO(UDMF_SERVICE, "CallingPid=%{public}d, code=%{public}u", pid, code);
38     HandleProgressSignalValue(data);
39     return E_OK;
40 }
41 
HandleProgressSignalValue(MessageParcel & data)42 void ProgressSignalCallback::HandleProgressSignalValue(MessageParcel &data)
43 {
44     int32_t cancelStatus = 0;
45     std::string signalValue = data.ReadString();
46 
47     char* end = nullptr;
48     errno = 0;
49     uint32_t convertResult = std::strtoul(signalValue.c_str(), &end, BASE_DECIMAL);
50     if (errno == ERANGE || end == signalValue || *end != '\0') {
51         LOG_ERROR(UDMF_CLIENT, "Failed to convert signalValue, signalValue=%{public}s", signalValue.c_str());
52         return;
53     }
54 
55     if (convertResult > INT32_MAX) {
56         LOG_ERROR(UDMF_CLIENT, "Signal value exceeds int32_t range, convertResult=%{public}u", convertResult);
57         return;
58     }
59 
60     cancelStatus = static_cast<int32_t>(convertResult);
61 
62     switch (cancelStatus) {
63         case NORMAL_PASTE:
64             break;
65         case CANCEL_PASTE:
66             UdmfAsyncClient::GetInstance().CancelOnSingleTask();
67             break;
68         case PASTE_TIME_OUT:
69             LOG_ERROR(UDMF_CLIENT, "Progress timed out");
70             break;
71         default:
72             LOG_ERROR(UDMF_CLIENT, "status error, status=%{public}d", cancelStatus);
73             break;
74     }
75 }
76 } // namespace UDMF
77 } // namespace OHOS