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 "message_option.h"
17 #include "message_parcel.h"
18 #include "pasteboard_delay_getter_proxy.h"
19 #include "pasteboard_error.h"
20 #include "pasteboard_hilog.h"
21 #include "paste_uri_handler.h"
22 
23 namespace OHOS {
24 namespace MiscServices {
PasteboardDelayGetterProxy(const sptr<IRemoteObject> & object)25 PasteboardDelayGetterProxy::PasteboardDelayGetterProxy(const sptr<IRemoteObject> &object)
26     : IRemoteProxy<IPasteboardDelayGetter>(object)
27 {
28 }
29 
GetPasteData(const std::string & type,PasteData & data)30 void PasteboardDelayGetterProxy::GetPasteData(const std::string &type, PasteData &data)
31 {
32     MessageParcel request;
33     MessageParcel reply;
34     MessageOption option;
35     if (!request.WriteInterfaceToken(GetDescriptor())) {
36         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write descriptor failed");
37         return;
38     }
39     if (!request.WriteString(type)) {
40         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write type failed");
41         return;
42     }
43     int result = Remote()->SendRequest(TransId::TRANS_GET_PASTE_DATA, request, reply, option);
44     if (result != ERR_OK) {
45         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "send request fail, error:%{public}d", result);
46         return;
47     }
48     int32_t rawDataSize = reply.ReadInt32();
49     if (rawDataSize <= 0) {
50         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "fail to get data size");
51         return;
52     }
53     const uint8_t *rawData = reinterpret_cast<const uint8_t *>(reply.ReadRawData(rawDataSize));
54     if (rawData == nullptr) {
55         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "fail to get raw data");
56         return;
57     }
58     std::vector<uint8_t> pasteDataTlv(rawData, rawData + rawDataSize);
59     bool ret = data.Decode(pasteDataTlv);
60     if (!ret) {
61         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "fail to decode paste data");
62         return;
63     }
64     PasteUriHandler pasteHandler;
65     if (!data.ReadUriFd(reply, pasteHandler)) {
66         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "failed to write record uri fd");
67         return;
68     }
69 }
70 
GetUnifiedData(const std::string & type,UDMF::UnifiedData & data)71 void PasteboardDelayGetterProxy::GetUnifiedData(const std::string &type, UDMF::UnifiedData &data)
72 {
73 }
74 } // namespace MiscServices
75 } // namespace OHOS