mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-18 17:24:37 -04:00
@@ -16,13 +16,13 @@
|
||||
#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H
|
||||
#define FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "i_input_method_agent.h"
|
||||
#include "input_channel.h"
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include "message_parcel.h"
|
||||
#include "input_attribute.h"
|
||||
#include "i_input_data_channel.h"
|
||||
|
||||
@@ -97,8 +97,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("InputMethodAbility::Initialize");
|
||||
InitialInputWindow();
|
||||
msgHandler = new MessageHandler();
|
||||
workThreadHandler = std::thread([this]
|
||||
{
|
||||
workThreadHandler = std::thread([this] {
|
||||
WorkThread();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputMethodSystemAbilityProxy : public IRemoteProxy<IInputMethodSystemAbility> {
|
||||
class InputMethodSystemAbilityProxy : public IRemoteProxy<IInputMethodSystemAbility> {
|
||||
public:
|
||||
explicit InputMethodSystemAbilityProxy(const sptr<IRemoteObject> &object);
|
||||
~InputMethodSystemAbilityProxy() = default;
|
||||
|
||||
@@ -64,7 +64,7 @@ using namespace MessageID;
|
||||
mInputDataChannel = new InputDataChannelStub();
|
||||
mInputDataChannel->SetHandler(msgHandler);
|
||||
|
||||
workThreadHandler = std::thread([this]{WorkThread();});
|
||||
workThreadHandler = std::thread([this] {WorkThread();});
|
||||
mAttribute.SetInputPattern(InputAttribute::PATTERN_TEXT);
|
||||
|
||||
textListener = nullptr;
|
||||
|
||||
@@ -23,17 +23,17 @@
|
||||
#include "global.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class IPlatformCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
NOTIFY_EVENT = OHOS::FIRST_CALL_TRANSACTION,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback");
|
||||
|
||||
virtual void notifyEvent(int eventId, int userId, const std::vector<std::u16string>& eventContent) = 0;
|
||||
namespace MiscServices {
|
||||
class IPlatformCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
NOTIFY_EVENT = OHOS::FIRST_CALL_TRANSACTION,
|
||||
};
|
||||
}
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback");
|
||||
|
||||
virtual void notifyEvent(int eventId, int userId, const std::vector<std::u16string>& eventContent) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // FM_IMMS_PROJECT_IPLATFORMCALLBACK_H
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H
|
||||
#define FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "i_input_method_agent.h"
|
||||
#include "input_channel.h"
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "message_parcel.h"
|
||||
#include "i_input_control_channel.h"
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace MiscServices {
|
||||
void setInputMethodCoreFromHap(MessageParcel& data);
|
||||
protected:
|
||||
int32_t getUserId(int32_t uid);
|
||||
int USER_ID_CHANGE_VALUE = 1000000;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace MessageID {
|
||||
};
|
||||
}
|
||||
|
||||
class MessageHandler {
|
||||
class MessageHandler {
|
||||
public:
|
||||
MessageHandler();
|
||||
~MessageHandler();
|
||||
|
||||
@@ -122,6 +122,7 @@ namespace MiscServices {
|
||||
int currentIndex;
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*> mapClients;
|
||||
int MIN_IME = 2;
|
||||
int IME_ERROR_CODE = 3;
|
||||
int COMMON_COUNT_THREE_HUNDRED = 300;
|
||||
|
||||
InputMethodProperty *currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime
|
||||
|
||||
@@ -23,17 +23,16 @@
|
||||
#include "i_platform_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class PlatformCallbackStub : public IRemoteStub<IPlatformCallback> {
|
||||
public:
|
||||
PlatformCallbackStub();
|
||||
~PlatformCallbackStub();
|
||||
namespace MiscServices {
|
||||
class PlatformCallbackStub : public IRemoteStub<IPlatformCallback> {
|
||||
public:
|
||||
PlatformCallbackStub();
|
||||
~PlatformCallbackStub();
|
||||
|
||||
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
virtual void notifyEvent(int eventId, int userId, const std::vector<std::u16string>& eventContent) override;
|
||||
};
|
||||
|
||||
}
|
||||
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
virtual void notifyEvent(int eventId, int userId, const std::vector<std::u16string>& eventContent) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H
|
||||
|
||||
@@ -26,13 +26,13 @@
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class Utils {
|
||||
public:
|
||||
static std::string to_utf8(std::u16string str16) {
|
||||
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(str16);
|
||||
}
|
||||
static std::u16string to_utf16(std::string str) {
|
||||
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(str);
|
||||
}
|
||||
public:
|
||||
static std::string to_utf8(std::u16string str16) {
|
||||
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(str16);
|
||||
}
|
||||
static std::u16string to_utf16(std::string str) {
|
||||
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.from_bytes(str);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include "message_handler.h"
|
||||
#include "input_control_channel_stub.h"
|
||||
#include "i_input_control_channel.h"
|
||||
|
||||
@@ -582,7 +582,7 @@ namespace MiscServices {
|
||||
std::map<int32_t, MessageHandler*>::iterator it = msgHandlers.find(userId);
|
||||
if (it != msgHandlers.end()) {
|
||||
MessageHandler *handler = it->second;
|
||||
Message *destMsg = new Message(MSG_ID_USER_LOCK , nullptr);
|
||||
Message *destMsg = new Message(MSG_ID_USER_LOCK, nullptr);
|
||||
if (destMsg != nullptr) {
|
||||
handler->SendMessage(destMsg);
|
||||
PerUserSession *userSession = GetUserSession(userId);
|
||||
|
||||
@@ -207,7 +207,6 @@ namespace MiscServices {
|
||||
|
||||
Message *msg = new Message(MSG_ID_RELEASE_INPUT, parcel);
|
||||
MessageHandler::Instance()->SendMessage(msg);
|
||||
|
||||
}
|
||||
|
||||
/*! Start input
|
||||
@@ -271,7 +270,7 @@ namespace MiscServices {
|
||||
*/
|
||||
int32_t InputMethodSystemAbilityStub::getUserId(int32_t uid)
|
||||
{
|
||||
return uid/1000000;
|
||||
return uid/USER_ID_CHANGE_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,9 +106,9 @@ namespace MiscServices {
|
||||
{
|
||||
mId = typeId;
|
||||
if (typeId != ID_NONE) {
|
||||
mHashCode = typeId;
|
||||
mHashCode = typeId;
|
||||
} else {
|
||||
mHashCode = ID_NONE;
|
||||
mHashCode = ID_NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace MiscServices {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mQueue.push(msg);
|
||||
}
|
||||
mCV.notify_one();
|
||||
mCV.notify_one();
|
||||
}
|
||||
|
||||
/*! Get a message
|
||||
@@ -56,7 +56,7 @@ namespace MiscServices {
|
||||
Message *MessageHandler::GetMessage()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mCV.wait(lock, [this]{
|
||||
mCV.wait(lock, [this] {
|
||||
return !this->mQueue.empty();
|
||||
});
|
||||
|
||||
|
||||
@@ -13,15 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include "unistd.h" //usleep
|
||||
#include "peruser_session.h"
|
||||
#include "platform.h"
|
||||
#include "parcel.h"
|
||||
#include "message_parcel.h"
|
||||
#include "utils.h"
|
||||
#include "want.h"
|
||||
#include "input_method_ability_connection_stub.h"
|
||||
#include <vector>
|
||||
#include "peruser_session.h"
|
||||
#include "ability_connect_callback_proxy.h"
|
||||
#include "ability_manager_interface.h"
|
||||
#include "sa_mgr_client.h"
|
||||
@@ -101,7 +100,7 @@ namespace MiscServices {
|
||||
void PerUserSession::CreateWorkThread(MessageHandler& handler)
|
||||
{
|
||||
msgHandler = &handler;
|
||||
workThreadHandler = std::thread([this]{WorkThread();});
|
||||
workThreadHandler = std::thread([this] {WorkThread();});
|
||||
}
|
||||
|
||||
/*! Wait till work thread exits
|
||||
@@ -266,10 +265,12 @@ namespace MiscServices {
|
||||
}
|
||||
if (flag) {
|
||||
int ret = StartInputMethod(i);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
needReshowClient = nullptr;
|
||||
break;
|
||||
}
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i) {
|
||||
if (ret == ErrorCode::NO_ERROR) {
|
||||
ShowKeyboard(needReshowClient);
|
||||
}
|
||||
ShowKeyboard(needReshowClient);
|
||||
needReshowClient = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -502,11 +503,13 @@ namespace MiscServices {
|
||||
|
||||
ret = imsCore[index]->showKeyboard(1);
|
||||
if (!ret) {
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! showKeyboard has error : %{public}s", ErrorCode::ToString(ret));
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! showKeyboard has error : %{public}s",
|
||||
ErrorCode::ToString(ret));
|
||||
|
||||
int ret_client = clientInfo->client->onInputReady(1, nullptr, nullptr);
|
||||
if (ret_client != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard onInputReady has error : %{public}s", ErrorCode::ToString(ret_client));
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard onInputReady has error : %{public}s",
|
||||
ErrorCode::ToString(ret_client));
|
||||
}
|
||||
return ErrorCode::ERROR_KBD_SHOW_FAILED;
|
||||
}
|
||||
@@ -517,7 +520,8 @@ namespace MiscServices {
|
||||
|
||||
int result = clientInfo->client->onInputReady(0, imsAgent, imsChannel);
|
||||
if (result != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! onInputReady return : %{public}s", ErrorCode::ToString(ret));
|
||||
IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! onInputReady return : %{public}s",
|
||||
ErrorCode::ToString(ret));
|
||||
return result;
|
||||
}
|
||||
currentClient = inputClient;
|
||||
@@ -564,7 +568,8 @@ namespace MiscServices {
|
||||
|
||||
int ret_client_stop = clientInfo->client->onInputReady(1, nullptr, nullptr);
|
||||
if (ret_client_stop != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("PerUserSession::HideKeyboard onInputReady return : %{public}s", ErrorCode::ToString(ret_client_stop));
|
||||
IMSA_HILOGE("PerUserSession::HideKeyboard onInputReady return : %{public}s",
|
||||
ErrorCode::ToString(ret_client_stop));
|
||||
}
|
||||
currentClient = nullptr;
|
||||
imsAgent = nullptr;
|
||||
@@ -692,7 +697,7 @@ namespace MiscServices {
|
||||
StopInputMethod(1 - index);
|
||||
}
|
||||
|
||||
if (IncreaseOrResetImeError(false, index) == 3) {
|
||||
if (IncreaseOrResetImeError(false, index) == IME_ERROR_CODE) {
|
||||
// call to disable the current input method.
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
parcel->WriteInt32(userId_);
|
||||
@@ -851,7 +856,7 @@ namespace MiscServices {
|
||||
return;
|
||||
}
|
||||
int size = 0;
|
||||
if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME] ) {
|
||||
if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) {
|
||||
size = currentIme[index]->mTypes.size();
|
||||
} else {
|
||||
std::u16string imeId = currentIme[index]->mImeId;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "unistd.h" //usleep
|
||||
#include "unistd.h"
|
||||
#include "peruser_setting.h"
|
||||
#include "platform.h"
|
||||
#include "utils.h"
|
||||
@@ -67,14 +67,15 @@ namespace MiscServices {
|
||||
}
|
||||
}
|
||||
|
||||
/*! Add an input method engine.
|
||||
\n It's called when a package is installed in the system.
|
||||
\param packageName the package name of installed package.
|
||||
\param[out] isSecurityIme check if the added ime is a security ime.
|
||||
\return ErrorCode::NO_ERROR The installed package is an IME package, and is added in the input method management system
|
||||
\return ErrorCode::ERROR_NOT_IME_PACKAGE The installed package is not an IME package.
|
||||
\return ErrorCode::ERROR_IME_PACKAGE_DUPLICATED The installed package is duplicated.
|
||||
*/
|
||||
/**
|
||||
* Add an input method engine.It's called when a package is installed in the system.
|
||||
* @param packageName the package name of installed package.
|
||||
* @param isSecurityIme check if the added ime is a security ime.
|
||||
* @return ErrorCode::NO_ERROR The installed package is an IME package,
|
||||
* and is added in the input method management system
|
||||
* ErrorCode::ERROR_NOT_IME_PACKAGE The installed package is not an IME package.
|
||||
* ErrorCode::ERROR_IME_PACKAGE_DUPLICATED The installed package is duplicated.
|
||||
*/
|
||||
int PerUserSetting::OnPackageAdded(std::u16string& packageName, bool isSecurityIme)
|
||||
{
|
||||
if (isSecurityIme) {
|
||||
|
||||
@@ -167,7 +167,6 @@ namespace MiscServices {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName,
|
||||
InputMethodProperty *inputMethodProperty)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user