• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 #ifndef PASTE_BOARD_RECORD_H
17 #define PASTE_BOARD_RECORD_H
18 
19 #include "common/constant.h"
20 #include "entry_getter.h"
21 #include "paste_data_entry.h"
22 
23 namespace OHOS {
24 namespace MiscServices {
25 enum ResultCode : int32_t { OK = 0, IPC_NO_DATA, IPC_ERROR };
26 
27 class API_EXPORT PasteDataRecord : public TLVWriteable, public TLVReadable {
28 public:
29     PasteDataRecord();
30     ~PasteDataRecord();
31     PasteDataRecord(const PasteDataRecord &record);
32     PasteDataRecord(std::string mimeType, std::shared_ptr<std::string> htmlText,
33         std::shared_ptr<OHOS::AAFwk::Want> want, std::shared_ptr<std::string> plainText,
34         std::shared_ptr<OHOS::Uri> uri);
35 
36     bool EncodeTLV(WriteOnlyBuffer &buffer) const override;
37     bool DecodeTLV(ReadOnlyBuffer &buffer) override;
38     size_t CountTLV() const override;
39 
40     static std::shared_ptr<PasteDataRecord> NewHtmlRecord(const std::string &htmlText);
41     static std::shared_ptr<PasteDataRecord> NewWantRecord(std::shared_ptr<OHOS::AAFwk::Want> want);
42     static std::shared_ptr<PasteDataRecord> NewPlainTextRecord(const std::string &text);
43     static std::shared_ptr<PasteDataRecord> NewPixelMapRecord(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
44     static std::shared_ptr<PasteDataRecord> NewUriRecord(const OHOS::Uri &uri);
45     static std::shared_ptr<PasteDataRecord> NewKvRecord(
46         const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer);
47     static std::shared_ptr<PasteDataRecord> NewMultiTypeRecord(
48         std::shared_ptr<std::map<std::string, std::shared_ptr<EntryValue>>> values,
49         const std::string &recordMimeType = "");
50     static std::shared_ptr<PasteDataRecord> NewMultiTypeDelayRecord(
51         std::vector<std::string> mimeTypes, const std::shared_ptr<UDMF::EntryGetter> entryGetter);
52 
53     bool isConvertUriFromRemote = false;
54     std::string GetMimeType() const;
55     std::set<std::string> GetMimeTypes() const;
56     std::shared_ptr<std::string> GetHtmlText() const;
57     std::shared_ptr<std::string> GetPlainText() const;
58     std::shared_ptr<OHOS::Media::PixelMap> GetPixelMap() const;
59     void ClearPixelMap();
60     std::shared_ptr<OHOS::Uri> GetUri() const;
61     void SetUri(std::shared_ptr<OHOS::Uri> uri);
62     std::shared_ptr<OHOS::Uri> GetOriginUri() const;
63     std::shared_ptr<OHOS::AAFwk::Want> GetWant() const;
64     std::shared_ptr<MineCustomData> GetCustomData() const;
65 
66     std::string ConvertToText() const;
67     void SetConvertUri(const std::string &value);
68     std::string GetConvertUri() const;
69     void SetGrantUriPermission(bool hasPermission);
70     bool HasGrantUriPermission();
71 
72     void SetTextContent(const std::string &content);
73     std::string GetTextContent() const;
74     void SetDetails(const Details &details);
75     std::shared_ptr<Details> GetDetails() const;
76     void SetSystemDefinedContent(const Details &contents);
77     std::shared_ptr<Details> GetSystemDefinedContent() const;
78     int32_t GetUDType() const;
79     void SetUDType(int32_t type);
80 
81     bool HasEmptyEntry() const;
82     void SetUDMFValue(const std::shared_ptr<EntryValue> &udmfValue);
83     std::shared_ptr<EntryValue> GetUDMFValue();
84 
85     void AddEntry(const std::string &utdType, std::shared_ptr<PasteDataEntry> value);
86     void AddEntryByMimeType(const std::string &mimeType, std::shared_ptr<PasteDataEntry> value);
87     std::shared_ptr<PasteDataEntry> GetEntry(const std::string &utdType);
88     std::shared_ptr<PasteDataEntry> GetEntryByMimeType(const std::string &mimeType);
89     std::vector<std::shared_ptr<PasteDataEntry>> GetEntries() const;
90     std::vector<std::string> GetValidTypes(const std::vector<std::string> &types) const;
91     std::vector<std::string> GetValidMimeTypes(const std::vector<std::string> &mimeTypes) const;
92 
93     void SetDelayRecordFlag(bool isDelay);
94     bool IsDelayRecord() const;
95     void SetDataId(uint32_t dataId);
96     uint32_t GetDataId() const;
97     void SetRecordId(uint32_t recordId);
98     uint32_t GetRecordId() const;
99 
100     void SetEntryGetter(const std::shared_ptr<UDMF::EntryGetter> entryGetter);
101     std::shared_ptr<UDMF::EntryGetter> GetEntryGetter();
102 
103     void SetFrom(uint32_t from);
104     uint32_t GetFrom() const;
105 
106     class Builder {
107     public:
108         explicit Builder(const std::string &mimeType);
109         Builder &SetHtmlText(std::shared_ptr<std::string> htmlText);
110         Builder &SetWant(std::shared_ptr<OHOS::AAFwk::Want> want);
111         Builder &SetPlainText(std::shared_ptr<std::string> plainText);
112         Builder &SetUri(std::shared_ptr<OHOS::Uri> uri);
113         Builder &SetPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
114         Builder &SetCustomData(std::shared_ptr<MineCustomData> customData);
115         Builder &SetMimeType(std::string mimeType);
116         std::shared_ptr<PasteDataRecord> Build();
117 
118     private:
119         std::shared_ptr<PasteDataRecord> record_ = nullptr;
120     };
121 
122 private:
123     std::string GetPassUri();
124     void AddUriEntry();
125     std::set<std::string> GetUdtTypes() const;
126 
127     std::string mimeType_;
128     std::shared_ptr<std::string> htmlText_;
129     std::shared_ptr<OHOS::AAFwk::Want> want_;
130     std::shared_ptr<std::string> plainText_;
131     std::shared_ptr<OHOS::Uri> uri_;
132     std::string convertUri_;
133     std::shared_ptr<OHOS::Media::PixelMap> pixelMap_;
134     std::shared_ptr<MineCustomData> customData_;
135     bool hasGrantUriPermission_ = false;
136     using DecodeFunc = std::function<bool(ReadOnlyBuffer &buffer, TLVHead &head)>;
137     std::map<uint16_t, DecodeFunc> decodeMap;
138     void InitDecodeMap();
139 
140     int32_t udType_ = UDMF::UD_BUTT;
141     std::shared_ptr<Details> details_;
142     std::string textContent_;
143     std::shared_ptr<Details> systemDefinedContents_;
144     std::shared_ptr<EntryValue> udmfValue_;
145     std::vector<std::shared_ptr<PasteDataEntry>> entries_;
146     uint32_t dataId_ = 0;
147     uint32_t recordId_ = 0;
148     bool isDelay_ = false;
149     std::shared_ptr<UDMF::EntryGetter> entryGetter_;
150     uint32_t from_ = 0;
151 };
152 } // namespace MiscServices
153 } // namespace OHOS
154 #endif // PASTE_BOARD_RECORD_H
155