Signed-off-by: ma-shaoyin <mashaoyin1@huawei.com>

Changes to be committed:
This commit is contained in:
ma-shaoyin 2023-07-13 11:12:06 +08:00
parent d99ec4a7a9
commit 0ad0ddf67b
7 changed files with 96 additions and 82 deletions

View File

@ -532,7 +532,7 @@ int32_t InputMethodAbility::HideKeyboardSelf()
IMSA_HILOGE("InputMethodAbility::HideKeyboardSelf controlChannel is nullptr");
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
}
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_SELF);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF);
return controlChannel->HideKeyboardSelf(1);
}

View File

@ -44,11 +44,7 @@ const std::unordered_map<std::string, EventType> EVENT_TYPE{ { "imeChange", IME_
{ "imeHide", IME_HIDE } };
InputMethodController::InputMethodController() : stop_(false)
{
IMSA_HILOGI("InputMethodController structure");
int32_t ret = Initialize();
if (ret != ErrorCode::NO_ERROR) {
InputMethodSysEvent::InputmethodFaultReporter(ret, "", "IMC initialize failed!");
}
IMSA_HILOGI("InputMethodController structure");
}
InputMethodController::~InputMethodController()
@ -64,7 +60,14 @@ sptr<InputMethodController> InputMethodController::GetInstance()
std::lock_guard<std::mutex> autoLock(instanceLock_);
if (instance_ == nullptr) {
IMSA_HILOGI("InputMethodController::GetInstance instance_ is nullptr");
instance_ = new InputMethodController();
instance_ = new (std::nothrow) InputMethodController();
if (instance_ == nullptr) {
return instance_;
}
int32_t ret = instance_->Initialize();
if (ret != ErrorCode::NO_ERROR) {
InputMethodSysEvent::InputmethodFaultReporter(ret, "", "IMC initialize failed!");
}
}
}
return instance_;
@ -436,7 +439,7 @@ int32_t InputMethodController::Attach(
IMSA_HILOGI("bind imf successfully, enter editable state");
if (isShowKeyboard) {
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_SHOW_ATTACH);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_SHOW_ATTACH);
}
return ErrorCode::NO_ERROR;
}
@ -449,7 +452,7 @@ int32_t InputMethodController::ShowTextInput()
return ErrorCode::ERROR_CLIENT_NOT_BOUND;
}
clientInfo_.isShowKeyboard = true;
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_SHOW_ENEDITABLE);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_SHOW_ENEDITABLE);
int32_t ret = StartInput(clientInfo_.client, true, false);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("failed to start input, ret: %{public}d", ret);
@ -468,7 +471,7 @@ int32_t InputMethodController::HideTextInput()
return ErrorCode::ERROR_CLIENT_NOT_BOUND;
}
isEditable_.store(false);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_UNEDITABLE);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_UNEDITABLE);
return StopInput(clientInfo_.client);
}
@ -485,7 +488,7 @@ int32_t InputMethodController::HideCurrentInput()
return ErrorCode::ERROR_EX_NULL_POINTER;
}
clientInfo_.isShowKeyboard = false;
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_NORMAL);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_NORMAL);
return proxy->HideCurrentInputDeprecated();
}
@ -502,7 +505,7 @@ int32_t InputMethodController::ShowCurrentInput()
return ErrorCode::ERROR_EX_NULL_POINTER;
}
clientInfo_.isShowKeyboard = true;
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_SHOW_NORMAL);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_SHOW_NORMAL);
return proxy->ShowCurrentInputDeprecated();
}
@ -523,8 +526,8 @@ int32_t InputMethodController::Close()
agentObject_ = nullptr;
}
ClearEditorCache();
isReportHide ? InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_UNBIND)
: InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_UNBIND);
isReportHide ? InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_UNBIND)
: InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_UNBIND);
return ReleaseInput(clientInfo_.client);
}
@ -922,7 +925,7 @@ int32_t InputMethodController::ShowSoftKeyboard()
return ErrorCode::ERROR_EX_NULL_POINTER;
}
clientInfo_.isShowKeyboard = true;
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_SHOW_NORMAL);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_SHOW_NORMAL);
return proxy->ShowCurrentInput();
}
@ -939,7 +942,7 @@ int32_t InputMethodController::HideSoftKeyboard()
return ErrorCode::ERROR_EX_NULL_POINTER;
}
clientInfo_.isShowKeyboard = false;
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_NORMAL);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_NORMAL);
return proxy->HideCurrentInput();
}

