1 /* 2 * Copyright (C) 2025 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 PASTEBOARD_DISPOSABLE_MANAGER_H 17 #define PASTEBOARD_DISPOSABLE_MANAGER_H 18 19 #include "ipasteboard_delay_getter.h" 20 #include "ipasteboard_entry_getter.h" 21 #include "ipasteboard_disposable_observer.h" 22 #include "paste_data.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 struct DisposableInfo { 27 pid_t pid; 28 uint32_t tokenId; 29 DisposableType type; 30 uint32_t maxLen; 31 std::string targetBundleName; 32 sptr<IPasteboardDisposableObserver> observer; 33 DisposableInfoDisposableInfo34 DisposableInfo(pid_t pid, uint32_t tokenId, const std::string &targetBundleName, DisposableType type, 35 uint32_t maxLen, const sptr<IPasteboardDisposableObserver> observer) : pid(pid), tokenId(tokenId), 36 type(type), maxLen(maxLen), targetBundleName(targetBundleName), observer(observer) {} 37 }; 38 39 class DisposableManager { 40 public: 41 static DisposableManager &GetInstance(); 42 bool TryProcessDisposableData(const std::string &bundleName, PasteData &pasteData, 43 const sptr<IPasteboardDelayGetter> &delayGetter, const sptr<IPasteboardEntryGetter> &entryGetter); 44 int32_t AddDisposableInfo(const DisposableInfo &info); 45 void RemoveDisposableInfo(pid_t pid, bool needNotify); 46 47 private: 48 std::string GetPlainText(PasteData &pasteData, 49 const sptr<IPasteboardDelayGetter> &delayGetter, const sptr<IPasteboardEntryGetter> &entryGetter); 50 void ProcessMatchedInfo(const std::vector<DisposableInfo> &matchedInfoList, PasteData &pasteData, 51 const sptr<IPasteboardDelayGetter> &delayGetter, const sptr<IPasteboardEntryGetter> &entryGetter); 52 void ProcessNoMatchInfo(const std::vector<DisposableInfo> &noMatchInfoList); 53 54 static constexpr int32_t DISPOSABLE_EXPIRATION_DEFAULT = 100; // ms 55 static constexpr int32_t DISPOSABLE_EXPIRATION_MIN = 1; // ms 56 static constexpr int32_t DISPOSABLE_EXPIRATION_MAX = 200; // ms 57 std::mutex disposableInfoMutex_; 58 std::vector<DisposableInfo> disposableInfoList_; 59 }; 60 } // namespace MiscServices 61 } // namespace OHOS 62 #endif // PASTEBOARD_DISPOSABLE_MANAGER_H 63