fix:add shortcut switch inputmethod sysevent

Signed-off-by: 吴成文 <wuchengwen4@huawei.com>
This commit is contained in:
吴成文 2024-10-26 17:22:14 +08:00 committed by wuchengwen
parent 11656567fb
commit 2aef4039ca
7 changed files with 49 additions and 5 deletions

View File

@ -19,7 +19,8 @@
"imf_screenlock_mgr_enable" "imf_screenlock_mgr_enable"
], ],
"hisysevent_config": [ "hisysevent_config": [
"//base/inputmethod/imf/hisysevent.yaml" "//base/inputmethod/imf/hisysevent.yaml",
"//base/inputmethod/imf/hisysevent_ue.yaml"
], ],
"adapted_system_type": [ "adapted_system_type": [
"standard" "standard"

View File

@ -55,6 +55,7 @@ public:
void ReportImeState(ImeState state, pid_t pid, const std::string &bundleName); void ReportImeState(ImeState state, pid_t pid, const std::string &bundleName);
bool StartTimerForReport(); bool StartTimerForReport();
void SetUserId(int32_t userId); void SetUserId(int32_t userId);
void ReportSystemShortCut(const std::string &shortcutName);
private: private:
InputMethodSysEvent() = default; InputMethodSysEvent() = default;

View File

@ -203,5 +203,15 @@ bool InputMethodSysEvent::StartTimerForReport()
std::lock_guard<std::mutex> lock(timerLock_); std::lock_guard<std::mutex> lock(timerLock_);
return StartTimer(reportCallback, ONE_DAY_IN_HOURS * ONE_HOUR_IN_SECONDS * SECONDS_TO_MILLISECONDS); return StartTimer(reportCallback, ONE_DAY_IN_HOURS * ONE_HOUR_IN_SECONDS * SECONDS_TO_MILLISECONDS);
} }
void InputMethodSysEvent::ReportSystemShortCut(const std::string &shortcutName)
{
IMSA_HILOGD("run in.");
int32_t ret = HiSysEventWrite(HiSysEventNameSpace::Domain::INPUTMETHOD_UE, "SYSTEM_SHORTCUT",
HiSysEventNameSpace::EventType::BEHAVIOR, "PROCESS_NAME", "inputmethod_service", "SHORTCUT_NAME", shortcutName);
if (ret != HiviewDFX::SUCCESS) {
IMSA_HILOGE("system shortcut: %{public}s report failed! ret: %{public}d", shortcutName.c_str(), ret);
}
}
} // namespace MiscServices } // namespace MiscServices
} // namespace OHOS } // namespace OHOS

19
hisysevent_ue.yaml Normal file
View File

@ -0,0 +1,19 @@
# Copyright (c) 2024 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.
domain: INPUTMETHOD_UE
SYSTEM_SHORTCUT:
__BASE: {type: BEHAVIOR, level: CRITICAL, desc: Operating the input method through system shortcuts, preserve: true}
PROCESS_NAME: {type: STRING, desc: 'process name'}
SHORTCUT_NAME: {type: STRING, desc: 'system shortcut name'}

View File

@ -22,10 +22,6 @@ namespace MiscServices {
uint32_t InputEventCallback::keyState_ = static_cast<uint32_t>(0); uint32_t InputEventCallback::keyState_ = static_cast<uint32_t>(0);
bool InputEventCallback::isKeyHandled_ = false; bool InputEventCallback::isKeyHandled_ = false;
const std::map<int32_t, uint8_t> MASK_MAP{ const std::map<int32_t, uint8_t> MASK_MAP{
{ MMI::KeyEvent::KEYCODE_SHIFT_LEFT, KeyboardEvent::SHIFT_LEFT_MASK },
{ MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, KeyboardEvent::SHIFT_RIGHT_MASK },
{ MMI::KeyEvent::KEYCODE_CTRL_LEFT, KeyboardEvent::CTRL_LEFT_MASK },
{ MMI::KeyEvent::KEYCODE_CTRL_RIGHT, KeyboardEvent::CTRL_RIGHT_MASK },
{ MMI::KeyEvent::KEYCODE_CAPS_LOCK, KeyboardEvent::CAPS_MASK }, { MMI::KeyEvent::KEYCODE_CAPS_LOCK, KeyboardEvent::CAPS_MASK },
}; };

View File

@ -21,6 +21,7 @@
#include "global.h" #include "global.h"
#include "input_event_callback.h" #include "input_event_callback.h"
#include "key_event.h" #include "key_event.h"
#include "inputmethod_sysevent.h"
namespace OHOS { namespace OHOS {
namespace MiscServices { namespace MiscServices {
@ -50,6 +51,7 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle)
IMSA_HILOGD("add monitor success, id: %{public}d.", monitorId); IMSA_HILOGD("add monitor success, id: %{public}d.", monitorId);
CombinationKeyCallBack combinationKeyCallBack = [callback](std::shared_ptr<MMI::KeyEvent> keyEvent) { CombinationKeyCallBack combinationKeyCallBack = [callback](std::shared_ptr<MMI::KeyEvent> keyEvent) {
InputMethodSysEvent::GetInstance().ReportSystemShortCut("usual.event.WIN_SPACE");
if (callback == nullptr) { if (callback == nullptr) {
IMSA_HILOGE("callback is nullptr!"); IMSA_HILOGE("callback is nullptr!");
return; return;
@ -58,6 +60,20 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle)
}; };
SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_META_LEFT, MMI::KeyEvent::KEYCODE_SPACE, combinationKeyCallBack); SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_META_LEFT, MMI::KeyEvent::KEYCODE_SPACE, combinationKeyCallBack);
SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_META_RIGHT, MMI::KeyEvent::KEYCODE_SPACE, combinationKeyCallBack); SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_META_RIGHT, MMI::KeyEvent::KEYCODE_SPACE, combinationKeyCallBack);
CombinationKeyCallBack ctrlShiftCallBack = [callback](std::shared_ptr<MMI::KeyEvent> keyEvent) {
InputMethodSysEvent::GetInstance().ReportSystemShortCut("usual.event.CTRL_SHIFT");
if (callback == nullptr) {
IMSA_HILOGE("callback is nullptr!");
return;
}
callback->TriggerSwitch();
};
SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT, ctrlShiftCallBack);
SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, ctrlShiftCallBack);
SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT, ctrlShiftCallBack);
SubscribeCombinationKey(MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, ctrlShiftCallBack);
return ErrorCode::NO_ERROR; return ErrorCode::NO_ERROR;
} }

View File

@ -56,6 +56,7 @@ ohos_static_library("settings_data_static") {
"data_share:datashare_consumer", "data_share:datashare_consumer",
"hilog:libhilog", "hilog:libhilog",
"resource_management:global_resmgr", "resource_management:global_resmgr",
"samgr:samgr_proxy",
] ]
subsystem_name = "inputmethod" subsystem_name = "inputmethod"