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_proxy.h"
17
18 #include "errors.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "pasteboard_hilog.h"
22 #include "pasteboard_serv_ipc_interface_code.h"
23
24 using namespace OHOS::Security::PasteboardServ;
25 namespace OHOS {
26 namespace MiscServices {
PasteboardObserverProxy(const sptr<IRemoteObject> & object)27 PasteboardObserverProxy::PasteboardObserverProxy(const sptr<IRemoteObject> &object)
28 : IRemoteProxy<IPasteboardChangedObserver>(object)
29 {
30 }
31
OnPasteboardChanged()32 void PasteboardObserverProxy::OnPasteboardChanged()
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option = { MessageOption::TF_ASYNC };
37 if (!data.WriteInterfaceToken(GetDescriptor())) {
38 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
39 return;
40 }
41
42 int ret = Remote()->SendRequest(
43 static_cast<int>(PasteboardObserverInterfaceCode::ON_PASTE_BOARD_CHANGE), data, reply, option);
44 if (ret != ERR_OK) {
45 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
46 }
47 return;
48 }
49
OnPasteboardEvent(std::string bundleName,int32_t status)50 void PasteboardObserverProxy::OnPasteboardEvent(std::string bundleName, int32_t status)
51 {
52 MessageParcel data;
53 MessageParcel reply;
54 MessageOption option = { MessageOption::TF_ASYNC };
55 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
56 if (!data.WriteInterfaceToken(GetDescriptor())) {
57 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
58 return;
59 }
60 data.WriteString(bundleName);
61 data.WriteInt32(status);
62 int ret = Remote()->SendRequest(
63 static_cast<int>(PasteboardObserverInterfaceCode::ON_PASTE_BOARD_EVENT), data, reply, option);
64 if (ret != ERR_OK) {
65 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
66 }
67 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
68 return;
69 }
70 } // namespace MiscServices
71 } // namespace OHOS
72