mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-27 08:51:48 +00:00
fix warning
Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
parent
716ed132be
commit
5d80dc7a92
@ -53,6 +53,7 @@ namespace MiscServices {
|
||||
int32_t displyId = 0;
|
||||
sptr<IRemoteObject> startInputToken;
|
||||
InputChannel *writeInputChannel;
|
||||
bool stop_;
|
||||
|
||||
// communicating with IMSA
|
||||
sptr<IInputControlChannel> inputControlChannel;
|
||||
|
@ -29,8 +29,9 @@ namespace MiscServices {
|
||||
sptr<InputMethodAbility> InputMethodAbility::instance_;
|
||||
std::mutex InputMethodAbility::instanceLock_;
|
||||
|
||||
InputMethodAbility::InputMethodAbility()
|
||||
InputMethodAbility::InputMethodAbility() : stop_(false)
|
||||
{
|
||||
writeInputChannel = nullptr;
|
||||
Initialize();
|
||||
OnConnect();
|
||||
}
|
||||
@ -41,6 +42,7 @@ namespace MiscServices {
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
}
|
||||
stop_ = true;
|
||||
}
|
||||
|
||||
sptr<InputMethodAbility> InputMethodAbility::GetInstance()
|
||||
@ -109,7 +111,7 @@ namespace MiscServices {
|
||||
|
||||
void InputMethodAbility::WorkThread()
|
||||
{
|
||||
while(1) {
|
||||
while (!stop_) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_INITIALIZE_INPUT: {
|
||||
|
@ -24,6 +24,7 @@ namespace MiscServices {
|
||||
|
||||
InputMethodAgentStub::InputMethodAgentStub()
|
||||
{
|
||||
msgHandler_ = nullptr;
|
||||
}
|
||||
|
||||
InputMethodAgentStub::~InputMethodAgentStub()
|
||||
|
@ -33,6 +33,7 @@ namespace MiscServices {
|
||||
InputMethodCoreStub::InputMethodCoreStub(int userId)
|
||||
{
|
||||
userId_ = userId;
|
||||
msgHandler_ = nullptr;
|
||||
}
|
||||
|
||||
InputMethodCoreStub::~InputMethodCoreStub()
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputClientStub : public IRemoteStub<IInputClient> {
|
||||
class InputClientStub : public IRemoteStub<IInputClient> {
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(InputClientStub);
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
@ -33,7 +33,7 @@ class InputClientStub : public IRemoteStub<IInputClient> {
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
||||
int32_t onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent,
|
||||
const InputChannel *channel) override;
|
||||
const InputChannel *channel) override;
|
||||
int32_t onInputReleased(int32_t retValue) override;
|
||||
int32_t setDisplayMode(int32_t mode) override;
|
||||
private:
|
||||
|
@ -26,7 +26,8 @@ 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;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
InputDataChannelStub();
|
||||
~InputDataChannelStub();
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
@ -77,6 +77,7 @@ namespace MiscServices {
|
||||
static sptr<InputMethodController> instance_;
|
||||
std::thread workThreadHandler;
|
||||
MessageHandler *msgHandler;
|
||||
bool stop_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ using namespace MessageID;
|
||||
sptr<InputMethodController> InputMethodController::instance_;
|
||||
std::mutex InputMethodController::instanceLock_;
|
||||
|
||||
InputMethodController::InputMethodController()
|
||||
InputMethodController::InputMethodController() : stop_(false)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController structure");
|
||||
Initialize();
|
||||
@ -35,6 +35,7 @@ using namespace MessageID;
|
||||
if (msgHandler != nullptr) {
|
||||
delete msgHandler;
|
||||
msgHandler = nullptr;
|
||||
stop_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +98,7 @@ using namespace MessageID;
|
||||
|
||||
void InputMethodController::WorkThread()
|
||||
{
|
||||
while(1) {
|
||||
while (!stop_) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_INSERT_CHAR: {
|
||||
|
@ -303,7 +303,7 @@ namespace MiscServices {
|
||||
|
||||
KeyboardType *keyType = reply.ReadParcelable<KeyboardType>();
|
||||
if (keyType == nullptr) {
|
||||
return ERROR_STATUS_BAD_INDEX;
|
||||
return ERROR_NULL_POINTER;
|
||||
}
|
||||
*retType = *keyType;
|
||||
delete keyType;
|
||||
|
@ -18,203 +18,203 @@
|
||||
#include "napi/native_node_api.h"
|
||||
#include "global.h"
|
||||
|
||||
using namespace OHOS::MiscServices;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
napi_value JS_Constructor(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_Constructor() is called!");
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, nullptr, nullptr, &thisVar, &data);
|
||||
|
||||
napi_value JS_Constructor(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_Constructor() is called!");
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, nullptr, nullptr, &thisVar, &data);
|
||||
|
||||
OHOS::MiscServices::EventTarget *eventTarget = new OHOS::MiscServices::EventTarget(env, thisVar);
|
||||
napi_wrap(env, thisVar, eventTarget,
|
||||
[](napi_env env, void *data, void *hint)
|
||||
{
|
||||
EventTarget *eventTarget = (EventTarget*)data;
|
||||
delete eventTarget;
|
||||
eventTarget = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
OHOS::sptr<EventTarget> eventTarget_ = eventTarget;
|
||||
InputMethodAbility::GetInstance()->setEventTarget(eventTarget_);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value JS_InsertText(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_InsertText() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
char type[64] = { 0 };
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
std::string text = type;
|
||||
InputMethodAbility::GetInstance()->InsertText(text);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
IMSA_HILOGI("JS_InsertText() is end!");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_DeleteBackward(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_DeleteBackward() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
int32_t value32 = 0;
|
||||
napi_get_value_int32(env, argv[0], &value32);
|
||||
InputMethodAbility::GetInstance()->DeleteBackward(value32);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_HideKeyboardSelf(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_HideKeyboardSelf() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
InputMethodAbility::GetInstance()->HideKeyboardSelf();
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_On(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_On() is called!");
|
||||
size_t requireArgc = 2;
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = 0;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "requires 2 parameter");
|
||||
|
||||
napi_valuetype eventValueType;
|
||||
napi_typeof(env, argv[0], &eventValueType);
|
||||
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
|
||||
|
||||
napi_valuetype eventHandleType;
|
||||
napi_typeof(env, argv[1], &eventHandleType);
|
||||
NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 2");
|
||||
|
||||
char type[64] = { 0 };
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
|
||||
IMSA_HILOGI("call ima on function");
|
||||
eventTarget->On((const char*)type, argv[1]);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
IMSA_HILOGI("JS_On() is end!");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_Off(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
size_t requireArgc = 1;
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = 0;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "requires 2 parameter");
|
||||
|
||||
napi_valuetype eventValueType;
|
||||
napi_typeof(env, argv[0], &eventValueType);
|
||||
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
|
||||
|
||||
char *type = nullptr;
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen);
|
||||
type = new char[typeLen + 1];
|
||||
napi_get_value_string_utf8(env, argv[0], type, typeLen + 1, &typeLen);
|
||||
|
||||
if (argc > requireArgc) {
|
||||
NAPI_ASSERT(env, eventValueType == napi_function, "type mismatch for parameter 2");
|
||||
eventTarget->Off(type, argv[1]);
|
||||
} else {
|
||||
eventTarget->Off(type);
|
||||
OHOS::MiscServices::EventTarget *eventTarget = new OHOS::MiscServices::EventTarget(env, thisVar);
|
||||
napi_wrap(env, thisVar, eventTarget,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
EventTarget *eventTarget = (EventTarget*)data;
|
||||
delete eventTarget;
|
||||
eventTarget = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
OHOS::sptr<EventTarget> eventTarget_ = eventTarget;
|
||||
InputMethodAbility::GetInstance()->setEventTarget(eventTarget_);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
delete type;
|
||||
delete type;
|
||||
type = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
napi_value JS_InsertText(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_InsertText() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
napi_value InputMethodEngineInit(napi_env env, napi_value exports)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEngineInit() is called!");
|
||||
const char className[] = "EventTarget";
|
||||
napi_value constructor = nullptr;
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("insertText", JS_InsertText),
|
||||
DECLARE_NAPI_FUNCTION("DeleteBackward", JS_DeleteBackward),
|
||||
DECLARE_NAPI_FUNCTION("HideKeyboardSelf", JS_HideKeyboardSelf),
|
||||
DECLARE_NAPI_FUNCTION("on", JS_On),
|
||||
DECLARE_NAPI_FUNCTION("off", JS_Off),
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
char type[64] = { 0 };
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
std::string text = type;
|
||||
InputMethodAbility::GetInstance()->InsertText(text);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
IMSA_HILOGI("JS_InsertText() is end!");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_DeleteBackward(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_DeleteBackward() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
int32_t value32 = 0;
|
||||
napi_get_value_int32(env, argv[0], &value32);
|
||||
InputMethodAbility::GetInstance()->DeleteBackward(value32);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_HideKeyboardSelf(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_HideKeyboardSelf() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
InputMethodAbility::GetInstance()->HideKeyboardSelf();
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_On(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_On() is called!");
|
||||
size_t requireArgc = 2;
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = 0;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "requires 2 parameter");
|
||||
|
||||
napi_valuetype eventValueType;
|
||||
napi_typeof(env, argv[0], &eventValueType);
|
||||
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
|
||||
|
||||
napi_valuetype eventHandleType;
|
||||
napi_typeof(env, argv[1], &eventHandleType);
|
||||
NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 2");
|
||||
|
||||
char type[64] = { 0 };
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &typeLen);
|
||||
|
||||
IMSA_HILOGI("call ima on function");
|
||||
eventTarget->On((const char*)type, argv[1]);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
IMSA_HILOGI("JS_On() is end!");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_Off(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
size_t requireArgc = 1;
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = 0;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "requires 2 parameter");
|
||||
|
||||
napi_valuetype eventValueType;
|
||||
napi_typeof(env, argv[0], &eventValueType);
|
||||
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
|
||||
|
||||
char *type = nullptr;
|
||||
size_t typeLen = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen);
|
||||
type = new char[typeLen + 1];
|
||||
napi_get_value_string_utf8(env, argv[0], type, typeLen + 1, &typeLen);
|
||||
|
||||
if (argc > requireArgc) {
|
||||
NAPI_ASSERT(env, eventValueType == napi_function, "type mismatch for parameter 2");
|
||||
eventTarget->Off(type, argv[1]);
|
||||
} else {
|
||||
eventTarget->Off(type);
|
||||
}
|
||||
|
||||
delete type;
|
||||
type = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value InputMethodEngineInit(napi_env env, napi_value exports)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEngineInit() is called!");
|
||||
const char className[] = "EventTarget";
|
||||
napi_value constructor = nullptr;
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("insertText", JS_InsertText),
|
||||
DECLARE_NAPI_FUNCTION("DeleteBackward", JS_DeleteBackward),
|
||||
DECLARE_NAPI_FUNCTION("HideKeyboardSelf", JS_HideKeyboardSelf),
|
||||
DECLARE_NAPI_FUNCTION("on", JS_On),
|
||||
DECLARE_NAPI_FUNCTION("off", JS_Off),
|
||||
};
|
||||
napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr,
|
||||
sizeof(desc) / sizeof(desc[0]), desc, &constructor);
|
||||
napi_set_named_property(env, exports, "InputMethodEngine", constructor);
|
||||
return exports;
|
||||
}
|
||||
|
||||
/*
|
||||
* module define
|
||||
*/
|
||||
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},
|
||||
};
|
||||
napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr,
|
||||
sizeof(desc) / sizeof(desc[0]), desc, &constructor);
|
||||
napi_set_named_property(env, exports, "InputMethodEngine", constructor);
|
||||
return exports;
|
||||
/*
|
||||
* module register
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void RegisterModule()
|
||||
{
|
||||
IMSA_HILOGI("RegisterModule() is called!");
|
||||
napi_module_register(&inputMethodEngineModule);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* module define
|
||||
*/
|
||||
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
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void RegisterModule()
|
||||
{
|
||||
IMSA_HILOGI("RegisterModule() is called!");
|
||||
napi_module_register(&inputMethodEngineModule);
|
||||
}
|
@ -51,7 +51,6 @@ namespace MiscServices {
|
||||
virtual int32_t listInputMethodEnabled(std::vector<InputMethodProperty*> *properties) override;
|
||||
virtual int32_t listInputMethod(std::vector<InputMethodProperty*> *properties) override;
|
||||
virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types) override;
|
||||
int32_t dump(int32_t fd, const std::vector<std::u16string>& args);
|
||||
virtual int32_t setInputMethodCore(sptr<IInputMethodCore> &core) override;
|
||||
protected:
|
||||
void OnStart() override;
|
||||
|
@ -94,7 +94,6 @@ namespace MiscServices {
|
||||
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:
|
||||
@ -112,7 +111,6 @@ namespace MiscServices {
|
||||
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);
|
||||
@ -123,6 +121,8 @@ namespace MiscServices {
|
||||
int displayId; // the id of the display screen on which the user is
|
||||
int currentIndex;
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*> mapClients;
|
||||
int MIN_IME = 2;
|
||||
int COMMON_COUNT_THREE_HUNDRED = 300;
|
||||
|
||||
InputMethodProperty *currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime
|
||||
|
||||
@ -156,8 +156,6 @@ namespace MiscServices {
|
||||
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();
|
||||
|
@ -58,6 +58,7 @@ namespace MiscServices {
|
||||
std::vector<InputMethodProperty*> inputMethodProperties; // a vector to save all IME installed for this user
|
||||
std::u16string currentImeId; // the id of the default input method engine.
|
||||
InputMethodSetting inputMethodSetting; // the object to manage the setting data for this user
|
||||
int COMMON_COUNT_ONE_HUNDRED_THOUSAND = 100000;
|
||||
|
||||
PerUserSetting(const PerUserSetting&);
|
||||
PerUserSetting& operator =(const PerUserSetting&);
|
||||
|
@ -309,12 +309,12 @@ namespace MiscServices {
|
||||
std::u16string::size_type left, right;
|
||||
left = 0;
|
||||
right = str.find(delim, 0);
|
||||
while(right != std::u16string::npos) {
|
||||
while (right != std::u16string::npos) {
|
||||
if (right - left) {
|
||||
retValue.emplace_back(str.substr(left, right-left));
|
||||
retValue.emplace_back(str.substr(left, right - left));
|
||||
}
|
||||
left = right + 1;
|
||||
right = str.find(delim,left);
|
||||
right = str.find(delim, left);
|
||||
}
|
||||
|
||||
if (left != str.size()) {
|
||||
|
@ -342,42 +342,6 @@ namespace MiscServices {
|
||||
return setting->ListKeyboardType(imeId, types);
|
||||
}
|
||||
|
||||
/* Print service information for the input method management service.
|
||||
* Run in binder thread
|
||||
* The information includes :
|
||||
* The user information in the service
|
||||
* The input method engine information
|
||||
* The input method setting data
|
||||
* The session information in the service.
|
||||
* param fd the raw file descriptor that the dump is being sent to
|
||||
* param args the parameters for dump command. This parameter is ignored here.
|
||||
*/
|
||||
int32_t InputMethodSystemAbility::dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
(void) args;
|
||||
dprintf(fd, "\nInputMethodSystemAbility State:\n");
|
||||
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) {
|
||||
PerUserSetting *setting = it->second;
|
||||
int32_t userId = it->first;
|
||||
int32_t userState = setting->GetUserState();
|
||||
if (userState == UserState::USER_STATE_STARTED) {
|
||||
dprintf(fd, "[%d] User information: UserId = %d, UserState = USER_STATE_STARTED\n", index++, userId);
|
||||
} else if (userState == UserState::USER_STATE_UNLOCKED) {
|
||||
dprintf(fd, "[%d] User information: UserId = %d, UserState = USER_STATE_UNLOCKED\n", index++, userId);
|
||||
setting->Dump(fd);
|
||||
PerUserSession *session = GetUserSession(userId);
|
||||
session->Dump(fd);
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
/*! Get the instance of PerUserSetting for the given user
|
||||
\param userId the user id of the given user
|
||||
\return a pointer of the instance if the user is found
|
||||
@ -411,7 +375,7 @@ namespace MiscServices {
|
||||
*/
|
||||
void InputMethodSystemAbility::WorkThread()
|
||||
{
|
||||
while(1) {
|
||||
while (1) {
|
||||
Message *msg = MessageHandler::Instance()->GetMessage();
|
||||
switch (msg->msgId_) {
|
||||
case MSG_ID_USER_START : {
|
||||
@ -619,11 +583,16 @@ namespace MiscServices {
|
||||
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;
|
||||
if (destMsg != nullptr) {
|
||||
handler->SendMessage(destMsg);
|
||||
PerUserSession *userSession = GetUserSession(userId);
|
||||
if (userSession != nullptr) {
|
||||
userSession->JoinWorkThread();
|
||||
}
|
||||
msgHandlers.erase(it);
|
||||
delete handler;
|
||||
handler = nullptr;
|
||||
}
|
||||
}
|
||||
setting->OnUserLocked();
|
||||
IMSA_HILOGI("End...[%d]\n", userId);
|
||||
@ -741,6 +710,10 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("Start...\n");
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
if (data == nullptr) {
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved data is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t userId = data->ReadInt32();
|
||||
int32_t size = data->ReadInt32();
|
||||
|
||||
@ -755,6 +728,10 @@ namespace MiscServices {
|
||||
return ErrorCode::ERROR_USER_NOT_UNLOCKED;
|
||||
}
|
||||
PerUserSession *session = GetUserSession(userId);
|
||||
if (session == nullptr) {
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved session is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
session->OnPackageRemoved(packageName);
|
||||
bool securityImeFlag = false;
|
||||
int32_t ret = setting->OnPackageRemoved(packageName, securityImeFlag);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* 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.
|
||||
@ -42,10 +42,10 @@ namespace MiscServices {
|
||||
*/
|
||||
void MessageHandler::SendMessage(Message *msg)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mQueue.push(msg);
|
||||
}
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mQueue.push(msg);
|
||||
}
|
||||
mCV.notify_one();
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ namespace MiscServices {
|
||||
if (msgHandler == nullptr) {
|
||||
return;
|
||||
}
|
||||
while(1) {
|
||||
while (1) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
switch (msg->msgId_) {
|
||||
@ -669,7 +669,7 @@ namespace MiscServices {
|
||||
*/
|
||||
void PerUserSession::OnImsDied(const wptr<IRemoteObject>& who)
|
||||
{
|
||||
(void) who; // temporary void it, as we will add support for security IME.
|
||||
(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++) {
|
||||
@ -864,7 +864,9 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
int num = currentKbdIndex[index]+1;
|
||||
num %= size;
|
||||
if (size != 0) {
|
||||
num %= size;
|
||||
}
|
||||
KeyboardType *type = GetKeyboardType(index, num);
|
||||
if (type == nullptr) {
|
||||
IMSA_HILOGW("No next keyboard is available. [%{public}d]\n", userId_);
|
||||
@ -966,111 +968,6 @@ namespace MiscServices {
|
||||
needReshowClient = nullptr;
|
||||
}
|
||||
|
||||
/* Print the session information of this user into the given stream
|
||||
* The information includes:
|
||||
* the information of all the input clients connected to the input method management system.
|
||||
* current input method engine information
|
||||
* security input method engine information
|
||||
* current session information
|
||||
* param fd the raw file descriptor that the dump is being sent to
|
||||
*/
|
||||
void PerUserSession::Dump(int fd)
|
||||
{
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*>::const_iterator it;
|
||||
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) {
|
||||
if (currentClient != nullptr &&
|
||||
Platform::RemoteBrokerToObject(currentClient) == it->first) {
|
||||
dprintf(fd, " *[%d] Client Information: (current client)\n", index++);
|
||||
} else {
|
||||
dprintf(fd, " [%d] Client Information:\n", index++);
|
||||
}
|
||||
DumpClientInfo(fd, *(it->second));
|
||||
}
|
||||
std::string header[2] = {"Current", "Security"};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (currentIme[i] != nullptr) {
|
||||
dprintf(fd, "\n * %s IME mImeId = %s\n", header[i].c_str(), Utils::to_utf8(currentIme[i]->mImeId).c_str());
|
||||
KeyboardType *type = currentIme[i]->mTypes.at(currentKbdIndex[i]);
|
||||
dprintf(fd, " %s KeyboardType mHashCode = %d, mLanguage = %s\n", header[i].c_str(),
|
||||
type->getHashCode(), Utils::to_utf8(type->getLanguage()).c_str());
|
||||
|
||||
if (imsCore[i] != nullptr) {
|
||||
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();
|
||||
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());
|
||||
} else {
|
||||
dprintf(fd, " %s IME Service = null (not started)\n", header[i].c_str());
|
||||
}
|
||||
} else {
|
||||
dprintf(fd, "\n * %s IME = null\n", header[i].c_str());
|
||||
}
|
||||
}
|
||||
DumpCurrentSession(fd);
|
||||
}
|
||||
|
||||
/*! dump current session
|
||||
\param fd the file descriptor to output the information
|
||||
*/
|
||||
void PerUserSession::DumpCurrentSession(int fd)
|
||||
{
|
||||
if (currentClient == nullptr) {
|
||||
dprintf(fd, "\n * Current Session = null (keyboard is not showing by any client)\n");
|
||||
return;
|
||||
}
|
||||
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());
|
||||
DumpClientInfo(fd, *(it->second));
|
||||
|
||||
dprintf(fd, " current IME mImeID = %s\n", Utils::to_utf8(currentIme[index]->mImeId).c_str());
|
||||
b = Platform::RemoteBrokerToObject(imsCore[index]);
|
||||
dprintf(fd, " IME service = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
b = Platform::RemoteBrokerToObject(imsAgent);
|
||||
dprintf(fd, " inputAgent = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
b = Platform::RemoteBrokerToObject(inputControlChannel[index]);
|
||||
dprintf(fd, " inputControlChannel = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
dprintf(fd, " inputMethodWindowToken = #%p\n", inputMethodToken[index].GetRefPtr());
|
||||
dprintf(fd, " displayId = %d\n", displayId);
|
||||
if (currentDisplayMode == 0) {
|
||||
dprintf(fd, " displayMode = %d [ part sceen ]\n", currentDisplayMode);
|
||||
} else {
|
||||
dprintf(fd, " displayMode = %d [ full sceen ]\n", currentDisplayMode);
|
||||
}
|
||||
int height = 0;
|
||||
GetKeyboardWindowHeight(height);
|
||||
dprintf(fd, " keyboard window height = %d\n", height);
|
||||
}
|
||||
|
||||
/*! dump a client information
|
||||
\param fd the file descriptor to output the information
|
||||
\param clientInfo client information of a remote input client
|
||||
*/
|
||||
void PerUserSession::DumpClientInfo(int fd, const ClientInfo& clientInfo)
|
||||
{
|
||||
dprintf(fd, " pid = %d\n", clientInfo.pid);
|
||||
dprintf(fd, " uid = %d\n", clientInfo.uid);
|
||||
dprintf(fd, " userId = %d\n", clientInfo.userId);
|
||||
dprintf(fd, " displayId = %d\n", clientInfo.displayId);
|
||||
|
||||
sptr<IRemoteObject> b = Platform::RemoteBrokerToObject(clientInfo.client);
|
||||
dprintf(fd, " inputClient = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
b = Platform::RemoteBrokerToObject(clientInfo.channel);
|
||||
dprintf(fd, " inputDataChannel = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
}
|
||||
|
||||
/*! Increase or reset ime error number
|
||||
\param resetFlag the flag to increase or reset number.
|
||||
\n resetFlag=true, reset error number to 0;
|
||||
@ -1080,8 +977,8 @@ namespace MiscServices {
|
||||
*/
|
||||
int PerUserSession::IncreaseOrResetImeError(bool resetFlag, int imeIndex)
|
||||
{
|
||||
static int errorNum[MIN_IME] = {0, 0};
|
||||
static time_t past[MIN_IME] = {time(0), time(0)};
|
||||
static int errorNum[2] = {0, 0};
|
||||
static time_t past[2] = {time(0), time(0)};
|
||||
if (resetFlag == true) {
|
||||
errorNum[imeIndex] = 0;
|
||||
past[imeIndex] = 0;
|
||||
@ -1093,7 +990,7 @@ namespace MiscServices {
|
||||
double diffSeconds = difftime(now, past[imeIndex]);
|
||||
|
||||
//time difference is more than 5 minutes, reset time and error num;
|
||||
if (diffSeconds > 300) {
|
||||
if (diffSeconds > COMMON_COUNT_THREE_HUNDRED) {
|
||||
past[imeIndex] = now;
|
||||
errorNum[imeIndex] = 1;
|
||||
}
|
||||
@ -1139,6 +1036,9 @@ namespace MiscServices {
|
||||
*/
|
||||
void PerUserSession::ResetCurrentKeyboardType(int imeIndex)
|
||||
{
|
||||
if (imeIndex < 0 || imeIndex > 1) {
|
||||
return;
|
||||
}
|
||||
currentKbdIndex[imeIndex] = 0;
|
||||
int hashCode = 0;
|
||||
if (imeIndex == DEFAULT_IME) {
|
||||
@ -1331,6 +1231,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility start");
|
||||
BindInputAbility();
|
||||
IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility end");
|
||||
currentClient = client;
|
||||
}
|
||||
|
||||
/*! Release input. Called by an input client.
|
||||
@ -1347,9 +1248,7 @@ namespace MiscServices {
|
||||
sptr<InputClientProxy> client = new InputClientProxy(clientObject);
|
||||
sptr<IInputClient> interface = client;
|
||||
int remainClientNum = 0;
|
||||
if (currentClient == interface) {
|
||||
HideKeyboard(client);
|
||||
}
|
||||
HideKeyboard(client);
|
||||
int ret = RemoveClient(client, remainClientNum);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("PerUserSession::OnReleaseInput Aborted! Failed to RemoveClient [%{public}d]\n", userId_);
|
||||
|
@ -165,8 +165,7 @@ namespace MiscServices {
|
||||
}
|
||||
Platform::Instance()->SetInputMethodSetting(userId_, imSetting);
|
||||
// wait for some time so that the setting change will not be overrided by the followed transact
|
||||
int32_t sleepTime = 100000;
|
||||
usleep(sleepTime);
|
||||
usleep(COMMON_COUNT_ONE_HUNDRED_THOUSAND);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@ -336,21 +335,22 @@ 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) {
|
||||
InputMethodProperty *imp = inputMethodProperties[i];
|
||||
if (CheckIfSecurityIme(*imp) == false) {
|
||||
continue;
|
||||
}
|
||||
// if systemLocales is not setting, return the first security ime
|
||||
if (systemLocales.size() == 0) {
|
||||
return inputMethodProperties[i];
|
||||
return imp;
|
||||
}
|
||||
if (ime == nullptr) {
|
||||
ime = inputMethodProperties[i];
|
||||
ime = imp;
|
||||
}
|
||||
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) {
|
||||
return inputMethodProperties[i];
|
||||
return imp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user