1 /*
2 * Copyright (c) 2023 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 "pasteboard_observer_stub.h"
17
18 #include "pasteboard_hilog.h"
19 #include "pasteboard_serv_ipc_interface_code.h"
20
21 using namespace OHOS::Security::PasteboardServ;
22 namespace OHOS {
23 namespace MiscServices {
PasteboardObserverStub()24 PasteboardObserverStub::PasteboardObserverStub()
25 {
26 memberFuncMap_[static_cast<uint32_t>(PasteboardObserverInterfaceCode::ON_PASTE_BOARD_CHANGE)] =
27 &PasteboardObserverStub::OnPasteboardChangedStub;
28 memberFuncMap_[static_cast<uint32_t>(PasteboardObserverInterfaceCode::ON_PASTE_BOARD_EVENT)] =
29 &PasteboardObserverStub::OnPasteboardEventStub;
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t PasteboardObserverStub::OnRemoteRequest(
33 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
34 {
35 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start##code = %{public}u", code);
36 std::u16string myDescriptor = PasteboardObserverStub::GetDescriptor();
37 std::u16string remoteDescriptor = data.ReadInterfaceToken();
38 if (myDescriptor != remoteDescriptor) {
39 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "end##descriptor checked fail");
40 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
41 }
42 pid_t pid = IPCSkeleton::GetCallingPid();
43 pid_t uid = IPCSkeleton::GetCallingUid();
44 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE,
45 "CallingPid = %{public}d, CallingUid = %{public}d, code = %{public}u", pid, uid, code);
46 auto itFunc = memberFuncMap_.find(code);
47 if (itFunc != memberFuncMap_.end()) {
48 auto memberFunc = itFunc->second;
49 if (memberFunc != nullptr) {
50 return (this->*memberFunc)(data, reply);
51 }
52 }
53 int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end##ret = %{public}d", ret);
55 return ret;
56 }
57
OnPasteboardChangedStub(MessageParcel & data,MessageParcel & reply)58 int32_t PasteboardObserverStub::OnPasteboardChangedStub(MessageParcel &data, MessageParcel &reply)
59 {
60 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
61 OnPasteboardChanged();
62 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
63 return ERR_OK;
64 }
65
OnPasteboardEventStub(MessageParcel & data,MessageParcel & reply)66 int32_t PasteboardObserverStub::OnPasteboardEventStub(MessageParcel &data, MessageParcel &reply)
67 {
68 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
69 std::string bundleName = data.ReadString();
70 int32_t status = data.ReadInt32();
71 OnPasteboardEvent(bundleName, status);
72 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
73 return ERR_OK;
74 }
75
~PasteboardObserverStub()76 PasteboardObserverStub::~PasteboardObserverStub()
77 {
78 memberFuncMap_.clear();
79 }
80 } // namespace MiscServices
81 } // namespace OHOS
82