mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 01:10:52 +00:00
!11637 autofill对接ffrt简单实现
Merge pull request !11637 from hanchenZz/autofill_ffrt_simplify
This commit is contained in:
commit
e5c96b1e73
@ -40,6 +40,7 @@ ohos_shared_library("autofillmanager_napi") {
|
||||
"ability_base:want",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"json:nlohmann_json_static",
|
||||
|
@ -31,7 +31,6 @@ ohos_shared_library("auto_fill_manager") {
|
||||
public_configs = [ ":auto_fill_manager_public_config" ]
|
||||
|
||||
sources = [
|
||||
"src/auto_fill_event_handler.cpp",
|
||||
"src/auto_fill_extension_callback.cpp",
|
||||
"src/auto_fill_manager.cpp",
|
||||
"src/auto_fill_manager_util.cpp",
|
||||
@ -49,6 +48,7 @@ ohos_shared_library("auto_fill_manager") {
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "auto_fill_custom_config.h"
|
||||
#include "auto_fill_event_handler.h"
|
||||
#include "auto_fill_extension_callback.h"
|
||||
#include "fill_request_callback_interface.h"
|
||||
#include "nocopyable.h"
|
||||
@ -29,6 +28,10 @@
|
||||
#include "ui_content.h"
|
||||
#endif // SUPPORT_GRAPHICS
|
||||
|
||||
namespace ffrt {
|
||||
class task_handle;
|
||||
};
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
@ -47,8 +50,7 @@ public:
|
||||
void UpdateCustomPopupUIExtension(uint32_t autoFillSessionId, const AbilityBase::ViewData &viewData);
|
||||
|
||||
void CloseUIExtension(uint32_t autoFillSessionId);
|
||||
|
||||
void HandleTimeOut(uint32_t eventId);
|
||||
void RemoveTask(uint32_t eventId);
|
||||
void SetTimeOutEvent(uint32_t eventId);
|
||||
void RemoveEvent(uint32_t eventId);
|
||||
|
||||
@ -56,7 +58,7 @@ public:
|
||||
Ace::ModalUIExtensionCallbacks &callback);
|
||||
void RemoveAutoFillExtensionCallback(uint32_t callbackId);
|
||||
private:
|
||||
AutoFillManager();
|
||||
AutoFillManager() = default;
|
||||
~AutoFillManager();
|
||||
DISALLOW_COPY_AND_MOVE(AutoFillManager);
|
||||
|
||||
@ -79,7 +81,8 @@ private:
|
||||
std::mutex extensionCallbacksMutex_;
|
||||
std::map<uint32_t, std::shared_ptr<AutoFillExtensionCallback>> extensionCallbacks_;
|
||||
|
||||
std::shared_ptr<AutoFillEventHandler> eventHandler_;
|
||||
std::mutex taskHandlesMutex_;
|
||||
std::map<uint32_t, std::shared_ptr<ffrt::task_handle>> taskHandles_;
|
||||
};
|
||||
#endif // SUPPORT_GRAPHICS
|
||||
} // AbilityRuntime
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "auto_fill_error.h"
|
||||
#include "auto_fill_manager_util.h"
|
||||
#include "extension_ability_info.h"
|
||||
#include "ffrt_inner.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "parameters.h"
|
||||
|
||||
@ -36,6 +37,7 @@ constexpr static char WANT_PARAMS_AUTO_FILL_TYPE_KEY[] = "ability.want.params.Au
|
||||
constexpr static char AUTO_FILL_MANAGER_THREAD[] = "AutoFillManager";
|
||||
constexpr static uint32_t AUTO_FILL_REQUEST_TIME_OUT_VALUE = 1000;
|
||||
constexpr static uint32_t AUTO_FILL_UI_EXTENSION_SESSION_ID_INVALID = 0;
|
||||
constexpr static uint32_t MILL_TO_MICRO = 1000;
|
||||
#endif //SUPPORT_GRAPHICS
|
||||
} // namespace
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
@ -45,12 +47,6 @@ AutoFillManager &AutoFillManager::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
AutoFillManager::AutoFillManager()
|
||||
{
|
||||
auto runner = AppExecFwk::EventRunner::Create(AUTO_FILL_MANAGER_THREAD);
|
||||
eventHandler_ = std::make_shared<AutoFillEventHandler>(runner);
|
||||
}
|
||||
|
||||
AutoFillManager::~AutoFillManager()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
|
||||
@ -269,35 +265,60 @@ bool AutoFillManager::ConvertAutoFillWindowType(const AutoFill::AutoFillRequest
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AutoFillManager::RemoveTask(uint32_t eventId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(taskHandlesMutex_);
|
||||
taskHandles_.erase(eventId);
|
||||
}
|
||||
|
||||
void AutoFillManager::SetTimeOutEvent(uint32_t eventId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
|
||||
if (eventHandler_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "null eventHandler");
|
||||
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "%{public}s called", __func__);
|
||||
auto taskWrap = [ eventId ]() {
|
||||
TAG_LOGI(AAFwkTag::AUTOFILLMGR, "execute HandleTimeout, eventId: %{public}d", eventId);
|
||||
auto extensionCallback = GetInstance().GetAutoFillExtensionCallback(eventId);
|
||||
if (extensionCallback == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "null extensionCallback");
|
||||
return;
|
||||
}
|
||||
extensionCallback->HandleTimeOut();
|
||||
TAG_LOGI(AAFwkTag::AUTOFILLMGR, "execute HandleTimeout done, eventId: %{public}d", eventId);
|
||||
AutoFillManager::GetInstance().RemoveTask(eventId);
|
||||
};
|
||||
ffrt::task_attr ffrtTaskAttr;
|
||||
ffrtTaskAttr.delay(AUTO_FILL_REQUEST_TIME_OUT_VALUE * MILL_TO_MICRO);
|
||||
auto ffrtTaskHandle = ffrt::submit_h(std::move(taskWrap), {}, {}, ffrtTaskAttr);
|
||||
if (ffrtTaskHandle == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "null ffrtTaskHandle");
|
||||
return;
|
||||
}
|
||||
eventHandler_->SendEvent(eventId, AUTO_FILL_REQUEST_TIME_OUT_VALUE);
|
||||
std::shared_ptr<ffrt::task_handle> taskHandle = std::make_shared<ffrt::task_handle>(
|
||||
std::move(ffrtTaskHandle));
|
||||
std::lock_guard<std::mutex> lock(taskHandlesMutex_);
|
||||
taskHandles_.emplace(eventId, taskHandle);
|
||||
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "%{public}s done", __func__);
|
||||
}
|
||||
|
||||
void AutoFillManager::RemoveEvent(uint32_t eventId)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::AUTOFILLMGR, "called");
|
||||
if (eventHandler_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "null eventHandler");
|
||||
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "%{public}s called", __func__);
|
||||
std::lock_guard<std::mutex> lock(taskHandlesMutex_);
|
||||
auto iter = taskHandles_.find(eventId);
|
||||
if (iter == taskHandles_.end()) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "not find, eventId: %{public}d", eventId);
|
||||
return;
|
||||
}
|
||||
eventHandler_->RemoveEvent(eventId);
|
||||
}
|
||||
|
||||
void AutoFillManager::HandleTimeOut(uint32_t eventId)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::AUTOFILLMGR, "called");
|
||||
auto extensionCallback = GetAutoFillExtensionCallback(eventId);
|
||||
if (extensionCallback == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "null extensionCallback");
|
||||
auto taskHandle = iter->second;
|
||||
if (!taskHandle) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "null taskHandle");
|
||||
return;
|
||||
}
|
||||
extensionCallback->HandleTimeOut();
|
||||
auto ret = ffrt::skip(*taskHandle);
|
||||
if (ret != 0) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "autofill task skip failed");
|
||||
}
|
||||
taskHandles_.erase(eventId);
|
||||
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "%{public}s done, eventId: %{public}d", __func__, eventId);
|
||||
}
|
||||
|
||||
bool AutoFillManager::IsNeedToCreatePopupWindow(const AbilityBase::AutoFillType &autoFillType)
|
||||
|
@ -26,7 +26,6 @@ ohos_unittest("auto_fill_manager_test") {
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_innerkits_path}/auto_fill_manager/src/auto_fill_event_handler.cpp",
|
||||
"${ability_runtime_innerkits_path}/auto_fill_manager/src/auto_fill_extension_callback.cpp",
|
||||
"${ability_runtime_innerkits_path}/auto_fill_manager/src/auto_fill_manager.cpp",
|
||||
"${ability_runtime_innerkits_path}/auto_fill_manager/src/auto_fill_manager_util.cpp",
|
||||
|
@ -120,56 +120,6 @@ HWTEST_F(AutoFillManagerTest, HandleRequestExecuteInner_0100, TestSize.Level1)
|
||||
EXPECT_EQ(ret, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AutoFillManager
|
||||
* Function: SetTimeOutEvent
|
||||
* SubFunction: NA
|
||||
* FunctionPoints:Calling SetTimeOutEvent can create an eventHandler_ object.
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify create eventHandler_ after calling SetTimeOutEvent, which is not empty.
|
||||
*/
|
||||
HWTEST_F(AutoFillManagerTest, SetTimeOutEvent_0100, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AutoFillManagerTest, SetTimeOutEvent_0100, TestSize.Level1";
|
||||
auto &manager = AbilityRuntime::AutoFillManager::GetInstance();
|
||||
manager.SetTimeOutEvent(EVENT_ID);
|
||||
EXPECT_NE(manager.eventHandler_, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AutoFillManager
|
||||
* Function: RemoveEvent
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: NA
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify only after calling SetTimeOutEvent can effectively call RemoveEvent.
|
||||
*/
|
||||
HWTEST_F(AutoFillManagerTest, RemoveEvent_0100, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AutoFillManagerTest, SetTimeOutEvent_0100, TestSize.Level1";
|
||||
auto &manager = AbilityRuntime::AutoFillManager::GetInstance();
|
||||
manager.SetTimeOutEvent(EVENT_ID);
|
||||
EXPECT_NE(manager.eventHandler_, nullptr);
|
||||
manager.RemoveEvent(EVENT_ID);
|
||||
EXPECT_NE(manager.eventHandler_, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AutoFillManager
|
||||
* Function: RemoveEvent
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: NA
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify directly calling remove is invalid.
|
||||
*/
|
||||
HWTEST_F(AutoFillManagerTest, RemoveEvent_0200, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AutoFillManagerTest, RemoveEvent_0200, TestSize.Level1";
|
||||
auto &manager = AbilityRuntime::AutoFillManager::GetInstance();
|
||||
manager.RemoveEvent(EVENT_ID);
|
||||
EXPECT_NE(manager.eventHandler_, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AutoFillManager
|
||||
* Function: UpdateCustomPopupUIExtension
|
||||
@ -187,26 +137,6 @@ HWTEST_F(AutoFillManagerTest, UpdateCustomPopupUIExtension_0100, TestSize.Level1
|
||||
manager.UpdateCustomPopupUIExtension(1, viewdata);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AutoFillManager
|
||||
* Function: HandleTimeOut
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: NA
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify if the processing timeout is valid.
|
||||
*/
|
||||
HWTEST_F(AutoFillManagerTest, HandleTimeOut_0100, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "AutoFillManagerTest, HandleTimeOut_0100, TestSize.Level1";
|
||||
auto &manager = AbilityRuntime::AutoFillManager::GetInstance();
|
||||
EXPECT_EQ(manager.extensionCallbacks_.size(), 0);
|
||||
auto extensionCallback = std::make_shared<AbilityRuntime::AutoFillExtensionCallback>();
|
||||
manager.extensionCallbacks_.emplace(extensionCallback->GetCallbackId(), extensionCallback);
|
||||
manager.HandleTimeOut(extensionCallback->GetCallbackId());
|
||||
EXPECT_EQ(manager.extensionCallbacks_.size(), 0);
|
||||
manager.extensionCallbacks_.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AutoFillManager
|
||||
* Function: ConvertAutoFillWindowType
|
||||
|
Loading…
Reference in New Issue
Block a user