1 /*
2 * Copyright (c) 2024 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_delay_getter_proxy.h"
17
18 #include "message_parcel_warp.h"
19 #include "pasteboard_hilog.h"
20
21 namespace OHOS {
22 namespace MiscServices {
PasteboardDelayGetterProxy(const sptr<IRemoteObject> & object)23 PasteboardDelayGetterProxy::PasteboardDelayGetterProxy(const sptr<IRemoteObject> &object)
24 : IRemoteProxy<IPasteboardDelayGetter>(object)
25 {
26 }
27
GetPasteData(const std::string & type,PasteData & data)28 void PasteboardDelayGetterProxy::GetPasteData(const std::string &type, PasteData &data)
29 {
30 MessageParcel request;
31 MessageParcel reply;
32 MessageOption option;
33 if (!request.WriteInterfaceToken(GetDescriptor())) {
34 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write descriptor failed");
35 return;
36 }
37 if (!request.WriteString(type)) {
38 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write type failed");
39 return;
40 }
41 int result = Remote()->SendRequest(TransId::TRANS_GET_PASTE_DATA, request, reply, option);
42 if (result != ERR_OK) {
43 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "send request fail, error:%{public}d", result);
44 return;
45 }
46 int64_t rawDataSize = reply.ReadInt64();
47 MessageParcelWarp messageReply;
48 if (rawDataSize <= 0 || rawDataSize > messageReply.GetRawDataSize()) {
49 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "invalid raw data size");
50 return;
51 }
52 const uint8_t *rawData = reinterpret_cast<const uint8_t *>(messageReply.ReadRawData(reply, rawDataSize));
53 PASTEBOARD_CHECK_AND_RETURN_LOGE(rawData != nullptr,
54 PASTEBOARD_MODULE_CLIENT, "fail to get raw data, size=%{public}" PRId64, rawDataSize);
55 std::vector<uint8_t> pasteDataTlv(rawData, rawData + rawDataSize);
56 bool ret = data.Decode(pasteDataTlv);
57 if (!ret) {
58 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "fail to decode paste data");
59 }
60 }
61
GetUnifiedData(const std::string & type,UDMF::UnifiedData & data)62 void PasteboardDelayGetterProxy::GetUnifiedData(const std::string &type, UDMF::UnifiedData &data) {}
63 } // namespace MiscServices
64 } // namespace OHOS