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     static constexpr uint32_t POPUP_INTERVAL = 1000;  // milliseconds
33     static constexpr uint32_t MAX_LIFE_TIME = 300 * 1000; // milliseconds
34     static constexpr uint32_t SHOW_TOAST_TIME = 3000; // milliseconds
35     static constexpr const char *DEFAULT_LABEL = "unknown";
36     using Cancel = std::function<void()>;
37     static PasteBoardDialog &GetInstance();
38     int32_t ShowToast(const ToastMessageInfo &message);
39     void CancelToast();
40 
41 private:
42     static sptr<OHOS::AAFwk::IAbilityManager> GetAbilityManagerService();
43 
44     static constexpr const char *PASTEBOARD_DIALOG_APP = "com.ohos.pasteboarddialog";
45     static constexpr const char *PASTEBOARD_TOAST_ABILITY = "ToastExtensionAbility";
46 
47     std::mutex connectionLock_;
48     sptr<DialogConnection> connection_;
49 };
50 } // namespace OHOS::MiscServices
51 #endif // PASTEBOARD_INTERFACES_KITS_NAPI_SRC_PASTE_BOARD_DAILOG_H
52