diff --git a/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h b/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h index f3b2e1342..a387c2976 100644 --- a/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h +++ b/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -26,7 +26,7 @@ public: /** * @brief Construct */ - AccessibilityUITestAbilityImpl() = default; + AccessibilityUITestAbilityImpl(); /** * @brief Destruct diff --git a/frameworks/aafwk/include/accessible_ability_client_impl.h b/frameworks/aafwk/include/accessible_ability_client_impl.h index 31c4626ff..2281e622a 100644 --- a/frameworks/aafwk/include/accessible_ability_client_impl.h +++ b/frameworks/aafwk/include/accessible_ability_client_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,11 +37,6 @@ public: */ ~AccessibleAbilityClientImpl(); - /** - * @brief Get the implement of accessibility ability client. - */ - static sptr GetAbilityClientImplement(); - /** * @brief Gets remote object. * @return Remote object. @@ -257,20 +252,6 @@ public: */ void NotifyServiceDied(const wptr &remote); - /** - * @brief Connect to AAMS. For UI test. - * @return Return RET_OK if the command of connection is sent successfully, - * otherwise refer to the RetError for the failure. - */ - RetError Connect(); - - /** - * @brief disconnect to AAMS. For UI test. - * @return Return RET_OK if the command of disconnect is sent successfully, - * otherwise refer to the RetError for the failure. - */ - RetError Disconnect(); - private: class AccessibleAbilityDeathRecipient final : public IRemoteObject::DeathRecipient { public: @@ -300,8 +281,6 @@ private: const std::vector &elementInfos); RetError SearchElementInfoFromAce(const int32_t windowId, const int32_t elementId, const uint32_t mode, AccessibilityElementInfo &info); - bool InitAccessibilityServiceProxy(); - static void OnParameterChanged(const char *key, const char *value, void *context); sptr deathRecipient_ = nullptr; sptr accessibilityServiceDeathRecipient_ = nullptr; diff --git a/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp b/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp index d8525706c..b0de427ea 100644 --- a/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp +++ b/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ #include "accessibility_ui_test_ability_impl.h" #include -#include "accessible_ability_client_impl.h" +#include "accessible_ability_client.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -36,6 +36,29 @@ std::shared_ptr AccessibilityUITestAbility::GetInsta return g_Instance; } +AccessibilityUITestAbilityImpl::AccessibilityUITestAbilityImpl() +{ + HILOG_DEBUG(); + + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + HILOG_ERROR("Failed to get ISystemAbilityManager"); + return; + } + + sptr object = samgr->GetSystemAbility(ACCESSIBILITY_MANAGER_SERVICE_ID); + if (!object) { + HILOG_ERROR("Get IAccessibleAbilityManagerService object from samgr failed"); + return; + } + + serviceProxy_ = iface_cast(object); + if (!serviceProxy_) { + HILOG_ERROR("Get aams proxy failed"); + return; + } +} + RetError AccessibilityUITestAbilityImpl::RegisterAbilityListener( const std::shared_ptr &listener) { @@ -56,23 +79,28 @@ RetError AccessibilityUITestAbilityImpl::RegisterAbilityListener( RetError AccessibilityUITestAbilityImpl::Connect() { HILOG_INFO(); - sptr aaClient = AccessibleAbilityClientImpl::GetAbilityClientImplement(); + if (!serviceProxy_) { + HILOG_ERROR("Failed to get aams service"); + return RET_ERR_SAMGR; + } + + sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); return RET_ERR_NULLPTR; } - return aaClient->Connect(); + + return serviceProxy_->EnableUITestAbility(aaClient->GetRemoteObject()); } RetError AccessibilityUITestAbilityImpl::Disconnect() { HILOG_INFO(); - sptr aaClient = AccessibleAbilityClientImpl::GetAbilityClientImplement(); - if (!aaClient) { - HILOG_ERROR("aaClient is nullptr"); - return RET_ERR_NULLPTR; + if (!serviceProxy_) { + HILOG_ERROR("Failed to get aams service"); + return RET_ERR_SAMGR; } - return aaClient->Disconnect(); + return serviceProxy_->DisableUITestAbility(); } RetError AccessibilityUITestAbilityImpl::GetFocus( diff --git a/frameworks/aafwk/src/accessible_ability_client_impl.cpp b/frameworks/aafwk/src/accessible_ability_client_impl.cpp index 67eb9232f..f4b4229c5 100644 --- a/frameworks/aafwk/src/accessible_ability_client_impl.cpp +++ b/frameworks/aafwk/src/accessible_ability_client_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,7 +23,6 @@ #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" -#include "parameter.h" #include "system_ability_definition.h" namespace OHOS { @@ -31,8 +30,6 @@ namespace Accessibility { // tmp: wait for window registing when client connect done constexpr int WAIT_WINDOW_REGIST = 500; namespace { - const std::string SYSTEM_PARAMETER_AAMS_NAME = "accessibility.config.ready"; - constexpr int32_t CONFIG_PARAMETER_VALUE_SIZE = 10; constexpr int32_t ROOT_NONE_ID = -1; std::mutex g_Mutex; sptr g_Instance = nullptr; @@ -48,71 +45,28 @@ sptr AccessibleAbilityClient::GetInstance() return g_Instance; } -sptr AccessibleAbilityClientImpl::GetAbilityClientImplement() -{ - HILOG_DEBUG(); - std::lock_guard lock(g_Mutex); - if (!g_Instance) { - g_Instance = new(std::nothrow) AccessibleAbilityClientImpl(); - } - return g_Instance; -} - AccessibleAbilityClientImpl::AccessibleAbilityClientImpl() { HILOG_DEBUG(); - char value[CONFIG_PARAMETER_VALUE_SIZE] = "default"; - int retSysParam = GetParameter(SYSTEM_PARAMETER_AAMS_NAME.c_str(), "false", value, CONFIG_PARAMETER_VALUE_SIZE); - if (retSysParam >= 0 && !std::strcmp(value, "true")) { - // Accessibility service is ready - if (!InitAccessibilityServiceProxy()) { - HILOG_ERROR("Init accessibility service proxy failed"); - } - } - - HILOG_DEBUG("Start watching accessibility service."); - retSysParam = WatchParameter(SYSTEM_PARAMETER_AAMS_NAME.c_str(), - &AccessibleAbilityClientImpl::OnParameterChanged, this); - if (retSysParam) { - HILOG_ERROR("Watch parameter failed, error = %{public}d", retSysParam); - } -} - -AccessibleAbilityClientImpl::~AccessibleAbilityClientImpl() -{ - HILOG_DEBUG(); - std::lock_guard lock(mutex_); - if (serviceProxy_ && serviceProxy_->AsObject()) { - HILOG_DEBUG("Remove service death recipient"); - serviceProxy_->AsObject()->RemoveDeathRecipient(accessibilityServiceDeathRecipient_); - } -} - -bool AccessibleAbilityClientImpl::InitAccessibilityServiceProxy() -{ - if (serviceProxy_) { - HILOG_DEBUG("Accessibility Service is connected"); - return true; - } sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { HILOG_ERROR("Failed to get ISystemAbilityManager"); - return false; + return; } HILOG_DEBUG("ISystemAbilityManager obtained"); sptr object = samgr->GetSystemAbility(ACCESSIBILITY_MANAGER_SERVICE_ID); if (!object) { HILOG_ERROR("Get IAccessibleAbilityManagerService object from samgr failed"); - return false; + return; } HILOG_DEBUG("Get remote object ok"); serviceProxy_ = iface_cast(object); if (!serviceProxy_) { HILOG_ERROR("Get aams proxy failed"); - return false; + return; } // Add death recipient @@ -120,7 +74,7 @@ bool AccessibleAbilityClientImpl::InitAccessibilityServiceProxy() accessibilityServiceDeathRecipient_ = new(std::nothrow) AccessibilityServiceDeathRecipient(*this); if (!accessibilityServiceDeathRecipient_) { HILOG_ERROR("Failed to create service deathRecipient."); - return false; + return; } } @@ -128,42 +82,25 @@ bool AccessibleAbilityClientImpl::InitAccessibilityServiceProxy() HILOG_DEBUG("Add death recipient"); serviceProxy_->AsObject()->AddDeathRecipient(accessibilityServiceDeathRecipient_); } - return true; } -void AccessibleAbilityClientImpl::OnParameterChanged(const char *key, const char *value, void *context) +AccessibleAbilityClientImpl::~AccessibleAbilityClientImpl() { - HILOG_DEBUG("Parameter key = [%{public}s] value = [%{public}s]", key, value); - - if (!key || std::strcmp(key, SYSTEM_PARAMETER_AAMS_NAME.c_str())) { - HILOG_WARN("not accessibility.config.ready callback"); - return; - } - - if (!value || std::strcmp(value, "true")) { - HILOG_WARN("accessibility.config.ready value not true"); - return; - } - - if (!context) { - HILOG_ERROR("accessibility.config.ready context NULL"); - return; - } - - AccessibleAbilityClientImpl* implPtr = static_cast(context); - { - HILOG_DEBUG("ConnectToService start."); - std::lock_guard lock(implPtr->mutex_); - if (implPtr->InitAccessibilityServiceProxy()) { - HILOG_DEBUG("ConnectToService Success"); - } + HILOG_DEBUG(); + if (serviceProxy_ && serviceProxy_->AsObject()) { + HILOG_DEBUG("Remove service death recipient"); + serviceProxy_->AsObject()->RemoveDeathRecipient(accessibilityServiceDeathRecipient_); } } sptr AccessibleAbilityClientImpl::GetRemoteObject() { HILOG_INFO(); - return this->AsObject(); + if (!g_Instance) { + HILOG_ERROR("instance is nullptr"); + return nullptr; + } + return g_Instance->AsObject(); } RetError AccessibleAbilityClientImpl::RegisterAbilityListener( @@ -617,7 +554,6 @@ void AccessibleAbilityClientImpl::NotifyServiceDied(const wptr &r listener_ = nullptr; object->RemoveDeathRecipient(accessibilityServiceDeathRecipient_); - serviceProxy_ = nullptr; channelClient_ = nullptr; HILOG_DEBUG("ResetAAClient OK"); } @@ -714,28 +650,5 @@ RetError AccessibleAbilityClientImpl::SearchElementInfoFromAce(const int32_t win info = elementInfos.front(); return RET_OK; } - -RetError AccessibleAbilityClientImpl::Connect() -{ - HILOG_DEBUG(); - std::lock_guard lock(mutex_); - if (!serviceProxy_) { - HILOG_ERROR("Failed to get aams service"); - return RET_ERR_SAMGR; - } - - return serviceProxy_->EnableUITestAbility(this->AsObject()); -} - -RetError AccessibleAbilityClientImpl::Disconnect() -{ - HILOG_DEBUG(); - std::lock_guard lock(mutex_); - if (!serviceProxy_) { - HILOG_ERROR("Failed to get aams service"); - return RET_ERR_SAMGR; - } - return serviceProxy_->DisableUITestAbility(); -} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/test/BUILD.gn b/frameworks/aafwk/test/BUILD.gn index 62aac516a..7ca21570d 100755 --- a/frameworks/aafwk/test/BUILD.gn +++ b/frameworks/aafwk/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2023 Huawei Device Co., Ltd. +# Copyright (C) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -77,7 +77,7 @@ ohos_unittest("accessibility_ui_test_ability_impl_test") { module_out_path = module_output_path sources = [ "../src/accessibility_ui_test_ability_impl.cpp", - "./mock/src/mock_accessible_ability_client_impl.cpp", + "//foundation/barrierfree/accessibility/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp", "//foundation/barrierfree/accessibility/frameworks/aafwk/test/mock/src/mock_accessible_ability_listener.cpp", "//foundation/barrierfree/accessibility/services/test/mock/mock_accessible_ability_manager_service_stub.cpp", "//foundation/barrierfree/accessibility/services/test/mock/mock_bundle_manager.cpp", @@ -104,8 +104,6 @@ ohos_unittest("accessibility_ui_test_ability_impl_test") { "c_utils:utils", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h b/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h new file mode 100644 index 000000000..c9972649d --- /dev/null +++ b/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCK_ACCESSIBLE_ABILITY_CLIENT_H +#define MOCK_ACCESSIBLE_ABILITY_CLIENT_H + +#include "accessible_ability_client.h" + +namespace OHOS { +namespace Accessibility { +class MockAccessibleAbilityClient : public AccessibleAbilityClient { +public: + MockAccessibleAbilityClient(); + ~MockAccessibleAbilityClient() = default; + sptr GetRemoteObject() override; + RetError RegisterAbilityListener(const std::shared_ptr &listener) override; + RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; + RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + AccessibilityElementInfo &elementInfo) override; + RetError InjectGesture(const std::shared_ptr &gesturePath) override; + RetError GetRoot(AccessibilityElementInfo &elementInfo) override; + RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + AccessibilityElementInfo &elementInfo) override; + RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; + RetError GetWindows(std::vector &windows) override; + RetError GetWindows(const uint64_t displayId, std::vector &windows) override; + RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + AccessibilityElementInfo &nextElementInfo) override; + RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + AccessibilityElementInfo &child) override; + RetError GetChildren(const AccessibilityElementInfo &parent, + std::vector &children) override; + RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + std::vector &elementInfos) override; + RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) override; + RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) override; + RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + const std::map &actionArguments) override; + RetError SetTargetBundleName(const std::vector &targetBundleNames) override; + RetError SetCacheMode(const int32_t cacheMode) override; +}; +} // namespace Accessibility +} // namespace OHOS +#endif // MOCK_ACCESSIBLE_ABILITY_CLIENT_H \ No newline at end of file diff --git a/frameworks/aafwk/test/mock/src/mock_accessible_ability_client_impl.cpp b/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp similarity index 59% rename from frameworks/aafwk/test/mock/src/mock_accessible_ability_client_impl.cpp rename to frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp index e567264d6..5c8585830 100644 --- a/frameworks/aafwk/test/mock/src/mock_accessible_ability_client_impl.cpp +++ b/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,240 +14,209 @@ */ #include "accessibility_ability_ut_helper.h" -#include "accessible_ability_client_impl.h" +#include "mock_accessible_ability_client.h" #include "hilog_wrapper.h" namespace OHOS { namespace Accessibility { namespace { - std::mutex g_Mutex; - sptr g_Instance = nullptr; + sptr g_Instance = nullptr; } // namespace sptr AccessibleAbilityClient::GetInstance() { HILOG_DEBUG(); - std::lock_guard lock(g_Mutex); + bool isNull = AccessibilityAbilityUtHelper::GetInstance().GetAbilityClientNullFlag(); if (isNull) { return nullptr; } - if (!g_Instance) { - g_Instance = new(std::nothrow) AccessibleAbilityClientImpl(); + g_Instance = new(std::nothrow) MockAccessibleAbilityClient(); } return g_Instance; } -sptr AccessibleAbilityClientImpl::GetAbilityClientImplement() +MockAccessibleAbilityClient::MockAccessibleAbilityClient() { HILOG_DEBUG(); - std::lock_guard lock(g_Mutex); - bool isNull = AccessibilityAbilityUtHelper::GetInstance().GetAbilityClientNullFlag(); - if (isNull) { - return nullptr; - } - - if (!g_Instance) { - g_Instance = new(std::nothrow) AccessibleAbilityClientImpl(); - } - return g_Instance; } -AccessibleAbilityClientImpl::AccessibleAbilityClientImpl() -{ -} - -AccessibleAbilityClientImpl::~AccessibleAbilityClientImpl() -{ -} - -sptr AccessibleAbilityClientImpl::GetRemoteObject() +sptr MockAccessibleAbilityClient::GetRemoteObject() { HILOG_DEBUG(); return nullptr; } -RetError AccessibleAbilityClientImpl::RegisterAbilityListener( +RetError MockAccessibleAbilityClient::RegisterAbilityListener( const std::shared_ptr &listener) { HILOG_DEBUG(); + (void)listener; return RET_OK; } -void AccessibleAbilityClientImpl::Init(const sptr &channel, const int32_t channelId) -{ -} - -void AccessibleAbilityClientImpl::Disconnect(const int32_t channelId) -{ -} - -void AccessibleAbilityClientImpl::OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) -{ -} - -void AccessibleAbilityClientImpl::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int32_t sequence) -{ -} - -RetError AccessibleAbilityClientImpl::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) +RetError MockAccessibleAbilityClient::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); + (void)focusType; (void)elementInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, +RetError MockAccessibleAbilityClient::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); + (void)sourceInfo; (void)focusType; (void)elementInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::InjectGesture(const std::shared_ptr &gesturePath) +RetError MockAccessibleAbilityClient::InjectGesture(const std::shared_ptr &gesturePath) { - HILOG_DEBUG(); + HILOG_INFO(); + (void)gesturePath; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetRoot(AccessibilityElementInfo &elementInfo) +RetError MockAccessibleAbilityClient::GetRoot(AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); + (void)elementInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, +RetError MockAccessibleAbilityClient::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); + (void)windowInfo; (void)elementInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError MockAccessibleAbilityClient::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_DEBUG(); + (void)windowId; (void)windowInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetWindows(std::vector &windows) +RetError MockAccessibleAbilityClient::GetWindows(std::vector &windows) { HILOG_DEBUG(); + (void)windows; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetWindows(const uint64_t displayId, +RetError MockAccessibleAbilityClient::GetWindows(const uint64_t displayId, std::vector &windows) { HILOG_DEBUG(); + (void)displayId; (void)windows; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetNext(const AccessibilityElementInfo &elementInfo, +RetError MockAccessibleAbilityClient::GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) { HILOG_DEBUG(); + (void)elementInfo; (void)direction; (void)nextElementInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, +RetError MockAccessibleAbilityClient::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) { HILOG_DEBUG(); + (void)index; (void)parent; (void)child; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &parent, +RetError MockAccessibleAbilityClient::GetChildren(const AccessibilityElementInfo &parent, std::vector &children) { HILOG_DEBUG(); + (void)parent; (void)children; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetByContent(const AccessibilityElementInfo &elementInfo, +RetError MockAccessibleAbilityClient::GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos) { HILOG_DEBUG(); + (void)elementInfo; (void)text; (void)elementInfos; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetSource(const AccessibilityEventInfo &eventInfo, +RetError MockAccessibleAbilityClient::GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); + (void)eventInfo; (void)elementInfo; return RET_OK; } -RetError AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityElementInfo &child, +RetError MockAccessibleAbilityClient::GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) { HILOG_DEBUG(); + (void)child; (void)parent; return RET_OK; } -RetError AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo, +RetError MockAccessibleAbilityClient::ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) { HILOG_DEBUG(); + (void)elementInfo; (void)action; (void)actionArguments; return RET_OK; } -RetError AccessibleAbilityClientImpl::SetTargetBundleName(const std::vector &targetBundleNames) +RetError MockAccessibleAbilityClient::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_DEBUG(); + (void)targetBundleNames; return RET_OK; } -RetError AccessibleAbilityClientImpl::SetCacheMode(const int32_t cacheMode) +RetError MockAccessibleAbilityClient::SetCacheMode(const int32_t cacheMode) { HILOG_DEBUG(); AccessibilityAbilityUtHelper::GetInstance().SetCacheMode(cacheMode); return RET_OK; } - -RetError AccessibleAbilityClientImpl::Connect() -{ - HILOG_DEBUG(); - return RET_OK; -} - -RetError AccessibleAbilityClientImpl::Disconnect() -{ - HILOG_DEBUG(); - return RET_OK; -} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp b/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp index e8395f4ca..934173247 100644 --- a/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp +++ b/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -143,7 +143,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, Connect_001, TestSize.Level1) GTEST_LOG_(INFO) << "Cann't get AccessibilityUITestAbilityImpl instance_"; return; } - EXPECT_EQ(RET_OK, instance_->Connect()); + EXPECT_EQ(RET_ERR_SAMGR, instance_->Connect()); GTEST_LOG_(INFO) << "Connect_001 end"; } @@ -161,7 +161,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, Disconnect_001, TestSize.Level1) GTEST_LOG_(INFO) << "Cann't get AccessibilityUITestAbilityImpl instance_"; return; } - EXPECT_EQ(instance_->Disconnect(), RET_OK); + EXPECT_EQ(instance_->Disconnect(), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "Disconnect_001 end"; } diff --git a/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h b/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h index 267c74809..209ae10b7 100644 --- a/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h +++ b/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -229,8 +229,6 @@ private: * @return True: The data of event type is valid; otherwise is not. */ bool CheckEventType(EventType eventType); - static void OnParameterChanged(const char *key, const char *value, void *context); - void ReregisterElementOperator(); std::mutex mutex_; StateArray stateArray_; diff --git a/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp b/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp index 8f06f4d75..e4d6d03e4 100644 --- a/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp +++ b/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,15 +17,12 @@ #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" -#include "parameter.h" #include "system_ability_definition.h" namespace OHOS { namespace Accessibility { namespace { constexpr int32_t REQUEST_WINDOW_ID_MASK_BIT = 16; - constexpr int32_t CONFIG_PARAMETER_VALUE_SIZE = 10; - const std::string SYSTEM_PARAMETER_AAMS_NAME = "accessibility.config.ready"; } // namespaces static std::mutex g_Mutex; @@ -46,19 +43,7 @@ std::shared_ptr AccessibilitySystemAbilityClie AccessibilitySystemAbilityClientImpl::AccessibilitySystemAbilityClientImpl() { HILOG_DEBUG(); - stateArray_.fill(false); - int retSysParam = WatchParameter(SYSTEM_PARAMETER_AAMS_NAME.c_str(), &OnParameterChanged, this); - if (retSysParam) { - HILOG_ERROR("Watch parameter failed, error = %{public}d", retSysParam); - } - - char value[CONFIG_PARAMETER_VALUE_SIZE] = "default"; - retSysParam = GetParameter(SYSTEM_PARAMETER_AAMS_NAME.c_str(), "false", value, CONFIG_PARAMETER_VALUE_SIZE); - if (retSysParam < 0 || std::strcmp(value, "true")) { - HILOG_ERROR("accessibility service is not ready."); - return; - } if (!ConnectToService()) { HILOG_ERROR("Failed to connect to aams service"); return; @@ -74,7 +59,6 @@ AccessibilitySystemAbilityClientImpl::~AccessibilitySystemAbilityClientImpl() bool AccessibilitySystemAbilityClientImpl::ConnectToService() { HILOG_DEBUG(); - if (serviceProxy_) { HILOG_DEBUG("AAMS Service is connected"); return true; @@ -92,12 +76,10 @@ bool AccessibilitySystemAbilityClientImpl::ConnectToService() return false; } + deathRecipient_ = new(std::nothrow) DeathRecipient(*this); if (!deathRecipient_) { - deathRecipient_ = new(std::nothrow) DeathRecipient(*this); - if (!deathRecipient_) { - HILOG_ERROR("Failed to create deathRecipient."); - return false; - } + HILOG_ERROR("Failed to create deathRecipient."); + return false; } if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) { @@ -110,55 +92,18 @@ bool AccessibilitySystemAbilityClientImpl::ConnectToService() HILOG_ERROR("IAccessibleAbilityManagerService iface_cast failed"); return false; } + return true; } -void AccessibilitySystemAbilityClientImpl::OnParameterChanged(const char *key, const char *value, void *context) -{ - HILOG_DEBUG("Parameter key = [%{public}s] value = [%{public}s]", key, value); - - if (!key || std::strcmp(key, SYSTEM_PARAMETER_AAMS_NAME.c_str())) { - HILOG_WARN("not accessibility.config.ready callback"); - return; - } - - if (!value || std::strcmp(value, "true")) { - HILOG_WARN("accessibility.config.ready value not true"); - return; - } - - if (!context) { - HILOG_ERROR("accessibility.config.ready context NULL"); - return; - } - - AccessibilitySystemAbilityClientImpl* implPtr = static_cast(context); - { - HILOG_DEBUG("ConnectToService start."); - std::lock_guard lock(implPtr->mutex_); - if (implPtr->serviceProxy_) { - HILOG_DEBUG("service is already started."); - return; - } - if (!implPtr->ConnectToService()) { - HILOG_ERROR("Failed to connect to aams service"); - return; - } - implPtr->Init(); - implPtr->ReregisterElementOperator(); - } -} - void AccessibilitySystemAbilityClientImpl::Init() { HILOG_DEBUG(); stateArray_.fill(false); + stateObserver_ = new(std::nothrow) AccessibleAbilityManagerStateObserverImpl(*this); if (!stateObserver_) { - stateObserver_ = new(std::nothrow) AccessibleAbilityManagerStateObserverImpl(*this); - if (!stateObserver_) { - HILOG_ERROR("Failed to create stateObserver."); - return; - } + HILOG_ERROR("Failed to create stateObserver."); + return; } uint32_t stateType = serviceProxy_->RegisterStateObserver(stateObserver_); if (stateType & STATE_ACCESSIBILITY_ENABLED) { @@ -219,19 +164,6 @@ RetError AccessibilitySystemAbilityClientImpl::RegisterElementOperator( return serviceProxy_->RegisterElementOperator(windowId, aamsInteractionOperator); } -void AccessibilitySystemAbilityClientImpl::ReregisterElementOperator() -{ - HILOG_DEBUG(); - - if (!serviceProxy_) { - HILOG_ERROR("serviceProxy_ is null."); - return; - } - for (auto iter = elementOperators_.begin(); iter != elementOperators_.end(); iter++) { - serviceProxy_->RegisterElementOperator(iter->first, iter->second); - } -} - RetError AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const int32_t windowId) { HILOG_INFO("Deregister windowId[%{public}d] start", windowId); diff --git a/frameworks/asacfwk/test/BUILD.gn b/frameworks/asacfwk/test/BUILD.gn index b709f57f0..d7f175737 100644 --- a/frameworks/asacfwk/test/BUILD.gn +++ b/frameworks/asacfwk/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2023 Huawei Device Co., Ltd. +# Copyright (C) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -42,7 +42,6 @@ config("module_private_config") { ohos_unittest("asac_unit_test") { module_out_path = module_output_path sources = [ - "../../../services/test/mock/mock_parameter.c", "../src/accessibility_element_operator_impl.cpp", "../src/accessibility_system_ability_client_impl.cpp", "//foundation/barrierfree/accessibility/frameworks/aafwk/src/accessibility_element_operator_callback_impl.cpp", diff --git a/interfaces/innerkits/aafwk/BUILD.gn b/interfaces/innerkits/aafwk/BUILD.gn index bd0f7e0a0..8124e5fb8 100644 --- a/interfaces/innerkits/aafwk/BUILD.gn +++ b/interfaces/innerkits/aafwk/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2023 Huawei Device Co., Ltd. +# Copyright (C) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -60,8 +60,6 @@ ohos_shared_library("accessibleability") { "c_utils:utils", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", "input:libmmi-client", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/interfaces/innerkits/asacfwk/BUILD.gn b/interfaces/innerkits/asacfwk/BUILD.gn index 595dedf37..43ecbc0ec 100644 --- a/interfaces/innerkits/asacfwk/BUILD.gn +++ b/interfaces/innerkits/asacfwk/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2023 Huawei Device Co., Ltd. +# Copyright (C) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -55,8 +55,6 @@ ohos_shared_library("accessibilityclient") { external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/services/aams/test/unittest/accessible_ability_manager_service_test.cpp b/services/aams/test/unittest/accessible_ability_manager_service_test.cpp index 1f66642be..1b21b9fcf 100644 --- a/services/aams/test/unittest/accessible_ability_manager_service_test.cpp +++ b/services/aams/test/unittest/accessible_ability_manager_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -147,8 +147,7 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, GetAbilityList_001, TestSize.L { GTEST_LOG_(INFO) << "AccessibleAbilityManagerServiceUnitTest_GetAbilityList_001 start"; std::vector infos; - Singleton::GetInstance().GetAbilityList( - ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_ENABLE, infos); + Singleton::GetInstance().GetAbilityList(0xFFFFFFFF, 3, infos); EXPECT_EQ(infos.size(), 0); GTEST_LOG_(INFO) << "AccessibleAbilityManagerServiceUnitTest_Unittest_GetAbilityList_001 end";