mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-23 14:49:59 +00:00
fix warning
Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
parent
96465d6a17
commit
d5cd7817f0
@ -33,11 +33,11 @@ namespace MiscServices {
|
||||
EventTarget(napi_env env, napi_value thisVar);
|
||||
virtual ~EventTarget();
|
||||
|
||||
virtual void On(const char* type, napi_value handler);
|
||||
virtual void Once(const char* type, napi_value handler);
|
||||
virtual void Off(const char* type, napi_value handler);
|
||||
virtual void Off(const char* type);
|
||||
virtual void Emit(const char* type, Event* event);
|
||||
virtual void On(const char *type, napi_value handler);
|
||||
virtual void Once(const char *type, napi_value handler);
|
||||
virtual void Off(const char *type, napi_value handler);
|
||||
virtual void Off(const char *type);
|
||||
virtual void Emit(const char *type, Event *event);
|
||||
|
||||
protected:
|
||||
napi_env env_;
|
||||
|
@ -41,11 +41,14 @@ 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;
|
||||
@ -53,22 +56,25 @@ namespace MiscServices {
|
||||
}
|
||||
napi_delete_reference(env_, i->handlerRef);
|
||||
delete i;
|
||||
i = nullptr;
|
||||
}
|
||||
napi_delete_reference(env_, thisVarRef_);
|
||||
}
|
||||
|
||||
void EventTarget::On(const char* type, napi_value handler)
|
||||
void EventTarget::On(const char *type, napi_value handler)
|
||||
{
|
||||
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;
|
||||
@ -79,18 +85,20 @@ namespace MiscServices {
|
||||
napi_create_reference(env_, handler, 1, &last_->handlerRef);
|
||||
}
|
||||
|
||||
void EventTarget::Once(const char* type, napi_value handler)
|
||||
void EventTarget::Once(const char *type, napi_value handler)
|
||||
{
|
||||
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;
|
||||
@ -106,20 +114,24 @@ 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;
|
||||
@ -136,14 +148,17 @@ namespace MiscServices {
|
||||
napi_close_handle_scope(env_, scope);
|
||||
}
|
||||
|
||||
void EventTarget::Off(const char* type)
|
||||
void EventTarget::Off(const char *type)
|
||||
{
|
||||
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;
|
||||
@ -158,7 +173,7 @@ namespace MiscServices {
|
||||
}
|
||||
}
|
||||
|
||||
void EventTarget::Emit(const char* type, Event *event)
|
||||
void EventTarget::Emit(const char *type, Event *event)
|
||||
{
|
||||
IMSA_HILOGI("EventTarget::Emit");
|
||||
napi_handle_scope scope = nullptr;
|
||||
@ -166,14 +181,17 @@ 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,17 +37,21 @@ namespace MiscServices {
|
||||
|
||||
InputMethodAbility::~InputMethodAbility()
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@ -60,13 +64,15 @@ 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;
|
||||
}
|
||||
@ -82,7 +88,8 @@ 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");
|
||||
@ -100,7 +107,8 @@ namespace MiscServices {
|
||||
});
|
||||
}
|
||||
|
||||
void InputMethodAbility::setEventTarget(sptr<EventTarget> &eventTarget) {
|
||||
void InputMethodAbility::setEventTarget(sptr<EventTarget> &eventTarget)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::setEventTarget");
|
||||
eventTarget_ = eventTarget;
|
||||
}
|
||||
@ -110,7 +118,7 @@ namespace MiscServices {
|
||||
while(1)
|
||||
{
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
switch(msg->msgId_) {
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_INITIALIZE_INPUT: {
|
||||
OnInitialInput(msg);
|
||||
break;
|
||||
@ -141,11 +149,12 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
|
||||
default:{
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete msg;
|
||||
msg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +164,8 @@ 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;
|
||||
}
|
||||
@ -209,8 +219,10 @@ namespace MiscServices {
|
||||
void InputMethodAbility::OnStopInput(Message *msg)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::OnStopInput");
|
||||
if (writeInputChannel != nullptr) {
|
||||
if (writeInputChannel != nullptr)
|
||||
{
|
||||
delete writeInputChannel;
|
||||
writeInputChannel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +264,8 @@ 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;
|
||||
}
|
||||
@ -263,7 +276,8 @@ 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,7 +28,8 @@ 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,7 +35,8 @@ 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;
|
||||
}
|
||||
|
||||
@ -44,7 +45,8 @@ 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);
|
||||
@ -61,7 +63,8 @@ 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,11 +31,13 @@ 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);
|
||||
@ -43,21 +45,23 @@ 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");
|
||||
}
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
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;
|
||||
}
|
||||
@ -69,7 +73,8 @@ namespace MiscServices {
|
||||
const InputAttribute& editorAttribute, bool supportPhysicalKbd)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::startInput");
|
||||
if (inputDataChannel == nullptr) {
|
||||
if (inputDataChannel == nullptr)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::startInput inputDataChannel is nullptr");
|
||||
}
|
||||
|
||||
@ -77,18 +82,19 @@ 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;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
@ -102,17 +108,18 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::stopInput");
|
||||
MessageParcel data, reply;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
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;
|
||||
}
|
||||
@ -123,23 +130,25 @@ 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;
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
|
||||
int32_t res = remote->SendRequest(SHOW_KEYBOARD, data, reply, option);
|
||||
if (res != ErrorCode::NO_ERROR) {
|
||||
if (res != ErrorCode::NO_ERROR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -149,22 +158,24 @@ 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;
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
|
||||
int32_t res = remote->SendRequest(HIDE_KEYBOARD, data, reply, option);
|
||||
if (res != ErrorCode::NO_ERROR) {
|
||||
if (res != ErrorCode::NO_ERROR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -176,12 +187,12 @@ namespace MiscServices {
|
||||
MessageParcel data, reply;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteParcelable(&type);
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
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();
|
||||
@ -193,16 +204,17 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::getKeyboardWindowHeight");
|
||||
MessageParcel data, reply;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
MessageOption option
|
||||
{
|
||||
MessageOption option {
|
||||
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,7 +44,8 @@ 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;
|
||||
}
|
||||
@ -54,11 +55,13 @@ 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");
|
||||
}
|
||||
|
||||
@ -71,7 +74,8 @@ 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);
|
||||
@ -118,17 +122,20 @@ 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());
|
||||
}
|
||||
@ -141,11 +148,13 @@ 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());
|
||||
}
|
||||
@ -159,7 +168,8 @@ 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();
|
||||
@ -171,7 +181,8 @@ namespace MiscServices {
|
||||
bool InputMethodCoreStub::showKeyboard(int32_t flags)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::showKeyboard");
|
||||
if (msgHandler_ == nullptr) {
|
||||
if (msgHandler_ == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
@ -186,7 +197,8 @@ 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();
|
||||
@ -201,7 +213,8 @@ 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();
|
||||
@ -215,7 +228,8 @@ 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();
|
||||
|
@ -24,19 +24,19 @@
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputClientStub : public IRemoteStub<IInputClient> {
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(InputClientStub);
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
InputClientStub();
|
||||
~InputClientStub();
|
||||
void SetHandler(MessageHandler *handler);
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(InputClientStub);
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
InputClientStub();
|
||||
~InputClientStub();
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
||||
int32_t onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent, const InputChannel *channel) override;
|
||||
int32_t onInputReleased(int32_t retValue) override;
|
||||
int32_t setDisplayMode(int32_t mode) override;
|
||||
private:
|
||||
MessageHandler *msgHandler = nullptr;
|
||||
};
|
||||
int32_t onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent, const InputChannel *channel) override;
|
||||
int32_t onInputReleased(int32_t retValue) override;
|
||||
int32_t setDisplayMode(int32_t mode) override;
|
||||
private:
|
||||
MessageHandler *msgHandler = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -24,19 +24,19 @@
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputDataChannelStub : public IRemoteStub<IInputDataChannel> {
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(InputDataChannelStub);
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
InputDataChannelStub();
|
||||
~InputDataChannelStub();
|
||||
void SetHandler(MessageHandler *handler);
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(InputDataChannelStub);
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
InputDataChannelStub();
|
||||
~InputDataChannelStub();
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
||||
bool InsertText(const std::u16string& text) override;
|
||||
bool DeleteBackward(int32_t length) override;
|
||||
void Close() override;
|
||||
private:
|
||||
MessageHandler *msgHandler;
|
||||
};
|
||||
bool InsertText(const std::u16string& text) override;
|
||||
bool DeleteBackward(int32_t length) override;
|
||||
void Close() override;
|
||||
private:
|
||||
MessageHandler *msgHandler;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -28,21 +28,25 @@ 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);
|
||||
@ -50,7 +54,8 @@ 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,15 +36,18 @@ 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>());
|
||||
}
|
||||
|
||||
@ -53,7 +56,8 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
case ON_INPUT_RELEASED: {
|
||||
if (msgHandler == nullptr) {
|
||||
if (msgHandler == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
@ -63,7 +67,8 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
case SET_DISPLAY_MODE: {
|
||||
if (msgHandler == nullptr) {
|
||||
if (msgHandler == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
|
@ -33,7 +33,8 @@ 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();
|
||||
@ -49,7 +50,8 @@ 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();
|
||||
@ -64,8 +66,8 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
|
||||
auto ret = Remote()->SendRequest(CLOSE, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,10 @@ namespace MiscServices {
|
||||
|
||||
InputDataChannelStub::~InputDataChannelStub()
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +35,8 @@ 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) {
|
||||
@ -60,7 +63,8 @@ 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);
|
||||
@ -74,7 +78,8 @@ 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);
|
||||
|
@ -32,17 +32,21 @@ using namespace MessageID;
|
||||
|
||||
InputMethodController::~InputMethodController()
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
if (msgHandler != nullptr)
|
||||
{
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@ -64,6 +68,8 @@ using namespace MessageID;
|
||||
|
||||
workThreadHandler = std::thread([this]{WorkThread();});
|
||||
mAttribute.SetInputPattern(InputAttribute::PATTERN_TEXT);
|
||||
|
||||
textListener = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -72,18 +78,21 @@ 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_);
|
||||
@ -96,70 +105,76 @@ using namespace MessageID;
|
||||
{
|
||||
while(1) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
switch(msg->msgId_) {
|
||||
case MSG_ID_INSERT_CHAR:{
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_INSERT_CHAR: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
std::u16string text = data->ReadString16();
|
||||
if(textListener != nullptr){
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
textListener->InsertText(text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_ID_DELETE_BACKWARD:{
|
||||
case MSG_ID_DELETE_BACKWARD: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t length = data->ReadInt32();
|
||||
if(textListener != nullptr){
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
textListener->DeleteBackward(length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_ID_SET_DISPLAY_MODE:{
|
||||
case MSG_ID_SET_DISPLAY_MODE: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
IMSA_HILOGI("MSG_ID_SET_DISPLAY_MODE : %{public}d", ret);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_ON_INPUT_READY:{
|
||||
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;
|
||||
mAgent = nullptr;
|
||||
break;
|
||||
}
|
||||
sptr<IRemoteObject> object = data->ReadRemoteObject();
|
||||
mAgent = new InputMethodAgentProxy(object);
|
||||
if (textListener != nullptr){
|
||||
if (textListener != nullptr)
|
||||
{
|
||||
textListener->SetKeyboardStatus(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_ID_EXIT_SERVICE:{
|
||||
case MSG_ID_EXIT_SERVICE: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
textListener = nullptr;
|
||||
IMSA_HILOGI("MSG_ID_EXIT_SERVICE : %{public}d", ret);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete msg;
|
||||
msg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodController::Attach()
|
||||
{
|
||||
PrepareInput(0,mClient,mInputDataChannel,mAttribute);
|
||||
PrepareInput(0, mClient, mInputDataChannel, mAttribute);
|
||||
}
|
||||
|
||||
void InputMethodController::ShowTextInput(sptr<OnTextChangedListener> &listener)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::ShowTextInput");
|
||||
textListener=listener;
|
||||
textListener = listener;
|
||||
StartInput(mClient);
|
||||
}
|
||||
|
||||
@ -178,15 +193,17 @@ using namespace MessageID;
|
||||
sptr<InputDataChannelStub> &channel, InputAttribute &attribute)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::PrepareInput");
|
||||
if(mImms == nullptr){
|
||||
if (mImms == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&&data.WriteInt32(displayId)
|
||||
&&data.WriteRemoteObject(client->AsObject())
|
||||
&&data.WriteRemoteObject(channel->AsObject())
|
||||
&&data.WriteParcelable(&attribute))){
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteInt32(displayId)
|
||||
&& data.WriteRemoteObject(client->AsObject())
|
||||
&& data.WriteRemoteObject(channel->AsObject())
|
||||
&& data.WriteParcelable(&attribute)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
mImms->prepareInput(data);
|
||||
@ -195,12 +212,14 @@ 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()))){
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(client->AsObject())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
mImms->startInput(data);
|
||||
@ -209,12 +228,14 @@ 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()))) {
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(client->AsObject().GetRefPtr())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
mImms->releaseInput(data);
|
||||
@ -223,12 +244,14 @@ 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()))) {
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(client->AsObject().GetRefPtr())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
mImms->stopInput(data);
|
||||
|
@ -29,13 +29,15 @@ 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;
|
||||
}
|
||||
@ -47,13 +49,15 @@ 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;
|
||||
}
|
||||
@ -65,14 +69,16 @@ namespace MiscServices {
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(START_INPUT,data,reply,option);
|
||||
if (ret != NO_ERROR) {
|
||||
auto ret = Remote()->SendRequest(START_INPUT, data, reply, option);
|
||||
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;
|
||||
}
|
||||
@ -84,14 +90,16 @@ namespace MiscServices {
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(STOP_INPUT,data,reply,option);
|
||||
if (ret != NO_ERROR) {
|
||||
auto ret = Remote()->SendRequest(STOP_INPUT, data, reply, option);
|
||||
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;
|
||||
}
|
||||
@ -110,11 +118,13 @@ namespace MiscServices {
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor())
|
||||
&& data.WriteRemoteObject(core->AsObject()))) {
|
||||
&& data.WriteRemoteObject(core->AsObject()))) {
|
||||
return -1;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option { MessageOption::TF_SYNC };
|
||||
MessageOption option {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
|
||||
int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_CORE, data, reply, option);
|
||||
|
||||
@ -131,9 +141,9 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
if (!(data.WriteInt32(displayId)
|
||||
&& data.WriteRemoteObject(client->AsObject())
|
||||
&& data.WriteRemoteObject(channel->AsObject())
|
||||
&& data.WriteParcelable(&attribute))) {
|
||||
&& data.WriteRemoteObject(client->AsObject())
|
||||
&& data.WriteRemoteObject(channel->AsObject())
|
||||
&& data.WriteParcelable(&attribute))) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
@ -300,8 +310,13 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
KeyboardType *keyType = reply.ReadParcelable<KeyboardType>();
|
||||
if (keyType == nullptr)
|
||||
{
|
||||
return ERROR_STATUS_BAD_INDEX;
|
||||
}
|
||||
*retType = *keyType;
|
||||
delete keyType;
|
||||
keyType = nullptr;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ import { AsyncCallback } from './basic';
|
||||
* @since 7
|
||||
* @devices phone, tablet, tv, wearable
|
||||
*/
|
||||
declare namespace inputMethodAbility {
|
||||
declare namespace inputMethodEngine {
|
||||
function on(type: 'keyboardShow', callback: () => void): void;
|
||||
function off(type: 'keyboardShow', callback: () => void): void;
|
||||
|
||||
@ -38,4 +38,4 @@ declare namespace inputMethodAbility {
|
||||
function HideKeyboardSelf(): Promise<void>;
|
||||
}
|
||||
|
||||
export default inputMethodAbility;
|
||||
export default inputMethodEngine;
|
@ -37,7 +37,7 @@ ohos_shared_library("inputmethodability") {
|
||||
"-g3",
|
||||
]
|
||||
|
||||
sources = [ "js_input_method_ability.cpp" ]
|
||||
sources = [ "js_input_method_engine.cpp" ]
|
||||
|
||||
configs = [ ":inputmethodability_native_config" ]
|
||||
|
||||
|
@ -24,14 +24,16 @@ napi_value JS_Constructor(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_Constructor() is called!");
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, nullptr, nullptr, &thisVar, &data);
|
||||
|
||||
OHOS::MiscServices::EventTarget *eventTarget = new OHOS::MiscServices::EventTarget(env,thisVar);
|
||||
OHOS::MiscServices::EventTarget *eventTarget = new OHOS::MiscServices::EventTarget(env, thisVar);
|
||||
napi_wrap(env, thisVar, eventTarget,
|
||||
[](napi_env env, void* data, void* hint){
|
||||
[](napi_env env, void *data, void *hint)
|
||||
{
|
||||
EventTarget *eventTarget = (EventTarget*)data;
|
||||
delete eventTarget;
|
||||
eventTarget = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
OHOS::sptr<EventTarget> eventTarget_ = eventTarget;
|
||||
@ -45,7 +47,7 @@ napi_value JS_InsertText(napi_env env, napi_callback_info cbInfo)
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
@ -54,7 +56,7 @@ napi_value JS_InsertText(napi_env env, napi_callback_info cbInfo)
|
||||
char type[64] = { 0 };
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
std::string text=type;
|
||||
std::string text = type;
|
||||
InputMethodAbility::GetInstance()->InsertText(text);
|
||||
|
||||
napi_value result = nullptr;
|
||||
@ -69,7 +71,7 @@ napi_value JS_DeleteBackward(napi_env env, napi_callback_info cbInfo)
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
@ -90,7 +92,7 @@ napi_value JS_HideKeyboardSelf(napi_env env, napi_callback_info cbInfo)
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
@ -110,7 +112,7 @@ napi_value JS_On(napi_env env, napi_callback_info cbInfo)
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = 0;
|
||||
void* data = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
@ -145,7 +147,7 @@ napi_value JS_Off(napi_env env, napi_callback_info cbInfo)
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = 0;
|
||||
void* data = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
@ -157,7 +159,7 @@ napi_value JS_Off(napi_env env, napi_callback_info cbInfo)
|
||||
napi_typeof(env, argv[0], &eventValueType);
|
||||
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
|
||||
|
||||
char* type = nullptr;
|
||||
char *type = nullptr;
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen);
|
||||
type = new char[typeLen + 1];
|
||||
@ -172,6 +174,7 @@ napi_value JS_Off(napi_env env, napi_callback_info cbInfo)
|
||||
|
||||
delete type;
|
||||
delete type;
|
||||
type = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
@ -189,7 +192,7 @@ napi_value InputMethodAbilityInit(napi_env env, napi_value exports)
|
||||
DECLARE_NAPI_FUNCTION("on", JS_On),
|
||||
DECLARE_NAPI_FUNCTION("off", JS_Off),
|
||||
};
|
||||
napi_define_class(env, className, sizeof(className),JS_Constructor, nullptr,
|
||||
napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr,
|
||||
sizeof(desc) / sizeof(desc[0]), desc, &constructor);
|
||||
napi_set_named_property(env, exports, "InputMethodAbility", constructor);
|
||||
return exports;
|
||||
@ -199,13 +202,13 @@ napi_value InputMethodAbilityInit(napi_env env, napi_value exports)
|
||||
* module define
|
||||
*/
|
||||
static napi_module inputMethodAbilityModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = InputMethodAbilityInit,
|
||||
.nm_modname = "inputMethodAbility",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = InputMethodAbilityInit,
|
||||
.nm_modname = "inputMethodEngine",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = {0},
|
||||
};
|
||||
/*
|
||||
* module register
|
@ -52,7 +52,7 @@ namespace MiscServices {
|
||||
virtual void releaseInput(MessageParcel& data) = 0;
|
||||
virtual void startInput(MessageParcel& data) = 0;
|
||||
virtual void stopInput(MessageParcel& data) = 0;
|
||||
virtual int32_t setInputMethodCore(sptr<IInputMethodCore> &core)=0;
|
||||
virtual int32_t setInputMethodCore(sptr<IInputMethodCore> &core) = 0;
|
||||
|
||||
virtual int32_t getDisplayMode(int32_t retMode) = 0;
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0;
|
||||
|
@ -23,7 +23,7 @@ namespace MiscServices {
|
||||
public:
|
||||
InputAttribute();
|
||||
InputAttribute(const InputAttribute& attribute);
|
||||
InputAttribute& operator=(const InputAttribute& attribute);
|
||||
InputAttribute& operator = (const InputAttribute& attribute);
|
||||
~InputAttribute();
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static InputAttribute *Unmarshalling(Parcel &parcel);
|
||||
|
@ -15,10 +15,10 @@
|
||||
|
||||
#ifndef FM_IMMS_PROJECT__INPUTCHANNEL_H
|
||||
#define FM_IMMS_PROJECT__INPUTCHANNEL_H
|
||||
#include <string>
|
||||
#include "parcel.h"
|
||||
#include "global.h"
|
||||
#include "message_parcel.h"
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -32,7 +32,7 @@ namespace MiscServices {
|
||||
std::u16string name;
|
||||
MessageParcel inputChannelParcel;
|
||||
InputChannel(const InputChannel& channel);
|
||||
InputChannel& operator=(const InputChannel& channel);
|
||||
InputChannel& operator = (const InputChannel& channel);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace OHOS {
|
||||
virtual void onKeyboardShowed() override;
|
||||
|
||||
void ResetFlag();
|
||||
bool GetAgentAndChannel(sptr<IInputMethodAgent>* retAgent, InputChannel** retChannel);
|
||||
bool GetAgentAndChannel(sptr<IInputMethodAgent> *retAgent, InputChannel **retChannel);
|
||||
bool WaitKeyboardReady();
|
||||
private:
|
||||
int userId_;
|
||||
|
@ -22,25 +22,25 @@
|
||||
#include "global.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputMethodAbilityConnectionStub : public AAFwk::AbilityConnectionStub {
|
||||
public:
|
||||
enum MessageID {
|
||||
MSG_ID_ABILITY_CONNECT_DONE = 1,
|
||||
MSG_ID_ABILITY_DISCONNECT_DONE,
|
||||
};
|
||||
|
||||
InputMethodAbilityConnectionStub(const int index);
|
||||
~InputMethodAbilityConnectionStub();
|
||||
void OnAbilityConnectDone(const AppExecFwk::ElementName &element,
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
||||
private:
|
||||
MessageHandler *messageHandler;
|
||||
int mIndex;
|
||||
namespace MiscServices {
|
||||
class InputMethodAbilityConnectionStub : public AAFwk::AbilityConnectionStub {
|
||||
public:
|
||||
enum MessageID {
|
||||
MSG_ID_ABILITY_CONNECT_DONE = 1,
|
||||
MSG_ID_ABILITY_DISCONNECT_DONE,
|
||||
};
|
||||
}
|
||||
|
||||
InputMethodAbilityConnectionStub(const int index);
|
||||
~InputMethodAbilityConnectionStub();
|
||||
void OnAbilityConnectDone(const AppExecFwk::ElementName &element,
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
||||
private:
|
||||
MessageHandler *messageHandler;
|
||||
int mIndex;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H
|
@ -16,8 +16,8 @@
|
||||
#ifndef FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H
|
||||
#define FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H
|
||||
#include <vector>
|
||||
#include "parcel.h"
|
||||
#include <string>
|
||||
#include "parcel.h"
|
||||
#include "keyboard_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -35,7 +35,7 @@ namespace MiscServices {
|
||||
InputMethodProperty();
|
||||
~InputMethodProperty();
|
||||
InputMethodProperty(const InputMethodProperty& property);
|
||||
InputMethodProperty& operator=(const InputMethodProperty& property);
|
||||
InputMethodProperty& operator = (const InputMethodProperty& property);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static InputMethodProperty *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
|
@ -17,9 +17,9 @@
|
||||
#define FM_IMMS_PROJECT_INPUTMETHODSETTING_H
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "string.h"
|
||||
#include "global.h"
|
||||
#include "parcel.h"
|
||||
#include "string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -36,7 +36,7 @@ namespace MiscServices {
|
||||
InputMethodSetting();
|
||||
~InputMethodSetting();
|
||||
InputMethodSetting(const InputMethodSetting& inputMethodSetting);
|
||||
InputMethodSetting& operator=(const InputMethodSetting& inputMethodSetting);
|
||||
InputMethodSetting& operator = (const InputMethodSetting& inputMethodSetting);
|
||||
|
||||
void SetValue(const std::u16string& key, const std::u16string& value);
|
||||
std::u16string GetValue(const std::u16string& key) const;
|
||||
|
@ -17,8 +17,8 @@
|
||||
#define FM_IMMS_PROJECT_KEYBOARDTYPE_H
|
||||
|
||||
#include <vector>
|
||||
#include "parcel.h"
|
||||
#include <string>
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -27,7 +27,7 @@ namespace MiscServices {
|
||||
KeyboardType();
|
||||
KeyboardType(const KeyboardType& type);
|
||||
~KeyboardType();
|
||||
KeyboardType& operator=(const KeyboardType& type);
|
||||
KeyboardType& operator = (const KeyboardType& type);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static KeyboardType *Unmarshalling(Parcel &parcel);
|
||||
void setId(int32_t typeId);
|
||||
|
@ -27,11 +27,11 @@ namespace MiscServices {
|
||||
MessageParcel *msgContent_ = nullptr; // message content
|
||||
Message(int32_t msgId, MessageParcel *msgContent);
|
||||
explicit Message(const Message& msg);
|
||||
Message& operator= (const Message& msg);
|
||||
Message& operator = (const Message& msg);
|
||||
~Message();
|
||||
private:
|
||||
Message(const Message&&);
|
||||
Message& operator= (const Message&&);
|
||||
Message& operator = (const Message&&);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -90,9 +90,9 @@ class MessageHandler {
|
||||
std::queue<Message*> mQueue ; // Message queue, guarded by mMutex;
|
||||
|
||||
MessageHandler(const MessageHandler&);
|
||||
MessageHandler& operator= (const MessageHandler&);
|
||||
MessageHandler& operator = (const MessageHandler&);
|
||||
MessageHandler(const MessageHandler&&);
|
||||
MessageHandler& operator= (const MessageHandler&&);
|
||||
MessageHandler& operator = (const MessageHandler&&);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -43,27 +43,27 @@
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class RemoteObjectDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
RemoteObjectDeathRecipient(int userId, int msgId);
|
||||
~RemoteObjectDeathRecipient();
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& who) override;
|
||||
private:
|
||||
int userId_; // the id of the user to whom the object is linking
|
||||
int msgId_; // the message id can be MessageID::MSG_ID_CLIENT_DIED and MessageID::MSG_ID_IMS_DIED
|
||||
};
|
||||
public:
|
||||
RemoteObjectDeathRecipient(int userId, int msgId);
|
||||
~RemoteObjectDeathRecipient();
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& who) override;
|
||||
private:
|
||||
int userId_; // the id of the user to whom the object is linking
|
||||
int msgId_; // the message id can be MessageID::MSG_ID_CLIENT_DIED and MessageID::MSG_ID_IMS_DIED
|
||||
};
|
||||
|
||||
/*! \class ClientInfo
|
||||
\brief The class defines the details of an input client.
|
||||
*/
|
||||
class ClientInfo {
|
||||
public:
|
||||
int pid; // the process id of the process in which the input client is running
|
||||
int uid; // the uid of the process in which the input client is running
|
||||
int userId; // the user if of the user under which the input client is running
|
||||
int displayId; // the display id on which the input client is showing
|
||||
sptr<IInputClient> client; // the remote object handler for the service to callback to the input client
|
||||
sptr<IInputDataChannel> channel; // the remote object handler for IMSA callback to input client
|
||||
InputAttribute attribute; // the input attribute of the input client
|
||||
public:
|
||||
int pid; // the process id of the process in which the input client is running
|
||||
int uid; // the uid of the process in which the input client is running
|
||||
int userId; // the user if of the user under which the input client is running
|
||||
int displayId; // the display id on which the input client is showing
|
||||
sptr<IInputClient> client; // the remote object handler for the service to callback to the input client
|
||||
sptr<IInputDataChannel> channel; // the remote object handler for IMSA callback to input client
|
||||
InputAttribute attribute; // the input attribute of the input client
|
||||
|
||||
ClientInfo(int pid, int uid, int userId, int displayId, const sptr<IInputClient>& client,
|
||||
const sptr<IInputDataChannel>& channel, const InputAttribute& attribute)
|
||||
@ -90,99 +90,99 @@ namespace MiscServices {
|
||||
This class manages the sessions between input clients and input method engines for each unlocked user.
|
||||
*/
|
||||
class PerUserSession {
|
||||
enum {
|
||||
DEFAULT_IME = 0, // index for default input method service
|
||||
SECURITY_IME = 1, // index for security input method service
|
||||
MAX_IME = 2, // the maximum count of ims started for a user
|
||||
};
|
||||
enum {
|
||||
DEFAULT_IME = 0, // index for default input method service
|
||||
SECURITY_IME = 1, // index for security input method service
|
||||
MAX_IME = 2, // the maximum count of ims started for a user
|
||||
};
|
||||
|
||||
public:
|
||||
explicit PerUserSession(int userId);
|
||||
~PerUserSession();
|
||||
public:
|
||||
explicit PerUserSession(int userId);
|
||||
~PerUserSession();
|
||||
|
||||
void SetCurrentIme(InputMethodProperty *ime);
|
||||
void SetSecurityIme(InputMethodProperty *ime);
|
||||
void SetInputMethodSetting(InputMethodSetting *setting);
|
||||
void ResetIme(InputMethodProperty *defaultIme, InputMethodProperty *securityIme);
|
||||
void OnPackageRemoved(const std::u16string& packageName);
|
||||
void SetCurrentIme(InputMethodProperty *ime);
|
||||
void SetSecurityIme(InputMethodProperty *ime);
|
||||
void SetInputMethodSetting(InputMethodSetting *setting);
|
||||
void ResetIme(InputMethodProperty *defaultIme, InputMethodProperty *securityIme);
|
||||
void OnPackageRemoved(const std::u16string& packageName);
|
||||
|
||||
int GetDisplayMode();
|
||||
int GetKeyboardWindowHeight(int retHeight);
|
||||
KeyboardType *GetCurrentKeyboardType();
|
||||
int GetDisplayMode();
|
||||
int GetKeyboardWindowHeight(int retHeight);
|
||||
KeyboardType *GetCurrentKeyboardType();
|
||||
|
||||
int OnSettingChanged(const std::u16string& key, const std::u16string& value);
|
||||
void Dump(int fd);
|
||||
void CreateWorkThread(MessageHandler& handler);
|
||||
void JoinWorkThread();
|
||||
void SetInputMethodAbility(sptr<InputMethodAbility> &inputMethodAbility);
|
||||
static void BindInputAbility();
|
||||
private:
|
||||
int userId_; // the id of the user to whom the object is linking
|
||||
int userState; // the state of the user to whom the object is linking
|
||||
int displayId; // the id of the display screen on which the user is
|
||||
int currentIndex;
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*> mapClients;
|
||||
int OnSettingChanged(const std::u16string& key, const std::u16string& value);
|
||||
void Dump(int fd);
|
||||
void CreateWorkThread(MessageHandler& handler);
|
||||
void JoinWorkThread();
|
||||
void SetInputMethodAbility(sptr<InputMethodAbility> &inputMethodAbility);
|
||||
static void BindInputAbility();
|
||||
private:
|
||||
int userId_; // the id of the user to whom the object is linking
|
||||
int userState; // the state of the user to whom the object is linking
|
||||
int displayId; // the id of the display screen on which the user is
|
||||
int currentIndex;
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*> mapClients;
|
||||
|
||||
InputMethodProperty *currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime
|
||||
InputMethodProperty *currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime
|
||||
|
||||
InputControlChannelStub *localControlChannel[MAX_IME];
|
||||
sptr<IInputControlChannel> inputControlChannel[MAX_IME];
|
||||
sptr<IInputMethodCore> imsCore[MAX_IME]; // the remote handlers of input method service
|
||||
sptr<IRemoteObject> inputMethodToken[MAX_IME]; // the window token of keyboard
|
||||
int currentKbdIndex[MAX_IME]; // current keyboard index
|
||||
int lastImeIndex; // The last ime which showed keyboard
|
||||
InputMethodSetting *inputMethodSetting; // The pointer referred to the object in PerUserSetting
|
||||
int currentDisplayMode; // the display mode of the current keyboard
|
||||
InputControlChannelStub *localControlChannel[MAX_IME];
|
||||
sptr<IInputControlChannel> inputControlChannel[MAX_IME];
|
||||
sptr<IInputMethodCore> imsCore[MAX_IME]; // the remote handlers of input method service
|
||||
sptr<IRemoteObject> inputMethodToken[MAX_IME]; // the window token of keyboard
|
||||
int currentKbdIndex[MAX_IME]; // current keyboard index
|
||||
int lastImeIndex; // The last ime which showed keyboard
|
||||
InputMethodSetting *inputMethodSetting; // The pointer referred to the object in PerUserSetting
|
||||
int currentDisplayMode; // the display mode of the current keyboard
|
||||
|
||||
sptr<IInputMethodAgent> imsAgent;
|
||||
InputChannel *imsChannel; // the write channel created by input method service
|
||||
sptr<IInputClient> currentClient; // the current input client
|
||||
sptr<IInputClient> needReshowClient; // the input client for which keyboard need to re-show
|
||||
sptr<IInputMethodAgent> imsAgent;
|
||||
InputChannel *imsChannel; // the write channel created by input method service
|
||||
sptr<IInputClient> currentClient; // the current input client
|
||||
sptr<IInputClient> needReshowClient; // the input client for which keyboard need to re-show
|
||||
|
||||
sptr<RemoteObjectDeathRecipient> clientDeathRecipient; // remote object death monitor for input client
|
||||
sptr<RemoteObjectDeathRecipient> imsDeathRecipient;
|
||||
MessageHandler *msgHandler = nullptr; // message handler working with Work Thread
|
||||
std::thread workThreadHandler; // work thread handler
|
||||
std::mutex mtx; // mutex to lock the operations among multi work threads
|
||||
sptr<AAFwk::AbilityConnectionProxy> connCallback;
|
||||
sptr<InputMethodAbility> inputMethodAbility_;
|
||||
sptr<RemoteObjectDeathRecipient> clientDeathRecipient; // remote object death monitor for input client
|
||||
sptr<RemoteObjectDeathRecipient> imsDeathRecipient;
|
||||
MessageHandler *msgHandler = nullptr; // message handler working with Work Thread
|
||||
std::thread workThreadHandler; // work thread handler
|
||||
std::mutex mtx; // mutex to lock the operations among multi work threads
|
||||
sptr<AAFwk::AbilityConnectionProxy> connCallback;
|
||||
sptr<InputMethodAbility> inputMethodAbility_;
|
||||
|
||||
PerUserSession(const PerUserSession&);
|
||||
PerUserSession& operator= (const PerUserSession&);
|
||||
PerUserSession(const PerUserSession&&);
|
||||
PerUserSession& operator= (const PerUserSession&&);
|
||||
int IncreaseOrResetImeError(bool resetFlag, int imeIndex);
|
||||
KeyboardType *GetKeyboardType(int imeIndex, int typeIndex);
|
||||
void ResetCurrentKeyboardType(int imeIndex);
|
||||
int OnCurrentKeyboardTypeChanged(int index, const std::u16string& value);
|
||||
void DumpClientInfo(int fd, const ClientInfo& clientInfo);
|
||||
void DumpCurrentSession(int fd);
|
||||
void CopyInputMethodService(int imeIndex);
|
||||
ClientInfo *GetClientInfo(const sptr<IInputClient>& inputClient);
|
||||
void WorkThread();
|
||||
void OnPrepareInput(Message *msg);
|
||||
void OnReleaseInput(Message *msg);
|
||||
void OnStartInput(Message *msg);
|
||||
void OnStopInput(Message *msg);
|
||||
void OnClientDied(const wptr<IRemoteObject>& who);
|
||||
void OnImsDied(const wptr<IRemoteObject>& who);
|
||||
void OnHideKeyboardSelf(int flags);
|
||||
void OnAdvanceToNext();
|
||||
void OnSetDisplayMode(int mode);
|
||||
void OnRestartIms(int index, const std::u16string& imeId);
|
||||
void OnUserLocked();
|
||||
int AddClient(int pid, int uid, int displayId, const sptr<IInputClient>& inputClient,
|
||||
const sptr<IInputDataChannel>& channel,
|
||||
const InputAttribute& attribute);
|
||||
int RemoveClient(const sptr<IInputClient>& inputClient, int retClientNum);
|
||||
int StartInputMethod(int index);
|
||||
int StopInputMethod(int index);
|
||||
int ShowKeyboard(const sptr<IInputClient>& inputClient);
|
||||
int HideKeyboard(const sptr<IInputClient>& inputClient);
|
||||
void SetDisplayId(int displayId);
|
||||
int GetImeIndex(const sptr<IInputClient>& inputClient);
|
||||
static sptr<AAFwk::IAbilityManager> GetAbilityManagerService();
|
||||
void onSetInputMethodCore(Message *msg);
|
||||
PerUserSession(const PerUserSession&);
|
||||
PerUserSession& operator = (const PerUserSession&);
|
||||
PerUserSession(const PerUserSession&&);
|
||||
PerUserSession& operator = (const PerUserSession&&);
|
||||
int IncreaseOrResetImeError(bool resetFlag, int imeIndex);
|
||||
KeyboardType *GetKeyboardType(int imeIndex, int typeIndex);
|
||||
void ResetCurrentKeyboardType(int imeIndex);
|
||||
int OnCurrentKeyboardTypeChanged(int index, const std::u16string& value);
|
||||
void DumpClientInfo(int fd, const ClientInfo& clientInfo);
|
||||
void DumpCurrentSession(int fd);
|
||||
void CopyInputMethodService(int imeIndex);
|
||||
ClientInfo *GetClientInfo(const sptr<IInputClient>& inputClient);
|
||||
void WorkThread();
|
||||
void OnPrepareInput(Message *msg);
|
||||
void OnReleaseInput(Message *msg);
|
||||
void OnStartInput(Message *msg);
|
||||
void OnStopInput(Message *msg);
|
||||
void OnClientDied(const wptr<IRemoteObject>& who);
|
||||
void OnImsDied(const wptr<IRemoteObject>& who);
|
||||
void OnHideKeyboardSelf(int flags);
|
||||
void OnAdvanceToNext();
|
||||
void OnSetDisplayMode(int mode);
|
||||
void OnRestartIms(int index, const std::u16string& imeId);
|
||||
void OnUserLocked();
|
||||
int AddClient(int pid, int uid, int displayId, const sptr<IInputClient>& inputClient,
|
||||
const sptr<IInputDataChannel>& channel,
|
||||
const InputAttribute& attribute);
|
||||
int RemoveClient(const sptr<IInputClient>& inputClient, int retClientNum);
|
||||
int StartInputMethod(int index);
|
||||
int StopInputMethod(int index);
|
||||
int ShowKeyboard(const sptr<IInputClient>& inputClient);
|
||||
int HideKeyboard(const sptr<IInputClient>& inputClient);
|
||||
void SetDisplayId(int displayId);
|
||||
int GetImeIndex(const sptr<IInputClient>& inputClient);
|
||||
static sptr<AAFwk::IAbilityManager> GetAbilityManagerService();
|
||||
void onSetInputMethodCore(Message *msg);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ namespace MiscServices {
|
||||
InputMethodSetting inputMethodSetting; // the object to manage the setting data for this user
|
||||
|
||||
PerUserSetting(const PerUserSetting&);
|
||||
PerUserSetting& operator= (const PerUserSetting&);
|
||||
PerUserSetting& operator = (const PerUserSetting&);
|
||||
PerUserSetting(const PerUserSetting&&);
|
||||
PerUserSetting& operator= (const PerUserSetting&&);
|
||||
PerUserSetting& operator = (const PerUserSetting&&);
|
||||
void InitInputMethodSetting();
|
||||
void ResetCurrentInputMethod();
|
||||
std::u16string GetKeyboardTypeLanguage(const InputMethodProperty *property, int32_t hashCode);
|
||||
|
@ -27,40 +27,39 @@
|
||||
#include "input_method_setting.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class Platform {
|
||||
public:
|
||||
static Platform *Instance();
|
||||
void SetPlatform(const sptr<IPlatformApi>& platformApi);
|
||||
sptr<IInputMethodCore> BindInputMethodService(int userId, const std::u16string& packageName,
|
||||
const std::u16string& intention);
|
||||
int UnbindInputMethodService(int userId, const std::u16string& packageName);
|
||||
sptr<IRemoteObject> CreateWindowToken(int userId, int displayId, const std::u16string& packageName);
|
||||
int DestroyWindowToken(int userId, const std::u16string& packageName);
|
||||
int ListInputMethod(int userId, std::vector<InputMethodProperty*> *properties);
|
||||
int GetInputMethodProperty(int userId, const std::u16string& packageName,
|
||||
InputMethodProperty *inputMethodProperty);
|
||||
int GetInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting);
|
||||
int SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting);
|
||||
bool CheckPhysicalKeyboard();
|
||||
bool IsValidWindow(int uid, int pid, int displayId);
|
||||
bool IsWindowFocused(int uid, int pid, int displayId);
|
||||
namespace MiscServices {
|
||||
class Platform {
|
||||
public:
|
||||
static Platform *Instance();
|
||||
void SetPlatform(const sptr<IPlatformApi>& platformApi);
|
||||
sptr<IInputMethodCore> BindInputMethodService(int userId, const std::u16string& packageName,
|
||||
const std::u16string& intention);
|
||||
int UnbindInputMethodService(int userId, const std::u16string& packageName);
|
||||
sptr<IRemoteObject> CreateWindowToken(int userId, int displayId, const std::u16string& packageName);
|
||||
int DestroyWindowToken(int userId, const std::u16string& packageName);
|
||||
int ListInputMethod(int userId, std::vector<InputMethodProperty*> *properties);
|
||||
int GetInputMethodProperty(int userId, const std::u16string& packageName,
|
||||
InputMethodProperty *inputMethodProperty);
|
||||
int GetInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting);
|
||||
int SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting);
|
||||
bool CheckPhysicalKeyboard();
|
||||
bool IsValidWindow(int uid, int pid, int displayId);
|
||||
bool IsWindowFocused(int uid, int pid, int displayId);
|
||||
|
||||
static inline sptr<IRemoteObject> RemoteBrokerToObject(const sptr<IRemoteBroker>& broker)
|
||||
{
|
||||
return broker->AsObject();
|
||||
}
|
||||
static inline sptr<IRemoteObject> RemoteBrokerToObject(const sptr<IRemoteBroker>& broker)
|
||||
{
|
||||
return broker->AsObject();
|
||||
}
|
||||
|
||||
private:
|
||||
sptr<IPlatformApi> platformApi;
|
||||
Platform();
|
||||
~Platform();
|
||||
Platform(const Platform&);
|
||||
Platform& operator = (const Platform&);
|
||||
Platform(const Platform&&);
|
||||
Platform& operator = (const Platform&&);
|
||||
};
|
||||
|
||||
}
|
||||
private:
|
||||
sptr<IPlatformApi> platformApi;
|
||||
Platform();
|
||||
~Platform();
|
||||
Platform(const Platform&);
|
||||
Platform& operator = (const Platform&);
|
||||
Platform(const Platform&&);
|
||||
Platform& operator = (const Platform&&);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // FM_IMMS_PROJECT_PLATFORMAPI_H
|
||||
|
@ -24,8 +24,9 @@ namespace MiscServices {
|
||||
gettimeofday(&tv, nullptr);
|
||||
struct tm nowTime;
|
||||
localtime_r(&tv.tv_sec, &nowTime);
|
||||
int32_t millSec = 1000;
|
||||
printf("%02d-%02d %02d:%02d:%02d.%03d\t", nowTime.tm_mon, nowTime.tm_mday,
|
||||
nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, (int)tv.tv_usec/1000);
|
||||
nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, (int)tv.tv_usec/millSec);
|
||||
}
|
||||
|
||||
namespace ErrorCode {
|
||||
|
@ -43,7 +43,7 @@ namespace MiscServices {
|
||||
\param attribute the source attribute copied to this instance
|
||||
\return return this
|
||||
*/
|
||||
InputAttribute& InputAttribute::operator=(const InputAttribute& attribute)
|
||||
InputAttribute& InputAttribute::operator =(const InputAttribute& attribute)
|
||||
{
|
||||
if (this == &attribute) {
|
||||
return *this;
|
||||
@ -62,8 +62,8 @@ namespace MiscServices {
|
||||
bool InputAttribute::Marshalling(OHOS::Parcel &parcel) const
|
||||
{
|
||||
if (!(parcel.WriteInt32(inputPattern)
|
||||
&& parcel.WriteInt32(enterKeyType)
|
||||
&& parcel.WriteInt32(inputOption)))
|
||||
&& parcel.WriteInt32(enterKeyType)
|
||||
&& parcel.WriteInt32(inputOption)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ namespace MiscServices {
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
IMSA_HILOGE("ConnectAbility: OnAbilityConnectDone.");
|
||||
if(messageHandler != nullptr){
|
||||
if (messageHandler != nullptr)
|
||||
{
|
||||
MessageParcel *data = new MessageParcel();
|
||||
data->WriteParcelable(&element);
|
||||
data->WriteRemoteObject(remoteObject);
|
||||
@ -46,7 +47,8 @@ namespace MiscServices {
|
||||
int resultCode)
|
||||
{
|
||||
IMSA_HILOGE("ConnectAbility: OnAbilityDisconnectDone.");
|
||||
if(messageHandler != nullptr){
|
||||
if (messageHandler != nullptr)
|
||||
{
|
||||
MessageParcel *data = new MessageParcel();
|
||||
data->WriteParcelable(&element);
|
||||
data->WriteInt32(mIndex);
|
||||
|
@ -28,7 +28,8 @@ namespace MiscServices {
|
||||
*/
|
||||
InputMethodProperty::~InputMethodProperty()
|
||||
{
|
||||
for(int32_t i=0; i<(int32_t)mTypes.size(); i++) {
|
||||
for (int32_t i = 0; i < (int32_t)mTypes.size(); i++)
|
||||
{
|
||||
delete mTypes[i];
|
||||
}
|
||||
mTypes.clear();
|
||||
@ -46,7 +47,8 @@ namespace MiscServices {
|
||||
isSystemIme = property.isSystemIme;
|
||||
mDefaultImeId = property.mDefaultImeId;
|
||||
|
||||
for(int i = 0; i < (int)mTypes.size(); i++) {
|
||||
for (int i = 0; i < (int)mTypes.size(); i++)
|
||||
{
|
||||
KeyboardType *type = new KeyboardType(*property.mTypes[i]);
|
||||
mTypes.push_back(type);
|
||||
}
|
||||
@ -56,7 +58,7 @@ namespace MiscServices {
|
||||
\param property the source property will be copied to this instance.
|
||||
\return return this
|
||||
*/
|
||||
InputMethodProperty& InputMethodProperty::operator=(const InputMethodProperty& property)
|
||||
InputMethodProperty& InputMethodProperty::operator = (const InputMethodProperty& property)
|
||||
{
|
||||
if (this == &property) {
|
||||
return *this;
|
||||
@ -68,7 +70,8 @@ namespace MiscServices {
|
||||
isSystemIme = property.isSystemIme;
|
||||
mDefaultImeId = property.mDefaultImeId;
|
||||
|
||||
for(int i = 0; i < (int)mTypes.size(); i++) {
|
||||
for (int i = 0; i < (int)mTypes.size(); i++)
|
||||
{
|
||||
KeyboardType *type = new KeyboardType(*property.mTypes[i]);
|
||||
mTypes.push_back(type);
|
||||
}
|
||||
@ -83,17 +86,20 @@ namespace MiscServices {
|
||||
bool InputMethodProperty::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!(parcel.WriteString16(mImeId)
|
||||
&&parcel.WriteString16(mPackageName)
|
||||
&&parcel.WriteString16(mAbilityName)
|
||||
&&parcel.WriteString16(mConfigurationPage)
|
||||
&&parcel.WriteBool(isSystemIme)
|
||||
&&parcel.WriteInt32(mDefaultImeId)))
|
||||
&& parcel.WriteString16(mPackageName)
|
||||
&& parcel.WriteString16(mAbilityName)
|
||||
&& parcel.WriteString16(mConfigurationPage)
|
||||
&& parcel.WriteBool(isSystemIme)
|
||||
&& parcel.WriteInt32(mDefaultImeId)))
|
||||
return false;
|
||||
int32_t size = (int32_t)mTypes.size();
|
||||
parcel.WriteInt32(size);
|
||||
if (size == 0)
|
||||
{
|
||||
return true;
|
||||
for(int i=0; i<size; i++){
|
||||
}
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
parcel.WriteParcelable(mTypes[i]);
|
||||
}
|
||||
return true;
|
||||
@ -117,7 +123,7 @@ namespace MiscServices {
|
||||
int32_t size = parcel.ReadInt32();
|
||||
if (size == 0)
|
||||
return info;
|
||||
for (int i =0; i < size; i++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
info->mTypes.push_back(parcel.ReadParcelable<KeyboardType>());
|
||||
}
|
||||
return info;
|
||||
|
@ -49,7 +49,7 @@ namespace MiscServices {
|
||||
\param inputMethodSetting the source InputMethodSetting copied to this instance
|
||||
\return return this instance
|
||||
*/
|
||||
InputMethodSetting& InputMethodSetting::operator=(const InputMethodSetting& inputMethodSetting)
|
||||
InputMethodSetting& InputMethodSetting::operator = (const InputMethodSetting& inputMethodSetting)
|
||||
{
|
||||
if (this == &inputMethodSetting) {
|
||||
return *this;
|
||||
@ -67,7 +67,8 @@ namespace MiscServices {
|
||||
int32_t size = setting.size();
|
||||
parcel.WriteInt32(size);
|
||||
std::map<std::u16string, std::u16string>::const_iterator it;
|
||||
for(it = setting.cbegin(); it != setting.cend(); ++it) {
|
||||
for (it = setting.cbegin(); it != setting.cend(); ++it)
|
||||
{
|
||||
parcel.WriteString16(it->first);
|
||||
parcel.WriteString16(it->second);
|
||||
}
|
||||
@ -82,7 +83,8 @@ namespace MiscServices {
|
||||
{
|
||||
auto ims = new InputMethodSetting();
|
||||
int32_t size = parcel.ReadInt32();
|
||||
for(int i = 0; i < size; i++) {
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
std::u16string key = parcel.ReadString16();
|
||||
std::u16string value = parcel.ReadString16();
|
||||
ims->setting.insert(std::pair<std::u16string, std::u16string>(key, value));
|
||||
@ -137,7 +139,8 @@ namespace MiscServices {
|
||||
std::u16string value = GetValue(ENABLED_INPUT_METHODS_TAG);
|
||||
std::vector<std::u16string> tmp1 = Split(value, DELIM_IME);
|
||||
std::vector<std::u16string> imeList;
|
||||
for(int i = 0; i < (int)tmp1.size(); i++) {
|
||||
for (int i = 0; i < (int)tmp1.size(); i++)
|
||||
{
|
||||
std::vector<std::u16string> tmp2 = Split(tmp1[i], DELIM_KBD_TYPE);
|
||||
imeList.push_back(tmp2[0]);
|
||||
tmp2.clear();
|
||||
@ -157,12 +160,14 @@ namespace MiscServices {
|
||||
std::vector<std::u16string> imeList = Split(str, DELIM_IME);
|
||||
|
||||
std::u16string typeStr;
|
||||
for(int i = 0; i < (int)types.size(); i++) {
|
||||
for (int i = 0; i < (int)types.size(); i++)
|
||||
{
|
||||
typeStr = typeStr + u";" + Utils::to_utf16(std::to_string(types[i]));
|
||||
}
|
||||
std::u16string imeStr = imeId + typeStr;
|
||||
bool flag = false;
|
||||
for(int i = 0; i < (int)imeList.size(); i++) {
|
||||
for (int i = 0; i < (int)imeList.size(); i++)
|
||||
{
|
||||
if (imeList[i] == imeStr) {
|
||||
return false;
|
||||
}
|
||||
@ -193,7 +198,8 @@ namespace MiscServices {
|
||||
std::vector<std::u16string> imeList = Split(str, DELIM_IME);
|
||||
bool flag = false;
|
||||
std::vector<std::u16string>::iterator it;
|
||||
for(it = imeList.begin(); it < imeList.end(); ++it) {
|
||||
for (it = imeList.begin(); it < imeList.end(); ++it)
|
||||
{
|
||||
if (it->find_first_of(imeId)) {
|
||||
imeList.erase(it);
|
||||
flag = true;
|
||||
@ -219,8 +225,10 @@ namespace MiscServices {
|
||||
std::vector<std::u16string> tmpVector = Split(value, DELIM_IME);
|
||||
bool flag = false;
|
||||
std::u16string imeStr;
|
||||
for(int i = 0; i < (int)tmpVector.size(); i++) {
|
||||
if (tmpVector[i].find_first_of(imeId) != std::u16string::npos) {
|
||||
for (int i = 0; i < (int)tmpVector.size(); i++)
|
||||
{
|
||||
if (tmpVector[i].find_first_of(imeId) != std::u16string::npos)
|
||||
{
|
||||
flag = true;
|
||||
imeStr = tmpVector[i];
|
||||
break;
|
||||
@ -232,7 +240,8 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::vector<std::u16string> tmp2 = Split(imeStr, DELIM_KBD_TYPE);
|
||||
for(int i = 1; i < (int)tmp2.size(); i++) {
|
||||
for (int i = 1; i < (int)tmp2.size(); i++)
|
||||
{
|
||||
std::u16string str = tmp2[i];
|
||||
retValue.push_back(std::atoi(Utils::to_utf8(str).c_str()));
|
||||
}
|
||||
@ -306,18 +315,21 @@ namespace MiscServices {
|
||||
std::vector<std::u16string> InputMethodSetting::Split(const std::u16string& str, char16_t delim)
|
||||
{
|
||||
std::vector<std::u16string> retValue;
|
||||
std::u16string::size_type left,right;
|
||||
std::u16string::size_type left, right;
|
||||
left = 0;
|
||||
right = str.find(delim, 0);
|
||||
while(right != std::u16string::npos){
|
||||
if(right-left){
|
||||
retValue.emplace_back(str.substr(left,right-left));
|
||||
while(right != std::u16string::npos)
|
||||
{
|
||||
if (right - left)
|
||||
{
|
||||
retValue.emplace_back(str.substr(left, right-left));
|
||||
}
|
||||
left = right + 1;
|
||||
right = str.find(delim,left);
|
||||
}
|
||||
|
||||
if(left != str.size()){
|
||||
if (left != str.size())
|
||||
{
|
||||
retValue.emplace_back(str.substr(left));
|
||||
}
|
||||
return retValue;
|
||||
@ -332,9 +344,11 @@ namespace MiscServices {
|
||||
{
|
||||
std::u16string retValue = u"";
|
||||
char16_t delimStr[] = {delim, 0};
|
||||
for(int i = 0; i < (int)vector.size(); i++) {
|
||||
for (int i = 0; i < (int)vector.size(); i++)
|
||||
{
|
||||
retValue += vector[i];
|
||||
if (i<(int)vector.size()-1) {
|
||||
if (i < (int)vector.size()-1)
|
||||
{
|
||||
retValue += std::u16string(delimStr);
|
||||
}
|
||||
}
|
||||
|
@ -58,24 +58,30 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::map<int32_t, PerUserSession*>::const_iterator it;
|
||||
for(it=userSessions.cbegin(); it!=userSessions.cend();) {
|
||||
for (it = userSessions.cbegin(); it != userSessions.cend();)
|
||||
{
|
||||
PerUserSession *session = it->second;
|
||||
it = userSessions.erase(it);
|
||||
delete session;
|
||||
session = nullptr;
|
||||
}
|
||||
userSessions.clear();
|
||||
std::map<int32_t, PerUserSetting*>::const_iterator it1;
|
||||
for(it1=userSettings.cbegin(); it1!=userSettings.cend();) {
|
||||
for (it1 = userSettings.cbegin(); it1 != userSettings.cend();)
|
||||
{
|
||||
PerUserSetting *setting = it1->second;
|
||||
it1 = userSettings.erase(it1);
|
||||
delete setting;
|
||||
setting = nullptr;
|
||||
}
|
||||
userSettings.clear();
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it2;
|
||||
for(it2=msgHandlers.cbegin(); it2!=msgHandlers.cend();) {
|
||||
for (it2 = msgHandlers.cbegin(); it2 != msgHandlers.cend();)
|
||||
{
|
||||
MessageHandler *handler = it2->second;
|
||||
it2 = msgHandlers.erase(it2);
|
||||
delete handler;
|
||||
handler = nullptr;
|
||||
}
|
||||
msgHandlers.clear();
|
||||
}
|
||||
@ -158,10 +164,10 @@ namespace MiscServices {
|
||||
workThreadHandler = std::thread([this] {
|
||||
WorkThread();
|
||||
});
|
||||
PerUserSetting *setting=new PerUserSetting(0);
|
||||
PerUserSession *session=new PerUserSession(0);
|
||||
userSettings.insert(std::pair<int32_t,PerUserSetting*>(0,setting));
|
||||
userSessions.insert(std::pair<int32_t,PerUserSession*>(0,session));
|
||||
PerUserSetting *setting = new PerUserSetting(0);
|
||||
PerUserSession *session = new PerUserSession(0);
|
||||
userSettings.insert(std::pair<int32_t, PerUserSetting*>(0, setting));
|
||||
userSessions.insert(std::pair<int32_t, PerUserSession*>(0, session));
|
||||
|
||||
setting->Initialize();
|
||||
}
|
||||
@ -253,7 +259,12 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_USER_NOT_UNLOCKED;
|
||||
}
|
||||
|
||||
KeyboardType *type = GetUserSession(userId)->GetCurrentKeyboardType();
|
||||
PerUserSession *userSession = GetUserSession(userId);
|
||||
if (userSession == nullptr)
|
||||
{
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
KeyboardType *type = userSession->GetCurrentKeyboardType();
|
||||
if (type == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
@ -279,7 +290,8 @@ namespace MiscServices {
|
||||
setting->ListInputMethodEnabled(properties);
|
||||
|
||||
std::vector<InputMethodProperty*>::iterator it;
|
||||
for(it=properties->begin(); it!=properties->end();) {
|
||||
for (it = properties->begin(); it != properties->end();)
|
||||
{
|
||||
if (*it && (*it)->isSystemIme) {
|
||||
it = properties->erase(it);
|
||||
} else {
|
||||
@ -306,7 +318,8 @@ namespace MiscServices {
|
||||
}
|
||||
setting->ListInputMethod(properties);
|
||||
std::vector<InputMethodProperty*>::iterator it;
|
||||
for(it=properties->begin(); it!=properties->end();) {
|
||||
for (it = properties->begin(); it != properties->end();)
|
||||
{
|
||||
if (*it && (*it)->isSystemIme) {
|
||||
it = properties->erase(it);
|
||||
} else {
|
||||
@ -352,7 +365,8 @@ namespace MiscServices {
|
||||
std::map<int32_t, PerUserSetting*>::const_iterator it;
|
||||
int32_t index = 0;
|
||||
dprintf(fd, "* User count = %d\n", userSettings.size());
|
||||
for(it=userSettings.cbegin(); it!=userSettings.cend(); ++it) {
|
||||
for (it = userSettings.cbegin(); it != userSettings.cend(); ++it)
|
||||
{
|
||||
PerUserSetting *setting = it->second;
|
||||
int32_t userId = it->first;
|
||||
int32_t userState = setting->GetUserState();
|
||||
@ -404,9 +418,9 @@ namespace MiscServices {
|
||||
*/
|
||||
void InputMethodSystemAbility::WorkThread()
|
||||
{
|
||||
while(1){
|
||||
while(1) {
|
||||
Message *msg = MessageHandler::Instance()->GetMessage();
|
||||
switch(msg->msgId_) {
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_USER_START : {
|
||||
OnUserStarted(msg);
|
||||
break;
|
||||
@ -461,15 +475,24 @@ namespace MiscServices {
|
||||
}
|
||||
case MSG_ID_EXIT_SERVICE: {
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it;
|
||||
for(it=msgHandlers.cbegin(); it!=msgHandlers.cend();) {
|
||||
for (it = msgHandlers.cbegin(); it != msgHandlers.cend();)
|
||||
{
|
||||
MessageHandler *handler = it->second;
|
||||
Message *destMsg = new Message(MSG_ID_EXIT_SERVICE, nullptr);
|
||||
handler->SendMessage(destMsg);
|
||||
GetUserSession(it->first)->JoinWorkThread();
|
||||
PerUserSession *userSession = GetUserSession(it->first);
|
||||
if (userSession == nullptr)
|
||||
{
|
||||
IMSA_HILOGE("getUserSession fail.");
|
||||
return;
|
||||
}
|
||||
userSession->JoinWorkThread();
|
||||
it = msgHandlers.erase(it);
|
||||
delete handler;
|
||||
handler = nullptr;
|
||||
}
|
||||
delete msg;
|
||||
msg = nullptr;
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
@ -533,10 +556,12 @@ namespace MiscServices {
|
||||
std::map<int32_t, PerUserSession*>::iterator itSession = userSessions.find(userId);
|
||||
userSessions.erase(itSession);
|
||||
delete session;
|
||||
session = nullptr;
|
||||
|
||||
std::map<int32_t, PerUserSetting*>::iterator itSetting = userSettings.find(userId);
|
||||
userSettings.erase(itSetting);
|
||||
delete setting;
|
||||
setting = nullptr;
|
||||
IMSA_HILOGI("End...[%d]\n", userId);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
@ -600,13 +625,14 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_USER_NOT_UNLOCKED;
|
||||
}
|
||||
std::map<int32_t, MessageHandler*>::iterator it = msgHandlers.find(userId);
|
||||
if (it!=msgHandlers.end()) {
|
||||
if (it != msgHandlers.end()) {
|
||||
MessageHandler *handler = it->second;
|
||||
Message *destMsg = new Message(MSG_ID_USER_LOCK , nullptr);
|
||||
handler->SendMessage(destMsg);
|
||||
GetUserSession(userId)->JoinWorkThread();
|
||||
msgHandlers.erase(it);
|
||||
delete handler;
|
||||
handler = nullptr;
|
||||
}
|
||||
setting->OnUserLocked();
|
||||
IMSA_HILOGI("End...[%d]\n", userId);
|
||||
@ -632,15 +658,19 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it = msgHandlers.find(userId);
|
||||
if(it==msgHandlers.end()) {
|
||||
if (it == msgHandlers.end()) {
|
||||
PerUserSession *session = GetUserSession(userId);
|
||||
MessageHandler *handler = new MessageHandler();
|
||||
if (session == nullptr)
|
||||
{
|
||||
IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr");
|
||||
}
|
||||
session->CreateWorkThread(*handler);
|
||||
msgHandlers.insert(std::pair<int32_t, MessageHandler*>(userId, handler));
|
||||
it = msgHandlers.find(userId);
|
||||
}
|
||||
|
||||
if (it!=msgHandlers.end()) {
|
||||
if (it != msgHandlers.end()) {
|
||||
MessageHandler *handler = it->second;
|
||||
handler->SendMessage(msg);
|
||||
}
|
||||
@ -664,7 +694,7 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it = msgHandlers.find(userId);
|
||||
if (it!=msgHandlers.end()) {
|
||||
if (it != msgHandlers.end()) {
|
||||
MessageHandler *handler = it->second;
|
||||
handler->SendMessage(msg);
|
||||
}
|
||||
@ -846,7 +876,7 @@ namespace MiscServices {
|
||||
}
|
||||
if (isCurrentIme) {
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it = msgHandlers.find(userId);
|
||||
if (it!=msgHandlers.end()) {
|
||||
if (it != msgHandlers.end()) {
|
||||
Message *destMsg = new Message(msg->msgId_, nullptr);
|
||||
it->second->SendMessage(destMsg);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
|
||||
}
|
||||
|
||||
switch(code) {
|
||||
switch (code) {
|
||||
case PREPARE_INPUT: {
|
||||
prepareInput(data);
|
||||
reply.WriteInt32(NO_ERROR);
|
||||
@ -61,7 +61,7 @@ namespace MiscServices {
|
||||
reply.WriteInt32(NO_ERROR);
|
||||
break;
|
||||
}
|
||||
case SET_INPUT_METHOD_CORE:{
|
||||
case SET_INPUT_METHOD_CORE: {
|
||||
MessageParcel *msgParcel = (MessageParcel*) &data;
|
||||
setInputMethodCoreFromHap(*msgParcel);
|
||||
reply.WriteInt32(NO_ERROR);
|
||||
@ -116,7 +116,8 @@ namespace MiscServices {
|
||||
reply.WriteInt32(NO_ERROR);
|
||||
int32_t size = properties.size();
|
||||
reply.WriteInt32(size);
|
||||
for(int32_t i=0; i<size; i++) {
|
||||
for (int32_t i = 0; i < size; i++)
|
||||
{
|
||||
reply.WriteParcelable(properties[i]);
|
||||
}
|
||||
properties.clear();
|
||||
@ -134,7 +135,8 @@ namespace MiscServices {
|
||||
reply.WriteInt32(NO_ERROR);
|
||||
int32_t size = properties.size();
|
||||
reply.WriteInt32(size);
|
||||
for(int32_t i=0; i<size; i++) {
|
||||
for (int32_t i = 0; i < size; i++)
|
||||
{
|
||||
reply.WriteParcelable(properties[i]);
|
||||
}
|
||||
properties.clear();
|
||||
@ -152,7 +154,8 @@ namespace MiscServices {
|
||||
reply.WriteInt32(NO_ERROR);
|
||||
int32_t size = kbdTypes.size();
|
||||
reply.WriteInt32(size);
|
||||
for(int32_t i=0; i<size; i++) {
|
||||
for (int32_t i = 0; i < size; i++)
|
||||
{
|
||||
reply.WriteParcelable(kbdTypes[i]);
|
||||
}
|
||||
kbdTypes.clear();
|
||||
|
@ -49,7 +49,7 @@ namespace MiscServices {
|
||||
\param type source instance
|
||||
\return return this
|
||||
*/
|
||||
KeyboardType& KeyboardType::operator=(const KeyboardType& type)
|
||||
KeyboardType& KeyboardType::operator = (const KeyboardType& type)
|
||||
{
|
||||
if (this == &type) {
|
||||
return *this;
|
||||
@ -72,13 +72,13 @@ namespace MiscServices {
|
||||
bool KeyboardType::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!(parcel.WriteInt32(mId)
|
||||
&& parcel.WriteInt32(mHashCode)
|
||||
&& parcel.WriteInt32(mLabelId)
|
||||
&& parcel.WriteInt32(mIconId)
|
||||
&& parcel.WriteBool(mIsAsciiCapable)
|
||||
&& parcel.WriteString16(mLanguage)
|
||||
&& parcel.WriteString16(mInputSource)
|
||||
&& parcel.WriteString16(mCustomizedValue)))
|
||||
&& parcel.WriteInt32(mHashCode)
|
||||
&& parcel.WriteInt32(mLabelId)
|
||||
&& parcel.WriteInt32(mIconId)
|
||||
&& parcel.WriteBool(mIsAsciiCapable)
|
||||
&& parcel.WriteString16(mLanguage)
|
||||
&& parcel.WriteString16(mInputSource)
|
||||
&& parcel.WriteString16(mCustomizedValue)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -115,47 +115,47 @@ namespace MiscServices {
|
||||
|
||||
void KeyboardType::setLabelId(int32_t labelId)
|
||||
{
|
||||
mLabelId = labelId;
|
||||
mLabelId = labelId;
|
||||
}
|
||||
|
||||
void KeyboardType::setIconId(int32_t iconId)
|
||||
{
|
||||
mIconId = iconId;
|
||||
mIconId = iconId;
|
||||
}
|
||||
|
||||
void KeyboardType::setAsciiCapability(bool isAsciiCapable)
|
||||
{
|
||||
mIsAsciiCapable = isAsciiCapable;
|
||||
mIsAsciiCapable = isAsciiCapable;
|
||||
}
|
||||
|
||||
void KeyboardType::setLanguage(u16string language)
|
||||
{
|
||||
mLanguage = language;
|
||||
mLanguage = language;
|
||||
}
|
||||
|
||||
void KeyboardType::setInputSource(u16string inputSource)
|
||||
{
|
||||
mInputSource = inputSource;
|
||||
mInputSource = inputSource;
|
||||
}
|
||||
|
||||
void KeyboardType::setCustomizedValue(u16string keyBoardTypeCustomizedValue)
|
||||
{
|
||||
mCustomizedValue = keyBoardTypeCustomizedValue;
|
||||
mCustomizedValue = keyBoardTypeCustomizedValue;
|
||||
}
|
||||
|
||||
int32_t KeyboardType::getId() const
|
||||
{
|
||||
return mId;
|
||||
return mId;
|
||||
}
|
||||
|
||||
int32_t KeyboardType::getLabelId() const
|
||||
{
|
||||
return mLabelId;
|
||||
return mLabelId;
|
||||
}
|
||||
|
||||
int32_t KeyboardType::getIconId() const
|
||||
{
|
||||
return mIconId;
|
||||
return mIconId;
|
||||
}
|
||||
|
||||
/*! Get hash code of the object
|
||||
@ -163,7 +163,7 @@ namespace MiscServices {
|
||||
*/
|
||||
int KeyboardType::getHashCode() const
|
||||
{
|
||||
return mHashCode;
|
||||
return mHashCode;
|
||||
}
|
||||
|
||||
/*! Get language of the object
|
||||
@ -171,17 +171,17 @@ namespace MiscServices {
|
||||
*/
|
||||
u16string KeyboardType::getLanguage() const
|
||||
{
|
||||
return mLanguage;
|
||||
return mLanguage;
|
||||
}
|
||||
|
||||
u16string KeyboardType::getInputSource() const
|
||||
{
|
||||
return mInputSource;
|
||||
return mInputSource;
|
||||
}
|
||||
|
||||
u16string KeyboardType::getCustomizedValue() const
|
||||
{
|
||||
return mCustomizedValue;
|
||||
return mCustomizedValue;
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ namespace MiscServices {
|
||||
msgId_ = msg.msgId_;
|
||||
if (msgContent_ != nullptr) {
|
||||
delete msgContent_;
|
||||
msgContent_ = nullptr;
|
||||
}
|
||||
MessageParcel *src = msg.msgContent_;
|
||||
if (src) {
|
||||
@ -46,7 +47,7 @@ namespace MiscServices {
|
||||
}
|
||||
}
|
||||
|
||||
Message& Message::operator=(const Message& msg)
|
||||
Message& Message::operator = (const Message& msg)
|
||||
{
|
||||
if (this == &msg) {
|
||||
return *this;
|
||||
@ -54,6 +55,7 @@ namespace MiscServices {
|
||||
msgId_ = msg.msgId_;
|
||||
if (msgContent_ != nullptr) {
|
||||
delete msgContent_;
|
||||
msgContent_ = nullptr;
|
||||
}
|
||||
if (msg.msgContent_) {
|
||||
msgContent_ = new MessageParcel();
|
||||
@ -67,6 +69,7 @@ namespace MiscServices {
|
||||
{
|
||||
if (msgContent_) {
|
||||
delete msgContent_;
|
||||
msgContent_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ namespace MiscServices {
|
||||
Message *msg = mQueue.front();
|
||||
mQueue.pop();
|
||||
delete msg;
|
||||
msg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,14 +125,15 @@ namespace MiscServices {
|
||||
if (msgHandler == nullptr) {
|
||||
return ;
|
||||
}
|
||||
while(1){
|
||||
while(1) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
switch(msg->msgId_) {
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_USER_LOCK:
|
||||
case MSG_ID_EXIT_SERVICE: {
|
||||
OnUserLocked();
|
||||
delete msg;
|
||||
msg = nullptr;
|
||||
return;
|
||||
}
|
||||
case MSG_ID_PREPARE_INPUT: {
|
||||
@ -151,7 +152,7 @@ namespace MiscServices {
|
||||
OnStopInput(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_SET_INPUT_METHOD_CORE:{
|
||||
case MSG_ID_SET_INPUT_METHOD_CORE: {
|
||||
onSetInputMethodCore(msg);
|
||||
break;
|
||||
}
|
||||
@ -190,6 +191,7 @@ namespace MiscServices {
|
||||
}
|
||||
}
|
||||
delete msg;
|
||||
msg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,17 +239,22 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("PerUserSession::ResetIme");
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
InputMethodProperty *ime[] = {defaultIme, securityIme};
|
||||
for(int i=0; i<2; i++) {
|
||||
if (currentIme[i] == ime[i] && ime[i] != nullptr) {
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (currentIme[i] == ime[i] && ime[i] != nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (imsCore[i]) {
|
||||
if (imsCore[i])
|
||||
{
|
||||
StopInputMethod(i);
|
||||
}
|
||||
IncreaseOrResetImeError(true, i);
|
||||
currentIme[i] = ime[i];
|
||||
if (currentIme[i]==nullptr) {
|
||||
if (needReshowClient && GetImeIndex(needReshowClient)==i) {
|
||||
if (currentIme[i] == nullptr)
|
||||
{
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i)
|
||||
{
|
||||
needReshowClient = nullptr;
|
||||
}
|
||||
continue;
|
||||
@ -255,17 +262,22 @@ namespace MiscServices {
|
||||
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*>::const_iterator it;
|
||||
bool flag = false;
|
||||
for(it=mapClients.cbegin(); it!=mapClients.cend(); ++it) {
|
||||
for (it = mapClients.cbegin(); it != mapClients.cend(); ++it)
|
||||
{
|
||||
if ((i == DEFAULT_IME && it->second->attribute.GetSecurityFlag() == false) ||
|
||||
(i == SECURITY_IME && it->second->attribute.GetSecurityFlag() == true)) {
|
||||
(i == SECURITY_IME && it->second->attribute.GetSecurityFlag() == true))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
int ret = StartInputMethod(i);
|
||||
if (needReshowClient && GetImeIndex(needReshowClient)==i) {
|
||||
if (ret==ErrorCode::NO_ERROR) {
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i)
|
||||
{
|
||||
if (ret == ErrorCode::NO_ERROR)
|
||||
{
|
||||
ShowKeyboard(needReshowClient);
|
||||
}
|
||||
needReshowClient = nullptr;
|
||||
@ -283,18 +295,22 @@ namespace MiscServices {
|
||||
InputMethodSetting tmpSetting;
|
||||
bool flag = false;
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
for(int i=0; i<MAX_IME; i++) {
|
||||
if (currentIme[i] && currentIme[i]->mPackageName == packageName) {
|
||||
if (currentClient && GetImeIndex(currentClient)==i) {
|
||||
for (int i = 0; i < MAX_IME; i++)
|
||||
{
|
||||
if (currentIme[i] && currentIme[i]->mPackageName == packageName)
|
||||
{
|
||||
if (currentClient && GetImeIndex(currentClient) == i)
|
||||
{
|
||||
needReshowClient = currentClient;
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
StopInputMethod(i);
|
||||
currentIme[i] = nullptr;
|
||||
if (i==DEFAULT_IME) {
|
||||
if (i == DEFAULT_IME)
|
||||
{
|
||||
tmpSetting.SetCurrentKeyboardType(-1);
|
||||
inputMethodSetting->SetCurrentKeyboardType(-1);
|
||||
} else if (i==SECURITY_IME) {
|
||||
} else if (i == SECURITY_IME) {
|
||||
tmpSetting.SetCurrentSysKeyboardType(-1);
|
||||
inputMethodSetting->SetCurrentSysKeyboardType(-1);
|
||||
}
|
||||
@ -302,7 +318,8 @@ namespace MiscServices {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting);
|
||||
}
|
||||
}
|
||||
@ -371,11 +388,14 @@ namespace MiscServices {
|
||||
IMSA_HILOGE("PerUserSession::RemoveClient onInputReleased fail %{public}s", ErrorCode::ToString(ret));
|
||||
}
|
||||
delete clientInfo;
|
||||
clientInfo = nullptr;
|
||||
mapClients.erase(it);
|
||||
|
||||
remainClientNum = 0;
|
||||
for(it=mapClients.begin(); it!=mapClients.end(); ++it) {
|
||||
if (it->second->attribute.GetSecurityFlag() == flag) {
|
||||
for (it = mapClients.begin(); it != mapClients.end(); ++it)
|
||||
{
|
||||
if (it->second->attribute.GetSecurityFlag() == flag)
|
||||
{
|
||||
remainClientNum++;
|
||||
}
|
||||
}
|
||||
@ -393,7 +413,7 @@ namespace MiscServices {
|
||||
*/
|
||||
int PerUserSession::StartInputMethod(int index)
|
||||
{
|
||||
IMSA_HILOGI("PerUserSession::StartInputMethod index=%{public}d [%{public}d]\n", index, userId_);
|
||||
IMSA_HILOGI("PerUserSession::StartInputMethod index = %{public}d [%{public}d]\n", index, userId_);
|
||||
|
||||
if (imsCore[index] == nullptr) {
|
||||
IMSA_HILOGI("PerUserSession::StartInputMethod imscore is null");
|
||||
@ -433,7 +453,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGE("Aborted! %{public}s", ErrorCode::ToString(ErrorCode::ERROR_IME_NOT_STARTED));
|
||||
return ErrorCode::ERROR_IME_NOT_STARTED;
|
||||
}
|
||||
if (currentIme[index] == currentIme[1-index] && imsCore[1-index] != nullptr) {
|
||||
if (currentIme[index] == currentIme[1 - index] && imsCore[1 - index] != nullptr) {
|
||||
imsCore[index] = nullptr;
|
||||
inputControlChannel[index] = nullptr;
|
||||
localControlChannel[index] = nullptr;
|
||||
@ -488,7 +508,7 @@ namespace MiscServices {
|
||||
localControlChannel[index]->ResetFlag();
|
||||
bool ret = imsCore[index]->startInput(clientInfo->channel, clientInfo->attribute, supportPhysicalKbd);
|
||||
if (!ret ||
|
||||
localControlChannel[index]->GetAgentAndChannel(&imsAgent, &imsChannel)==false) {
|
||||
localControlChannel[index]->GetAgentAndChannel(&imsAgent, &imsChannel) == false) {
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! client is not ready");
|
||||
int result = clientInfo->client->onInputReady(1, nullptr, nullptr);
|
||||
if (result != ErrorCode::NO_ERROR) {
|
||||
@ -508,7 +528,8 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_KBD_SHOW_FAILED;
|
||||
}
|
||||
|
||||
if(clientInfo->client == nullptr){
|
||||
if (clientInfo->client == nullptr)
|
||||
{
|
||||
IMSA_HILOGI("PerUserSession::ShowKeyboard clientInfo->client is nullptr");
|
||||
}
|
||||
|
||||
@ -539,7 +560,8 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_CLIENT_NOT_FOUND;
|
||||
}
|
||||
ClientInfo *clientInfo = GetClientInfo(inputClient);
|
||||
if(clientInfo == nullptr){
|
||||
if (clientInfo == nullptr)
|
||||
{
|
||||
IMSA_HILOGE("PerUserSession::HideKeyboard GetClientInfo pointer nullptr");
|
||||
}
|
||||
if (imsCore[index] == nullptr) {
|
||||
@ -554,9 +576,10 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_KBD_IS_NOT_SHOWING;
|
||||
}
|
||||
bool ret = imsCore[index]->hideKeyboard(1);
|
||||
if(!ret) {
|
||||
if (!ret)
|
||||
{
|
||||
IMSA_HILOGE("PerUserSession::HideKeyboard [imsCore->hideKeyboard] failed");
|
||||
ret=ErrorCode::ERROR_KBD_HIDE_FAILED;
|
||||
ret = ErrorCode::ERROR_KBD_HIDE_FAILED;
|
||||
}
|
||||
|
||||
int ret_client_stop = clientInfo->client->onInputReady(1, nullptr, nullptr);
|
||||
@ -623,8 +646,10 @@ namespace MiscServices {
|
||||
hashCode = hashCodeList[0];
|
||||
}
|
||||
|
||||
for(int i=0; i<(int)currentIme[DEFAULT_IME]->mTypes.size(); i++) {
|
||||
if (currentIme[DEFAULT_IME]->mTypes[i]->getHashCode() == hashCode) {
|
||||
for (int i = 0; i < (int)currentIme[DEFAULT_IME]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[DEFAULT_IME]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
return currentIme[DEFAULT_IME]->mTypes[i];
|
||||
}
|
||||
}
|
||||
@ -641,7 +666,7 @@ namespace MiscServices {
|
||||
bool flag = false;
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*>::iterator it;
|
||||
|
||||
for (it=mapClients.begin(); it!=mapClients.end(); ++it) {
|
||||
for (it = mapClients.begin(); it != mapClients.end(); ++it) {
|
||||
if (it->first == who) {
|
||||
flag = true;
|
||||
break;
|
||||
@ -669,27 +694,33 @@ namespace MiscServices {
|
||||
(void) who; // temporary void it, as we will add support for security IME.
|
||||
IMSA_HILOGI("Start...[%{public}d]\n", userId_);
|
||||
int index = 0;
|
||||
for(int i=0; i<MAX_IME; i++) {
|
||||
if(imsCore[i] == nullptr) {
|
||||
for (int i = 0; i < MAX_IME; i++)
|
||||
{
|
||||
if (imsCore[i] == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sptr<IRemoteObject> b = imsCore[i]->AsObject();
|
||||
if (b == who) {
|
||||
if (b == who)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentClient && (GetImeIndex(currentClient)==index ||
|
||||
currentIme[index] == currentIme[1-index])) {
|
||||
if (currentClient && (GetImeIndex(currentClient) == index ||
|
||||
currentIme[index] == currentIme[1 - index]))
|
||||
{
|
||||
needReshowClient = currentClient;
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
StopInputMethod(index);
|
||||
if (currentIme[index] == currentIme[1-index]) {
|
||||
StopInputMethod(1-index);
|
||||
if (currentIme[index] == currentIme[1 - index])
|
||||
{
|
||||
StopInputMethod(1 - index);
|
||||
}
|
||||
|
||||
if (IncreaseOrResetImeError(false, index) == 3) {
|
||||
if (IncreaseOrResetImeError(false, index) == 3)
|
||||
{
|
||||
// call to disable the current input method.
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
parcel->WriteInt32(userId_);
|
||||
@ -743,7 +774,7 @@ namespace MiscServices {
|
||||
value == currentIme[DEFAULT_IME]->mImeId) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
if (currentClient != nullptr && GetImeIndex(currentClient)==DEFAULT_IME) {
|
||||
if (currentClient != nullptr && GetImeIndex(currentClient) == DEFAULT_IME) {
|
||||
needReshowClient = currentClient;
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
@ -752,9 +783,9 @@ namespace MiscServices {
|
||||
currentKbdIndex[DEFAULT_IME] = 0;
|
||||
inputMethodSetting->SetCurrentKeyboardType(-1);
|
||||
} else if (key == InputMethodSetting::ENABLED_INPUT_METHODS_TAG) {
|
||||
if (currentIme[DEFAULT_IME] && currentIme[DEFAULT_IME]!=currentIme[SECURITY_IME] &&
|
||||
value.find(currentIme[DEFAULT_IME]->mImeId) == std::string::npos) {
|
||||
if (currentClient != nullptr && GetImeIndex(currentClient)==DEFAULT_IME) {
|
||||
if (currentIme[DEFAULT_IME] && currentIme[DEFAULT_IME] != currentIme[SECURITY_IME]
|
||||
&& value.find(currentIme[DEFAULT_IME]->mImeId) == std::string::npos) {
|
||||
if (currentClient != nullptr && GetImeIndex(currentClient) == DEFAULT_IME) {
|
||||
needReshowClient = currentClient;
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
@ -787,8 +818,10 @@ namespace MiscServices {
|
||||
if (currentIme[index]->mTypes[num]->getHashCode() == hashCode) {
|
||||
return ErrorCode::ERROR_SETTING_SAME_VALUE;
|
||||
}
|
||||
for(int i=0; i<(int)currentIme[index]->mTypes.size(); i++) {
|
||||
if (currentIme[index]->mTypes[i]->getHashCode() == hashCode) {
|
||||
for (int i = 0; i < (int)currentIme[index]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[index]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
currentKbdIndex[index] = i;
|
||||
break;
|
||||
}
|
||||
@ -800,8 +833,10 @@ namespace MiscServices {
|
||||
if (currentKbdTypes[num] == hashCode) {
|
||||
return ErrorCode::ERROR_SETTING_SAME_VALUE;
|
||||
}
|
||||
for(int i=0; i<(int)currentKbdTypes.size(); i++) {
|
||||
if (currentKbdTypes[i] == hashCode) {
|
||||
for (int i = 0; i < (int)currentKbdTypes.size(); i++)
|
||||
{
|
||||
if (currentKbdTypes[i] == hashCode)
|
||||
{
|
||||
currentKbdIndex[index] = i;
|
||||
break;
|
||||
}
|
||||
@ -815,10 +850,10 @@ namespace MiscServices {
|
||||
IMSA_HILOGE("setKeyboardType return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_);
|
||||
}
|
||||
}
|
||||
if (imsCore[index] == imsCore[1-index]) {
|
||||
if (imsCore[index] == imsCore[1 - index]) {
|
||||
inputMethodSetting->SetCurrentKeyboardType(type->getHashCode());
|
||||
inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode());
|
||||
currentKbdIndex[1-index] = currentKbdIndex[index];
|
||||
currentKbdIndex[1 - index] = currentKbdIndex[index];
|
||||
} else if (index == DEFAULT_IME) {
|
||||
inputMethodSetting->SetCurrentKeyboardType(type->getHashCode());
|
||||
} else {
|
||||
@ -848,7 +883,7 @@ namespace MiscServices {
|
||||
return ;
|
||||
}
|
||||
int size = 0;
|
||||
if (index==SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME] ) {
|
||||
if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME] ) {
|
||||
size = currentIme[index]->mTypes.size();
|
||||
} else {
|
||||
std::u16string imeId = currentIme[index]->mImeId;
|
||||
@ -868,7 +903,7 @@ namespace MiscServices {
|
||||
return;
|
||||
}
|
||||
InputMethodSetting tmpSetting;
|
||||
if (imsCore[index] == imsCore[1-index]) {
|
||||
if (imsCore[index] == imsCore[1 - index]) {
|
||||
tmpSetting.SetCurrentKeyboardType(type->getHashCode());
|
||||
tmpSetting.SetCurrentSysKeyboardType(type->getHashCode());
|
||||
}
|
||||
@ -904,13 +939,13 @@ namespace MiscServices {
|
||||
*/
|
||||
void PerUserSession::OnRestartIms(int index, const std::u16string& imeId)
|
||||
{
|
||||
if (index<0 || index>=MAX_IME) {
|
||||
if (index < 0 || index >= MAX_IME) {
|
||||
return ;
|
||||
}
|
||||
IMSA_HILOGI("Start...[%{public}d]\n", userId_);
|
||||
if (currentIme[index] && currentIme[index]->mImeId == imeId) {
|
||||
int ret = StartInputMethod(index);
|
||||
if (needReshowClient && GetImeIndex(needReshowClient)==index) {
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == index) {
|
||||
if (ret == ErrorCode::NO_ERROR) {
|
||||
ShowKeyboard(needReshowClient);
|
||||
}
|
||||
@ -931,25 +966,31 @@ namespace MiscServices {
|
||||
}
|
||||
userState = UserState::USER_STATE_STARTED;
|
||||
// hide current keyboard
|
||||
if (currentClient != nullptr) {
|
||||
if (currentClient != nullptr)
|
||||
{
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
for(int i=0; i<2; i++) {
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
StopInputMethod(i);
|
||||
currentIme[i] = nullptr;
|
||||
}
|
||||
// disconnect all clients.
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*>::iterator it;
|
||||
for(it=mapClients.begin(); it!=mapClients.end();) {
|
||||
for (it = mapClients.begin(); it != mapClients.end();)
|
||||
{
|
||||
sptr<IRemoteObject> b = it->first;
|
||||
b->RemoveDeathRecipient(clientDeathRecipient);
|
||||
ClientInfo *clientInfo = it->second;
|
||||
if (clientInfo != nullptr) {
|
||||
if (clientInfo != nullptr)
|
||||
{
|
||||
int ret = clientInfo->client->onInputReleased(0);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
if (ret != ErrorCode::NO_ERROR)
|
||||
{
|
||||
IMSA_HILOGE("2-onInputReleased return : %{public}s", ErrorCode::ToString(ret));
|
||||
}
|
||||
delete clientInfo;
|
||||
clientInfo = nullptr;
|
||||
}
|
||||
IMSA_HILOGD("erase client..\n");
|
||||
it = mapClients.erase(it);
|
||||
@ -976,9 +1017,11 @@ namespace MiscServices {
|
||||
dprintf(fd, "\n - User Session State :\n");
|
||||
dprintf(fd, " * Client count = %d\n", mapClients.size());
|
||||
int index = 0;
|
||||
for(it=mapClients.cbegin(); it!=mapClients.cend(); ++it) {
|
||||
for (it = mapClients.cbegin(); it != mapClients.cend(); ++it)
|
||||
{
|
||||
if (currentClient != nullptr &&
|
||||
Platform::RemoteBrokerToObject(currentClient) == it->first) {
|
||||
Platform::RemoteBrokerToObject(currentClient) == it->first)
|
||||
{
|
||||
dprintf(fd, " *[%d] Client Information: (current client)\n", index++);
|
||||
} else {
|
||||
dprintf(fd, " [%d] Client Information:\n", index++);
|
||||
@ -986,18 +1029,21 @@ namespace MiscServices {
|
||||
DumpClientInfo(fd, *(it->second));
|
||||
}
|
||||
std::string header[2] = {"Current", "Security"};
|
||||
for(int i=0; i<2; i++) {
|
||||
if (currentIme[i] != nullptr) {
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (currentIme[i] != nullptr)
|
||||
{
|
||||
dprintf(fd, "\n * %s IME mImeId = %s\n", header[i].c_str(), Utils::to_utf8(currentIme[i]->mImeId).c_str());
|
||||
KeyboardType *type = currentIme[i]->mTypes.at(currentKbdIndex[i]);
|
||||
dprintf(fd, " %s KeyboardType mHashCode = %d, mLanguage = %s\n", header[i].c_str(),
|
||||
type->getHashCode(), Utils::to_utf8(type->getLanguage()).c_str());
|
||||
|
||||
if (imsCore[i] != nullptr) {
|
||||
if (imsCore[i] != nullptr)
|
||||
{
|
||||
sptr<IRemoteObject> b = imsCore[i]->AsObject();
|
||||
dprintf(fd, " %s IME Service = %s#%p\n", header[i].c_str(),
|
||||
Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
b=inputControlChannel[i]->AsObject();
|
||||
b = inputControlChannel[i]->AsObject();
|
||||
dprintf(fd, " %s InputControlChannel = %s#%p\n",
|
||||
header[i].c_str(), Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
dprintf(fd, " %s inputMethodWindowToken = %p\n", header[i].c_str(), inputMethodToken[i].GetRefPtr());
|
||||
@ -1023,6 +1069,10 @@ namespace MiscServices {
|
||||
sptr<IRemoteObject> b = Platform::RemoteBrokerToObject(currentClient);
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*>::iterator it = mapClients.find(b);
|
||||
int index = GetImeIndex(currentClient);
|
||||
if (index < 0 || index > MAX_IME)
|
||||
{
|
||||
dprintf(fd, "\n * PerUserSession::DumpCurrentSession: invalid index\n");
|
||||
}
|
||||
dprintf(fd, "\n * Current Session State :\n");
|
||||
dprintf(fd, " current client [= %s#%p] information :\n",
|
||||
Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
@ -1068,7 +1118,7 @@ namespace MiscServices {
|
||||
\param resetFlag the flag to increase or reset number.
|
||||
\n resetFlag=true, reset error number to 0;
|
||||
\n resetFlag=false, increase error number.
|
||||
\param imeIndex index=0 default ime; index=1 security ime
|
||||
\param imeIndex index = 0 default ime; index=1 security ime
|
||||
\return return the error count value. It is less or equal 3.
|
||||
*/
|
||||
int PerUserSession::IncreaseOrResetImeError(bool resetFlag, int imeIndex)
|
||||
@ -1102,7 +1152,7 @@ namespace MiscServices {
|
||||
*/
|
||||
KeyboardType *PerUserSession::GetKeyboardType(int imeIndex, int typeIndex)
|
||||
{
|
||||
if(typeIndex < 0) {
|
||||
if (typeIndex < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (imeIndex == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) {
|
||||
@ -1118,8 +1168,10 @@ namespace MiscServices {
|
||||
return nullptr;
|
||||
}
|
||||
int hashCode = currentKbdTypes[typeIndex];
|
||||
for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) {
|
||||
if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode) {
|
||||
for (int i = 0; i < (int)currentIme[imeIndex]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
return currentIme[imeIndex]->mTypes[i];
|
||||
}
|
||||
}
|
||||
@ -1145,8 +1197,10 @@ namespace MiscServices {
|
||||
} else {
|
||||
bool flag = false;
|
||||
if (imeIndex == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) {
|
||||
for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) {
|
||||
if (currentIme[imeIndex]->mTypes[i]->getHashCode()==hashCode) {
|
||||
for (int i = 0; i < (int)currentIme[imeIndex]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
currentKbdIndex[imeIndex] = i;
|
||||
flag = true;
|
||||
break;
|
||||
@ -1154,8 +1208,10 @@ namespace MiscServices {
|
||||
}
|
||||
} else {
|
||||
std::vector<int> hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[imeIndex]->mImeId);
|
||||
for(int i=0; i<(int)hashCodeList.size(); i++) {
|
||||
if (hashCode == hashCodeList[i]) {
|
||||
for (int i = 0; i < (int)hashCodeList.size(); i++)
|
||||
{
|
||||
if (hashCode == hashCodeList[i])
|
||||
{
|
||||
currentKbdIndex[imeIndex] = i;
|
||||
flag = true;
|
||||
break;
|
||||
@ -1165,16 +1221,16 @@ namespace MiscServices {
|
||||
if (flag == false) {
|
||||
IMSA_HILOGW("The current keyboard type is not found in the current IME. Reset it!");
|
||||
type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]);
|
||||
} else if (imsCore[imeIndex] == imsCore[1-imeIndex]) {
|
||||
currentKbdIndex[1-imeIndex] = currentKbdIndex[imeIndex];
|
||||
} else if (imsCore[imeIndex] == imsCore[1 - imeIndex]) {
|
||||
currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex];
|
||||
}
|
||||
}
|
||||
if (type != nullptr) {
|
||||
InputMethodSetting tmpSetting;
|
||||
if (imsCore[imeIndex] == imsCore[1-imeIndex]) {
|
||||
if (imsCore[imeIndex] == imsCore[1 - imeIndex]) {
|
||||
inputMethodSetting->SetCurrentKeyboardType(type->getHashCode());
|
||||
inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode());
|
||||
currentKbdIndex[1-imeIndex] = currentKbdIndex[imeIndex];
|
||||
currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex];
|
||||
tmpSetting.SetCurrentKeyboardType(type->getHashCode());
|
||||
tmpSetting.SetCurrentSysKeyboardType(type->getHashCode());
|
||||
} else if (imeIndex == DEFAULT_IME) {
|
||||
@ -1219,16 +1275,16 @@ namespace MiscServices {
|
||||
*/
|
||||
void PerUserSession::CopyInputMethodService(int imeIndex)
|
||||
{
|
||||
imsCore[imeIndex] = imsCore[1-imeIndex];
|
||||
localControlChannel[imeIndex] = localControlChannel[1-imeIndex];
|
||||
inputControlChannel[imeIndex] = inputControlChannel[1-imeIndex];
|
||||
inputMethodToken[imeIndex] = inputMethodToken[1-imeIndex];
|
||||
currentKbdIndex[imeIndex] = currentKbdIndex[1-imeIndex];
|
||||
imsCore[imeIndex] = imsCore[1 - imeIndex];
|
||||
localControlChannel[imeIndex] = localControlChannel[1 - imeIndex];
|
||||
inputControlChannel[imeIndex] = inputControlChannel[1 - imeIndex];
|
||||
inputMethodToken[imeIndex] = inputMethodToken[1 - imeIndex];
|
||||
currentKbdIndex[imeIndex] = currentKbdIndex[1 - imeIndex];
|
||||
int hashCode[2];
|
||||
hashCode[0] = inputMethodSetting->GetCurrentKeyboardType();
|
||||
hashCode[1] = inputMethodSetting->GetCurrentSysKeyboardType();
|
||||
if (hashCode[imeIndex] != hashCode[1-imeIndex]) {
|
||||
hashCode[imeIndex] = hashCode[1-imeIndex];
|
||||
if (hashCode[imeIndex] != hashCode[1 - imeIndex]) {
|
||||
hashCode[imeIndex] = hashCode[1 - imeIndex];
|
||||
inputMethodSetting->SetCurrentKeyboardType(hashCode[0]);
|
||||
inputMethodSetting->SetCurrentSysKeyboardType(hashCode[1]);
|
||||
|
||||
@ -1266,7 +1322,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGE("PerUserSession::BindInputAbility");
|
||||
AAFwk::Want want;
|
||||
want.SetAction("action.system.inputmethod");
|
||||
want.SetElementName("com.example.kikakeyboard","com.example.kikakeyboard.MainAbility");
|
||||
want.SetElementName("com.example.kikakeyboard", "com.example.kikakeyboard.MainAbility");
|
||||
sptr<InputMethodAbilityConnectionStub> stub(new (std::nothrow) InputMethodAbilityConnectionStub(0));
|
||||
sptr<AAFwk::AbilityConnectionProxy> connCallback = new (std::nothrow) AAFwk::AbilityConnectionProxy(stub);
|
||||
GetAbilityManagerService()->StartAbility(want);
|
||||
@ -1308,7 +1364,7 @@ namespace MiscServices {
|
||||
}
|
||||
sptr<InputDataChannelProxy> channel = new InputDataChannelProxy(channelObject);
|
||||
InputAttribute *attribute = data->ReadParcelable<InputAttribute>();
|
||||
if (attribute ==nullptr) {
|
||||
if (attribute == nullptr) {
|
||||
IMSA_HILOGI("PerUserSession::OnPrepareInput attribute is nullptr");
|
||||
}
|
||||
|
||||
@ -1319,7 +1375,7 @@ namespace MiscServices {
|
||||
}
|
||||
SetDisplayId(displayId);
|
||||
int index = GetImeIndex(client);
|
||||
IMSA_HILOGI("PerUserSession::OnPrepareInput index = %{public}d",index);
|
||||
IMSA_HILOGI("PerUserSession::OnPrepareInput index = %{public}d", index);
|
||||
currentIndex = index;
|
||||
IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility start");
|
||||
BindInputAbility();
|
||||
@ -1386,7 +1442,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("PerUserSession::onSetInputMethodCore End... Input Method Service has already been started ! ");
|
||||
return;
|
||||
}
|
||||
imsCore[index]=core;
|
||||
imsCore[index] = core;
|
||||
int ret = StartInputMethod(index);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("PerUserSession::onSetInputMethodCore Aborted! %{public}s", ErrorCode::ToString(ret));
|
||||
|
@ -33,7 +33,8 @@ namespace MiscServices {
|
||||
*/
|
||||
PerUserSetting::~PerUserSetting()
|
||||
{
|
||||
if (userState == UserState::USER_STATE_UNLOCKED) {
|
||||
if (userState == UserState::USER_STATE_UNLOCKED)
|
||||
{
|
||||
OnUserLocked();
|
||||
}
|
||||
}
|
||||
@ -49,20 +50,24 @@ namespace MiscServices {
|
||||
|
||||
inputMethodProperties.clear();
|
||||
int ret = Platform::Instance()->ListInputMethod(userId_, &inputMethodProperties);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
if (ret != ErrorCode::NO_ERROR)
|
||||
{
|
||||
IMSA_HILOGE("Failed to listInputMethod [%d]\n", userId_);
|
||||
}
|
||||
int size = inputMethodProperties.size();
|
||||
if (size == 0) {
|
||||
if (size == 0)
|
||||
{
|
||||
currentImeId = Utils::to_utf16("");
|
||||
}
|
||||
|
||||
ret = Platform::Instance()->GetInputMethodSetting(userId_, &inputMethodSetting);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
if (ret != ErrorCode::NO_ERROR)
|
||||
{
|
||||
IMSA_HILOGE("Failed to getInputMethodSetting [%d]\n", userId_);
|
||||
} else {
|
||||
if (size > 0) {
|
||||
InitInputMethodSetting();
|
||||
if (size > 0)
|
||||
{
|
||||
InitInputMethodSetting();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,32 +82,39 @@ namespace MiscServices {
|
||||
*/
|
||||
int PerUserSetting::OnPackageAdded(std::u16string& packageName, bool isSecurityIme)
|
||||
{
|
||||
if (isSecurityIme) {
|
||||
if (isSecurityIme)
|
||||
{
|
||||
isSecurityIme = false;
|
||||
}
|
||||
std::u16string imeId = GetImeId(packageName);
|
||||
if (imeId.size() != 0) {
|
||||
if (imeId.size() != 0)
|
||||
{
|
||||
IMSA_HILOGI("%s [%d]\n", ErrorCode::ToString(ErrorCode::ERROR_IME_PACKAGE_DUPLICATED), userId_);
|
||||
return ErrorCode::ERROR_IME_PACKAGE_DUPLICATED;
|
||||
}
|
||||
// retake the input method list installed in the system.
|
||||
InputMethodProperty *property = new InputMethodProperty();
|
||||
int ret = Platform::Instance()->GetInputMethodProperty(userId_, packageName, property);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
if (ret != ErrorCode::NO_ERROR)
|
||||
{
|
||||
delete property;
|
||||
property = nullptr;
|
||||
IMSA_HILOGI("%s [%d]\n", ErrorCode::ToString(ErrorCode::ERROR_NOT_IME_PACKAGE), userId_);
|
||||
return ErrorCode::ERROR_NOT_IME_PACKAGE;
|
||||
}
|
||||
inputMethodProperties.push_back(property);
|
||||
if (CheckIfSecurityIme(*property)) {
|
||||
if (isSecurityIme) {
|
||||
if (CheckIfSecurityIme(*property))
|
||||
{
|
||||
if (isSecurityIme)
|
||||
{
|
||||
isSecurityIme = true;
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
std::vector<int> types;
|
||||
for(int i=0; i<(int)property->mTypes.size(); i++) {
|
||||
for (int i = 0; i < (int)property->mTypes.size(); i++)
|
||||
{
|
||||
types.push_back(property->mTypes[i]->getHashCode());
|
||||
}
|
||||
|
||||
@ -124,29 +136,36 @@ namespace MiscServices {
|
||||
*/
|
||||
int PerUserSetting::OnPackageRemoved(std::u16string& packageName, bool isSecurityIme)
|
||||
{
|
||||
if (isSecurityIme) {
|
||||
if (isSecurityIme)
|
||||
{
|
||||
isSecurityIme = false;
|
||||
}
|
||||
std::u16string imeId = GetImeId(packageName);
|
||||
if (imeId.size() == 0) {
|
||||
if (imeId.size() == 0)
|
||||
{
|
||||
IMSA_HILOGI("%s [%d]\n", ErrorCode::ToString(ErrorCode::ERROR_NOT_IME_PACKAGE), userId_);
|
||||
return ErrorCode::ERROR_NOT_IME_PACKAGE;
|
||||
}
|
||||
bool securityFlag = false;
|
||||
std::vector<InputMethodProperty*>::iterator it;
|
||||
for(it=inputMethodProperties.begin(); it<inputMethodProperties.end(); ++it) {
|
||||
InputMethodProperty *node = (InputMethodProperty*) *it;
|
||||
for (it = inputMethodProperties.begin(); it < inputMethodProperties.end(); ++it)
|
||||
{
|
||||
InputMethodProperty *node = (InputMethodProperty*)*it;
|
||||
if (node->mImeId == imeId) {
|
||||
if (CheckIfSecurityIme(*node)==true) {
|
||||
if (CheckIfSecurityIme(*node) == true)
|
||||
{
|
||||
securityFlag = true;
|
||||
}
|
||||
inputMethodProperties.erase(it);
|
||||
delete node;
|
||||
node = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (securityFlag) {
|
||||
if (isSecurityIme) {
|
||||
if (securityFlag)
|
||||
{
|
||||
if (isSecurityIme)
|
||||
{
|
||||
isSecurityIme = true;
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
@ -157,13 +176,15 @@ namespace MiscServices {
|
||||
imSetting.SetValue(key, inputMethodSetting.GetValue(key));
|
||||
|
||||
int flag = imSetting.RemoveEnabledInputMethod(imeId);
|
||||
if (flag == false) {
|
||||
if (flag == false)
|
||||
{
|
||||
IMSA_HILOGI("The package removed is not an enabled IME. [%d]\n", userId_);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
Platform::Instance()->SetInputMethodSetting(userId_, imSetting);
|
||||
// wait for some time so that the setting change will not be overrided by the followed transact
|
||||
usleep(100*1000);
|
||||
int32_t sleepTime = 100000;
|
||||
usleep(sleepTime);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@ -178,17 +199,21 @@ namespace MiscServices {
|
||||
{
|
||||
std::u16string currentValue = inputMethodSetting.GetValue(key);
|
||||
|
||||
if (currentValue == value) {
|
||||
if (currentValue == value)
|
||||
{
|
||||
return ErrorCode::ERROR_SETTING_SAME_VALUE;
|
||||
}
|
||||
|
||||
inputMethodSetting.SetValue(key, value);
|
||||
|
||||
if (key == InputMethodSetting::CURRENT_INPUT_METHOD_TAG) {
|
||||
if (key == InputMethodSetting::CURRENT_INPUT_METHOD_TAG)
|
||||
{
|
||||
currentImeId = inputMethodSetting.GetCurrentInputMethod();
|
||||
} else if (key == InputMethodSetting::ENABLED_INPUT_METHODS_TAG) {
|
||||
if ((currentImeId.size()>0 && value.find(currentImeId) == std::string::npos) ||
|
||||
currentImeId.size()==0 ){
|
||||
} else if (key == InputMethodSetting::ENABLED_INPUT_METHODS_TAG)
|
||||
{
|
||||
if ((currentImeId.size() > 0 && value.find(currentImeId) == std::string::npos) ||
|
||||
currentImeId.size() == 0)
|
||||
{
|
||||
ResetCurrentInputMethod();
|
||||
InputMethodSetting tmpSetting;
|
||||
tmpSetting.ClearData();
|
||||
@ -209,26 +234,33 @@ namespace MiscServices {
|
||||
std::u16string imeId;
|
||||
std::u16string nextImeId = Utils::to_utf16("");
|
||||
InputMethodProperty *firstEnabledProperty = nullptr;
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
imeId = inputMethodProperties[i]->mImeId;
|
||||
if (imeId == currentImeId) {
|
||||
if (imeId == currentImeId)
|
||||
{
|
||||
flag = true;
|
||||
} else if (enabledInputMethods.find(imeId) != std::string::npos) {
|
||||
if (flag == true) {
|
||||
} else if (enabledInputMethods.find(imeId) != std::string::npos)
|
||||
{
|
||||
if (flag == true)
|
||||
{
|
||||
nextImeId = imeId;
|
||||
break;
|
||||
} else if (firstEnabledProperty == nullptr) {
|
||||
} else if (firstEnabledProperty == nullptr)
|
||||
{
|
||||
firstEnabledProperty = inputMethodProperties[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nextImeId.size() == 0 && firstEnabledProperty) {
|
||||
if (nextImeId.size() == 0 && firstEnabledProperty)
|
||||
{
|
||||
nextImeId = firstEnabledProperty->mImeId;
|
||||
}
|
||||
|
||||
// next enabled ime is not available.
|
||||
if (nextImeId.size() == 0) {
|
||||
if (nextImeId.size() == 0)
|
||||
{
|
||||
IMSA_HILOGW("No next IME is available. [%d]\n", userId_);
|
||||
return ;
|
||||
}
|
||||
@ -246,7 +278,8 @@ namespace MiscServices {
|
||||
*/
|
||||
void PerUserSetting::OnUserLocked()
|
||||
{
|
||||
if (userState == UserState::USER_STATE_STARTED) {
|
||||
if (userState == UserState::USER_STATE_STARTED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
userState = UserState::USER_STATE_STARTED;
|
||||
@ -254,11 +287,14 @@ namespace MiscServices {
|
||||
|
||||
// release input method properties
|
||||
std::vector<InputMethodProperty*>::iterator it;
|
||||
for(it=inputMethodProperties.begin(); it<inputMethodProperties.end();) {
|
||||
InputMethodProperty *node = (InputMethodProperty*) *it;
|
||||
if (node != nullptr) {
|
||||
for (it = inputMethodProperties.begin(); it < inputMethodProperties.end();)
|
||||
{
|
||||
InputMethodProperty *node = (InputMethodProperty*)*it;
|
||||
if (node != nullptr)
|
||||
{
|
||||
it = inputMethodProperties.erase(it);
|
||||
delete node;
|
||||
node = nullptr;
|
||||
}
|
||||
}
|
||||
inputMethodProperties.clear();
|
||||
@ -280,14 +316,17 @@ namespace MiscServices {
|
||||
dprintf(fd, " * Installed IME count = %d\n", size);
|
||||
std::vector<std::u16string> imeList = inputMethodSetting.GetEnabledInputMethodList();
|
||||
size = imeList.size();
|
||||
dprintf(fd, "\n * Enabled IME count : %d\n",size);
|
||||
for(int i=0; i<size; i++) {
|
||||
dprintf(fd, "\n * Enabled IME count : %d\n", size);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
dprintf(fd, " [%d] ImeId = %s\n", i, Utils::to_utf8(imeList[i]).c_str());
|
||||
std::vector<int> hashCodeList = inputMethodSetting.GetEnabledKeyboardTypes(imeList[i]);
|
||||
dprintf(fd, " Enabled keyboard count = %d, hashcode list : ", hashCodeList.size());
|
||||
for(int j=0; j<(int)hashCodeList.size(); j++) {
|
||||
for (int j = 0; j < (int)hashCodeList.size(); j++)
|
||||
{
|
||||
dprintf(fd, "%d", hashCodeList[j]);
|
||||
if (j<(int)hashCodeList.size()-1) {
|
||||
if (j < (int)hashCodeList.size()-1)
|
||||
{
|
||||
dprintf(fd, ", ");
|
||||
}
|
||||
}
|
||||
@ -313,7 +352,7 @@ namespace MiscServices {
|
||||
*/
|
||||
InputMethodProperty *PerUserSetting::GetCurrentInputMethod()
|
||||
{
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++) {
|
||||
if (currentImeId == inputMethodProperties[i]->mImeId) {
|
||||
return inputMethodProperties[i];
|
||||
}
|
||||
@ -331,21 +370,27 @@ namespace MiscServices {
|
||||
{
|
||||
InputMethodProperty *ime = nullptr;
|
||||
std::u16string systemLocales = inputMethodSetting.GetValue(InputMethodSetting::SYSTEM_LOCALE_TAG);
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
if (CheckIfSecurityIme(*inputMethodProperties[i])==false) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
if (CheckIfSecurityIme(*inputMethodProperties[i]) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// if systemLocales is not setting, return the first security ime
|
||||
if (systemLocales.size()==0) {
|
||||
if (systemLocales.size() == 0)
|
||||
{
|
||||
return inputMethodProperties[i];
|
||||
}
|
||||
if (ime==nullptr) {
|
||||
if (ime == nullptr)
|
||||
{
|
||||
ime = inputMethodProperties[i];
|
||||
}
|
||||
for(int j=0; j<(int)inputMethodProperties[i]->mTypes.size(); j++) {
|
||||
for (int j = 0; j < (int)inputMethodProperties[i]->mTypes.size(); j++)
|
||||
{
|
||||
std::u16string language = inputMethodProperties[i]->mTypes[j]->getLanguage();
|
||||
// if the keyboard language is in the list of system locales, return the ime
|
||||
if (systemLocales.find(language) != std::string::npos) {
|
||||
if (systemLocales.find(language) != std::string::npos)
|
||||
{
|
||||
return inputMethodProperties[i];
|
||||
}
|
||||
}
|
||||
@ -364,14 +409,19 @@ namespace MiscServices {
|
||||
std::u16string enabledInputMethods = inputMethodSetting.GetValue(InputMethodSetting::ENABLED_INPUT_METHODS_TAG);
|
||||
std::u16string imeId;
|
||||
InputMethodProperty *firstEnabledProperty = nullptr;
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
imeId = inputMethodProperties[i]->mImeId;
|
||||
if (imeId == currentImeId) {
|
||||
if (imeId == currentImeId)
|
||||
{
|
||||
flag = true;
|
||||
} else if (enabledInputMethods.find(imeId) != std::string::npos) {
|
||||
if (flag == true) {
|
||||
} else if (enabledInputMethods.find(imeId) != std::string::npos)
|
||||
{
|
||||
if (flag == true)
|
||||
{
|
||||
return inputMethodProperties[i];
|
||||
} else if (firstEnabledProperty == nullptr) {
|
||||
} else if (firstEnabledProperty == nullptr)
|
||||
{
|
||||
firstEnabledProperty = inputMethodProperties[i];
|
||||
}
|
||||
}
|
||||
@ -395,9 +445,10 @@ namespace MiscServices {
|
||||
int32_t PerUserSetting::ListInputMethodEnabled(std::vector<InputMethodProperty*> *properties)
|
||||
{
|
||||
std::u16string enabledInputMethods = inputMethodSetting.GetValue(InputMethodSetting::ENABLED_INPUT_METHODS_TAG);
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
|
||||
if (enabledInputMethods.find(inputMethodProperties[i]->mImeId) != std::string::npos) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
if (enabledInputMethods.find(inputMethodProperties[i]->mImeId) != std::string::npos)
|
||||
{
|
||||
properties->push_back(inputMethodProperties[i]);
|
||||
}
|
||||
}
|
||||
@ -410,7 +461,8 @@ namespace MiscServices {
|
||||
*/
|
||||
int32_t PerUserSetting::ListInputMethod(std::vector<InputMethodProperty*> *properties)
|
||||
{
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
properties->push_back(inputMethodProperties[i]);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
@ -423,9 +475,12 @@ namespace MiscServices {
|
||||
*/
|
||||
int32_t PerUserSetting::ListKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types)
|
||||
{
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
if (imeId == inputMethodProperties[i]->mImeId) {
|
||||
for(int j=0; j<(int)inputMethodProperties[i]->mTypes.size(); j++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
if (imeId == inputMethodProperties[i]->mImeId)
|
||||
{
|
||||
for (int j = 0; j < (int)inputMethodProperties[i]->mTypes.size(); j++)
|
||||
{
|
||||
types->push_back(inputMethodProperties[i]->mTypes[j]);
|
||||
}
|
||||
break;
|
||||
@ -442,7 +497,8 @@ namespace MiscServices {
|
||||
*/
|
||||
InputMethodProperty *PerUserSetting::GetInputMethodProperty(const std::u16string& imeId)
|
||||
{
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
if (inputMethodProperties[i]->mImeId == imeId) {
|
||||
return inputMethodProperties[i];
|
||||
}
|
||||
@ -458,8 +514,10 @@ namespace MiscServices {
|
||||
*/
|
||||
std::u16string PerUserSetting::GetKeyboardTypeLanguage(const InputMethodProperty *property, int hashCode)
|
||||
{
|
||||
for(int i=0; i<(int)property->mTypes.size(); i++) {
|
||||
if (property->mTypes[i]->getHashCode() == hashCode) {
|
||||
for (int i = 0; i < (int)property->mTypes.size(); i++)
|
||||
{
|
||||
if (property->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
return property->mTypes[i]->getLanguage();
|
||||
}
|
||||
}
|
||||
@ -471,13 +529,17 @@ namespace MiscServices {
|
||||
void PerUserSetting::InitInputMethodSetting()
|
||||
{
|
||||
bool flag = inputMethodSetting.FindKey(InputMethodSetting::ENABLED_INPUT_METHODS_TAG);
|
||||
if (flag == false) {
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
if (CheckIfSecurityIme(*inputMethodProperties[i])==true) {
|
||||
if (flag == false)
|
||||
{
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
if (CheckIfSecurityIme(*inputMethodProperties[i]) == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::vector<int> types;
|
||||
for(int j=0; j<(int)inputMethodProperties[i]->mTypes.size(); j++) {
|
||||
for (int j = 0; j < (int)inputMethodProperties[i]->mTypes.size(); j++)
|
||||
{
|
||||
types.push_back(inputMethodProperties[i]->mTypes[j]->getHashCode());
|
||||
}
|
||||
inputMethodSetting.AddEnabledInputMethod(inputMethodProperties[i]->mImeId, types);
|
||||
@ -487,13 +549,15 @@ namespace MiscServices {
|
||||
|
||||
flag = inputMethodSetting.FindKey(InputMethodSetting::CURRENT_INPUT_METHOD_TAG);
|
||||
std::u16string imeId = inputMethodSetting.GetCurrentInputMethod();
|
||||
if (flag == false) {
|
||||
if (flag == false)
|
||||
{
|
||||
ResetCurrentInputMethod();
|
||||
} else {
|
||||
currentImeId = imeId;
|
||||
}
|
||||
flag = inputMethodSetting.FindKey(InputMethodSetting::CURRENT_SYS_KEYBOARD_TYPE_TAG);
|
||||
if (flag==false) {
|
||||
if (flag == false)
|
||||
{
|
||||
inputMethodSetting.SetCurrentSysKeyboardType(-1);
|
||||
}
|
||||
Platform::Instance()->SetInputMethodSetting(userId_, inputMethodSetting);
|
||||
@ -513,33 +577,41 @@ namespace MiscServices {
|
||||
InputMethodProperty *firstEnabledIme = nullptr;
|
||||
bool flag = false;
|
||||
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
imeId = inputMethodProperties[i]->mImeId;
|
||||
if (enabledInputMethods.find(imeId) == std::string::npos) {
|
||||
if (enabledInputMethods.find(imeId) == std::string::npos)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (firstEnabledIme == nullptr) {
|
||||
if (firstEnabledIme == nullptr)
|
||||
{
|
||||
firstEnabledIme = inputMethodProperties[i];
|
||||
}
|
||||
|
||||
std::vector<int> hashCodeList = inputMethodSetting.GetEnabledKeyboardTypes(imeId);
|
||||
for(int j=0; j<(int)hashCodeList.size(); j++) {
|
||||
for (int j = 0; j < (int)hashCodeList.size(); j++)
|
||||
{
|
||||
std::u16string language = GetKeyboardTypeLanguage(inputMethodProperties[i], hashCodeList[j]);
|
||||
if (systemLocales.find(language) != std::string::npos) {
|
||||
if (systemLocales.find(language) != std::string::npos)
|
||||
{
|
||||
currentImeId = imeId;
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we cannot find any keyboard type which belongs to system locales,
|
||||
// we will use the first enabled ime as current ime.
|
||||
if (flag == false) {
|
||||
if (firstEnabledIme) {
|
||||
if (flag == false)
|
||||
{
|
||||
if (firstEnabledIme)
|
||||
{
|
||||
currentImeId = firstEnabledIme->mImeId;
|
||||
} else {
|
||||
currentImeId = Utils::to_utf16("");
|
||||
@ -555,8 +627,10 @@ namespace MiscServices {
|
||||
*/
|
||||
std::u16string PerUserSetting::GetImeId(const std::u16string& packageName)
|
||||
{
|
||||
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
|
||||
if (inputMethodProperties[i]->mPackageName == packageName) {
|
||||
for (int i = 0; i < (int)inputMethodProperties.size(); i++)
|
||||
{
|
||||
if (inputMethodProperties[i]->mPackageName == packageName)
|
||||
{
|
||||
return inputMethodProperties[i]->mImeId;
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteRemoteObject(cb->AsObject());
|
||||
int32_t status = Remote()->SendRequest(REGISTER_CALLBACK, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(REGISTER_CALLBACK, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
@ -70,13 +70,13 @@ namespace MiscServices {
|
||||
data.WriteString16(packageName);
|
||||
data.WriteString16(intention);
|
||||
data.WriteInt32(userId);
|
||||
int32_t status = Remote()->SendRequest(BIND_IMS, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(BIND_IMS, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
LOG_DEBUG("status = %s\n", ErrorCode::ToString(status));
|
||||
return nullptr;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) {// code=0, means no exception.
|
||||
if (code != 0) {// code = 0, means no exception.
|
||||
LOG_DEBUG("exception code : %d\n", code);
|
||||
return nullptr;
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(userId);
|
||||
data.WriteString16(packageName);
|
||||
int32_t status = Remote()->SendRequest(UNBIND_IMS, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(UNBIND_IMS, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
@ -111,12 +111,12 @@ namespace MiscServices {
|
||||
data.WriteInt32(userId);
|
||||
data.WriteInt32(displayId);
|
||||
data.WriteString16(packageName);
|
||||
int32_t status = Remote()->SendRequest(CREATE_WINDOW_TOKEN, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(CREATE_WINDOW_TOKEN, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return nullptr;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) { // code=0, means no exception.
|
||||
if (code != 0) { // code = 0, means no exception.
|
||||
IMSA_HILOGE("Exception code = %d\n", code);
|
||||
return nullptr;
|
||||
}
|
||||
@ -131,13 +131,13 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(userId);
|
||||
data.WriteString16(packageName);
|
||||
int32_t status = Remote()->SendRequest(DESTROY_WINDOW_TOKEN, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(DESTROY_WINDOW_TOKEN, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) {
|
||||
// code=0, means no exception.
|
||||
// code = 0, means no exception.
|
||||
return code;
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
@ -149,13 +149,13 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(userId);
|
||||
int32_t status = Remote()->SendRequest(LIST_INPUT_METHOD, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(LIST_INPUT_METHOD, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) {
|
||||
// code=0, means no exception.
|
||||
// code = 0, means no exception.
|
||||
return code;
|
||||
}
|
||||
int size = reply.ReadInt32();
|
||||
@ -176,13 +176,13 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(userId);
|
||||
data.WriteString16(packageName);
|
||||
int32_t status = Remote()->SendRequest(GET_INPUT_METHOD_PROPERTY, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(GET_INPUT_METHOD_PROPERTY, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) {
|
||||
// code=0, means no exception.
|
||||
// code = 0, means no exception.
|
||||
return code;
|
||||
}
|
||||
inputMethodProperty = reply.ReadParcelable<InputMethodProperty>();
|
||||
@ -195,13 +195,13 @@ namespace MiscServices {
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(userId);
|
||||
int32_t status = Remote()->SendRequest(GET_INPUT_METHOD_SETTING, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(GET_INPUT_METHOD_SETTING, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) {
|
||||
// code=0, means no exception.
|
||||
// code = 0, means no exception.
|
||||
return code;
|
||||
}
|
||||
inputMethodSetting = reply.ReadParcelable<InputMethodSetting>();
|
||||
@ -215,13 +215,13 @@ namespace MiscServices {
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(userId);
|
||||
data.WriteParcelable(&inputMethodSetting);
|
||||
int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_SETTING, data, reply,option);
|
||||
int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_SETTING, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
return status;
|
||||
}
|
||||
int code = reply.ReadException();
|
||||
if (code != 0) {
|
||||
// code=0, means no exception.
|
||||
// code = 0, means no exception.
|
||||
return code;
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
|
@ -28,127 +28,128 @@
|
||||
#include "message_handler.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::MiscServices;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputMethodAbilityTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
class InputMethodAbilityTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
void InputMethodAbilityTest::SetUpTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::SetUpTestCase");
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::SetUpTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::SetUpTestCase");
|
||||
void InputMethodAbilityTest::TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase");
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::SetUp(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::SetUp");
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::TearDown(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::TearDown");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputMethodAgent
|
||||
* @tc.desc: Checkout IInputMethodAgent.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodAgent, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodAgentStub> mInputMethodAgentStub = new InputMethodAgentStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputMethodAgentStub->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputMethodAgent> iface = iface_cast<IInputMethodAgent>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputMethodCore
|
||||
* @tc.desc: Checkout IInputMethodCore.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodCore, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> mInputMethodCoreStub = new InputMethodCoreStub(0);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputMethodCoreStub->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputMethodCore> iface = iface_cast<IInputMethodCore>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputControlChannel
|
||||
* @tc.desc: Checkout IInputControlChannel.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputControlChannel, TestSize.Level0)
|
||||
{
|
||||
sptr<InputControlChannelStub> mInputControlChannelStub = new InputControlChannelStub(0);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputControlChannelStub->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputControlChannel> iface = iface_cast<IInputControlChannel>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetInputMethodAbilityInstance
|
||||
* @tc.desc: Checkout the function of getInstance.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetInputMethodAbilityInstance, TestSize.Level0)
|
||||
{
|
||||
auto ima = InputMethodAbility::GetInstance();
|
||||
EXPECT_TRUE(ima != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSerializedInputAttribute
|
||||
* @tc.desc: Checkout the serialization of InputAttribute.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
|
||||
{
|
||||
sptr<InputAttribute> mInputAttribute = new InputAttribute();
|
||||
mInputAttribute->SetInputPattern(InputAttribute::PATTERN_PASSWORD);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteParcelable(mInputAttribute);
|
||||
EXPECT_TRUE(ret);
|
||||
sptr<InputAttribute> deserialization = data.ReadParcelable<InputAttribute>();
|
||||
EXPECT_TRUE(deserialization != nullptr);
|
||||
EXPECT_TRUE(deserialization->GetSecurityFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSerializedKeyboardType
|
||||
* @tc.desc: Checkout the serialization of KeyboardType.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedKeyboardType, TestSize.Level0)
|
||||
{
|
||||
int32_t def_value = 2021;
|
||||
sptr<KeyboardType> mKeyboardType = new KeyboardType();
|
||||
mKeyboardType->setId(def_value);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteParcelable(mKeyboardType);
|
||||
EXPECT_TRUE(ret);
|
||||
sptr<KeyboardType> deserialization = data.ReadParcelable<KeyboardType>();
|
||||
EXPECT_TRUE(deserialization != nullptr);
|
||||
EXPECT_TRUE(deserialization->getId() == def_value);
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase");
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::SetUp(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::SetUp");
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::TearDown(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::TearDown");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputMethodAgent
|
||||
* @tc.desc: Checkout IInputMethodAgent.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodAgent, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodAgentStub> mInputMethodAgentStub = new InputMethodAgentStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputMethodAgentStub->AsObject());
|
||||
ASSERT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputMethodAgent> iface = iface_cast<IInputMethodAgent>(remoteObject);
|
||||
ASSERT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputMethodCore
|
||||
* @tc.desc: Checkout IInputMethodCore.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodCore, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> mInputMethodCoreStub = new InputMethodCoreStub(0);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputMethodCoreStub->AsObject());
|
||||
ASSERT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputMethodCore> iface = iface_cast<IInputMethodCore>(remoteObject);
|
||||
ASSERT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputControlChannel
|
||||
* @tc.desc: Checkout IInputControlChannel.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputControlChannel, TestSize.Level0)
|
||||
{
|
||||
sptr<InputControlChannelStub> mInputControlChannelStub = new InputControlChannelStub(0);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputControlChannelStub->AsObject());
|
||||
ASSERT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputControlChannel> iface = iface_cast<IInputControlChannel>(remoteObject);
|
||||
ASSERT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetInputMethodAbilityInstance
|
||||
* @tc.desc: Checkout the function of getInstance.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetInputMethodAbilityInstance, TestSize.Level0)
|
||||
{
|
||||
auto ima = InputMethodAbility::GetInstance();
|
||||
ASSERT_TRUE(ima != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSerializedInputAttribute
|
||||
* @tc.desc: Checkout the serialization of InputAttribute.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
|
||||
{
|
||||
sptr<InputAttribute> mInputAttribute = new InputAttribute();
|
||||
mInputAttribute->SetInputPattern(InputAttribute::PATTERN_PASSWORD);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteParcelable(mInputAttribute);
|
||||
ASSERT_TRUE(ret);
|
||||
sptr<InputAttribute> deserialization = data.ReadParcelable<InputAttribute>();
|
||||
ASSERT_TRUE(deserialization != nullptr);
|
||||
ASSERT_TRUE(deserialization->GetSecurityFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSerializedKeyboardType
|
||||
* @tc.desc: Checkout the serialization of KeyboardType.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedKeyboardType, TestSize.Level0)
|
||||
{
|
||||
int32_t def_value = 2021;
|
||||
sptr<KeyboardType> mKeyboardType = new KeyboardType();
|
||||
mKeyboardType->setId(def_value);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteParcelable(mKeyboardType);
|
||||
ASSERT_TRUE(ret);
|
||||
sptr<KeyboardType> deserialization = data.ReadParcelable<KeyboardType>();
|
||||
ASSERT_TRUE(deserialization != nullptr);
|
||||
ASSERT_TRUE(deserialization->getId() == def_value);
|
||||
}
|
@ -32,187 +32,188 @@
|
||||
#include "input_method_setting.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::MiscServices;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class TextListener : public OnTextChangedListener {
|
||||
public:
|
||||
TextListener() {}
|
||||
~TextListener() {}
|
||||
void InsertText(const std::u16string& text)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", MiscServices::Utils::to_utf8(text).c_str());
|
||||
}
|
||||
|
||||
class TextListener : public OnTextChangedListener {
|
||||
public:
|
||||
TextListener() {}
|
||||
~TextListener() {}
|
||||
void InsertText(const std::u16string& text)
|
||||
void DeleteBackward(int32_t length)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST TextListener DeleteBackward length: %{public}d", length);
|
||||
}
|
||||
|
||||
void SetKeyboardStatus(bool status)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status);
|
||||
}
|
||||
};
|
||||
class InputMethodControllerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void InputMethodControllerTest::SetUpTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", MiscServices::Utils::to_utf8(text).c_str());
|
||||
IMSA_HILOGI("InputMethodControllerTest::SetUpTestCase");
|
||||
}
|
||||
|
||||
void DeleteBackward(int32_t length)
|
||||
void InputMethodControllerTest::TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST TextListener DeleteBackward length: %{public}d", length);
|
||||
IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase");
|
||||
}
|
||||
|
||||
void SetKeyboardStatus(bool status)
|
||||
void InputMethodControllerTest::SetUp(void)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status);
|
||||
IMSA_HILOGI("InputMethodControllerTest::SetUp");
|
||||
}
|
||||
};
|
||||
class InputMethodControllerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void InputMethodControllerTest::SetUpTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::SetUpTestCase");
|
||||
void InputMethodControllerTest::TearDown(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::TearDown");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetIMSAProxy
|
||||
* @tc.desc: Get Imsa Proxy.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testGetIMSAProxy, TestSize.Level0)
|
||||
{
|
||||
auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
EXPECT_TRUE(systemAbilityManager != nullptr);
|
||||
auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
|
||||
EXPECT_TRUE(systemAbility != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteReadIInputDataChannel
|
||||
* @tc.desc: Checkout IInputDataChannel.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testWriteReadIInputDataChannel, TestSize.Level0)
|
||||
{
|
||||
sptr<InputDataChannelStub> mInputDataChannel = new InputDataChannelStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputDataChannel->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputDataChannel> iface = iface_cast<IInputDataChannel>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIMCBindToIMSA
|
||||
* @tc.desc: Bind IMSA.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testIMCBindToIMSA, TestSize.Level0)
|
||||
{
|
||||
sptr<InputClientStub> mClient = new InputClientStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mClient->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputClient> iface = iface_cast<IInputClient>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodSettingValue
|
||||
* @tc.desc: Checkout setting.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodSettingValue, TestSize.Level0)
|
||||
{
|
||||
InputMethodSetting setting;
|
||||
std::u16string key = InputMethodSetting::CURRENT_INPUT_METHOD_TAG;
|
||||
std::u16string oldValue = setting.GetValue(key);
|
||||
std::u16string newValue = u"testCurrentImeId";
|
||||
setting.SetValue(key, newValue);
|
||||
EXPECT_EQ(setting.GetValue(key), newValue);
|
||||
|
||||
setting.SetValue(key, oldValue);
|
||||
EXPECT_EQ(setting.GetValue(key), oldValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodSettingCurrentInputMethod
|
||||
* @tc.desc: Checkout setting.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodSettingCurrentInputMethod, TestSize.Level0)
|
||||
{
|
||||
InputMethodSetting setting;
|
||||
std::u16string curIme = setting.GetCurrentInputMethod();
|
||||
std::u16string testIme = u"testCurrentImeId";
|
||||
setting.SetCurrentInputMethod(testIme);
|
||||
EXPECT_EQ(setting.GetCurrentInputMethod(), testIme);
|
||||
|
||||
setting.SetCurrentInputMethod(curIme);
|
||||
EXPECT_EQ(setting.GetCurrentInputMethod(), curIme);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodSettingCurrentKeyboard
|
||||
* @tc.desc: Checkout setting.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodSettingCurrentKeyboard, TestSize.Level0)
|
||||
{
|
||||
InputMethodSetting setting;
|
||||
int32_t curType = setting.GetCurrentKeyboardType();
|
||||
int32_t testType = 10;
|
||||
setting.SetCurrentKeyboardType(testType);
|
||||
EXPECT_EQ(setting.GetCurrentKeyboardType(), testType);
|
||||
|
||||
setting.SetCurrentKeyboardType(curType);
|
||||
EXPECT_EQ(setting.GetCurrentKeyboardType(), curType);
|
||||
|
||||
curType = setting.GetCurrentKeyboardType();
|
||||
setting.SetCurrentKeyboardType(testType);
|
||||
EXPECT_EQ(setting.GetCurrentKeyboardType(), testType);
|
||||
|
||||
setting.SetCurrentKeyboardType(curType);
|
||||
EXPECT_EQ(setting.GetCurrentKeyboardType(), curType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodWholeProcess
|
||||
* @tc.desc: Bind IMSA.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodWholeProcess, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST START");
|
||||
sptr<InputMethodController> imc = InputMethodController::GetInstance();
|
||||
EXPECT_TRUE(imc != nullptr);
|
||||
sptr<OnTextChangedListener> textListener = new TextListener();
|
||||
|
||||
IMSA_HILOGI("IMC Attach START");
|
||||
imc->Attach();
|
||||
int waitForStatusOk = 2;
|
||||
sleep(waitForStatusOk);
|
||||
|
||||
IMSA_HILOGI("IMC ShowTextInput START");
|
||||
imc->ShowTextInput(textListener);
|
||||
sleep(10);
|
||||
|
||||
IMSA_HILOGI("IMC HideTextInput START");
|
||||
imc->HideTextInput();
|
||||
sleep(waitForStatusOk);
|
||||
|
||||
IMSA_HILOGI("IMC Close START");
|
||||
imc->Close();
|
||||
sleep(waitForStatusOk);
|
||||
IMSA_HILOGI("IMC TEST OVER");
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodControllerTest::TearDownTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase");
|
||||
}
|
||||
|
||||
void InputMethodControllerTest::SetUp(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::SetUp");
|
||||
}
|
||||
|
||||
void InputMethodControllerTest::TearDown(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodControllerTest::TearDown");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetIMSAProxy
|
||||
* @tc.desc: Get Imsa Proxy.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testGetIMSAProxy, TestSize.Level0)
|
||||
{
|
||||
auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
ASSERT_TRUE(systemAbilityManager != nullptr);
|
||||
auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
|
||||
ASSERT_TRUE(systemAbility != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteReadIInputDataChannel
|
||||
* @tc.desc: Checkout IInputDataChannel.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testWriteReadIInputDataChannel, TestSize.Level0)
|
||||
{
|
||||
sptr<InputDataChannelStub> mInputDataChannel = new InputDataChannelStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputDataChannel->AsObject());
|
||||
ASSERT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputDataChannel> iface = iface_cast<IInputDataChannel>(remoteObject);
|
||||
ASSERT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testIMCBindToIMSA
|
||||
* @tc.desc: Bind IMSA.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testIMCBindToIMSA, TestSize.Level0)
|
||||
{
|
||||
sptr<InputClientStub> mClient = new InputClientStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mClient->AsObject());
|
||||
ASSERT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputClient> iface = iface_cast<IInputClient>(remoteObject);
|
||||
ASSERT_TRUE(iface != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodSettingValue
|
||||
* @tc.desc: Checkout setting.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodSettingValue, TestSize.Level0)
|
||||
{
|
||||
InputMethodSetting setting;
|
||||
std::u16string key = InputMethodSetting::CURRENT_INPUT_METHOD_TAG;
|
||||
std::u16string oldValue = setting.GetValue(key);
|
||||
std::u16string newValue = u"testCurrentImeId";
|
||||
setting.SetValue(key, newValue);
|
||||
ASSERT_TRUE(newValue == setting.GetValue(key));
|
||||
|
||||
setting.SetValue(key, oldValue);
|
||||
ASSERT_TRUE(oldValue == setting.GetValue(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodSettingCurrentInputMethod
|
||||
* @tc.desc: Checkout setting.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodSettingCurrentInputMethod, TestSize.Level0)
|
||||
{
|
||||
InputMethodSetting setting;
|
||||
std::u16string curIme = setting.GetCurrentInputMethod();
|
||||
std::u16string testIme = u"testCurrentImeId";
|
||||
setting.SetCurrentInputMethod(testIme);
|
||||
ASSERT_TRUE(testIme == setting.GetCurrentInputMethod());
|
||||
|
||||
setting.SetCurrentInputMethod(curIme);
|
||||
ASSERT_TRUE(curIme == setting.GetCurrentInputMethod());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodSettingCurrentKeyboard
|
||||
* @tc.desc: Checkout setting.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodSettingCurrentKeyboard, TestSize.Level0)
|
||||
{
|
||||
InputMethodSetting setting;
|
||||
int32_t curType = setting.GetCurrentKeyboardType();
|
||||
int32_t testType = 10;
|
||||
setting.SetCurrentKeyboardType(testType);
|
||||
ASSERT_TRUE(testType == setting.GetCurrentKeyboardType());
|
||||
|
||||
setting.SetCurrentKeyboardType(curType);
|
||||
ASSERT_TRUE(curType == setting.GetCurrentKeyboardType());
|
||||
|
||||
curType = setting.GetCurrentKeyboardType();
|
||||
setting.SetCurrentKeyboardType(testType);
|
||||
ASSERT_TRUE(testType == setting.GetCurrentKeyboardType());
|
||||
|
||||
setting.SetCurrentKeyboardType(curType);
|
||||
ASSERT_TRUE(curType == setting.GetCurrentKeyboardType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testInputMethodWholeProcess
|
||||
* @tc.desc: Bind IMSA.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodControllerTest, testInputMethodWholeProcess, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("IMC TEST START");
|
||||
sptr<InputMethodController> imc = InputMethodController::GetInstance();
|
||||
ASSERT_TRUE(imc!=nullptr);
|
||||
sptr<OnTextChangedListener> textListener = new TextListener();
|
||||
|
||||
IMSA_HILOGI("IMC Attach START");
|
||||
imc->Attach();
|
||||
int waitForStatusOk =2;
|
||||
sleep(waitForStatusOk);
|
||||
|
||||
IMSA_HILOGI("IMC ShowTextInput START");
|
||||
imc->ShowTextInput(textListener);
|
||||
sleep(10);
|
||||
|
||||
IMSA_HILOGI("IMC HideTextInput START");
|
||||
imc->HideTextInput();
|
||||
sleep(waitForStatusOk);
|
||||
|
||||
IMSA_HILOGI("IMC Close START");
|
||||
imc->Close();
|
||||
sleep(waitForStatusOk);
|
||||
IMSA_HILOGI("IMC TEST OVER");
|
||||
}
|
Loading…
Reference in New Issue
Block a user