diff --git a/common/interface/include/accessibility_enable_ability_lists_observer_proxy.h b/common/interface/include/accessibility_enable_ability_lists_observer_proxy.h index 6e660a27..e48aa1c1 100644 --- a/common/interface/include/accessibility_enable_ability_lists_observer_proxy.h +++ b/common/interface/include/accessibility_enable_ability_lists_observer_proxy.h @@ -38,6 +38,11 @@ public: * @brief Receive the state notify from AAMS and send it to the observer registered. */ virtual void OnAccessibilityEnableAbilityListsChanged() override; + + /** + * @brief Receive the install state notify from AAMS and send it to the observer registered. + */ + virtual void OnAccessibilityInstallAbilityListsChanged() override; private: /** * @brief Write the descriptor of IPC. diff --git a/common/interface/include/accessibility_enable_ability_lists_observer_stub.h b/common/interface/include/accessibility_enable_ability_lists_observer_stub.h index b3deecee..39ade707 100644 --- a/common/interface/include/accessibility_enable_ability_lists_observer_stub.h +++ b/common/interface/include/accessibility_enable_ability_lists_observer_stub.h @@ -52,6 +52,14 @@ private: * @return NO_ERROR: successful; otherwise is failed. */ ErrCode HandleOnAccessibilityEnableAbilityListsChanged(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleOnInstallStateChanged. + * @param data The data of process communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleOnAccessibilityInstallAbilityListsChanged(MessageParcel &data, MessageParcel &reply); }; } // namespace Accessibility } // namespace OHOS diff --git a/common/interface/include/accessibility_ipc_interface_code.h b/common/interface/include/accessibility_ipc_interface_code.h index b4eae760..41578b16 100644 --- a/common/interface/include/accessibility_ipc_interface_code.h +++ b/common/interface/include/accessibility_ipc_interface_code.h @@ -34,6 +34,7 @@ namespace Accessibility { OUTSIDE_TOUCH, ON_ACCESSIBILITY_ENABLE_ABILITY_LISTS_CHANGED = 300, + ON_ACCESSIBILITY_INSTALL_ABILITY_LISTS_CHANGED, SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID = 400, SEARCH_ELEMENTINFOS_BY_TEXT, diff --git a/common/interface/include/i_accessibility_enable_ability_lists_observer.h b/common/interface/include/i_accessibility_enable_ability_lists_observer.h index 5c11519d..b6b65f7b 100644 --- a/common/interface/include/i_accessibility_enable_ability_lists_observer.h +++ b/common/interface/include/i_accessibility_enable_ability_lists_observer.h @@ -28,6 +28,11 @@ public: * @brief Receive the state notify from AAMS and send it to the observer registered. */ virtual void OnAccessibilityEnableAbilityListsChanged() = 0; + + /** + * @brief Receive the isntall state notify from AAMS and send it to the observer registered. + */ + virtual void OnAccessibilityInstallAbilityListsChanged() = 0; }; } // namespace Accessibility } // namespace OHOS diff --git a/common/interface/src/accessibility_enable_ability_lists_observer_proxy.cpp b/common/interface/src/accessibility_enable_ability_lists_observer_proxy.cpp index 04a51d94..563f3ebd 100644 --- a/common/interface/src/accessibility_enable_ability_lists_observer_proxy.cpp +++ b/common/interface/src/accessibility_enable_ability_lists_observer_proxy.cpp @@ -62,5 +62,32 @@ void AccessibilityEnableAbilityListsObserverProxy::OnAccessibilityEnableAbilityL HILOG_ERROR("OnAccessibilityEnableAbilityListsChanged fail, error: %{public}d", result); } } + +void AccessibilityEnableAbilityListsObserverProxy::OnAccessibilityInstallAbilityListsChanged() +{ + HILOG_DEBUG(); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("write interface token failed"); + return; + } + + sptr remote = Remote(); + if (!remote) { + HILOG_ERROR("fail to send transact cmd due to remote object"); + return; + } + + int32_t result = remote->SendRequest(static_cast( + AccessibilityInterfaceCode::ON_ACCESSIBILITY_INSTALL_ABILITY_LISTS_CHANGED), + data, reply, option); + if (result != NO_ERROR) { + HILOG_ERROR("OnAccessibilityInstallAbilityListsChanged fail, error: %{public}d", result); + } +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/common/interface/src/accessibility_enable_ability_lists_observer_stub.cpp b/common/interface/src/accessibility_enable_ability_lists_observer_stub.cpp index 809af940..35595f8b 100644 --- a/common/interface/src/accessibility_enable_ability_lists_observer_stub.cpp +++ b/common/interface/src/accessibility_enable_ability_lists_observer_stub.cpp @@ -49,5 +49,13 @@ ErrCode AccessibilityEnableAbilityListsObserverStub::HandleOnAccessibilityEnable OnAccessibilityEnableAbilityListsChanged(); return NO_ERROR; } + +ErrCode AccessibilityEnableAbilityListsObserverStub::HandleOnAccessibilityInstallAbilityListsChanged( + MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG(); + OnAccessibilityInstallAbilityListsChanged(); + return NO_ERROR; +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/common/interface/test/fuzztest/accessibilityenableabilitylistsobserverstub_fuzzer/accessibilityenableabilitylistsobserverstub_fuzzer.cpp b/common/interface/test/fuzztest/accessibilityenableabilitylistsobserverstub_fuzzer/accessibilityenableabilitylistsobserverstub_fuzzer.cpp index 83425dd8..a463d7c2 100644 --- a/common/interface/test/fuzztest/accessibilityenableabilitylistsobserverstub_fuzzer/accessibilityenableabilitylistsobserverstub_fuzzer.cpp +++ b/common/interface/test/fuzztest/accessibilityenableabilitylistsobserverstub_fuzzer/accessibilityenableabilitylistsobserverstub_fuzzer.cpp @@ -31,6 +31,7 @@ public: ~EnableAbilityListsObserverTmplFuzzTest() = default; void OnAccessibilityEnableAbilityListsChanged() override {}; + void OnAccessibilityInstallAbilityListsChanged() override {}; }; template diff --git a/frameworks/acfwk/include/accessibility_config_impl.h b/frameworks/acfwk/include/accessibility_config_impl.h index 0ba6587a..fbaeef52 100644 --- a/frameworks/acfwk/include/accessibility_config_impl.h +++ b/frameworks/acfwk/include/accessibility_config_impl.h @@ -101,6 +101,7 @@ public: void OnAccessibleAbilityManagerClickResponseTimeChanged(const uint32_t clickResponseTime); void OnAccessibleAbilityManagerIgnoreRepeatClickTimeChanged(const uint32_t ignoreRepeatClickTime); void OnAccessibilityEnableAbilityListsChanged(); + void OnAccessibilityInstallAbilityListsChanged(); private: class AccessibilityEnableAbilityListsObserverImpl : @@ -114,6 +115,11 @@ private: { client_.OnAccessibilityEnableAbilityListsChanged(); } + + virtual void OnAccessibilityInstallAbilityListsChanged() override + { + client_.OnAccessibilityInstallAbilityListsChanged(); + } private: Impl &client_; }; diff --git a/frameworks/acfwk/src/accessibility_config_impl.cpp b/frameworks/acfwk/src/accessibility_config_impl.cpp index dc793119..94f7b49b 100644 --- a/frameworks/acfwk/src/accessibility_config_impl.cpp +++ b/frameworks/acfwk/src/accessibility_config_impl.cpp @@ -1346,6 +1346,23 @@ void AccessibilityConfig::Impl::OnAccessibilityEnableAbilityListsChanged() } } +void AccessibilityConfig::Impl::OnAccessibilityInstallAbilityListsChanged() +{ + HILOG_DEBUG("observer's size is %{public}zu", enableAbilityListsObservers_.size()); + std::vector> observers; + { + std::lock_guard lock(mutex_); + observers = enableAbilityListsObservers_; + } + for (auto &enableAbilityListsObserver : observers) { + if (enableAbilityListsObserver != nullptr) { + enableAbilityListsObserver->OnInstallAbilityListsStateChanged(); + } else { + HILOG_ERROR("enableAbilityListsObserver is null"); + } + } +} + void AccessibilityConfig::Impl::OnIgnoreRepeatClickStateChanged(const uint32_t stateType) { if (stateType & Accessibility::STATE_IGNORE_REPEAT_CLICK_ENABLED) { diff --git a/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp b/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp index a2c84aae..dbb8ed7a 100644 --- a/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp +++ b/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp @@ -67,6 +67,8 @@ public: MockAccessibilityEnableAbilityListsObserverImpl() = default; void OnEnableAbilityListsStateChanged() override {} + void OnInstallAbilityListsStateChanged() override + {} }; /** diff --git a/interfaces/innerkits/acfwk/include/accessibility_config.h b/interfaces/innerkits/acfwk/include/accessibility_config.h index 738b209c..07644d60 100644 --- a/interfaces/innerkits/acfwk/include/accessibility_config.h +++ b/interfaces/innerkits/acfwk/include/accessibility_config.h @@ -96,6 +96,11 @@ public: * @brief Called when the enable ability lists changed. */ virtual void OnEnableAbilityListsStateChanged() = 0; + + /** + * @brief Called when the enable ability lists changed. + */ + virtual void OnInstallAbilityListsStateChanged() = 0; }; class AccessibilityConfig { diff --git a/interfaces/innerkits/test/fuzztest/accessibilityconfig_fuzzer/accessibilityconfig_fuzzer.cpp b/interfaces/innerkits/test/fuzztest/accessibilityconfig_fuzzer/accessibilityconfig_fuzzer.cpp index bd693d31..f4a6414d 100644 --- a/interfaces/innerkits/test/fuzztest/accessibilityconfig_fuzzer/accessibilityconfig_fuzzer.cpp +++ b/interfaces/innerkits/test/fuzztest/accessibilityconfig_fuzzer/accessibilityconfig_fuzzer.cpp @@ -42,6 +42,9 @@ public: void OnEnableAbilityListsStateChanged() override { } + void OnInstallAbilityListsStateChanged() override + { + } }; template diff --git a/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h b/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h index a459b99c..8f871021 100644 --- a/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h +++ b/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h @@ -37,14 +37,19 @@ class EnableAbilityListsObserverImpl : public OHOS::AccessibilityConfig::Accessi public: EnableAbilityListsObserverImpl() = default; void OnEnableAbilityListsStateChanged() override; + void OnInstallAbilityListsStateChanged() override; void SubscribeToFramework(); void SubscribeObserver(napi_env env, napi_value observer); + void SubscribeInstallObserver(napi_env env, napi_value observer); void UnsubscribeObserver(napi_env env, napi_value observer); void UnsubscribeObservers(); + void UnsubscribeInstallObserver(napi_env env, napi_value observer); + void UnsubscribeInstallObservers(); private: std::mutex mutex_; std::vector> enableAbilityListsObservers_ = {}; + std::vector> installAbilityListsObservers_ = {}; }; struct NAccessibilityConfigData { diff --git a/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp b/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp index d356dcce..a9bba0e0 100644 --- a/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp +++ b/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp @@ -240,13 +240,14 @@ napi_value NAccessibilityConfig::SubscribeState(napi_env env, napi_callback_info errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } + std::string observerType = ""; if (errCode == OHOS::Accessibility::RET_OK) { - std::string observerType = ""; if (!ParseString(env, observerType, args[PARAM0])) { HILOG_ERROR("observer type parse failed"); errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } else { - if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") != 0) { + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") != 0 || + std::strcmp(observerType.c_str(), "installedAccessibilityListChange") != 0) { HILOG_ERROR("args[PARAM0] is wrong[%{public}s", observerType.c_str()); errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } @@ -268,8 +269,16 @@ napi_value NAccessibilityConfig::SubscribeState(napi_env env, napi_callback_info napi_throw(env, err); return nullptr; } - - enableAbilityListsObservers_->SubscribeObserver(env, args[PARAM1]); + if (enableAbilityListsObservers_ == nullptr) { + HILOG_ERROR("enableAbilityListsObservers_ is null"); + return nullptr; + } + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") == 0) { + enableAbilityListsObservers_->SubscribeObserver(env, args[PARAM1]); + } + if (std::strcmp(observerType.c_str(), "installedAccessibilityListChange") == 0) { + enableAbilityListsObservers_->SubscribeInstallObserver(env, args[PARAM1]); + } return nullptr; } @@ -288,14 +297,14 @@ napi_value NAccessibilityConfig::UnsubscribeState(napi_env env, napi_callback_in HILOG_ERROR("argc is invalid: %{public}zu", argc); errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } - + std::string observerType = ""; if (errCode == OHOS::Accessibility::RET_OK) { - std::string observerType = ""; if (!ParseString(env, observerType, args[PARAM0])) { HILOG_ERROR("observer type parse failed"); errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } else { - if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") != 0) { + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") != 0 || + std::strcmp(observerType.c_str(), "installedAccessibilityListChange") != 0) { HILOG_ERROR("args[PARAM0] is wrong[%{public}s", observerType.c_str()); errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } @@ -308,11 +317,22 @@ napi_value NAccessibilityConfig::UnsubscribeState(napi_env env, napi_callback_in napi_throw(env, err); return nullptr; } - + if (enableAbilityListsObservers_ == nullptr) { + HILOG_ERROR("enableAbilityListsObservers_ is null"); + return nullptr; + } if (argc > ARGS_SIZE_TWO - 1 && CheckJsFunction(env, args[PARAM1])) { - enableAbilityListsObservers_->UnsubscribeObserver(env, args[PARAM1]); + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") == 0) { + enableAbilityListsObservers_->UnsubscribeObserver(env, args[PARAM1]); + } else { + enableAbilityListsObservers_->UnsubscribeInstallObserver(env, args[PARAM1]); + } } else { - enableAbilityListsObservers_->UnsubscribeObservers(); + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") == 0) { + enableAbilityListsObservers_->UnsubscribeObservers(); + } else { + enableAbilityListsObservers_->UnsubscribeInstallObservers(); + } } return nullptr; } @@ -933,6 +953,19 @@ void EnableAbilityListsObserverImpl::OnEnableAbilityListsStateChanged() } } +void EnableAbilityListsObserverImpl::OnInstallAbilityListsStateChanged() +{ + HILOG_DEBUG(); + std::lock_guard lock(mutex_); + for (auto &observer : installAbilityListsObservers_) { + if (observer) { + observer->OnEnableAbilityListsStateChanged(); + } else { + HILOG_ERROR("observer is null"); + } + } +} + void EnableAbilityListsObserverImpl::SubscribeObserver(napi_env env, napi_value observer) { HILOG_DEBUG(); @@ -955,6 +988,28 @@ void EnableAbilityListsObserverImpl::SubscribeObserver(napi_env env, napi_value HILOG_DEBUG("observer size%{public}zu", enableAbilityListsObservers_.size()); } +void EnableAbilityListsObserverImpl::SubscribeInstallObserver(napi_env env, napi_value observer) +{ + HILOG_DEBUG(); + std::lock_guard lock(mutex_); + for (auto iter = installAbilityListsObservers_.begin(); iter != installAbilityListsObservers_.end();) { + if (CheckObserverEqual(env, observer, (*iter)->env_, (*iter)->callback_)) { + HILOG_DEBUG("Observer exist"); + return; + } else { + iter++; + } + } + + napi_ref callback = nullptr; + napi_create_reference(env, observer, 1, &callback); + std::shared_ptr observerPtr = + std::make_shared(env, callback); + + installAbilityListsObservers_.emplace_back(observerPtr); + HILOG_DEBUG("observer size%{public}zu", installAbilityListsObservers_.size()); +} + void EnableAbilityListsObserverImpl::UnsubscribeObserver(napi_env env, napi_value observer) { HILOG_DEBUG(); @@ -974,4 +1029,25 @@ void EnableAbilityListsObserverImpl::UnsubscribeObservers() HILOG_DEBUG(); std::lock_guard lock(mutex_); enableAbilityListsObservers_.clear(); -} \ No newline at end of file +} + +void EnableAbilityListsObserverImpl::UnsubscribeInstallObserver(napi_env env, napi_value observer) +{ + HILOG_DEBUG(); + std::lock_guard lock(mutex_); + for (auto iter = installAbilityListsObservers_.begin(); iter != installAbilityListsObservers_.end();) { + if (CheckObserverEqual(env, observer, (*iter)->env_, (*iter)->callback_)) { + installAbilityListsObservers_.erase(iter); + return; + } else { + iter++; + } + } +} + +void EnableAbilityListsObserverImpl::UnsubscribeInstallObservers() +{ + HILOG_DEBUG(); + std::lock_guard lock(mutex_); + installAbilityListsObservers_.clear(); +} diff --git a/services/aams/include/accessibility_account_data.h b/services/aams/include/accessibility_account_data.h index ef1ee50c..2a2d4a6f 100644 --- a/services/aams/include/accessibility_account_data.h +++ b/services/aams/include/accessibility_account_data.h @@ -249,6 +249,7 @@ public: void Init(); void UpdateEnableAbilityListsState(); + void UpdateInstallAbilityListsState(); void AddConfigCallback(const sptr& callback); void RemoveConfigCallback(const wptr& callback); diff --git a/services/aams/src/accessibility_account_data.cpp b/services/aams/src/accessibility_account_data.cpp index d1685ba7..8c756c79 100644 --- a/services/aams/src/accessibility_account_data.cpp +++ b/services/aams/src/accessibility_account_data.cpp @@ -185,6 +185,16 @@ void AccessibilityAccountData::UpdateEnableAbilityListsState() } } +void AccessibilityAccountData::UpdateInstallAbilityListsState() +{ + HILOG_DEBUG("observer's size is %{public}zu", enableAbilityListsObservers_.size()); + for (auto &observer : enableAbilityListsObservers_) { + if (observer) { + observer->OnAccessibilityInstallAbilityListsChanged(); + } + } +} + void AccessibilityAccountData::AddAccessibilityWindowConnection( const int32_t windowId, const sptr& interactionConnection) { @@ -253,6 +263,7 @@ void AccessibilityAccountData::AddInstalledAbility(AccessibilityAbilityInfo& abi } } installedAbilities_.push_back(abilityInfo); + UpdateInstallAbilityListsState(); HILOG_DEBUG("push back installed ability successfully and installedAbilities_'s size is %{public}zu", installedAbilities_.size()); } @@ -265,9 +276,11 @@ void AccessibilityAccountData::RemoveInstalledAbility(const std::string &bundleN HILOG_DEBUG("Removed %{public}s from InstalledAbility: ", bundleName.c_str()); if (!config_) { it = installedAbilities_.erase(it); + UpdateInstallAbilityListsState(); continue; } it = installedAbilities_.erase(it); + UpdateInstallAbilityListsState(); } else { ++it; } diff --git a/services/aams/test/mock/include/mock_accessible_ability_manager_service_config_observer_stub.h b/services/aams/test/mock/include/mock_accessible_ability_manager_service_config_observer_stub.h index 5d6fd8cb..deec490b 100644 --- a/services/aams/test/mock/include/mock_accessible_ability_manager_service_config_observer_stub.h +++ b/services/aams/test/mock/include/mock_accessible_ability_manager_service_config_observer_stub.h @@ -57,6 +57,7 @@ public: MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD0(OnAccessibilityEnableAbilityListsChanged, void()); + MOCK_METHOD0(OnAccessibilityInstallAbilityListsChanged, void()); };