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