!97 同步安全问题和bug

Merge pull request !97 from demon/OpenHarmony-3.1-Release
This commit is contained in:
openharmony_ci
2022-03-16 08:07:40 +00:00
committed by Gitee
9 changed files with 62 additions and 11 deletions
@@ -92,6 +92,7 @@ namespace MiscServices {
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest START_INPUT inputDataChannel is nulltpr");
}
startInput(inputDataChannel, *editorAttribute, supportPhysicalKbd);
delete editorAttribute;
reply.WriteNoException();
break;
}
@@ -120,6 +121,7 @@ namespace MiscServices {
case SET_KEYBOARD_TYPE: {
KeyboardType *type = data.ReadParcelable<KeyboardType>();
setKeyboardType(*type);
delete type;
reply.WriteNoException();
break;
}
@@ -158,6 +158,7 @@ using namespace MessageID;
if (textListener != nullptr) {
textListener->SendKeyboardInfo(*info);
}
delete info;
break;
}
case MSG_ID_SEND_FUNCTION_KEY: {
@@ -169,6 +170,7 @@ using namespace MessageID;
if (textListener != nullptr) {
textListener->SendKeyboardInfo(*info);
}
delete info;
break;
}
case MSG_ID_MOVE_CURSOR: {
@@ -35,6 +35,7 @@ namespace MiscServices {
virtual ~JsInputMethodEngineListener() = default;
void RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value);
void UnregisterListenerWithType(std::string type, NativeValue* value);
void UnregisterAllListenerWithType(std::string type);
void OnKeyboardStatus(bool isShow);
void OnInputStart();
void OnInputStop(std::string imeId);
@@ -35,6 +35,7 @@ namespace MiscServices {
virtual ~JsKeyboardDelegateListener() = default;
void RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value);
void UnregisterListenerWithType(std::string type, NativeValue* value);
void UnregisterAllListenerWithType(std::string type);
bool OnKeyEvent(int32_t keyCode, int32_t keyStatus);
void OnCursorUpdate(int32_t positionX, int32_t positionY, int height);
void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd);
@@ -94,13 +94,17 @@ namespace MiscServices {
return engine.CreateUndefined();
}
std::lock_guard<std::mutex> lock(mtx_);
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
if (info.argc == 1) {
imeListener_->UnregisterAllListenerWithType(cbType);
} else {
std::lock_guard<std::mutex> lock(mtx_);
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
}
imeListener_->UnregisterListenerWithType(cbType, value);
}
imeListener_->UnregisterListenerWithType(cbType, value);
return engine.CreateUndefined();
}
}
@@ -47,6 +47,24 @@ namespace MiscServices {
return;
}
void JsInputMethodEngineListener::UnregisterAllListenerWithType(std::string type)
{
IMSA_HILOGI("JsInputMethodEngineListener::UnregisterAllListenerWithType");
// should do type check
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str());
return;
}
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
jsCbMap_[type].erase(it);
}
// one type with multi jscallback, erase type when there is no callback in one type
if (jsCbMap_[type].empty()) {
jsCbMap_.erase(type);
}
return;
}
void JsInputMethodEngineListener::UnregisterListenerWithType(std::string type, NativeValue* value)
{
IMSA_HILOGI("JsInputMethodEngineListener::UnregisterListenerWithType");
@@ -95,12 +95,17 @@ namespace MiscServices {
}
std::lock_guard<std::mutex> lock(mtx_);
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsKeyboardDelegate::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
if (info.argc == 1) {
kdListener_->UnregisterAllListenerWithType(cbType);
} else {
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
IMSA_HILOGI("JsKeyboardDelegate::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
return engine.CreateUndefined();
}
kdListener_->UnregisterListenerWithType(cbType, value);
}
kdListener_->UnregisterListenerWithType(cbType, value);
return engine.CreateUndefined();
}
}
@@ -45,6 +45,23 @@ namespace MiscServices {
static_cast<uint32_t>(jsCbMap_.size()), type.c_str(), static_cast<uint32_t>(jsCbMap_[type].size()));
return;
}
void JsKeyboardDelegateListener::UnregisterAllListenerWithType(std::string type)
{
IMSA_HILOGI("JsKeyboardDelegateListener::UnregisterAllListenerWithType");
// should do type check
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str());
return;
}
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
jsCbMap_[type].erase(it);
}
// one type with multi jscallback, erase type when there is no callback in one type
if (jsCbMap_[type].empty()) {
jsCbMap_.erase(type);
}
return;
}
void JsKeyboardDelegateListener::UnregisterListenerWithType(std::string type, NativeValue* value)
{
+1
View File
@@ -1185,6 +1185,7 @@ namespace MiscServices {
}
int ret = AddClient(pid, uid, displayId, client, channel, *attribute);
delete attribute;
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("PerUserSession::OnPrepareInput Aborted! %{public}s", ErrorCode::ToString(ret));
return;