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
16 #include "ipc_skeleton.h"
17 #include "pasteboard_error.h"
18 #include "pasteboard_signal_stub.h"
19
20 namespace OHOS {
21 namespace MiscServices {
PasteboardSignalStub()22 PasteboardSignalStub::PasteboardSignalStub()
23 {
24 memberFuncMap_[static_cast<uint32_t>(PasteboardSignalStub::GET_PROGRESS_SIGNAL)] =
25 &PasteboardSignalStub::OnGetProgressSignal;
26 }
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t PasteboardSignalStub::OnRemoteRequest(
29 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31 std::u16string myDescriptor = PasteboardSignalStub::GetDescriptor();
32 std::u16string remoteDescriptor = data.ReadInterfaceToken();
33 if (myDescriptor != remoteDescriptor) {
34 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "end##descriptor checked fail");
35 return static_cast<int32_t>(PasteboardError::CHECK_DESCRIPTOR_ERROR);
36 }
37 pid_t pid = IPCSkeleton::GetCallingPid();
38 pid_t uid = IPCSkeleton::GetCallingUid();
39 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE,
40 "CallingPid = %{public}d, CallingUid = %{public}d, code = %{public}u", pid, uid, code);
41 auto itFunc = memberFuncMap_.find(code);
42 if (itFunc != memberFuncMap_.end()) {
43 auto memberFunc = itFunc->second;
44 if (memberFunc != nullptr) {
45 return (this->*memberFunc)(data, reply);
46 }
47 }
48 int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end##ret = %{public}d", ret);
50 return ret;
51 }
52
OnGetProgressSignal(MessageParcel & data,MessageParcel & reply)53 int32_t PasteboardSignalStub::OnGetProgressSignal(MessageParcel &data, MessageParcel &reply)
54 {
55 std::string signalValue = data.ReadString();
56 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnGetProgressSignal signalValue is %{public}s", signalValue.c_str());
57 HandleProgressSignalValue(signalValue);
58 return ERR_OK;
59 }
60
~PasteboardSignalStub()61 PasteboardSignalStub::~PasteboardSignalStub()
62 {
63 memberFuncMap_.clear();
64 }
65 } // namespace MiscServices
66 } // namespace OHOS