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 ACCESSIBILITY_SHORT_KEY_DIALOG_H
17 #define ACCESSIBILITY_SHORT_KEY_DIALOG_H
18 
19 #include "ability_connection.h"
20 #include "ability_connect_callback_interface.h"
21 #include "ability_connect_callback_stub.h"
22 #include "iremote_object.h"
23 #include "iremote_proxy.h"
24 #include "message_parcel.h"
25 #include "nocopyable.h"
26 #include <cstdint>
27 
28 namespace OHOS {
29 namespace Accessibility {
30 
31 enum ShortKeyDialogType {
32     FUNCTION_SELECT = 0,
33     RECONFIRM = 1
34 };
35 
36 class ShortkeyAbilityConnection : public AAFwk::AbilityConnectionStub {
37 public:
ShortkeyAbilityConnection(const std::string commandStr)38     explicit ShortkeyAbilityConnection(const std::string commandStr)
39     {
40         commandStr_ = commandStr;
41     }
42 
43     virtual ~ShortkeyAbilityConnection() = default;
44 
45     void OnAbilityConnectDone(const AppExecFwk::ElementName &element,
46         const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override;
47     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override;
48     std::string GetCommandString();
49 
50 private:
51     std::string commandStr_;
52 };
53 
54 class ReConfirmAbilityConnection : public AAFwk::AbilityConnectionStub {
55 public:
ReConfirmAbilityConnection(const std::string commandStr)56     explicit ReConfirmAbilityConnection(const std::string commandStr)
57     {
58         commandStr_ = commandStr;
59     }
60 
61     virtual ~ReConfirmAbilityConnection() = default;
62 
63     void OnAbilityConnectDone(const AppExecFwk::ElementName &element,
64         const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override;
65     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override;
66     std::string GetCommandString();
67 
68 private:
69     std::string commandStr_;
70 };
71 
72 class AccessibilityShortkeyDialog {
73 public:
74     AccessibilityShortkeyDialog();
75     ~AccessibilityShortkeyDialog();
76     bool ConnectDialog(ShortKeyDialogType dialogType);
77 
78 private:
79     bool ConnectExtension(ShortKeyDialogType dialogType);
80     bool ConnectExtensionAbility(const AAFwk::Want &want, const std::string commandStr, ShortKeyDialogType dialogType);
81     bool DisconnectExtension(ShortKeyDialogType dialogType) const;
82     std::string BuildStartCommand();
83 
84 private:
85     sptr<ShortkeyAbilityConnection> functionSelectConn_ {nullptr};
86     sptr<ReConfirmAbilityConnection> reConfirmConn_ {nullptr};
87 };
88 
89 } // namespace Accessibility
90 } // namespace OHOS
91 #endif // ACCESSIBILITY_SHORT_KEY_DIALOG_H