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