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