View File

@ -14,24 +14,24 @@
domain: INPUTMETHOD
SERVICE_INIT_FAILED:
__BASE: {type: FAULT, level: CRITICAL, tag: IMFServiceFailed, desc: Inputmethod service init report}
__BASE: {type: FAULT, level: CRITICAL, tag: IMFServiceFailed, desc: Input method service init fault}
USER_ID: {type: INT32, desc: The user id}
COMPONENT_ID: {type: STRING, desc: Component name}
ERROR_CODE: {type: INT32, desc: Error code}
INPUTMETHOD_UNAVAILABLE:
__BASE: {type: FAULT, level: CRITICAL, tag: IMEUnavaliable, desc: inputmethod unavailable}
__BASE: {type: FAULT, level: CRITICAL, tag: IMEUnavaliable, desc: Inputmethod unavailable}
USER_ID: {type: INT32, desc: The user id}
APP_NAME: {type: STRING, desc: app name}
APP_NAME: {type: STRING, desc: App name}
ERROR_CODE: {type: INT32, desc: Error code}
INFO: {type: STRING, desc: Error information}
IME_USAGE:
__BASE: {type: STATISTIC, level: MINOR, tag: IMEUsage, desc: inputmethod using report}
IME_START: {type: INT32, desc: the number of ime starts}
IME_CHANGE: {type: INT32, desc: the number of ime switchs}
__BASE: {type: STATISTIC, level: MINOR, tag: IMEUsage, desc: Inputmethod using report}
IME_START: {type: INT32, desc: The count of ime starts}
IME_CHANGE: {type: INT32, desc: The count of ime switchs}
OPERATE_SOFTKEYBOARD:
__BASE: {type: BEHAVIOR, level: MINOR, tag: IMEOperate, desc: Operate the soft keyboard report}
OPERATING: {type: STRING, desc: show, hide or unbind soft keyboard}
OPERATING: {type: STRING, desc: Show, hide or unbind soft keyboard}
OPERATE_INFO: {type: STRING, desc: Manipulate to show, hide, or unbind soft keyboard information}

View File

