!1 修复静态扫描及修改js接口

Merge pull request !1 from demon/master
This commit is contained in:
openharmony_ci
2021-09-27 12:11:27 +00:00
committed by Gitee
51 changed files with 1117 additions and 1104 deletions
+3 -3
View File
@@ -19,12 +19,12 @@ group("inputmethod_native_packages") {
if (is_standard_system) {
deps = [
"etc/init:inputmethodservice.rc",
"services:inputmethod_service",
"frameworks/inputmethod_controller:inputmethod_client",
"frameworks/inputmethod_ability:inputmethod_ability",
"frameworks/inputmethod_controller:inputmethod_client",
"interfaces/kits/js/declaration:inputmethod",
"interfaces/kits/js/napi:inputmethodability",
"interfaces/kits/js/napi:inputmethodengine",
"profile:miscservices_inputmethod_sa_profiles",
"services:inputmethod_service",
]
}
}
+68 -73
View File
@@ -1,73 +1,68 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethod_ability_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
]
}
config("inputmethod_ability_native_public_config") {
visibility = []
include_dirs = [ "include" ]
}
ohos_shared_library("inputmethod_ability") {
sources = [
"src/input_method_ability.cpp",
"src/input_method_agent_proxy.cpp",
"src/input_method_agent_stub.cpp",
"src/input_method_core_stub.cpp",
"src/input_method_core_proxy.cpp",
"src/event_target.cpp",
"../inputmethod_controller/src/input_method_system_ability_proxy.cpp",
]
configs = [ ":inputmethod_ability_native_config" ]
deps = [
"//utils/native/base:utils",
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/ace/napi/:ace_napi",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//base/miscservices/inputmethod/services:inputmethod_service",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
]
public_configs = [
":inputmethod_ability_native_config",
]
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethod_ability_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
]
}
config("inputmethod_ability_native_public_config") {
visibility = []
include_dirs = [ "include" ]
}
ohos_shared_library("inputmethod_ability") {
sources = [
"../inputmethod_controller/src/input_method_system_ability_proxy.cpp",
"src/event_target.cpp",
"src/input_method_ability.cpp",
"src/input_method_agent_proxy.cpp",
"src/input_method_agent_stub.cpp",
"src/input_method_core_proxy.cpp",
"src/input_method_core_stub.cpp",
]
configs = [ ":inputmethod_ability_native_config" ]
deps = [
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/ace/napi/:ace_napi",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//utils/native/base:utils",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
public_configs = [ ":inputmethod_ability_native_config" ]
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
@@ -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,7 +41,7 @@ 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_) {
first_ = first_->next;
@@ -53,11 +53,12 @@ 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();
@@ -79,7 +80,7 @@ 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();
@@ -136,7 +137,7 @@ 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;
@@ -158,7 +159,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;
@@ -39,6 +39,7 @@ namespace MiscServices {
{
if (msgHandler != nullptr) {
delete msgHandler;
msgHandler = nullptr;
}
}
@@ -100,17 +101,17 @@ namespace MiscServices {
});
}
void InputMethodAbility::setEventTarget(sptr<EventTarget> &eventTarget) {
void InputMethodAbility::setEventTarget(sptr<EventTarget> &eventTarget)
{
IMSA_HILOGI("InputMethodAbility::setEventTarget");
eventTarget_ = eventTarget;
}
void InputMethodAbility::WorkThread()
{
while(1)
{
while(1) {
Message *msg = msgHandler->GetMessage();
switch(msg->msgId_) {
switch (msg->msgId_) {
case MSG_ID_INITIALIZE_INPUT: {
OnInitialInput(msg);
break;
@@ -141,11 +142,12 @@ namespace MiscServices {
break;
}
default:{
default: {
break;
}
}
delete msg;
msg = nullptr;
}
}
@@ -161,8 +163,7 @@ namespace MiscServices {
}
sptr<InputControlChannelProxy> channelProxy = new InputControlChannelProxy(channelObject);
inputControlChannel = channelProxy;
if (inputControlChannel == nullptr)
{
if (inputControlChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::OnInitialInput inputControlChannel is nullptr");
return;
}
@@ -175,20 +176,17 @@ namespace MiscServices {
MessageParcel *data = msg->msgContent_;
sptr<InputDataChannelProxy> channalProxy = new InputDataChannelProxy(data->ReadRemoteObject());
inputDataChannel = channalProxy;
if (inputDataChannel == nullptr)
{
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::OnStartInput inputDataChannel is nullptr");
}
editorAttribute = data->ReadParcelable<InputAttribute>();
if (editorAttribute == nullptr)
{
if (editorAttribute == nullptr) {
IMSA_HILOGI("InputMethodAbility::OnStartInput editorAttribute is nullptr");
}
mSupportPhysicalKbd = data->ReadBool();
CreateInputMethodAgent(mSupportPhysicalKbd);
if (inputControlChannel != nullptr)
{
if (inputControlChannel != nullptr) {
IMSA_HILOGI("InputMethodAbility::OnStartInput inputControlChannel is not nullptr");
inputControlChannel->onAgentCreated(inputMethodAgent, nullptr);
}
@@ -211,6 +209,7 @@ namespace MiscServices {
IMSA_HILOGI("InputMethodAbility::OnStopInput");
if (writeInputChannel != nullptr) {
delete writeInputChannel;
writeInputChannel = nullptr;
}
}
@@ -252,7 +251,7 @@ namespace MiscServices {
bool InputMethodAbility::InsertText(const std::string text)
{
IMSA_HILOGI("InputMethodAbility::InsertText");
if (inputDataChannel == nullptr){
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::InsertText inputDataChanel is nullptr");
return false;
}
@@ -263,7 +262,7 @@ namespace MiscServices {
void InputMethodAbility::DeleteBackward(int32_t length)
{
IMSA_HILOGI("InputMethodAbility::DeleteBackward");
if (inputDataChannel == nullptr){
if (inputDataChannel == nullptr) {
IMSA_HILOGI("InputMethodAbility::DeleteBackward inputDataChanel is nullptr");
return;
}
@@ -52,8 +52,7 @@ namespace MiscServices {
} 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);
@@ -82,8 +81,7 @@ namespace MiscServices {
return false;
}
MessageParcel reply;
MessageOption option
{
MessageOption option {
MessageOption::TF_SYNC
};
@@ -102,8 +100,7 @@ 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);
@@ -133,8 +130,7 @@ namespace MiscServices {
return false;
}
MessageParcel reply;
MessageOption option
{
MessageOption option {
MessageOption::TF_SYNC
};
@@ -158,8 +154,7 @@ namespace MiscServices {
return false;
}
MessageParcel reply;
MessageOption option
{
MessageOption option {
MessageOption::TF_SYNC
};
@@ -176,8 +171,7 @@ 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);
@@ -193,8 +187,7 @@ 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);
+64 -68
View File
@@ -1,68 +1,64 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethod_client_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"//utils/native/base/include",
]
}
config("inputmethod_client_native_public_config") {
visibility = []
include_dirs = [
"//base/miscservices/inputmethod/frameworks/inputmethod_controller/include",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/miscservices/inputmethod/services/include",
"//utils/native/base/include",
]
}
ohos_shared_library("inputmethod_client") {
sources = [
"src/input_data_channel_stub.cpp",
"src/input_data_channel_proxy.cpp",
"src/input_client_proxy.cpp",
"src/input_client_stub.cpp",
"src/input_method_system_ability_proxy.cpp",
"src/input_method_controller.cpp",
]
deps = [
"//utils/native/base:utils",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
]
configs = [
":inputmethod_client_native_config",
]
public_configs = [ ":inputmethod_client_native_public_config" ]
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethod_client_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"//utils/native/base/include",
]
}
config("inputmethod_client_native_public_config") {
visibility = []
include_dirs = [
"//base/miscservices/inputmethod/frameworks/inputmethod_controller/include",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/miscservices/inputmethod/services/include",
"//utils/native/base/include",
]
}
ohos_shared_library("inputmethod_client") {
sources = [
"src/input_client_proxy.cpp",
"src/input_client_stub.cpp",
"src/input_data_channel_proxy.cpp",
"src/input_data_channel_stub.cpp",
"src/input_method_controller.cpp",
"src/input_method_system_ability_proxy.cpp",
]
deps = [
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//utils/native/base:utils",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
configs = [ ":inputmethod_client_native_config" ]
public_configs = [ ":inputmethod_client_native_public_config" ]
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
@@ -24,19 +24,21 @@
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
@@ -23,20 +23,20 @@
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);
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);
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
@@ -32,10 +32,10 @@ using namespace ErrorCode;
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);
@@ -65,7 +65,6 @@ namespace MiscServices {
auto ret = Remote()->SendRequest(CLOSE, data, reply, option);
if (ret != NO_ERROR) {
}
}
}
@@ -25,6 +25,7 @@ namespace MiscServices {
{
if (msgHandler != nullptr) {
delete msgHandler;
msgHandler = nullptr;
}
}
@@ -86,7 +87,6 @@ namespace MiscServices {
void InputDataChannelStub::Close()
{
}
void InputDataChannelStub::SetHandler(MessageHandler *handler)
@@ -34,6 +34,7 @@ using namespace MessageID;
{
if (msgHandler != nullptr) {
delete msgHandler;
msgHandler = nullptr;
}
}
@@ -64,6 +65,8 @@ using namespace MessageID;
workThreadHandler = std::thread([this]{WorkThread();});
mAttribute.SetInputPattern(InputAttribute::PATTERN_TEXT);
textListener = nullptr;
return true;
}
@@ -96,70 +99,71 @@ 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 +182,15 @@ 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 +199,12 @@ using namespace MessageID;
void InputMethodController::StartInput(sptr<InputClientStub> &client)
{
IMSA_HILOGI("InputMethodController::StartInput");
if(mImms == nullptr){
if (mImms == nullptr) {
return;
}
MessageParcel data;
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
&&data.WriteRemoteObject(client->AsObject()))){
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
&& data.WriteRemoteObject(client->AsObject()))) {
return;
}
mImms->startInput(data);
@@ -209,12 +213,12 @@ using namespace MessageID;
void InputMethodController::ReleaseInput(sptr<InputClientStub> &client)
{
IMSA_HILOGI("InputMethodController::ReleaseInput");
if(mImms == nullptr){
if (mImms == nullptr) {
return;
}
MessageParcel data;
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
&&data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
&& data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
return;
}
mImms->releaseInput(data);
@@ -223,12 +227,12 @@ using namespace MessageID;
void InputMethodController::StopInput(sptr<InputClientStub> &client)
{
IMSA_HILOGI("InputMethodController::StopInput");
if(mImms == nullptr){
if (mImms == nullptr) {
return;
}
MessageParcel data;
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
&&data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
&& data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
return;
}
mImms->stopInput(data);
@@ -65,7 +65,7 @@ namespace MiscServices {
MessageParcel reply;
MessageOption option;
auto ret = Remote()->SendRequest(START_INPUT,data,reply,option);
auto ret = Remote()->SendRequest(START_INPUT, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput SendRequest failed");
return;
@@ -84,7 +84,7 @@ namespace MiscServices {
MessageParcel reply;
MessageOption option;
auto ret = Remote()->SendRequest(STOP_INPUT,data,reply,option);
auto ret = Remote()->SendRequest(STOP_INPUT, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput SendRequest failed");
return;
@@ -110,11 +110,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 +133,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 +302,12 @@ namespace MiscServices {
}
KeyboardType *keyType = reply.ReadParcelable<KeyboardType>();
if (keyType == nullptr) {
return ERROR_STATUS_BAD_INDEX;
}
*retType = *keyType;
delete keyType;
keyType = nullptr;
return NO_ERROR;
}
+2 -6
View File
@@ -16,15 +16,11 @@ import("//build/ohos/ace/ace.gni")
js_declaration("inputmethod") {
part_name = "inputmethod_native"
sources = [
"./api",
]
sources = [ "./api" ]
}
ohos_copy("inputmethod_declaration") {
sources = [
"./api"
]
sources = [ "./api" ]
outputs = [ target_out_dir + "/$target_name/" ]
module_source_dir = target_out_dir + "/$target_name"
module_install_name = ""
@@ -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;
+15 -18
View File
@@ -13,20 +13,17 @@
import("//build/ohos.gni")
config("inputmethodability_native_config") {
config("inputmethodengine_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
]
include_dirs = [ "include" ]
}
config("inputmethodability_native_public_config") {
config("inputmethodengine_native_public_config") {
visibility = []
include_dirs = [ "include" ]
}
ohos_shared_library("inputmethodability") {
ohos_shared_library("inputmethodengine") {
include_dirs = [
"//third_party/node/src",
"//foundation/ace/napi/interfaces/kits",
@@ -37,31 +34,31 @@ ohos_shared_library("inputmethodability") {
"-g3",
]
sources = [ "js_input_method_ability.cpp" ]
sources = [ "js_input_method_engine.cpp" ]
configs = [ ":inputmethodability_native_config" ]
configs = [ ":inputmethodengine_native_config" ]
deps = [
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//foundation/ace/napi/:ace_napi",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//utils/native/base:utils",
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/ace/napi/:ace_napi",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//utils/native/base:utils",
]
external_deps = [
@@ -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,14 +174,15 @@ 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;
}
napi_value InputMethodAbilityInit(napi_env env, napi_value exports)
napi_value InputMethodEngineInit(napi_env env, napi_value exports)
{
IMSA_HILOGI("InputMethodAbilityInit() is called!");
IMSA_HILOGI("InputMethodEngineInit() is called!");
const char className[] = "EventTarget";
napi_value constructor = nullptr;
napi_property_descriptor desc[] = {
@@ -189,23 +192,23 @@ 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);
napi_set_named_property(env, exports, "InputMethodEngine", constructor);
return 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 },
static napi_module inputMethodEngineModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = InputMethodEngineInit,
.nm_modname = "inputMethodEngine",
.nm_priv = ((void*)0),
.reserved = {0},
};
/*
* module register
@@ -213,5 +216,5 @@ static napi_module inputMethodAbilityModule = {
extern "C" __attribute__((constructor)) void RegisterModule()
{
IMSA_HILOGI("RegisterModule() is called!");
napi_module_register(&inputMethodAbilityModule);
napi_module_register(&inputMethodEngineModule);
}
+89 -96
View File
@@ -1,96 +1,89 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethod_services_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${inputmethod_path}/frameworks/inputmethod_ability/include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
]
cflags_cc = [ "-fexceptions" ]
}
ohos_shared_library("inputmethod_service") {
sources = [
"../services/src/input_attribute.cpp",
"../services/src/global.cpp",
"../services/src/input_channel.cpp",
"../services/src/keyboard_type.cpp",
"../services/src/input_method_property.cpp",
"../services/src/message.cpp",
"../services/src/message_handler.cpp",
"../services/src/input_method_system_ability_stub.cpp",
"../services/src/input_method_setting.cpp",
"../services/src/peruser_setting.cpp",
"../services/src/peruser_session.cpp",
"../services/src/input_method_system_ability.cpp",
"../services/src/input_control_channel_proxy.cpp",
"../services/src/input_control_channel_stub.cpp",
"../services/src/platform.cpp",
"../services/src/platform_callback_stub.cpp",
"../services/src/platform_callback_proxy.cpp",
"../services/src/platform_api_proxy.cpp",
"../services/src/input_method_ability_connection_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_ability.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp",
]
configs = [ ":inputmethod_services_native_config" ]
public_configs = [
":inputmethod_services_native_config",
]
deps = [
"//utils/native/base:utils",
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/ace/napi/:ace_napi",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/ace/napi/:ace_napi",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
]
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/miscservices/inputmethod/inputmethod.gni")
import("//build/ohos.gni")
config("inputmethod_services_native_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${inputmethod_path}/frameworks/inputmethod_ability/include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
]
cflags_cc = [ "-fexceptions" ]
}
ohos_shared_library("inputmethod_service") {
sources = [
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_ability.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp",
"../services/src/global.cpp",
"../services/src/input_attribute.cpp",
"../services/src/input_channel.cpp",
"../services/src/input_control_channel_proxy.cpp",
"../services/src/input_control_channel_stub.cpp",
"../services/src/input_method_ability_connection_stub.cpp",
"../services/src/input_method_property.cpp",
"../services/src/input_method_setting.cpp",
"../services/src/input_method_system_ability.cpp",
"../services/src/input_method_system_ability_stub.cpp",
"../services/src/keyboard_type.cpp",
"../services/src/message.cpp",
"../services/src/message_handler.cpp",
"../services/src/peruser_session.cpp",
"../services/src/peruser_setting.cpp",
"../services/src/platform.cpp",
"../services/src/platform_api_proxy.cpp",
"../services/src/platform_callback_proxy.cpp",
"../services/src/platform_callback_stub.cpp",
]
configs = [ ":inputmethod_services_native_config" ]
public_configs = [ ":inputmethod_services_native_config" ]
deps = [
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/base:base",
"//foundation/aafwk/standard/interfaces/innerkits/intent:intent",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/ace/napi/:ace_napi",
"//foundation/ace/napi/:ace_napi",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event:mmi_event",
"//utils/native/base:utils",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
subsystem_name = "miscservices"
part_name = "inputmethod_native"
}
@@ -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;
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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);
};
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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&&);
};
}
}
+3 -3
View File
@@ -87,12 +87,12 @@ class MessageHandler {
private:
std::mutex mMutex; // a mutex to guard message queue
std::condition_variable mCV; // condition variable to work with mMutex
std::queue<Message*> mQueue ; // Message queue, guarded by mMutex;
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&&);
};
}
}
+101 -100
View File
@@ -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,100 @@ 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
MIN_IME = 2,
};
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);
};
}
}
+2 -2
View File
@@ -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);
+32 -33
View File
@@ -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
+2 -1
View File
@@ -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 {
+3 -3
View File
@@ -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;
}
+1 -1
View File
@@ -106,7 +106,7 @@ namespace MiscServices {
\param channel channel for sending physical keyboard event from input client to input method service
*/
void InputControlChannelStub::onAgentCreated(sptr < IInputMethodAgent >& agent, InputChannel *channel)
{
{
IMSA_HILOGI("InputControlChannelStub::onAgentCreated");
{
std::unique_lock<std::mutex> lck(mtx);
@@ -32,7 +32,7 @@ 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 +46,7 @@ namespace MiscServices {
int resultCode)
{
IMSA_HILOGE("ConnectAbility: OnAbilityDisconnectDone.");
if(messageHandler != nullptr){
if (messageHandler != nullptr) {
MessageParcel *data = new MessageParcel();
data->WriteParcelable(&element);
data->WriteInt32(mIndex);
+1 -1
View File
@@ -33,7 +33,7 @@ namespace MiscServices {
}
~InputMethodAgentProxy()
{
{
}
int32_t dispatchKey(int key, int status)
+13 -12
View File
@@ -28,7 +28,7 @@ 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 +46,7 @@ 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 +56,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 +68,7 @@ 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 +83,18 @@ 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)
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 +118,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;
+16 -16
View File
@@ -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,7 @@ 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 +82,7 @@ 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 +137,7 @@ 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 +157,12 @@ 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 +193,7 @@ 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,7 +219,7 @@ 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++) {
for (int i = 0; i < (int)tmpVector.size(); i++) {
if (tmpVector[i].find_first_of(imeId) != std::u16string::npos) {
flag = true;
imeStr = tmpVector[i];
@@ -232,7 +232,7 @@ 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 +306,18 @@ 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 +332,9 @@ 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);
}
}
+40 -20
View File
@@ -58,24 +58,27 @@ 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 +161,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 +256,11 @@ 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 +286,7 @@ 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 +313,7 @@ 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 +359,7 @@ 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 +411,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 +468,22 @@ 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 +547,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 +616,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 +649,18 @@ 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 +684,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 +866,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,7 @@ 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 +134,7 @@ 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 +152,7 @@ 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();
+21 -21
View File
@@ -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;
}
}
}
+4 -1
View File
@@ -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;
}
}
}
+1
View File
@@ -32,6 +32,7 @@ namespace MiscServices {
Message *msg = mQueue.front();
mQueue.pop();
delete msg;
msg = nullptr;
}
}
+82 -75
View File
@@ -123,16 +123,17 @@ namespace MiscServices {
void PerUserSession::WorkThread()
{
if (msgHandler == nullptr) {
return ;
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,7 +239,7 @@ namespace MiscServices {
IMSA_HILOGI("PerUserSession::ResetIme");
std::unique_lock<std::mutex> lock(mtx);
InputMethodProperty *ime[] = {defaultIme, securityIme};
for(int i=0; i<2; i++) {
for (int i = 0; i < MIN_IME; i++) {
if (currentIme[i] == ime[i] && ime[i] != nullptr) {
continue;
}
@@ -246,8 +248,8 @@ namespace MiscServices {
}
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,7 +257,7 @@ 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)) {
flag = true;
@@ -264,8 +266,8 @@ namespace MiscServices {
}
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 +285,18 @@ namespace MiscServices {
InputMethodSetting tmpSetting;
bool flag = false;
std::unique_lock<std::mutex> lock(mtx);
for(int i=0; i<MAX_IME; i++) {
for (int i = 0; i < MAX_IME; i++) {
if (currentIme[i] && currentIme[i]->mPackageName == packageName) {
if (currentClient && GetImeIndex(currentClient)==i) {
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);
}
@@ -371,10 +373,11 @@ 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) {
for (it = mapClients.begin(); it != mapClients.end(); ++it) {
if (it->second->attribute.GetSecurityFlag() == flag) {
remainClientNum++;
}
@@ -393,7 +396,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 +436,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 +491,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 +511,7 @@ 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 +542,7 @@ 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 +557,9 @@ 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,7 +626,7 @@ namespace MiscServices {
hashCode = hashCodeList[0];
}
for(int i=0; i<(int)currentIme[DEFAULT_IME]->mTypes.size(); i++) {
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 +644,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,8 +672,8 @@ 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();
@@ -679,14 +682,14 @@ namespace MiscServices {
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) {
@@ -743,7 +746,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 +755,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,7 +790,7 @@ 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++) {
for (int i = 0; i < (int)currentIme[index]->mTypes.size(); i++) {
if (currentIme[index]->mTypes[i]->getHashCode() == hashCode) {
currentKbdIndex[index] = i;
break;
@@ -800,7 +803,7 @@ namespace MiscServices {
if (currentKbdTypes[num] == hashCode) {
return ErrorCode::ERROR_SETTING_SAME_VALUE;
}
for(int i=0; i<(int)currentKbdTypes.size(); i++) {
for (int i = 0; i < (int)currentKbdTypes.size(); i++) {
if (currentKbdTypes[i] == hashCode) {
currentKbdIndex[index] = i;
break;
@@ -815,10 +818,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 {
@@ -845,19 +848,19 @@ namespace MiscServices {
int index = GetImeIndex(currentClient);
if (index == -1) {
IMSA_HILOGW("%{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_);
return ;
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;
std::vector<int> currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId);
size = currentKbdTypes.size();
}
if (size < 2) {
if (size < MIN_IME) {
IMSA_HILOGW("No next keyboard is available. [%{public}d]\n", userId_);
return ;
return;
}
int num = currentKbdIndex[index]+1;
@@ -868,7 +871,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());
}
@@ -890,7 +893,7 @@ namespace MiscServices {
ClientInfo *clientInfo = GetClientInfo(currentClient);
if (clientInfo == nullptr) {
IMSA_HILOGE("%{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_);
return ;
return;
}
int ret = clientInfo->client->setDisplayMode(mode);
if (ret != ErrorCode::NO_ERROR) {
@@ -904,13 +907,13 @@ namespace MiscServices {
*/
void PerUserSession::OnRestartIms(int index, const std::u16string& imeId)
{
if (index<0 || index>=MAX_IME) {
return ;
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);
}
@@ -934,13 +937,13 @@ namespace MiscServices {
if (currentClient != nullptr) {
HideKeyboard(currentClient);
}
for(int i=0; i<2; i++) {
for (int i = 0; i < MIN_IME; 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;
@@ -950,6 +953,7 @@ namespace MiscServices {
IMSA_HILOGE("2-onInputReleased return : %{public}s", ErrorCode::ToString(ret));
}
delete clientInfo;
clientInfo = nullptr;
}
IMSA_HILOGD("erase client..\n");
it = mapClients.erase(it);
@@ -976,7 +980,7 @@ 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) {
dprintf(fd, " *[%d] Client Information: (current client)\n", index++);
@@ -986,7 +990,7 @@ namespace MiscServices {
DumpClientInfo(fd, *(it->second));
}
std::string header[2] = {"Current", "Security"};
for(int i=0; i<2; i++) {
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]);
@@ -997,7 +1001,7 @@ namespace MiscServices {
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 +1027,9 @@ 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,13 +1075,13 @@ 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)
{
static int errorNum[2] = {0, 0};
static time_t past[2] = {time(0), time(0)};
static int errorNum[MIN_IME] = {0, 0};
static time_t past[MIN_IME] = {time(0), time(0)};
if (resetFlag == true) {
errorNum[imeIndex] = 0;
past[imeIndex] = 0;
@@ -1102,7 +1109,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,7 +1125,7 @@ namespace MiscServices {
return nullptr;
}
int hashCode = currentKbdTypes[typeIndex];
for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) {
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 +1152,8 @@ 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,7 +1161,7 @@ namespace MiscServices {
}
} else {
std::vector<int> hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[imeIndex]->mImeId);
for(int i=0; i<(int)hashCodeList.size(); i++) {
for (int i = 0; i < (int)hashCodeList.size(); i++) {
if (hashCode == hashCodeList[i]) {
currentKbdIndex[imeIndex] = i;
flag = true;
@@ -1165,16 +1172,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 +1226,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 +1273,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 +1315,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 +1326,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 +1393,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));
+40 -37
View File
@@ -62,7 +62,7 @@ namespace MiscServices {
IMSA_HILOGE("Failed to getInputMethodSetting [%d]\n", userId_);
} else {
if (size > 0) {
InitInputMethodSetting();
InitInputMethodSetting();
}
}
}
@@ -90,6 +90,7 @@ namespace MiscServices {
int ret = Platform::Instance()->GetInputMethodProperty(userId_, packageName, property);
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;
}
@@ -102,7 +103,7 @@ namespace MiscServices {
}
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());
}
@@ -134,14 +135,15 @@ namespace MiscServices {
}
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;
}
}
@@ -163,7 +165,8 @@ namespace MiscServices {
}
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;
}
@@ -187,8 +190,8 @@ namespace MiscServices {
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 ){
if ((currentImeId.size() > 0 && value.find(currentImeId) == std::string::npos) ||
currentImeId.size() == 0) {
ResetCurrentInputMethod();
InputMethodSetting tmpSetting;
tmpSetting.ClearData();
@@ -209,7 +212,7 @@ 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) {
flag = true;
@@ -230,7 +233,7 @@ namespace MiscServices {
// next enabled ime is not available.
if (nextImeId.size() == 0) {
IMSA_HILOGW("No next IME is available. [%d]\n", userId_);
return ;
return;
}
InputMethodSetting tmpSetting;
@@ -254,11 +257,12 @@ namespace MiscServices {
// release input method properties
std::vector<InputMethodProperty*>::iterator it;
for(it=inputMethodProperties.begin(); it<inputMethodProperties.end();) {
InputMethodProperty *node = (InputMethodProperty*) *it;
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 +284,14 @@ 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 +317,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,18 +335,18 @@ 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) {
@@ -364,7 +368,7 @@ 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) {
flag = true;
@@ -395,8 +399,7 @@ 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++) {
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 +413,7 @@ 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 +426,9 @@ namespace MiscServices {
*/
int32_t PerUserSetting::ListKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types)
{
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
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 j = 0; j < (int)inputMethodProperties[i]->mTypes.size(); j++) {
types->push_back(inputMethodProperties[i]->mTypes[j]);
}
break;
@@ -442,7 +445,7 @@ 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,7 +461,7 @@ namespace MiscServices {
*/
std::u16string PerUserSetting::GetKeyboardTypeLanguage(const InputMethodProperty *property, int hashCode)
{
for(int i=0; i<(int)property->mTypes.size(); i++) {
for (int i = 0; i < (int)property->mTypes.size(); i++) {
if (property->mTypes[i]->getHashCode() == hashCode) {
return property->mTypes[i]->getLanguage();
}
@@ -472,12 +475,12 @@ namespace MiscServices {
{
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) {
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);
@@ -493,7 +496,7 @@ namespace MiscServices {
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,7 +516,7 @@ 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) {
continue;
@@ -523,7 +526,7 @@ namespace MiscServices {
}
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) {
currentImeId = imeId;
@@ -555,7 +558,7 @@ namespace MiscServices {
*/
std::u16string PerUserSetting::GetImeId(const std::u16string& packageName)
{
for(int i=0; i<(int)inputMethodProperties.size(); i++) {
for (int i = 0; i < (int)inputMethodProperties.size(); i++) {
if (inputMethodProperties[i]->mPackageName == packageName) {
return inputMethodProperties[i]->mImeId;
}
+16 -16
View File
@@ -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;
+1 -1
View File
@@ -86,7 +86,7 @@ namespace MiscServices {
break;
}
default: {
return ;
return;
}
}
+27 -36
View File
@@ -16,9 +16,7 @@ import("//build/test.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
]
include_dirs = [ "include" ]
}
module_output_path = "inputmethod_native/inputmethod_service"
@@ -26,67 +24,57 @@ module_output_path = "inputmethod_native/inputmethod_service"
ohos_unittest("InputMethodControllerTest") {
module_out_path = module_output_path
sources = [
"src/input_method_controller_test.cpp"]
sources = [ "src/input_method_controller_test.cpp" ]
configs = [
":module_private_config",
]
configs = [ ":module_private_config" ]
deps = [
"//base/miscservices/inputmethod/frameworks/inputmethod_controller:inputmethod_client",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//base/miscservices/inputmethod/frameworks/inputmethod_controller:inputmethod_client",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//utils/native/base:utils",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/ace/napi/:ace_napi",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/ace/napi/:ace_napi",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
"//utils/native/base:utils",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
ohos_unittest("InputMethodAbilityTest") {
module_out_path = module_output_path
sources = [
"src/input_method_ability_test.cpp"]
sources = [ "src/input_method_ability_test.cpp" ]
configs = [
":module_private_config",
]
configs = [ ":module_private_config" ]
deps = [
"//base/miscservices/inputmethod/frameworks/inputmethod_controller:inputmethod_client",
"//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability",
"//base/miscservices/inputmethod/frameworks/inputmethod_controller:inputmethod_client",
"//base/miscservices/inputmethod/services:inputmethod_service",
"//utils/native/base:utils",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/ace/napi/:ace_napi",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/ace/napi/:ace_napi",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
"//utils/native/base:utils",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
group("unittest") {
@@ -94,5 +82,8 @@ group("unittest") {
deps = []
deps += [ ":InputMethodControllerTest", ":InputMethodAbilityTest" ]
deps += [
":InputMethodAbilityTest",
":InputMethodControllerTest",
]
}
+121 -120
View File
@@ -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);
}
+173 -172
View File
@@ -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");
}