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 MessageInfo { 30 std::string appName{ "unknown" }; 31 std::string deviceType{ "unknown" }; 32 }; 33 struct ToastMessageInfo { 34 std::string fromAppName{ "unknown" }; 35 std::string toAppName{ "unknown" }; 36 }; 37 static constexpr uint32_t POPUP_INTERVAL = 1; // seconds 38 static constexpr uint32_t MAX_LIFE_TIME = 300; // seconds 39 static constexpr uint32_t SHOW_TOAST_TIME = 2000; // milliseconds 40 static constexpr const char *DEFAULT_LABEL = "unknown"; 41 using Cancel = std::function<void()>; 42 static PasteBoardDialog &GetInstance(); 43 int32_t ShowDialog(const MessageInfo &message, const Cancel &cancel); 44 int32_t ShowToast(const ToastMessageInfo &message); 45 void CancelDialog(); 46 void CancelToast(); 47 48 private: 49 static sptr<OHOS::AAFwk::IAbilityManager> GetAbilityManagerService(); 50 51 static constexpr const char *PASTEBOARD_DIALOG_APP = "cn.openharmony.pasteboarddialog"; 52 static constexpr const char *PASTEBOARD_DIALOG_ABILITY = "DialogExtensionAbility"; 53 static constexpr const char *PASTEBOARD_TOAST_ABILITY = "ToastExtensionAbility"; 54 55 std::mutex connectionLock_; 56 std::mutex toastConnectionLock_; 57 sptr<DialogConnection> connection_; 58 sptr<DialogConnection> toastConnection_; 59 }; 60 } // namespace OHOS::MiscServices 61 #endif // PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DAILOG_H 62