1 /*
2  * Copyright (c) 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 POWERMGR_POWER_MANAGER_SHUTDOWN_DIALOG_H
17 #define POWERMGR_POWER_MANAGER_SHUTDOWN_DIALOG_H
18 
19 #include <mutex>
20 
21 #include "ability_connect_callback_interface.h"
22 #include "ability_connect_callback_stub.h"
23 #include "ffrt_utils.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class ShutdownDialog {
28 public:
29     ShutdownDialog();
30     ~ShutdownDialog();
31     void KeyMonitorInit();
32     void KeyMonitorCancel();
33     bool ConnectSystemUi();
34     bool IsLongPress() const;
35     void ResetLongPressFlag();
36     void StartVibrator();
37     void LoadDialogConfig();
GetBundleName()38     static std::string GetBundleName()
39     {
40         return bundleName_;
41     }
42 
GetAbilityName()43     static std::string GetAbilityName()
44     {
45         return abilityName_;
46     }
47 
GetUiExtensionType()48     static std::string GetUiExtensionType()
49     {
50         return uiExtensionType_;
51     }
52 private:
53     class DialogAbilityConnection : public OHOS::AAFwk::AbilityConnectionStub {
54     public:
55         void OnAbilityConnectDone(
56             const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override;
57         void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
58 
59     private:
60         std::mutex mutex_;
61     };
62 
63     int32_t longPressId_ {0};
64     sptr<OHOS::AAFwk::IAbilityConnection> dialogConnectionCallback_ {nullptr};
65     FFRTQueue queue_ {"shutdown_dialog"};
66     static std::string bundleName_;
67     static std::string abilityName_;
68     static std::string uiExtensionType_;
69     static std::string dialogBundleName_;
70     static std::string dialogAbilityName_;
71 };
72 } // namespace PowerMgr
73 } // namespace OHOS
74 
75 #endif // POWERMGR_POWER_MANAGER_SHUTDOWN_DIALOG_H
76