mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-19 12:08:05 -04:00
@@ -41,14 +41,11 @@ namespace MiscServices {
|
||||
EventTarget::~EventTarget()
|
||||
{
|
||||
EventListener *temp = nullptr;
|
||||
for (EventListener *i = first_; i != nullptr; i = temp)
|
||||
{
|
||||
for (EventListener *i = first_; i != nullptr; i = temp) {
|
||||
temp = i->next;
|
||||
if (i == first_)
|
||||
{
|
||||
if (i == first_) {
|
||||
first_ = first_->next;
|
||||
} else if (i == last_)
|
||||
{
|
||||
} else if (i == last_) {
|
||||
last_ = last_->back;
|
||||
} else {
|
||||
i->next->back = i->back;
|
||||
@@ -66,15 +63,13 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("EventTarget::On");
|
||||
auto tmp = new EventListener();
|
||||
|
||||
if (strncpy_s(tmp->type, LISTENER_TYPTE_MAX_LENGTH, type, strlen(type)) == -1)
|
||||
{
|
||||
if (strncpy_s(tmp->type, LISTENER_TYPTE_MAX_LENGTH, type, strlen(type)) == -1) {
|
||||
delete tmp;
|
||||
tmp = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (first_ == nullptr)
|
||||
{
|
||||
if (first_ == nullptr) {
|
||||
first_ = last_ = tmp;
|
||||
} else {
|
||||
last_->next = tmp;
|
||||
@@ -90,15 +85,13 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("EventTarget::Once");
|
||||
auto tmp = new EventListener();
|
||||
|
||||
if (strncpy_s(tmp->type, LISTENER_TYPTE_MAX_LENGTH, type, strlen(type)) == -1)
|
||||
{
|
||||
if (strncpy_s(tmp->type, LISTENER_TYPTE_MAX_LENGTH, type, strlen(type)) == -1) {
|
||||
delete tmp;
|
||||
tmp = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (first_ == nullptr)
|
||||
{
|
||||
if (first_ == nullptr) {
|
||||
first_ = last_ = tmp;
|
||||
} else {
|
||||
last_->next = tmp;
|
||||
@@ -114,24 +107,20 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("EventTarget::Off");
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(env_, &scope);
|
||||
if (scope == nullptr)
|
||||
{
|
||||
if (scope == nullptr) {
|
||||
HILOG_ERROR("scope is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
EventListener *temp = nullptr;
|
||||
for (EventListener *eventListener = first_; eventListener != nullptr; eventListener = temp)
|
||||
{
|
||||
for (EventListener *eventListener = first_; eventListener != nullptr; eventListener = temp) {
|
||||
temp = eventListener->next;
|
||||
bool isEquals = false;
|
||||
napi_value handlerTemp = nullptr;
|
||||
napi_get_reference_value(env_, eventListener->handlerRef, &handlerTemp);
|
||||
napi_strict_equals(env_, handlerTemp, handler, &isEquals);
|
||||
if (strcmp(eventListener->type, type) == 0 && isEquals)
|
||||
{
|
||||
if (eventListener == first_)
|
||||
{
|
||||
if (strcmp(eventListener->type, type) == 0 && isEquals) {
|
||||
if (eventListener == first_) {
|
||||
first_ = first_->next;
|
||||
} else if (eventListener == last_) {
|
||||
last_ = last_->back;
|
||||
@@ -152,13 +141,10 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("EventTarget::Off");
|
||||
EventListener *temp = nullptr;
|
||||
for (EventListener *eventListener = first_; eventListener != nullptr; eventListener = temp)
|
||||
{
|
||||
for (EventListener *eventListener = first_; eventListener != nullptr; eventListener = temp) {
|
||||
temp = eventListener->next;
|
||||
if (strcmp(eventListener->type, type) == 0)
|
||||
{
|
||||
if (eventListener == first_)
|
||||
{
|
||||
if (strcmp(eventListener->type, type) == 0) {
|
||||
if (eventListener == first_) {
|
||||
first_ = first_->next;
|
||||
} else if (eventListener == last_) {
|
||||
last_ = last_->back;
|
||||
@@ -181,17 +167,14 @@ namespace MiscServices {
|
||||
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_reference_value(env_, thisVarRef_, &thisVar);
|
||||
for (EventListener *eventListener = first_; eventListener != nullptr; eventListener = eventListener->next)
|
||||
{
|
||||
if (strcmp(eventListener->type, type) == 0)
|
||||
{
|
||||
for (EventListener *eventListener = first_; eventListener != nullptr; eventListener = eventListener->next) {
|
||||
if (strcmp(eventListener->type, type) == 0) {
|
||||
napi_value jsEvent = event ? event->ToJsObject() : nullptr;
|
||||
napi_value handler = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_get_reference_value(env_, eventListener->handlerRef, &handler);
|
||||
napi_call_function(env_, thisVar, handler, jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result);
|
||||
if (eventListener->isOnce)
|
||||
{
|
||||
if (eventListener->isOnce) {
|
||||
Off(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace MiscServices {
|
||||
|
||||
InputMethodAbility::~InputMethodAbility()
|
||||
{
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
@@ -47,11 +46,9 @@ namespace MiscServices {
|
||||
sptr<InputMethodAbility> InputMethodAbility::GetInstance()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::GetInstance");
|
||||
if (instance_ == nullptr)
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr)
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::GetInstance need new IMA");
|
||||
instance_ = new InputMethodAbility();
|
||||
}
|
||||
@@ -64,15 +61,13 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("InputMethodAbility::GetImsaProxy");
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr)
|
||||
{
|
||||
if (systemAbilityManager == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::GetImsaProxy systemAbilityManager is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
|
||||
if (systemAbility == nullptr)
|
||||
{
|
||||
if (systemAbility == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::GetImsaProxy systemAbility is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -88,8 +83,7 @@ namespace MiscServices {
|
||||
sptr<InputMethodCoreStub> stub = new InputMethodCoreStub(0);
|
||||
stub->SetMessageHandler(msgHandler);
|
||||
sptr<IInputMethodCore> stub2 = stub;
|
||||
if (mImms != nullptr)
|
||||
{
|
||||
if (mImms != nullptr) {
|
||||
mImms->setInputMethodCore(stub2);
|
||||
}
|
||||
IMSA_HILOGI("InputMethodAbility::OnConnect() mImms is nullptr");
|
||||
@@ -115,8 +109,7 @@ namespace MiscServices {
|
||||
|
||||
void InputMethodAbility::WorkThread()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
while(1) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_INITIALIZE_INPUT: {
|
||||
@@ -164,15 +157,13 @@ namespace MiscServices {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
displyId = data->ReadInt32();
|
||||
sptr<IRemoteObject> channelObject = data->ReadRemoteObject();
|
||||
if (channelObject == nullptr)
|
||||
{
|
||||
if (channelObject == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::OnInitialInput channelObject is nullptr");
|
||||
return;
|
||||
}
|
||||
sptr<InputControlChannelProxy> channelProxy = new InputControlChannelProxy(channelObject);
|
||||
inputControlChannel = channelProxy;
|
||||
if (inputControlChannel == nullptr)
|
||||
{
|
||||
if (inputControlChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::OnInitialInput inputControlChannel is nullptr");
|
||||
return;
|
||||
}
|
||||
@@ -185,20 +176,17 @@ namespace MiscServices {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
sptr<InputDataChannelProxy> channalProxy = new InputDataChannelProxy(data->ReadRemoteObject());
|
||||
inputDataChannel = channalProxy;
|
||||
if (inputDataChannel == nullptr)
|
||||
{
|
||||
if (inputDataChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::OnStartInput inputDataChannel is nullptr");
|
||||
}
|
||||
editorAttribute = data->ReadParcelable<InputAttribute>();
|
||||
if (editorAttribute == nullptr)
|
||||
{
|
||||
if (editorAttribute == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::OnStartInput editorAttribute is nullptr");
|
||||
}
|
||||
mSupportPhysicalKbd = data->ReadBool();
|
||||
|
||||
CreateInputMethodAgent(mSupportPhysicalKbd);
|
||||
if (inputControlChannel != nullptr)
|
||||
{
|
||||
if (inputControlChannel != nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::OnStartInput inputControlChannel is not nullptr");
|
||||
inputControlChannel->onAgentCreated(inputMethodAgent, nullptr);
|
||||
}
|
||||
@@ -219,8 +207,7 @@ namespace MiscServices {
|
||||
void InputMethodAbility::OnStopInput(Message *msg)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::OnStopInput");
|
||||
if (writeInputChannel != nullptr)
|
||||
{
|
||||
if (writeInputChannel != nullptr) {
|
||||
delete writeInputChannel;
|
||||
writeInputChannel = nullptr;
|
||||
}
|
||||
@@ -264,8 +251,7 @@ namespace MiscServices {
|
||||
bool InputMethodAbility::InsertText(const std::string text)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::InsertText");
|
||||
if (inputDataChannel == nullptr)
|
||||
{
|
||||
if (inputDataChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::InsertText inputDataChanel is nullptr");
|
||||
return false;
|
||||
}
|
||||
@@ -276,8 +262,7 @@ namespace MiscServices {
|
||||
void InputMethodAbility::DeleteBackward(int32_t length)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::DeleteBackward");
|
||||
if (inputDataChannel == nullptr)
|
||||
{
|
||||
if (inputDataChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodAbility::DeleteBackward inputDataChanel is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("InputMethodAgentProxy::DispatchKey key = %{public}d, status = %{public}d", key, status);
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor()))
|
||||
{
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
IMSA_HILOGI("InputMethodAgentProxy::DispatchKey descriptor is not match");
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAgentStub::OnRemoteRequest code = %{public}d", code);
|
||||
auto descriptorToken = data.ReadInterfaceToken();
|
||||
if (descriptorToken != GetDescriptor())
|
||||
{
|
||||
if (descriptorToken != GetDescriptor()) {
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
|
||||
}
|
||||
|
||||
@@ -45,8 +44,7 @@ namespace MiscServices {
|
||||
int32_t key = data.ReadInt32();
|
||||
int32_t status = data.ReadInt32();
|
||||
int32_t result = DispatchKey(key, status);
|
||||
if (result == ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (result == ErrorCode::NO_ERROR) {
|
||||
reply.WriteNoException();
|
||||
} else {
|
||||
reply.WriteInt32(result);
|
||||
@@ -63,8 +61,7 @@ namespace MiscServices {
|
||||
int32_t InputMethodAgentStub::DispatchKey(int32_t key, int32_t status)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAgentStub::DispatchKey key = %{public}d, status = %{public}d", key, status);
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
|
||||
@@ -31,13 +31,11 @@ namespace MiscServices {
|
||||
sptr<IInputControlChannel> &inputControlChannel)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput");
|
||||
if (startInputToken == nullptr)
|
||||
{
|
||||
if (startInputToken == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput startInputToken is nullptr");
|
||||
}
|
||||
|
||||
if (inputControlChannel == nullptr)
|
||||
{
|
||||
if (inputControlChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput inputControlChannel is nullptr");
|
||||
}
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput displayId = %{public}d", displayId);
|
||||
@@ -45,13 +43,11 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(displayId);
|
||||
sptr<IRemoteObject> channelObject = inputControlChannel->AsObject();
|
||||
if (channelObject == nullptr)
|
||||
{
|
||||
if (channelObject == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput channelObject is nullptr");
|
||||
}
|
||||
bool wor = data.WriteRemoteObject(channelObject);
|
||||
if (wor)
|
||||
{
|
||||
if (wor) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput Success to write inputControlChannel");
|
||||
} else {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput Failed to write inputControlChannel");
|
||||
@@ -60,8 +56,7 @@ namespace MiscServices {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
int32_t status = Remote()->SendRequest(INITIALIZE_INPUT, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::initializeInput status = %{public}d", status);
|
||||
return status;
|
||||
}
|
||||
@@ -73,8 +68,7 @@ namespace MiscServices {
|
||||
const InputAttribute& editorAttribute, bool supportPhysicalKbd)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::startInput");
|
||||
if (inputDataChannel == nullptr)
|
||||
{
|
||||
if (inputDataChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::startInput inputDataChannel is nullptr");
|
||||
}
|
||||
|
||||
@@ -82,8 +76,7 @@ namespace MiscServices {
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor())
|
||||
&& data.WriteRemoteObject(inputDataChannel->AsObject())
|
||||
&& data.WriteParcelable(&editorAttribute)
|
||||
&& data.WriteBool(supportPhysicalKbd)))
|
||||
{
|
||||
&& data.WriteBool(supportPhysicalKbd))) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::startInput write error");
|
||||
return false;
|
||||
}
|
||||
@@ -93,8 +86,7 @@ namespace MiscServices {
|
||||
};
|
||||
|
||||
int32_t status = Remote()->SendRequest(START_INPUT, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::startInput status = %{public}d", status);
|
||||
return false;
|
||||
}
|
||||
@@ -112,14 +104,12 @@ namespace MiscServices {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
int32_t status = Remote()->SendRequest(STOP_INPUT, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::stopInput status = %{public}d", status);
|
||||
return status;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (code != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::stopInput code = %{public}d", code);
|
||||
return code;
|
||||
}
|
||||
@@ -130,15 +120,13 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::showKeyboard");
|
||||
auto remote = Remote();
|
||||
if (remote == nullptr)
|
||||
{
|
||||
if (remote == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::showKeyboard remote is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteInt32(flags)))
|
||||
{
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteInt32(flags))) {
|
||||
return false;
|
||||
}
|
||||
MessageParcel reply;
|
||||
@@ -147,8 +135,7 @@ namespace MiscServices {
|
||||
};
|
||||
|
||||
int32_t res = remote->SendRequest(SHOW_KEYBOARD, data, reply, option);
|
||||
if (res != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (res != ErrorCode::NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -158,14 +145,12 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::hideKeyboard");
|
||||
auto remote = Remote();
|
||||
if (remote == nullptr)
|
||||
{
|
||||
if (remote == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteInt32(flags)))
|
||||
{
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteInt32(flags))) {
|
||||
return false;
|
||||
}
|
||||
MessageParcel reply;
|
||||
@@ -174,8 +159,7 @@ namespace MiscServices {
|
||||
};
|
||||
|
||||
int32_t res = remote->SendRequest(HIDE_KEYBOARD, data, reply, option);
|
||||
if (res != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (res != ErrorCode::NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -191,8 +175,7 @@ namespace MiscServices {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
int32_t status = Remote()->SendRequest(SET_KEYBOARD_TYPE, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int32_t code = reply.ReadException();
|
||||
@@ -208,13 +191,11 @@ namespace MiscServices {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
int32_t status = Remote()->SendRequest(GET_KEYBOARD_WINDOW_HEIGHT, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int32_t code = reply.ReadException();
|
||||
if (code != 0)
|
||||
{
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
retHeight = reply.ReadInt32();
|
||||
|
||||
@@ -44,8 +44,7 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest");
|
||||
auto descriptorToken = data.ReadInterfaceToken();
|
||||
if (descriptorToken != GetDescriptor())
|
||||
{
|
||||
if (descriptorToken != GetDescriptor()) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest descriptorToken is invalid");
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
|
||||
}
|
||||
@@ -55,13 +54,11 @@ namespace MiscServices {
|
||||
int32_t displayId = data.ReadInt32();
|
||||
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest displayId = %{public}d", displayId);
|
||||
sptr<IRemoteObject> channelObject = data.ReadRemoteObject();
|
||||
if (channelObject == nullptr)
|
||||
{
|
||||
if (channelObject == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest channelObject is nullptr");
|
||||
}
|
||||
sptr<IInputControlChannel> inputControlChannel = new InputControlChannelProxy(channelObject);
|
||||
if (inputControlChannel == nullptr)
|
||||
{
|
||||
if (inputControlChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest inputControlChannel is nullptr");
|
||||
}
|
||||
|
||||
@@ -74,8 +71,7 @@ namespace MiscServices {
|
||||
InputAttribute *editorAttribute = data.ReadParcelable<InputAttribute>();
|
||||
bool supportPhysicalKbd = data.ReadBool();
|
||||
|
||||
if (inputDataChannel == nullptr)
|
||||
{
|
||||
if (inputDataChannel == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest START_INPUT inputDataChannel is nulltpr");
|
||||
}
|
||||
startInput(inputDataChannel, *editorAttribute, supportPhysicalKbd);
|
||||
@@ -122,20 +118,17 @@ namespace MiscServices {
|
||||
sptr<IInputControlChannel>& inputControlChannel)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::initializeInput");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (startInputToken == nullptr)
|
||||
{
|
||||
if (startInputToken == nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::initializeInput startInputToken is nullptr");
|
||||
}
|
||||
|
||||
MessageParcel *data = new MessageParcel();
|
||||
data->WriteInt32(displayId);
|
||||
if (inputControlChannel != nullptr)
|
||||
{
|
||||
if (inputControlChannel != nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::initializeInput. inputControlChannel is not nullptr");
|
||||
data->WriteRemoteObject(inputControlChannel->AsObject());
|
||||
}
|
||||
@@ -148,13 +141,11 @@ namespace MiscServices {
|
||||
const InputAttribute& editorAttribute, bool supportPhysicalKbd)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::startInput");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
if (inputDataChannel != nullptr)
|
||||
{
|
||||
if (inputDataChannel != nullptr) {
|
||||
IMSA_HILOGI("InputMethodCoreStub::startInput inputDataChannel is not nullptr");
|
||||
data->WriteRemoteObject(inputDataChannel->AsObject());
|
||||
}
|
||||
@@ -168,8 +159,7 @@ namespace MiscServices {
|
||||
int32_t InputMethodCoreStub::stopInput()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::stopInput");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
@@ -181,8 +171,7 @@ namespace MiscServices {
|
||||
bool InputMethodCoreStub::showKeyboard(int32_t flags)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::showKeyboard");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
@@ -197,8 +186,7 @@ namespace MiscServices {
|
||||
bool InputMethodCoreStub::hideKeyboard(int32_t flags)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::hideKeyboard");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
@@ -213,8 +201,7 @@ namespace MiscServices {
|
||||
int32_t InputMethodCoreStub::setKeyboardType(const KeyboardType& type)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::setKeyboardType");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
@@ -228,8 +215,7 @@ namespace MiscServices {
|
||||
int32_t InputMethodCoreStub::getKeyboardWindowHeight(int32_t retHeight)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::getKeyboardWindowHeight");
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
if (msgHandler_ == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
|
||||
@@ -28,25 +28,21 @@ using namespace ErrorCode;
|
||||
IMSA_HILOGI("InputClientProxy::onInputReady");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor()))
|
||||
{
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(retValue))
|
||||
{
|
||||
if (!data.WriteInt32(retValue)) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
if (agent == nullptr)
|
||||
{
|
||||
if (agent == nullptr) {
|
||||
data.WriteInt32(0);
|
||||
} else {
|
||||
data.WriteInt32(1);
|
||||
data.WriteRemoteObject(agent->AsObject().GetRefPtr());
|
||||
}
|
||||
|
||||
if (channel == nullptr)
|
||||
{
|
||||
if (channel == nullptr) {
|
||||
data.WriteInt32(0);
|
||||
} else {
|
||||
data.WriteInt32(1);
|
||||
@@ -54,8 +50,7 @@ using namespace ErrorCode;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(ON_INPUT_READY, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputClientProxy::onInputReady SendRequest failed");
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
@@ -36,18 +36,15 @@ namespace MiscServices {
|
||||
}
|
||||
switch (code) {
|
||||
case ON_INPUT_READY: {
|
||||
if (msgHandler == nullptr)
|
||||
{
|
||||
if (msgHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
parcel->WriteInt32(data.ReadInt32());
|
||||
if (data.ReadInt32() > 0)
|
||||
{
|
||||
if (data.ReadInt32() > 0) {
|
||||
parcel->WriteRemoteObject(data.ReadRemoteObject());
|
||||
}
|
||||
if (data.ReadInt32() > 0)
|
||||
{
|
||||
if (data.ReadInt32() > 0) {
|
||||
parcel->WriteParcelable(data.ReadParcelable<InputChannel>());
|
||||
}
|
||||
|
||||
@@ -56,8 +53,7 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
case ON_INPUT_RELEASED: {
|
||||
if (msgHandler == nullptr)
|
||||
{
|
||||
if (msgHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
@@ -67,8 +63,7 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
case SET_DISPLAY_MODE: {
|
||||
if (msgHandler == nullptr)
|
||||
{
|
||||
if (msgHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
|
||||
@@ -33,8 +33,7 @@ namespace MiscServices {
|
||||
data.WriteString16(text);
|
||||
|
||||
auto ret = Remote()->SendRequest(INSERT_TEXT, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
auto result = reply.ReadBool();
|
||||
@@ -50,8 +49,7 @@ namespace MiscServices {
|
||||
data.WriteInt32(length);
|
||||
|
||||
auto ret = Remote()->SendRequest(DELETE_BACKWARD, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
auto result = reply.ReadBool();
|
||||
@@ -66,8 +64,7 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
|
||||
auto ret = Remote()->SendRequest(CLOSE, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace MiscServices {
|
||||
|
||||
InputDataChannelStub::~InputDataChannelStub()
|
||||
{
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
@@ -35,8 +34,7 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::OnRemoteRequest code = %{public}d", code);
|
||||
auto descriptorToken = data.ReadInterfaceToken();
|
||||
if (descriptorToken != GetDescriptor())
|
||||
{
|
||||
if (descriptorToken != GetDescriptor()) {
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
|
||||
}
|
||||
switch (code) {
|
||||
@@ -63,8 +61,7 @@ namespace MiscServices {
|
||||
bool InputDataChannelStub::InsertText(const std::u16string& text)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::InsertText");
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
MessageParcel *parcel = new MessageParcel;
|
||||
parcel->WriteString16(text);
|
||||
Message *msg = new Message(MessageID::MSG_ID_INSERT_CHAR, parcel);
|
||||
@@ -78,8 +75,7 @@ namespace MiscServices {
|
||||
bool InputDataChannelStub::DeleteBackward(int32_t length)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::DeleteBackward");
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
MessageParcel *parcel = new MessageParcel;
|
||||
parcel->WriteInt32(length);
|
||||
Message *msg = new Message(MessageID::MSG_ID_DELETE_BACKWARD, parcel);
|
||||
@@ -91,7 +87,6 @@ namespace MiscServices {
|
||||
|
||||
void InputDataChannelStub::Close()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InputDataChannelStub::SetHandler(MessageHandler *handler)
|
||||
|
||||
@@ -32,8 +32,7 @@ using namespace MessageID;
|
||||
|
||||
InputMethodController::~InputMethodController()
|
||||
{
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
@@ -42,11 +41,9 @@ using namespace MessageID;
|
||||
sptr<InputMethodController> InputMethodController::GetInstance()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetInstance");
|
||||
if (instance_ == nullptr)
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr)
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::GetInstance instance_ is nullptr");
|
||||
instance_ = new InputMethodController();
|
||||
}
|
||||
@@ -78,21 +75,18 @@ using namespace MessageID;
|
||||
IMSA_HILOGI("InputMethodController::GetImsaProxy");
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr)
|
||||
{
|
||||
if (systemAbilityManager == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::GetImsaProxy systemAbilityManager is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
|
||||
if (systemAbility == nullptr)
|
||||
{
|
||||
if (systemAbility == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::GetImsaProxy systemAbility is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (deathRecipient_ == nullptr)
|
||||
{
|
||||
if (deathRecipient_ == nullptr) {
|
||||
deathRecipient_ = new ImsaDeathRecipient();
|
||||
}
|
||||
systemAbility->AddDeathRecipient(deathRecipient_);
|
||||
@@ -109,8 +103,7 @@ using namespace MessageID;
|
||||
case MSG_ID_INSERT_CHAR: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
std::u16string text = data->ReadString16();
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
if (textListener != nullptr) {
|
||||
textListener->InsertText(text);
|
||||
}
|
||||
break;
|
||||
@@ -118,8 +111,7 @@ using namespace MessageID;
|
||||
case MSG_ID_DELETE_BACKWARD: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t length = data->ReadInt32();
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
if (textListener != nullptr) {
|
||||
textListener->DeleteBackward(length);
|
||||
}
|
||||
break;
|
||||
@@ -133,10 +125,8 @@ using namespace MessageID;
|
||||
case MSG_ID_ON_INPUT_READY: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
if (ret != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
if (textListener != nullptr) {
|
||||
textListener->SetKeyboardStatus(false);
|
||||
}
|
||||
mAgent = nullptr;
|
||||
@@ -144,8 +134,7 @@ using namespace MessageID;
|
||||
}
|
||||
sptr<IRemoteObject> object = data->ReadRemoteObject();
|
||||
mAgent = new InputMethodAgentProxy(object);
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
if (textListener != nullptr) {
|
||||
textListener->SetKeyboardStatus(true);
|
||||
}
|
||||
break;
|
||||
@@ -193,8 +182,7 @@ using namespace MessageID;
|
||||
sptr<InputDataChannelStub> &channel, InputAttribute &attribute)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::PrepareInput");
|
||||
if (mImms == nullptr)
|
||||
{
|
||||
if (mImms == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
@@ -202,8 +190,7 @@ using namespace MessageID;
|
||||
&& data.WriteInt32(displayId)
|
||||
&& data.WriteRemoteObject(client->AsObject())
|
||||
&& data.WriteRemoteObject(channel->AsObject())
|
||||
&& data.WriteParcelable(&attribute)))
|
||||
{
|
||||
&& data.WriteParcelable(&attribute))) {
|
||||
return;
|
||||
}
|
||||
mImms->prepareInput(data);
|
||||
@@ -212,14 +199,12 @@ using namespace MessageID;
|
||||
void InputMethodController::StartInput(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::StartInput");
|
||||
if (mImms == nullptr)
|
||||
{
|
||||
if (mImms == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(client->AsObject())))
|
||||
{
|
||||
&& data.WriteRemoteObject(client->AsObject()))) {
|
||||
return;
|
||||
}
|
||||
mImms->startInput(data);
|
||||
@@ -228,14 +213,12 @@ using namespace MessageID;
|
||||
void InputMethodController::ReleaseInput(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::ReleaseInput");
|
||||
if (mImms == nullptr)
|
||||
{
|
||||
if (mImms == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(client->AsObject().GetRefPtr())))
|
||||
{
|
||||
&& data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
|
||||
return;
|
||||
}
|
||||
mImms->releaseInput(data);
|
||||
@@ -244,14 +227,12 @@ using namespace MessageID;
|
||||
void InputMethodController::StopInput(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::StopInput");
|
||||
if (mImms == nullptr)
|
||||
{
|
||||
if (mImms == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(client->AsObject().GetRefPtr())))
|
||||
{
|
||||
&& data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
|
||||
return;
|
||||
}
|
||||
mImms->stopInput(data);
|
||||
|
||||
@@ -29,15 +29,13 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput reply failed");
|
||||
return;
|
||||
}
|
||||
@@ -49,15 +47,13 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput reply failed");
|
||||
return;
|
||||
}
|
||||
@@ -70,15 +66,13 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(START_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput reply failed");
|
||||
return;
|
||||
}
|
||||
@@ -91,15 +85,13 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(STOP_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput reply failed");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user