@ -26,7 +26,7 @@
namespace OHOS {
namespace MiscServices {
enum OperateIMEInfoCode : int32_t {
enum class OperateIMEInfoCode : int32_t {
IME_SHOW_ATTACH = 0,
IME_SHOW_ENEDITABLE,
IME_SHOW_NORMAL,
@ -38,7 +38,7 @@ enum OperateIMEInfoCode : int32_t {
IME_HIDE_SELF,
};
enum IMEBehaviour : int32_t {
enum class IMEBehaviour : int32_t {
START_IME = 0,
CHANGE_IME,
};
@ -47,19 +47,19 @@ class InputMethodSysEvent {
public:
static void ServiceFaultReporter(const std::string &bundleName, int32_t errCode);
static void InputmethodFaultReporter(int32_t errCode, const std::string &name, const std::string &info);
static void EventRecorder(IMEBehaviour behaciour);
static void RecordEvent(IMEBehaviour behaviour);
static void OperateSoftkeyboardBehaviour(OperateIMEInfoCode infoCode);
static void StartTimerForReport();
static bool StartTimerForReport();
static void SetUserId(int32_t userId);
private:
using TimerCallback = std::function<void()>;
static void ImeUsageBehaviourReporter();
static const std::string GetOperateInfo(OperateIMEInfoCode infoCode);
static std::string GetOperateAction(OperateIMEInfoCode infoCode);
static void StartTimer(const TimerCallback &callback, uint32_t interval);
static void StopTimer();
static const std::string GetOperateInfo(int32_t infoCode);
static std::string GetOperateAction(int32_t infoCode);
static bool StartTimer(const TimerCallback &callback, uint32_t interval);
static int32_t GetReportTime();
static void UpdateTimer(const TimerCallback &callback, uint32_t interval);
private:
static const std::unordered_map<int32_t, std::string> operateInfo_;

View File

@ -27,20 +27,22 @@ using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent;
} // namespace
const std::unordered_map<int32_t, std::string> InputMethodSysEvent::operateInfo_ = {
{IME_SHOW_ATTACH, "Attach: attach, bind and show soft keyboard."},
{IME_SHOW_ENEDITABLE, "ShowTextInput: enter editable state, show soft keyboard."},
{IME_SHOW_NORMAL, "ShowSoftKeyboard: show soft keyboard."},
{IME_UNBIND, "Close: unbind."},
{IME_HIDE_UNBIND, "Close: hide soft keyboard, and unbind."},
{IME_HIDE_UNEDITABLE, "HideTextInput: hide soft keyboard, quit editable state."},
{IME_HIDE_NORMAL, "HideSoftKeyboard, hide soft keyboard."},
{IME_HIDE_UNFOCUSED, "OnUnfocused: unfocused, hide soft keyboard."},
{IME_HIDE_SELF, "HideKeyboardSelf: hide soft keyboard self."}
{ static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ATTACH), "Attach: attach, bind and show soft keyboard." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ENEDITABLE), "ShowTextInput: enter editable state, show soft "
"keyboard." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL), "ShowSoftKeyboard: show soft keyboard." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_UNBIND), "Close: unbind." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNBIND), "Close: hide soft keyboard, and unbind." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNEDITABLE), "HideTextInput: hide soft keyboard, quit "
"editable state." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL), "HideSoftKeyboard, hide soft keyboard." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNFOCUSED), "OnUnfocused: unfocused, hide soft keyboard." },
{ static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_SELF), "HideKeyboardSelf: hide soft keyboard self." }
};
std::map<int32_t, int32_t> InputMethodSysEvent::inputmethodBehaviour_ = {
{START_IME, 0},
{CHANGE_IME, 0}
{static_cast<int32_t>(IMEBehaviour::START_IME), 0},
{static_cast<int32_t>(IMEBehaviour::CHANGE_IME), 0}
};
Utils::Timer InputMethodSysEvent::timer_("imfTimer");
@ -52,6 +54,7 @@ int32_t InputMethodSysEvent::userId_ = 0;
void InputMethodSysEvent::ServiceFaultReporter(const std::string &bundleName, int32_t errCode)
{
IMSA_HILOGD("run in.");
int32_t ret = HiSysEventWrite(HiSysEventNameSpace::Domain::INPUTMETHOD, "SERVICE_INIT_FAILED",
HiSysEventNameSpace::EventType::FAULT, "USER_ID", userId_, "COMPONENT_ID", bundleName, "ERROR_CODE", errCode);
if (ret != HiviewDFX::SUCCESS) {
@ -61,6 +64,7 @@ void InputMethodSysEvent::ServiceFaultReporter(const std::string &bundleName, in
void InputMethodSysEvent::InputmethodFaultReporter(int32_t errCode, const std::string &name, const std::string &info)
{
IMSA_HILOGD("run in.");
int32_t ret = HiSysEventWrite(HiSysEventNameSpace::Domain::INPUTMETHOD, "INPUTMETHOD_UNAVAILABLE",
HiSysEventNameSpace::EventType::FAULT, "USER_ID", userId_, "APP_NAME", name, "ERROR_CODE", errCode, "INFO",
info);
@ -71,63 +75,66 @@ void InputMethodSysEvent::InputmethodFaultReporter(int32_t errCode, const std::s
void InputMethodSysEvent::ImeUsageBehaviourReporter()
{
IMSA_HILOGE("msy ImeUsageBehaviourReporter");
IMSA_HILOGD("run in.");
std::lock_guard<std::mutex> lock(behaviourMutex_);
int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::INPUTMETHOD, "IME_USAGE",
HiSysEventNameSpace::EventType::STATISTIC, "IME_START", inputmethodBehaviour_[START_IME], "IME_CHANGE",
inputmethodBehaviour_[CHANGE_IME]);
HiSysEventNameSpace::EventType::STATISTIC, "IME_START",
inputmethodBehaviour_[static_cast<int32_t>(IMEBehaviour::START_IME)], "IME_CHANGE",
inputmethodBehaviour_[static_cast<int32_t>(IMEBehaviour::CHANGE_IME)]);
if (ret != HiviewDFX::SUCCESS) {
IMSA_HILOGE("hisysevent BehaviourReporter failed! ret %{public}d", ret);
}
inputmethodBehaviour_[START_IME] = 0;
inputmethodBehaviour_[CHANGE_IME] = 0;
inputmethodBehaviour_[static_cast<int32_t>(IMEBehaviour::START_IME)] = 0;
inputmethodBehaviour_[static_cast<int32_t>(IMEBehaviour::CHANGE_IME)] = 0;
StartTimerForReport();
}
void InputMethodSysEvent::EventRecorder(IMEBehaviour behaviour)
void InputMethodSysEvent::RecordEvent(IMEBehaviour behaviour)
{
IMSA_HILOGD("run in.");
std::lock_guard<std::mutex> lock(behaviourMutex_);
if (behaviour == IMEBehaviour::START_IME) {
inputmethodBehaviour_[START_IME]++;
++inputmethodBehaviour_[static_cast<int32_t>(IMEBehaviour::START_IME)];
} else if (behaviour == IMEBehaviour::CHANGE_IME) {
inputmethodBehaviour_[CHANGE_IME]++;
++inputmethodBehaviour_[static_cast<int32_t>(IMEBehaviour::CHANGE_IME)];
}
}
void InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode infoCode)
{
IMSA_HILOGD("run in.");
int32_t ret = HiSysEventWrite(HiSysEventNameSpace::Domain::INPUTMETHOD, "OPERATE_SOFTKEYBOARD",
HiSysEventNameSpace::EventType::BEHAVIOR, "OPERATING", GetOperateAction(infoCode), "OPERATE_INFO",
GetOperateInfo(infoCode));
HiSysEventNameSpace::EventType::BEHAVIOR, "OPERATING", GetOperateAction(static_cast<int32_t>(infoCode)),
"OPERATE_INFO", GetOperateInfo(static_cast<int32_t>(infoCode)));
if (ret != HiviewDFX::SUCCESS) {
IMSA_HILOGE("Hisysevent: operate soft keyboard report failed! ret %{public}d", ret);
}
}
const std::string InputMethodSysEvent::GetOperateInfo(OperateIMEInfoCode infoCode)
const std::string InputMethodSysEvent::GetOperateInfo(int32_t infoCode)
{
auto iter = operateInfo_.find(infoCode);
auto iter = operateInfo_.find(static_cast<int32_t>(infoCode));
if (iter != operateInfo_.end()) {
return iter->second;
}
return "unknow operating.";
}
std::string InputMethodSysEvent::GetOperateAction(OperateIMEInfoCode infoCode)
std::string InputMethodSysEvent::GetOperateAction(int32_t infoCode)
{
switch (infoCode) {
case IME_SHOW_ATTACH:
case IME_SHOW_ENEDITABLE:
case IME_SHOW_NORMAL:
case static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ATTACH):
case static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ENEDITABLE):
case static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL):
return "show";
case IME_UNBIND:
case static_cast<int32_t>(OperateIMEInfoCode::IME_UNBIND):
return "unbind";
case IME_HIDE_UNBIND:
case static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNBIND):
return "hide and unbind";
case IME_HIDE_UNEDITABLE:
case IME_HIDE_NORMAL:
case IME_HIDE_UNFOCUSED:
case IME_HIDE_SELF:
case static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNEDITABLE):
case static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL):
case static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNFOCUSED):
case static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_SELF):
return "hide";
default:
break;
@ -140,47 +147,47 @@ void InputMethodSysEvent::SetUserId(int32_t userId)
userId_ = userId;
}
void InputMethodSysEvent::StartTimer(const TimerCallback &callback, uint32_t interval)
bool InputMethodSysEvent::StartTimer(const TimerCallback &callback, uint32_t interval)
{
IMSA_HILOGD("run in");
isTimerStart_ = true;
uint32_t ret = timer_.Setup();
if (ret != Utils::TIMER_ERR_OK) {
IMSA_HILOGE("Create Timer error");
return;
isTimerStart_ = false;
return false;
}
timerId_ = timer_.Register(callback, interval, true);
return true;
}
void InputMethodSysEvent::StopTimer()
void InputMethodSysEvent::UpdateTimer(const TimerCallback &callback, uint32_t interval)
{
IMSA_HILOGD("run in");
timer_.Unregister(timerId_);
timer_.Shutdown();
isTimerStart_ = false;
timerId_ = timer_.Register(callback, interval, false);
}
void InputMethodSysEvent::StartTimerForReport()
bool InputMethodSysEvent::StartTimerForReport()
{
IMSA_HILOGD("run in");
auto reportCallback = []() { ImeUsageBehaviourReporter(); };
std::lock_guard<std::mutex> lock(timerLock_);
if (isTimerStart_) {
IMSA_HILOGD("isTimerStart_ is true. Update timer.");
timer_.Unregister(timerId_);
timerId_ =
timer_.Register(reportCallback, ONE_DAY_IN_HOURS * ONE_HOUR_IN_SECONDS * SECONDS_TO_MILLISECONDS, false);
} else {
int32_t interval = GetReportTime();
if (interval >= 0) {
StartTimer(reportCallback, interval);
}
UpdateTimer(reportCallback, ONE_DAY_IN_HOURS * ONE_HOUR_IN_SECONDS * SECONDS_TO_MILLISECONDS);
return true;
}
int32_t interval = GetReportTime();
if (interval >= 0) {
return StartTimer(reportCallback, interval);
}
return false;
}
int32_t InputMethodSysEvent::GetReportTime()
{
IMSA_HILOGD("GetReportTime run in.");
IMSA_HILOGD("run in.");
time_t current = time(nullptr);
if (current == -1) {
IMSA_HILOGE("Get current time failed!");

View File

@ -73,7 +73,11 @@ InputMethodSystemAbility::~InputMethodSystemAbility()
void InputMethodSystemAbility::OnStart()
{
IMSA_HILOGI("InputMethodSystemAbility::OnStart.");
InputMethodSysEvent::StartTimerForReport();
if (!InputMethodSysEvent::StartTimerForReport()) {
IMSA_HILOGE("Start timer failed. Try again.");
auto callback = [=]() { InputMethodSysEvent::StartTimerForReport(); };
serviceHandler_->PostTask(callback, RETRY_INTERVAL);
}
if (state_ == ServiceRunningState::STATE_RUNNING) {
IMSA_HILOGI("ImsaService is already running.");
return;
@ -369,7 +373,7 @@ int32_t InputMethodSystemAbility::SwitchInputMethod(const std::string &bundleNam
int32_t InputMethodSystemAbility::OnSwitchInputMethod(const SwitchInfo &switchInfo, bool isCheckPermission)
{
IMSA_HILOGD("run in, switchInfo: %{public}s|%{public}s", switchInfo.bundleName.c_str(), switchInfo.subName.c_str());
InputMethodSysEvent::EventRecorder(IMEBehaviour::CHANGE_IME);
InputMethodSysEvent::RecordEvent(IMEBehaviour::CHANGE_IME);
if (!switchQueue_.IsReady(switchInfo)) {
IMSA_HILOGD("start wait");
switchQueue_.Wait(switchInfo);

View File

@ -562,7 +562,7 @@ void PerUserSession::OnUnfocused(int32_t pid, int32_t uid)
if (mapClient.second->pid == pid) {
IMSA_HILOGI("clear unfocused client info: %{public}d", pid);
UnbindClient(mapClient.second->client);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_UNFOCUSED);
InputMethodSysEvent::OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_UNFOCUSED);
break;
}
}