• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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();
38     void ParseJsonConfig(std::string& contentStr);
GetBundleName()39     static std::string GetBundleName()
40     {
41         return bundleName_;
42     }
43 
GetAbilityName()44     static std::string GetAbilityName()
45     {
46         return abilityName_;
47     }
48 
GetUiExtensionType()49     static std::string GetUiExtensionType()
50     {
51         return uiExtensionType_;
52     }
53 private:
54     class DialogAbilityConnection : public OHOS::AAFwk::AbilityConnectionStub {
55     public:
56         void OnAbilityConnectDone(
57             const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override;
58         void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
59 
60     private:
61         std::mutex mutex_;
62     };
63 
64     int32_t longPressId_ {0};
65     sptr<OHOS::AAFwk::IAbilityConnection> dialogConnectionCallback_ {nullptr};
66     FFRTQueue queue_ {"shutdown_dialog"};
67     static std::string bundleName_;
68     static std::string abilityName_;
69     static std::string uiExtensionType_;
70     static std::string dialogBundleName_;
71     static std::string dialogAbilityName_;
72 };
73 } // namespace PowerMgr
74 } // namespace OHOS
75 
76 #endif // POWERMGR_POWER_MANAGER_SHUTDOWN_DIALOG_H
77