mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-27 17:01:21 +00:00
!1136 publish panel status change event and code optimization
Merge pull request !1136 from cy7717/master
This commit is contained in:
commit
913c219af8
@ -147,6 +147,8 @@ private:
|
||||
|
||||
int32_t HideKeyboard(Trigger trigger);
|
||||
std::shared_ptr<InputMethodPanel> GetSoftKeyboardPanel();
|
||||
/* param flag: ShowPanel is async, show/hide softkeyboard in alphabet keyboard attached,
|
||||
flag will be changed before finishing show/hide */
|
||||
int32_t ShowPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, PanelFlag flag, Trigger trigger);
|
||||
int32_t HidePanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, PanelFlag flag, Trigger trigger);
|
||||
int32_t ShowSysPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, PanelFlag flag);
|
||||
|
@ -50,7 +50,7 @@ int32_t ImeEventMonitorManagerImpl::RegisterImeEventListener(
|
||||
return ret;
|
||||
}
|
||||
for (uint32_t i = 0; i < MAX_EVENT_NUM; i++) {
|
||||
auto eventMask = eventFlag & (1u << (MAX_EVENT_NUM - (i + 1)));
|
||||
auto eventMask = eventFlag & (1u << i);
|
||||
if (eventMask == 0) {
|
||||
continue;
|
||||
}
|
||||
@ -70,7 +70,7 @@ int32_t ImeEventMonitorManagerImpl::UnRegisterImeEventListener(
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
bool isAbsentParam = false;
|
||||
for (uint32_t i = 0; i < MAX_EVENT_NUM; i++) {
|
||||
auto eventMask = eventFlag & (1u << (MAX_EVENT_NUM - (i + 1)));
|
||||
auto eventMask = eventFlag & (1u << i);
|
||||
if (eventMask == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ std::mutex InputMethodController::instanceLock_;
|
||||
constexpr int32_t LOOP_COUNT = 5;
|
||||
constexpr int64_t DELAY_TIME = 100;
|
||||
constexpr int32_t ACE_DEAL_TIME_OUT = 200;
|
||||
constexpr uint32_t GET_IMSA_MAX_RETRY_TIME = 10;
|
||||
constexpr uint32_t GET_IMSA_RETRY_INTERVAL = 100;
|
||||
InputMethodController::InputMethodController()
|
||||
{
|
||||
IMSA_HILOGD("IMC structure");
|
||||
@ -89,6 +91,9 @@ int32_t InputMethodController::UpdateListenEventFlag(uint32_t finalEventFlag, ui
|
||||
{
|
||||
auto oldEventFlag = clientInfo_.eventFlag;
|
||||
clientInfo_.eventFlag = finalEventFlag;
|
||||
// js has no errcode, ensure not failed in GetSystemAbilityProxy();
|
||||
BlockRetry(
|
||||
GET_IMSA_RETRY_INTERVAL, GET_IMSA_MAX_RETRY_TIME, [this]() { return GetSystemAbilityProxy() != nullptr; });
|
||||
auto proxy = GetSystemAbilityProxy();
|
||||
if (proxy == nullptr && isOn) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
@ -1015,6 +1020,7 @@ int32_t InputMethodController::InsertText(const std::u16string &text)
|
||||
int64_t start = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||
{
|
||||
InputMethodSyncTrace aceTracer("ACE_InsertText");
|
||||
IMSA_HILOGD("ACE InsertText");
|
||||
listener->InsertText(text);
|
||||
}
|
||||
PrintLogIfAceTimeout(start);
|
||||
|
@ -65,6 +65,7 @@ ohos_shared_library("inputmethod_client") {
|
||||
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/keyevent_consumer_proxy.cpp",
|
||||
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/keyevent_consumer_stub.cpp",
|
||||
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/system_cmd_channel_stub.cpp",
|
||||
"${inputmethod_path}/services/src/global.cpp",
|
||||
"${inputmethod_path}/services/src/message.cpp",
|
||||
"${inputmethod_path}/services/src/message_handler.cpp",
|
||||
]
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
static bool Read(const std::string &path, const std::string &key, std::string &content);
|
||||
static bool Write(
|
||||
const std::string &path, const std::string &content, int32_t flags, mode_t mode = S_IRUSR | S_IWUSR);
|
||||
static std::string GetRealPath(const char *path);
|
||||
|
||||
private:
|
||||
static constexpr int32_t SUCCESS = 0;
|
||||
|
@ -83,21 +83,11 @@ bool FileOperator::Read(const std::string &path, const std::string &key, std::st
|
||||
}
|
||||
// parse config files, ordered by priority from high to low
|
||||
for (int32_t i = MAX_CFG_POLICY_DIRS_CNT - 1; i >= 0; i--) {
|
||||
auto pathTemp = cfgFiles->paths[i];
|
||||
if (pathTemp == nullptr) {
|
||||
auto realPath = GetRealPath(cfgFiles->paths[i]);
|
||||
if (realPath.empty()) {
|
||||
continue;
|
||||
}
|
||||
auto size = strnlen(pathTemp, PATH_MAX);
|
||||
if (size == 0 || size == PATH_MAX) {
|
||||
continue;
|
||||
}
|
||||
char realPath[PATH_MAX] = { 0x00 };
|
||||
if (realpath(pathTemp, realPath) == nullptr) {
|
||||
IMSA_HILOGE("failed to get realpath");
|
||||
continue;
|
||||
}
|
||||
std::string cfgPath(realPath);
|
||||
content = Read(cfgPath, key);
|
||||
content = Read(realPath, key);
|
||||
if (!content.empty()) {
|
||||
break;
|
||||
}
|
||||
@ -120,5 +110,22 @@ std::string FileOperator::Read(const std::string &path, const std::string &key)
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
std::string FileOperator::GetRealPath(const char *path)
|
||||
{
|
||||
if (path == nullptr) {
|
||||
return "";
|
||||
}
|
||||
auto size = strnlen(path, PATH_MAX);
|
||||
if (size == 0 || size == PATH_MAX) {
|
||||
return "";
|
||||
}
|
||||
char realPath[PATH_MAX] = { 0x00 };
|
||||
if (realpath(path, realPath) == nullptr) {
|
||||
IMSA_HILOGE("failed to get realpath");
|
||||
return "";
|
||||
}
|
||||
return std::string(realPath);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "common_event_subscriber.h"
|
||||
#include "common_event_support.h"
|
||||
#include "focus_monitor_manager.h"
|
||||
#include "input_window_info.h"
|
||||
#include "keyboard_event.h"
|
||||
#include "matching_skills.h"
|
||||
#include "system_ability_status_change_stub.h"
|
||||
@ -42,8 +43,9 @@ public:
|
||||
bool SubscribeKeyboardEvent(KeyHandle handle);
|
||||
bool SubscribeWindowManagerService(FocusHandle handle, Handler inputHandler);
|
||||
bool SubscribeAccountManagerService(Handler handle);
|
||||
|
||||
bool UnsubscribeEvent();
|
||||
// only public the status change of softKeyboard in FLG_FIXED or FLG_FLOATING
|
||||
int32_t PublishPanelStatusChangeEvent(const InputWindowStatus &status, const ImeWindowInfo &info);
|
||||
class EventSubscriber : public EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
|
||||
|
@ -33,6 +33,9 @@ using namespace MessageID;
|
||||
sptr<ImCommonEventManager> ImCommonEventManager::instance_;
|
||||
std::mutex ImCommonEventManager::instanceLock_;
|
||||
using namespace OHOS::EventFwk;
|
||||
constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
|
||||
constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
|
||||
constexpr const char *COMMON_EVENT_PARAM_PANEL_RECT = "panelRect";
|
||||
ImCommonEventManager::ImCommonEventManager()
|
||||
{
|
||||
}
|
||||
@ -254,5 +257,21 @@ void ImCommonEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbil
|
||||
int32_t systemAbilityId, const std::string &deviceId)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t ImCommonEventManager::PublishPanelStatusChangeEvent(const InputWindowStatus &status, const ImeWindowInfo &info)
|
||||
{
|
||||
EventFwk::CommonEventPublishInfo publicInfo;
|
||||
publicInfo.SetOrdered(false);
|
||||
AAFwk::Want want;
|
||||
want.SetAction(COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED);
|
||||
bool visible = (status == InputWindowStatus::SHOW);
|
||||
std::vector<int32_t> panelRect = { info.windowInfo.left, info.windowInfo.top,
|
||||
static_cast<int32_t>(info.windowInfo.width), static_cast<int32_t>(info.windowInfo.height) };
|
||||
want.SetParam(COMMON_EVENT_PARAM_PANEL_STATE, visible);
|
||||
want.SetParam(COMMON_EVENT_PARAM_PANEL_RECT, panelRect);
|
||||
EventFwk::CommonEventData data;
|
||||
data.SetWant(want);
|
||||
return EventFwk::CommonEventManager::NewPublishCommonEvent(data, publicInfo);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -26,8 +26,7 @@
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
namespace {
|
||||
constexpr const char *IME_CFG_DIR = "/data/service/el1/public/imf/ime_cfg";
|
||||
constexpr const char *IME_CFG_FILE_PATH = "/data/service/el1/public/imf/ime_cfg/ime_cfg.json";
|
||||
constexpr const char *IME_CFG_FILE_PATH = "/data/service/el1/public/imf/ime_cfg.json";
|
||||
} // namespace
|
||||
ImeCfgManager &ImeCfgManager::GetInstance()
|
||||
{
|
||||
@ -42,13 +41,12 @@ void ImeCfgManager::Init()
|
||||
|
||||
void ImeCfgManager::ReadImeCfg()
|
||||
{
|
||||
std::string path(IME_CFG_FILE_PATH);
|
||||
if (!FileOperator::IsExist(path)) {
|
||||
if (!FileOperator::IsExist(IME_CFG_FILE_PATH)) {
|
||||
IMSA_HILOGD("ime cfg file not find");
|
||||
return;
|
||||
}
|
||||
std::string cfg;
|
||||
bool ret = FileOperator::Read(path, cfg);
|
||||
bool ret = FileOperator::Read(IME_CFG_FILE_PATH, cfg);
|
||||
if (!ret) {
|
||||
IMSA_HILOGE("ReadJsonFile failed");
|
||||
return;
|
||||
@ -63,13 +61,6 @@ void ImeCfgManager::WriteImeCfg()
|
||||
IMSA_HILOGE("Package imeCfg failed");
|
||||
return;
|
||||
}
|
||||
std::string path(IME_CFG_DIR);
|
||||
if (!FileOperator::IsExist(path)) {
|
||||
if (!FileOperator::Create(path, S_IRWXU)) {
|
||||
IMSA_HILOGE("ime cfg dir create failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!FileOperator::Write(IME_CFG_FILE_PATH, content, O_CREAT | O_WRONLY | O_SYNC | O_TRUNC)) {
|
||||
IMSA_HILOGE("WriteJsonFile failed");
|
||||
}
|
||||
|
@ -454,6 +454,11 @@ int32_t InputMethodSystemAbility::PanelStatusChange(const InputWindowStatus &sta
|
||||
IMSA_HILOGE("not current ime");
|
||||
return ErrorCode::ERROR_NOT_CURRENT_IME;
|
||||
}
|
||||
auto commonEventManager = ImCommonEventManager::GetInstance();
|
||||
if (commonEventManager != nullptr) {
|
||||
auto ret = ImCommonEventManager::GetInstance()->PublishPanelStatusChangeEvent(status, info);
|
||||
IMSA_HILOGD("public panel status change event:%{public}d", ret);
|
||||
}
|
||||
return userSession_->OnPanelStatusChange(status, info);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ bool SysCfgParser::ParseSystemConfig(SystemConfig &systemConfig)
|
||||
|
||||
bool SysCfgParser::ParseInputType(std::vector<InputTypeInfo> &inputType)
|
||||
{
|
||||
auto content = GetSysCfgContent(GET_NAME(systemConfig));
|
||||
auto content = GetSysCfgContent(GET_NAME(supportedInputTypeList));
|
||||
if (content.empty()) {
|
||||
IMSA_HILOGE("empty content");
|
||||
return false;
|
||||
|
@ -268,6 +268,7 @@ ohos_unittest("InputMethodPanelTest") {
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"graphic_2d:window_animation",
|
||||
"hilog:libhilog",
|
||||
|
@ -25,11 +25,17 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "common_event_data.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_subscribe_info.h"
|
||||
#include "common_event_subscriber.h"
|
||||
#include "common_event_support.h"
|
||||
#include "display_manager.h"
|
||||
#include "global.h"
|
||||
#include "input_method_ability.h"
|
||||
#include "input_method_controller.h"
|
||||
#include "input_method_engine_listener_impl.h"
|
||||
#include "matching_skills.h"
|
||||
#include "panel_status_listener.h"
|
||||
#include "scope_utils.h"
|
||||
#include "tdd_util.h"
|
||||
@ -41,6 +47,8 @@ namespace MiscServices {
|
||||
constexpr uint32_t IMC_WAIT_PANEL_STATUS_LISTEN_TIME = 200;
|
||||
constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
|
||||
constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1;
|
||||
constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
|
||||
constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
|
||||
enum ListeningStatus : uint32_t { ON, OFF, NONE };
|
||||
class InputMethodPanelTest : public testing::Test {
|
||||
public:
|
||||
@ -134,6 +142,31 @@ public:
|
||||
InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
class TestEventSubscriber : public EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
explicit TestEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
|
||||
: EventFwk::CommonEventSubscriber(subscribeInfo)
|
||||
{
|
||||
}
|
||||
void OnReceiveEvent(const EventFwk::CommonEventData &data)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
|
||||
auto const &want = data.GetWant();
|
||||
action_ = want.GetAction();
|
||||
bool visible = want.GetBoolParam(COMMON_EVENT_PARAM_PANEL_STATE, false);
|
||||
status_ = visible ? InputWindowStatus::SHOW : InputWindowStatus::HIDE;
|
||||
InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
|
||||
}
|
||||
void ResetParam()
|
||||
{
|
||||
action_ = "";
|
||||
status_ = InputWindowStatus::NONE;
|
||||
}
|
||||
std::string action_;
|
||||
InputWindowStatus status_{ InputWindowStatus::NONE };
|
||||
};
|
||||
|
||||
std::condition_variable InputMethodPanelTest::panelListenerCv_;
|
||||
std::mutex InputMethodPanelTest::panelListenerLock_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> InputMethodPanelTest::panelHandler_{ nullptr };
|
||||
@ -1080,6 +1113,45 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_007, TestSize.Level0)
|
||||
InputMethodPanelTest::ImcPanelHideNumCheck(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: testPanelStatusChangeEventPublicTest
|
||||
* @tc.desc: test subscriber can receive the panel status change event published by IMSA
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodPanelTest, testPanelStatusChangeEventPublicTest, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodPanelTest::testPanelStatusChangeEventPublicTest start.");
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED);
|
||||
EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
auto subscriber = std::make_shared<TestEventSubscriber>(subscriberInfo);
|
||||
auto ret = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
InputMethodPanelTest::TestShowPanel(InputMethodPanelTest::inputMethodPanel_);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
|
||||
auto waitRet = imcPanelStatusListenerCv_.wait_for(
|
||||
lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
|
||||
return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED
|
||||
&& subscriber->status_ == InputWindowStatus::SHOW;
|
||||
});
|
||||
EXPECT_TRUE(waitRet);
|
||||
}
|
||||
|
||||
subscriber->ResetParam();
|
||||
InputMethodPanelTest::TestHidePanel(InputMethodPanelTest::inputMethodPanel_);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
|
||||
auto waitRet = imcPanelStatusListenerCv_.wait_for(
|
||||
lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [subscriber]() {
|
||||
return subscriber->action_ == COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED
|
||||
&& subscriber->status_ == InputWindowStatus::HIDE;
|
||||
});
|
||||
EXPECT_TRUE(waitRet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSetCallingWindow
|
||||
* @tc.desc: test SetCallingWindow
|
||||
|
Loading…
Reference in New Issue
Block a user