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 #include "pasteboard_hilog.h"
18
19 #define MAX_RAWDATA_SIZE (128 * 1024 * 1024)
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 int32_t rawDataSize = reply.ReadInt32();
47 if (rawDataSize <= 0 || rawDataSize > MAX_RAWDATA_SIZE) {
48 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "invalid raw data size");
49 return;
50 }
51 const uint8_t *rawData = reinterpret_cast<const uint8_t *>(reply.ReadRawData(rawDataSize));
52 if (rawData == nullptr) {
53 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "fail to get raw data");
54 return;
55 }
56 std::vector<uint8_t> pasteDataTlv(rawData, rawData + rawDataSize);
57 bool ret = data.Decode(pasteDataTlv);
58 if (!ret) {
59 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "fail to decode paste data");
60 }
61 }
62
GetUnifiedData(const std::string & type,UDMF::UnifiedData & data)63 void PasteboardDelayGetterProxy::GetUnifiedData(const std::string &type, UDMF::UnifiedData &data) {}
64 } // namespace MiscServices
65 } // namespace OHOS