!100 修改硬键盘回调接口为子线程

Merge pull request !100 from demon/OpenHarmony-3.1-Release
This commit is contained in:
openharmony_ci
2022-03-21 12:52:11 +00:00
committed by Gitee
4 changed files with 34 additions and 22 deletions
@@ -43,6 +43,7 @@ namespace MiscServices {
if (inputControlChannel == nullptr) {
IMSA_HILOGI("InputMethodCoreProxy::initializeInput inputControlChannel is nullptr");
return ErrorCode::ERROR_NULL_POINTER;
}
IMSA_HILOGI("InputMethodCoreProxy::initializeInput displayId = %{public}d", displayId);
MessageParcel data, reply;
@@ -51,6 +52,7 @@ namespace MiscServices {
sptr<IRemoteObject> channelObject = inputControlChannel->AsObject();
if (channelObject == nullptr) {
IMSA_HILOGI("InputMethodCoreProxy::initializeInput channelObject is nullptr");
return ErrorCode::ERROR_NULL_POINTER;
}
bool wor = data.WriteRemoteObject(channelObject);
if (wor) {
@@ -137,6 +139,7 @@ namespace MiscServices {
}
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodCoreProxy::startInput inputDataChannel is nullptr");
return false;
}
MessageParcel data;
@@ -149,22 +149,28 @@ namespace MiscServices {
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsKeyboardDelegateListener::OnKeyEvent");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return false;
}
NativeValue* argv[] = {nativeValue};
std::string methodName;
if (keyStatus == 2) {
methodName = "keyDown";
} else {
methodName = "keyUp";
}
object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast<uint32_t>(keyCode)));
object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast<uint32_t>(keyStatus)));
return CallJsMethodReturnBool(methodName, argv, ArraySize(argv));
auto result = false;
auto task = [this, keyCode, keyStatus, &result] () {
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
NativeValue* argv[] = {nativeValue};
std::string methodName;
if (keyStatus == 2) {
methodName = "keyDown";
} else {
methodName = "keyUp";
}
object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast<uint32_t>(keyCode)));
object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast<uint32_t>(keyStatus)));
result = CallJsMethodReturnBool(methodName, argv, ArraySize(argv));
};
mainHandler_->PostSyncTask(task);
return result;
}
void JsKeyboardDelegateListener::OnCursorUpdate(int32_t positionX, int32_t positionY, int height)
+8 -6
View File
@@ -209,11 +209,11 @@ namespace MiscServices {
if (it == msgHandlers.end()) {
IMSA_HILOGE("InputMethodSystemAbility::StartInputService() need start handler");
MessageHandler *handler = new MessageHandler();
if (session == nullptr) {
IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr");
if (session != nullptr) {
IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is not nullptr");
session->CreateWorkThread(*handler);
msgHandlers.insert(std::pair<int32_t, MessageHandler*>(MAIN_USER_ID, handler));
}
session->CreateWorkThread(*handler);
msgHandlers.insert(std::pair<int32_t, MessageHandler*>(MAIN_USER_ID, handler));
}
bool isStartSuccess = false;
@@ -245,6 +245,7 @@ namespace MiscServices {
PerUserSession *session = GetUserSession(MAIN_USER_ID);
if (session == nullptr){
IMSA_HILOGE("InputMethodSystemAbility::StopInputService abort session is nullptr");
return;
}
session->StopInputService(imeId);
@@ -723,8 +724,6 @@ namespace MiscServices {
}
if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) {
IMSA_HILOGE("InputMethodSystemAbility::OnHandleMessage Aborted! userId = %{public}d,", userId);
IMSA_HILOGE("InputMethodSystemAbility::OnHandleMessage Aborted! userState = %{public}d",
setting->GetUserState());
return ErrorCode::ERROR_USER_NOT_UNLOCKED;
}
@@ -848,6 +847,9 @@ namespace MiscServices {
return ErrorCode::ERROR_USER_NOT_UNLOCKED;
}
PerUserSession *session = GetUserSession(userId);
if (session == nullptr) {
return ErrorCode::ERROR_NULL_POINTER;
}
int32_t ret = session->OnSettingChanged(updatedKey, updatedValue);
if (ret == ErrorCode::ERROR_SETTING_SAME_VALUE) {
IMSA_HILOGI("End...No need to update\n");
+1
View File
@@ -1182,6 +1182,7 @@ namespace MiscServices {
InputAttribute *attribute = data->ReadParcelable<InputAttribute>();
if (attribute == nullptr) {
IMSA_HILOGI("PerUserSession::OnPrepareInput attribute is nullptr");
return;
}
int ret = AddClient(pid, uid, displayId, client, channel, *attribute);