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_DIALOG_H 17 #define PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DIALOG_H 18 19 #include "ability_manager_interface.h" 20 21 namespace OHOS::MiscServices { 22 class DialogConnection; 23 class PasteBoardDialog { 24 public: 25 struct ToastMessageInfo { 26 std::string appName{ DEFAULT_LABEL }; 27 }; 28 struct ProgressMessageInfo { 29 std::string promptText{ DEFAULT_LABEL }; 30 std::string remoteDeviceName{ DEFAULT_LABEL }; 31 std::string progressKey{ DEFAULT_LABEL }; 32 bool isRemote { false }; 33 int32_t windowId { 0 }; 34 sptr<IRemoteObject> callerToken { nullptr }; 35 sptr<IRemoteObject> clientCallback { nullptr }; 36 }; 37 static constexpr uint32_t POPUP_INTERVAL = 1000; // milliseconds 38 static constexpr uint32_t MAX_LIFE_TIME = 300 * 1000; // milliseconds 39 static constexpr uint32_t SHOW_TOAST_TIME = 3000; // milliseconds 40 static constexpr const char *DEFAULT_LABEL = "unknown"; 41 using Cancel = std::function<void()>; 42 static PasteBoardDialog &GetInstance(); 43 int32_t ShowToast(const ToastMessageInfo &message); 44 void CancelToast(); 45 int32_t ShowProgress(const ProgressMessageInfo &message); 46 47 private: 48 static sptr<OHOS::AAFwk::IAbilityManager> GetAbilityManagerService(); 49 50 static constexpr const char *PASTEBOARD_DIALOG_APP = "com.ohos.pasteboarddialog"; 51 static constexpr const char *PASTEBOARD_TOAST_ABILITY = "ToastExtensionAbility"; 52 static constexpr const char *PASTEBOARD_PROGRESS_ABILITY = "PasteboardProgressAbility"; 53 54 std::mutex connectionLock_; 55 sptr<DialogConnection> connection_; 56 }; 57 } // namespace OHOS::MiscServices 58 #endif // PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DIALOG_H 59