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 READER_EXCLUSIVE = 2 35 }; 36 37 class ShortkeyAbilityConnection : public AAFwk::AbilityConnectionStub { 38 public: ShortkeyAbilityConnection(const std::string commandStr)39 explicit ShortkeyAbilityConnection(const std::string commandStr) 40 { 41 commandStr_ = commandStr; 42 } 43 44 virtual ~ShortkeyAbilityConnection() = default; 45 46 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, 47 const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override; 48 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 49 std::string GetCommandString(); 50 51 private: 52 std::string commandStr_; 53 }; 54 55 class ReConfirmAbilityConnection : public AAFwk::AbilityConnectionStub { 56 public: ReConfirmAbilityConnection(const std::string commandStr)57 explicit ReConfirmAbilityConnection(const std::string commandStr) 58 { 59 commandStr_ = commandStr; 60 } 61 62 virtual ~ReConfirmAbilityConnection() = default; 63 64 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, 65 const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override; 66 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 67 std::string GetCommandString(); 68 69 private: 70 std::string commandStr_; 71 }; 72 73 class ExclusiveAbilityConnection : public AAFwk::AbilityConnectionStub { 74 public: ExclusiveAbilityConnection(const std::string commandStr)75 explicit ExclusiveAbilityConnection(const std::string commandStr) 76 { 77 commandStr_ = commandStr; 78 } 79 80 virtual ~ExclusiveAbilityConnection() = default; 81 82 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, 83 const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override; 84 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 85 std::string GetCommandString(); 86 87 private: 88 std::string commandStr_; 89 }; 90 91 class AccessibilityShortkeyDialog { 92 public: 93 AccessibilityShortkeyDialog(); 94 ~AccessibilityShortkeyDialog(); 95 bool ConnectDialog(ShortKeyDialogType dialogType); 96 97 private: 98 bool ConnectExtension(ShortKeyDialogType dialogType); 99 bool ConnectExtensionAbility(const AAFwk::Want &want, const std::string commandStr, ShortKeyDialogType dialogType); 100 bool DisconnectExtension(ShortKeyDialogType dialogType) const; 101 std::string BuildStartCommand(); 102 103 private: 104 sptr<ShortkeyAbilityConnection> functionSelectConn_ {nullptr}; 105 sptr<ReConfirmAbilityConnection> reConfirmConn_ {nullptr}; 106 sptr<ExclusiveAbilityConnection> readerExclusiveConn_ {nullptr}; 107 }; 108 109 } // namespace Accessibility 110 } // namespace OHOS 111 #endif // ACCESSIBILITY_SHORT_KEY_DIALOG_H