1 /* 2 * Copyright (c) 2022-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 PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DAILOG_H 17 #define PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DAILOG_H 18 #include <functional> 19 #include <mutex> 20 #include <string> 21 22 #include "ability_manager_interface.h" 23 #include "refbase.h" 24 25 namespace OHOS::MiscServices { 26 class DialogConnection; 27 class PasteBoardDialog { 28 public: 29 struct ToastMessageInfo { 30 std::string fromAppName{ "unknown" }; 31 std::string toAppName{ "unknown" }; 32 }; 33 static constexpr uint32_t POPUP_INTERVAL = 1; // seconds 34 static constexpr uint32_t MAX_LIFE_TIME = 300; // seconds 35 static constexpr uint32_t SHOW_TOAST_TIME = 2000; // milliseconds 36 static constexpr const char *DEFAULT_LABEL = "unknown"; 37 using Cancel = std::function<void()>; 38 static PasteBoardDialog &GetInstance(); 39 int32_t ShowToast(const ToastMessageInfo &message); 40 void CancelToast(); 41 42 private: 43 static sptr<OHOS::AAFwk::IAbilityManager> GetAbilityManagerService(); 44 45 static constexpr const char *PASTEBOARD_DIALOG_APP = "com.ohos.pasteboarddialog"; 46 static constexpr const char *PASTEBOARD_TOAST_ABILITY = "ToastExtensionAbility"; 47 48 std::mutex connectionLock_; 49 sptr<DialogConnection> connection_; 50 }; 51 } // namespace OHOS::MiscServices 52 #endif // PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DAILOG_H 53