/* * Copyright (C) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PASTE_BOARD_DATA_H #define PASTE_BOARD_DATA_H #include #include #include #include #include #include #include "paste_data_record.h" #include "pasteboard_hilog.h" #include "tlv_object.h" #include "uri.h" #include "want.h" #include "want_params.h" #include "parcel.h" namespace OHOS { namespace MiscServices { enum ShareOption : int32_t { InApp = 0, LocalDevice, CrossDevice }; enum ScreenEvent : int32_t { Default = 0, ScreenLocked, ScreenUnlocked }; struct API_EXPORT PasteDataProperty : public TLVObject { PasteDataProperty() = default; ~PasteDataProperty(); explicit PasteDataProperty(const PasteDataProperty &property); PasteDataProperty& operator=(const PasteDataProperty &property); AAFwk::WantParams additions; std::vector mimeTypes; std::string tag; std::int64_t timestamp; bool localOnly; ShareOption shareOption; uint32_t tokenId = 0; bool isRemote = false; std::string bundleName; std::string setTime; ScreenEvent screenStatus = ScreenEvent::Default; bool Encode(std::vector &buffer) override; bool Decode(const std::vector &buffer) override; bool DecodeTag(const std::vector &buffer); size_t Count() override; }; class API_EXPORT PasteData : public TLVObject, public Parcelable { public: static constexpr const std::uint32_t MAX_RECORD_NUM = 512; PasteData(); ~PasteData(); PasteData(const PasteData &data); PasteData& operator=(const PasteData &data); explicit PasteData(std::vector> records); void AddHtmlRecord(const std::string &html); void AddKvRecord(const std::string &mimeType, const std::vector &arrayBuffer); void AddPixelMapRecord(std::shared_ptr pixelMap); void AddTextRecord(const std::string &text); void AddUriRecord(const OHOS::Uri &uri); void AddWantRecord(std::shared_ptr want); void AddRecord(std::shared_ptr record); void AddRecord(PasteDataRecord &record); std::vector GetMimeTypes(); std::vector GetMimeTypesWithEntry(); std::shared_ptr GetPrimaryHtml(); std::shared_ptr GetPrimaryPixelMap(); std::shared_ptr GetPrimaryText(); std::shared_ptr GetPrimaryUri(); std::shared_ptr GetPrimaryMimeType(); std::shared_ptr GetPrimaryWant(); std::shared_ptr GetRecordAt(std::size_t index) const; std::size_t GetRecordCount() const; bool RemoveRecordAt(std::size_t number); bool ReplaceRecordAt(std::size_t number, std::shared_ptr record); bool HasMimeType(const std::string &mimeType); PasteDataProperty GetProperty() const; void SetProperty(const PasteDataProperty &property); ShareOption GetShareOption(); void SetShareOption(ShareOption shareOption); uint32_t GetTokenId(); void SetTokenId(uint32_t tokenId); std::vector> AllRecords() const; bool IsDraggedData() const; void SetDraggedDataFlag(bool isDraggedData); bool IsLocalPaste() const; void SetLocalPasteFlag(bool isLocalPaste); void SetBundleName(const std::string &bundleName); std::string GetBundleName() const; void SetOrginAuthority(const std::string &bundleName); std::string GetOrginAuthority() const; void SetRemote(bool isRemote); bool IsRemote(); void SetTime(const std::string &time); std::string GetTime(); void SetScreenStatus(ScreenEvent screenStatus); ScreenEvent GetScreenStatus(); void SetTag(std::string &tag); std::string GetTag(); void SetAdditions(AAFwk::WantParams &additions); void SetAddition(const std::string &key, AAFwk::IInterface *value); void SetLocalOnly(bool localOnly); bool GetLocalOnly(); bool Encode(std::vector &buffer) override; bool Decode(const std::vector &buffer) override; size_t Count() override; bool WriteUriFd(MessageParcel &parcel, UriHandler &uriHandler, bool isClient = true); bool ReadUriFd(MessageParcel &parcel, UriHandler &uriHandler); void ReplaceShareUri(int32_t userId); bool IsValid() const; void SetInvalid(); void SetDelayData(bool isDelay); bool IsDelayData() const; void SetDelayRecord(bool isDelay); bool IsDelayRecord() const; void SetDataId(uint32_t dataId); uint32_t GetDataId() const; void SetPasteId(const std::string &pasteId); std::string GetPasteId() const; std::string GetDeviceId() const; static void ShareOptionToString(ShareOption shareOption, std::string &out); bool Marshalling(Parcel &parcel) const override; static PasteData* Unmarshalling(Parcel &parcel); static std::string sharePath; static std::string WEBVIEW_PASTEDATA_TAG; static const std::string DISTRIBUTEDFILES_TAG; static const std::string PATH_SHARE; static const std::string FILE_SCHEME_PREFIX; static const std::string IMG_LOCAL_URI; static const std::string SHARE_PATH_PREFIX; static const std::string SHARE_PATH_PREFIX_ACCOUNT; static const std::string REMOTE_FILE_SIZE; std::string deviceId_; static const std::string REMOTE_FILE_SIZE_LONG; private: void RefreshMimeProp(); bool ReadFromParcel(Parcel &parcel); PasteDataProperty props_; std::vector> records_; std::string orginAuthority_; bool valid_ = true; bool isDraggedData_ = false; bool isLocalPaste_ = false; // local in app paste bool isDelayData_ = false; std::string pasteId_; bool isDelayRecord_ = false; uint32_t dataId_ = 0; uint32_t recordId_ = 0; using Func = std::function &buffer, TLVHead &head)>; std::map decodeMap_; void InitDecodeMap(); }; } // namespace MiscServices } // namespace OHOS #endif // PASTE_BOARD_DATA_H