1885b47fbSopenharmony_ci/* 2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License. 5885b47fbSopenharmony_ci * You may obtain a copy of the License at 6885b47fbSopenharmony_ci * 7885b47fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8885b47fbSopenharmony_ci * 9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and 13885b47fbSopenharmony_ci * limitations under the License. 14885b47fbSopenharmony_ci */ 15885b47fbSopenharmony_ci 16885b47fbSopenharmony_ci#ifndef ACCESSIBLE_ABILITY_CONNECTION_H 17885b47fbSopenharmony_ci#define ACCESSIBLE_ABILITY_CONNECTION_H 18885b47fbSopenharmony_ci 19885b47fbSopenharmony_ci#include "ability_connect_callback_stub.h" 20885b47fbSopenharmony_ci#include "accessibility_ability_info.h" 21885b47fbSopenharmony_ci#include "accessible_ability_channel.h" 22885b47fbSopenharmony_ci#include "accessible_ability_client_proxy.h" 23885b47fbSopenharmony_ci#include "ffrt.h" 24885b47fbSopenharmony_ci#include "common_event_manager.h" 25885b47fbSopenharmony_ci 26885b47fbSopenharmony_cinamespace OHOS { 27885b47fbSopenharmony_cinamespace Accessibility { 28885b47fbSopenharmony_ci#define UID_MASK 200000 29885b47fbSopenharmony_ci 30885b47fbSopenharmony_ciclass AccessibilityAccountData; 31885b47fbSopenharmony_ci 32885b47fbSopenharmony_ciclass AccessibleAbilityConnection : public AAFwk::AbilityConnectionStub { 33885b47fbSopenharmony_cipublic: 34885b47fbSopenharmony_ci AccessibleAbilityConnection(int32_t accountId, int32_t connectionId, AccessibilityAbilityInfo &abilityInfo); 35885b47fbSopenharmony_ci 36885b47fbSopenharmony_ci virtual ~AccessibleAbilityConnection(); 37885b47fbSopenharmony_ci 38885b47fbSopenharmony_ci void HandleNoEventHandler(const AppExecFwk::ElementName &element); 39885b47fbSopenharmony_ci 40885b47fbSopenharmony_ci virtual void OnAbilityConnectDone(const AppExecFwk::ElementName &element, 41885b47fbSopenharmony_ci const sptr<IRemoteObject> &remoteObject, 42885b47fbSopenharmony_ci int32_t resultCode) override; 43885b47fbSopenharmony_ci 44885b47fbSopenharmony_ci virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 45885b47fbSopenharmony_ci 46885b47fbSopenharmony_ci // For AccessibleAbilityClientProxy 47885b47fbSopenharmony_ci void OnAccessibilityEvent(AccessibilityEventInfo &eventInfo); 48885b47fbSopenharmony_ci 49885b47fbSopenharmony_ci bool OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int32_t sequence); 50885b47fbSopenharmony_ci 51885b47fbSopenharmony_ci void SetAbilityInfoTargetBundleName(const std::vector<std::string> &targetBundleNames); 52885b47fbSopenharmony_ci 53885b47fbSopenharmony_ci // Get Attribution 54885b47fbSopenharmony_ci inline AccessibilityAbilityInfo& GetAbilityInfo() 55885b47fbSopenharmony_ci { 56885b47fbSopenharmony_ci return abilityInfo_; 57885b47fbSopenharmony_ci } 58885b47fbSopenharmony_ci 59885b47fbSopenharmony_ci inline AppExecFwk::ElementName& GetElementName() 60885b47fbSopenharmony_ci { 61885b47fbSopenharmony_ci return elementName_; 62885b47fbSopenharmony_ci } 63885b47fbSopenharmony_ci 64885b47fbSopenharmony_ci inline sptr<IAccessibleAbilityClient> GetAbilityClient() 65885b47fbSopenharmony_ci { 66885b47fbSopenharmony_ci return abilityClient_; 67885b47fbSopenharmony_ci } 68885b47fbSopenharmony_ci 69885b47fbSopenharmony_ci void Disconnect(); 70885b47fbSopenharmony_ci 71885b47fbSopenharmony_ci bool Connect(const AppExecFwk::ElementName &element); 72885b47fbSopenharmony_ci 73885b47fbSopenharmony_ci int32_t GetChannelId(); 74885b47fbSopenharmony_ci 75885b47fbSopenharmony_ci void OnAbilityConnectDoneSync(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject); 76885b47fbSopenharmony_ci void OnAbilityDisconnectDoneSync(const AppExecFwk::ElementName &element); 77885b47fbSopenharmony_ci 78885b47fbSopenharmony_ciprivate: 79885b47fbSopenharmony_ci class AccessibleAbilityConnectionDeathRecipient final : public IRemoteObject::DeathRecipient { 80885b47fbSopenharmony_ci public: 81885b47fbSopenharmony_ci AccessibleAbilityConnectionDeathRecipient(int32_t accountId, 82885b47fbSopenharmony_ci AppExecFwk::ElementName& elementName, std::shared_ptr<AppExecFwk::EventHandler> handler) 83885b47fbSopenharmony_ci : accountId_(accountId), recipientElementName_(elementName), handler_(handler) {}; 84885b47fbSopenharmony_ci ~AccessibleAbilityConnectionDeathRecipient() = default; 85885b47fbSopenharmony_ci DISALLOW_COPY_AND_MOVE(AccessibleAbilityConnectionDeathRecipient); 86885b47fbSopenharmony_ci 87885b47fbSopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject>& remote); 88885b47fbSopenharmony_ci 89885b47fbSopenharmony_ci int32_t accountId_ = -1; 90885b47fbSopenharmony_ci AppExecFwk::ElementName recipientElementName_; 91885b47fbSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 92885b47fbSopenharmony_ci }; 93885b47fbSopenharmony_ci 94885b47fbSopenharmony_ci bool IsWantedEvent(int32_t eventType); 95885b47fbSopenharmony_ci void InitAbilityClient(const sptr<IRemoteObject> &remoteObject); 96885b47fbSopenharmony_ci 97885b47fbSopenharmony_ci int32_t accountId_ = -1; 98885b47fbSopenharmony_ci int32_t connectionId_ = -1; 99885b47fbSopenharmony_ci sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 100885b47fbSopenharmony_ci sptr<IAccessibleAbilityClient> abilityClient_ = nullptr; 101885b47fbSopenharmony_ci sptr<AccessibleAbilityChannel> channel_ = nullptr; 102885b47fbSopenharmony_ci AccessibilityAbilityInfo abilityInfo_ {}; 103885b47fbSopenharmony_ci AppExecFwk::ElementName elementName_ {}; 104885b47fbSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; 105885b47fbSopenharmony_ci}; 106885b47fbSopenharmony_ci} // namespace Accessibility 107885b47fbSopenharmony_ci} // namespace OHOS 108885b47fbSopenharmony_ci#endif // ACCESSIBLE_ABILITY_CONNECTION_H