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 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
38 if (!data.WriteInterfaceToken(GetDescriptor())) {
39 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
40 return;
41 }
42
43 int ret = Remote()->SendRequest(
44 static_cast<int>(PasteboardObserverInterfaceCode::ON_PASTE_BOARD_CHANGE), data, reply, option);
45 if (ret != ERR_OK) {
46 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
47 }
48 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
49 return;
50 }
51
OnPasteboardEvent(std::string bundleName,int32_t status)52 void PasteboardObserverProxy::OnPasteboardEvent(std::string bundleName, int32_t status)
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option = { MessageOption::TF_ASYNC };
57 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
60 return;
61 }
62 data.WriteString(bundleName);
63 data.WriteInt32(status);
64 int ret = Remote()->SendRequest(
65 static_cast<int>(PasteboardObserverInterfaceCode::ON_PASTE_BOARD_EVENT), data, reply, option);
66 if (ret != ERR_OK) {
67 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
68 }
69 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
70 return;
71 }
72 } // namespace MiscServices
73 } // namespace OHOS
74