1 /* 2 * Copyright (C) 2022 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 ACCESSIBLE_ABILITY_CONNECTION_H 17 #define ACCESSIBLE_ABILITY_CONNECTION_H 18 19 #include "ability_connect_callback_stub.h" 20 #include "accessibility_ability_info.h" 21 #include "accessible_ability_channel.h" 22 #include "accessible_ability_client_proxy.h" 23 #include "ffrt.h" 24 #include "common_event_manager.h" 25 26 namespace OHOS { 27 namespace Accessibility { 28 #define UID_MASK 200000 29 30 class AccessibilityAccountData; 31 32 class AccessibleAbilityConnection : public AAFwk::AbilityConnectionStub { 33 public: 34 AccessibleAbilityConnection(int32_t accountId, int32_t connectionId, AccessibilityAbilityInfo &abilityInfo); 35 36 virtual ~AccessibleAbilityConnection(); 37 38 void HandleNoEventHandler(const AppExecFwk::ElementName &element); 39 40 virtual void OnAbilityConnectDone(const AppExecFwk::ElementName &element, 41 const sptr<IRemoteObject> &remoteObject, 42 int32_t resultCode) override; 43 44 virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 45 46 // For AccessibleAbilityClientProxy 47 void OnAccessibilityEvent(AccessibilityEventInfo &eventInfo); 48 49 bool OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int32_t sequence); 50 51 void SetAbilityInfoTargetBundleName(const std::vector<std::string> &targetBundleNames); 52 53 // Get Attribution GetAbilityInfo()54 inline AccessibilityAbilityInfo& GetAbilityInfo() 55 { 56 return abilityInfo_; 57 } 58 GetElementName()59 inline AppExecFwk::ElementName& GetElementName() 60 { 61 return elementName_; 62 } 63 GetAbilityClient()64 inline sptr<IAccessibleAbilityClient> GetAbilityClient() 65 { 66 return abilityClient_; 67 } 68 69 void Disconnect(); 70 71 bool Connect(const AppExecFwk::ElementName &element); 72 73 int32_t GetChannelId(); 74 75 void OnAbilityConnectDoneSync(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject); 76 void OnAbilityDisconnectDoneSync(const AppExecFwk::ElementName &element); 77 bool GetIsRegisterDisconnectCallback() const; 78 void SetIsRegisterDisconnectCallback(bool isRegister); 79 void NotifyDisconnect(); 80 void DisconnectAbility(); 81 82 private: 83 class AccessibleAbilityConnectionDeathRecipient final : public IRemoteObject::DeathRecipient { 84 public: AccessibleAbilityConnectionDeathRecipient(int32_t accountId,AppExecFwk::ElementName & elementName,std::shared_ptr<AppExecFwk::EventHandler> handler)85 AccessibleAbilityConnectionDeathRecipient(int32_t accountId, 86 AppExecFwk::ElementName& elementName, std::shared_ptr<AppExecFwk::EventHandler> handler) 87 : accountId_(accountId), recipientElementName_(elementName), handler_(handler) {}; 88 ~AccessibleAbilityConnectionDeathRecipient() = default; 89 DISALLOW_COPY_AND_MOVE(AccessibleAbilityConnectionDeathRecipient); 90 91 void OnRemoteDied(const wptr<IRemoteObject>& remote); 92 93 int32_t accountId_ = -1; 94 AppExecFwk::ElementName recipientElementName_; 95 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 96 }; 97 98 bool IsWantedEvent(int32_t eventType); 99 void InitAbilityClient(const sptr<IRemoteObject> &remoteObject); 100 101 int32_t accountId_ = -1; 102 int32_t connectionId_ = -1; 103 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 104 sptr<IAccessibleAbilityClient> abilityClient_ = nullptr; 105 sptr<AccessibleAbilityChannel> channel_ = nullptr; 106 AccessibilityAbilityInfo abilityInfo_ {}; 107 AppExecFwk::ElementName elementName_ {}; 108 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; 109 bool isRegisterDisconnectCallback_ = false; 110 }; 111 } // namespace Accessibility 112 } // namespace OHOS 113 #endif // ACCESSIBLE_ABILITY_CONNECTION_H