mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-19 12:08:05 -04:00
@@ -123,7 +123,7 @@ namespace MiscServices {
|
||||
void PerUserSession::WorkThread()
|
||||
{
|
||||
if (msgHandler == nullptr) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
while(1) {
|
||||
Message *msg = msgHandler->GetMessage();
|
||||
@@ -239,22 +239,17 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("PerUserSession::ResetIme");
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
InputMethodProperty *ime[] = {defaultIme, securityIme};
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (currentIme[i] == ime[i] && ime[i] != nullptr)
|
||||
{
|
||||
for (int i = 0; i < MIN_IME; i++) {
|
||||
if (currentIme[i] == ime[i] && ime[i] != nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (imsCore[i])
|
||||
{
|
||||
if (imsCore[i]) {
|
||||
StopInputMethod(i);
|
||||
}
|
||||
IncreaseOrResetImeError(true, i);
|
||||
currentIme[i] = ime[i];
|
||||
if (currentIme[i] == nullptr)
|
||||
{
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i)
|
||||
{
|
||||
if (currentIme[i] == nullptr) {
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i) {
|
||||
needReshowClient = nullptr;
|
||||
}
|
||||
continue;
|
||||
@@ -262,22 +257,17 @@ namespace MiscServices {
|
||||
|
||||
std::map<sptr<IRemoteObject>, ClientInfo*>::const_iterator it;
|
||||
bool flag = false;
|
||||
for (it = mapClients.cbegin(); it != mapClients.cend(); ++it)
|
||||
{
|
||||
for (it = mapClients.cbegin(); it != mapClients.cend(); ++it) {
|
||||
if ((i == DEFAULT_IME && it->second->attribute.GetSecurityFlag() == false) ||
|
||||
(i == SECURITY_IME && it->second->attribute.GetSecurityFlag() == true))
|
||||
{
|
||||
(i == SECURITY_IME && it->second->attribute.GetSecurityFlag() == true)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
if (flag) {
|
||||
int ret = StartInputMethod(i);
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i)
|
||||
{
|
||||
if (ret == ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (needReshowClient && GetImeIndex(needReshowClient) == i) {
|
||||
if (ret == ErrorCode::NO_ERROR) {
|
||||
ShowKeyboard(needReshowClient);
|
||||
}
|
||||
needReshowClient = nullptr;
|
||||
@@ -295,19 +285,15 @@ namespace MiscServices {
|
||||
InputMethodSetting tmpSetting;
|
||||
bool flag = false;
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
for (int i = 0; i < MAX_IME; i++)
|
||||
{
|
||||
if (currentIme[i] && currentIme[i]->mPackageName == packageName)
|
||||
{
|
||||
if (currentClient && GetImeIndex(currentClient) == i)
|
||||
{
|
||||
for (int i = 0; i < MAX_IME; i++) {
|
||||
if (currentIme[i] && currentIme[i]->mPackageName == packageName) {
|
||||
if (currentClient && GetImeIndex(currentClient) == i) {
|
||||
needReshowClient = currentClient;
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
StopInputMethod(i);
|
||||
currentIme[i] = nullptr;
|
||||
if (i == DEFAULT_IME)
|
||||
{
|
||||
if (i == DEFAULT_IME) {
|
||||
tmpSetting.SetCurrentKeyboardType(-1);
|
||||
inputMethodSetting->SetCurrentKeyboardType(-1);
|
||||
} else if (i == SECURITY_IME) {
|
||||
@@ -318,8 +304,7 @@ namespace MiscServices {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
if (flag) {
|
||||
Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting);
|
||||
}
|
||||
}
|
||||
@@ -392,10 +377,8 @@ namespace MiscServices {
|
||||
mapClients.erase(it);
|
||||
|
||||
remainClientNum = 0;
|
||||
for (it = mapClients.begin(); it != mapClients.end(); ++it)
|
||||
{
|
||||
if (it->second->attribute.GetSecurityFlag() == flag)
|
||||
{
|
||||
for (it = mapClients.begin(); it != mapClients.end(); ++it) {
|
||||
if (it->second->attribute.GetSecurityFlag() == flag) {
|
||||
remainClientNum++;
|
||||
}
|
||||
}
|
||||
@@ -528,8 +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");
|
||||
}
|
||||
|
||||
@@ -560,8 +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) {
|
||||
@@ -576,8 +557,7 @@ 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;
|
||||
}
|
||||
@@ -646,10 +626,8 @@ namespace MiscServices {
|
||||
hashCode = hashCodeList[0];
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)currentIme[DEFAULT_IME]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[DEFAULT_IME]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
for (int i = 0; i < (int)currentIme[DEFAULT_IME]->mTypes.size(); i++) {
|
||||
if (currentIme[DEFAULT_IME]->mTypes[i]->getHashCode() == hashCode) {
|
||||
return currentIme[DEFAULT_IME]->mTypes[i];
|
||||
}
|
||||
}
|
||||
@@ -694,33 +672,27 @@ namespace MiscServices {
|
||||
(void) who; // temporary void it, as we will add support for security IME.
|
||||
IMSA_HILOGI("Start...[%{public}d]\n", userId_);
|
||||
int index = 0;
|
||||
for (int i = 0; i < MAX_IME; i++)
|
||||
{
|
||||
if (imsCore[i] == nullptr)
|
||||
{
|
||||
for (int i = 0; i < MAX_IME; i++) {
|
||||
if (imsCore[i] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
sptr<IRemoteObject> b = imsCore[i]->AsObject();
|
||||
if (b == who)
|
||||
{
|
||||
if (b == who) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentClient && (GetImeIndex(currentClient) == index ||
|
||||
currentIme[index] == currentIme[1 - index]))
|
||||
{
|
||||
currentIme[index] == currentIme[1 - index])) {
|
||||
needReshowClient = currentClient;
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
StopInputMethod(index);
|
||||
if (currentIme[index] == currentIme[1 - index])
|
||||
{
|
||||
if (currentIme[index] == currentIme[1 - index]) {
|
||||
StopInputMethod(1 - index);
|
||||
}
|
||||
|
||||
if (IncreaseOrResetImeError(false, index) == 3)
|
||||
{
|
||||
if (IncreaseOrResetImeError(false, index) == 3) {
|
||||
// call to disable the current input method.
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
parcel->WriteInt32(userId_);
|
||||
@@ -818,10 +790,8 @@ namespace MiscServices {
|
||||
if (currentIme[index]->mTypes[num]->getHashCode() == hashCode) {
|
||||
return ErrorCode::ERROR_SETTING_SAME_VALUE;
|
||||
}
|
||||
for (int i = 0; i < (int)currentIme[index]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[index]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
for (int i = 0; i < (int)currentIme[index]->mTypes.size(); i++) {
|
||||
if (currentIme[index]->mTypes[i]->getHashCode() == hashCode) {
|
||||
currentKbdIndex[index] = i;
|
||||
break;
|
||||
}
|
||||
@@ -833,10 +803,8 @@ namespace MiscServices {
|
||||
if (currentKbdTypes[num] == hashCode) {
|
||||
return ErrorCode::ERROR_SETTING_SAME_VALUE;
|
||||
}
|
||||
for (int i = 0; i < (int)currentKbdTypes.size(); i++)
|
||||
{
|
||||
if (currentKbdTypes[i] == hashCode)
|
||||
{
|
||||
for (int i = 0; i < (int)currentKbdTypes.size(); i++) {
|
||||
if (currentKbdTypes[i] == hashCode) {
|
||||
currentKbdIndex[index] = i;
|
||||
break;
|
||||
}
|
||||
@@ -880,7 +848,7 @@ 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] ) {
|
||||
@@ -890,9 +858,9 @@ namespace MiscServices {
|
||||
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;
|
||||
@@ -925,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) {
|
||||
@@ -940,7 +908,7 @@ namespace MiscServices {
|
||||
void PerUserSession::OnRestartIms(int index, const std::u16string& imeId)
|
||||
{
|
||||
if (index < 0 || index >= MAX_IME) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
IMSA_HILOGI("Start...[%{public}d]\n", userId_);
|
||||
if (currentIme[index] && currentIme[index]->mImeId == imeId) {
|
||||
@@ -966,27 +934,22 @@ namespace MiscServices {
|
||||
}
|
||||
userState = UserState::USER_STATE_STARTED;
|
||||
// hide current keyboard
|
||||
if (currentClient != nullptr)
|
||||
{
|
||||
if (currentClient != nullptr) {
|
||||
HideKeyboard(currentClient);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int i = 0; i < 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;
|
||||
if (clientInfo != nullptr)
|
||||
{
|
||||
if (clientInfo != nullptr) {
|
||||
int ret = clientInfo->client->onInputReleased(0);
|
||||
if (ret != ErrorCode::NO_ERROR)
|
||||
{
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("2-onInputReleased return : %{public}s", ErrorCode::ToString(ret));
|
||||
}
|
||||
delete clientInfo;
|
||||
@@ -1017,11 +980,9 @@ namespace MiscServices {
|
||||
dprintf(fd, "\n - User Session State :\n");
|
||||
dprintf(fd, " * Client count = %d\n", mapClients.size());
|
||||
int index = 0;
|
||||
for (it = mapClients.cbegin(); it != mapClients.cend(); ++it)
|
||||
{
|
||||
for (it = mapClients.cbegin(); it != mapClients.cend(); ++it) {
|
||||
if (currentClient != nullptr &&
|
||||
Platform::RemoteBrokerToObject(currentClient) == it->first)
|
||||
{
|
||||
Platform::RemoteBrokerToObject(currentClient) == it->first) {
|
||||
dprintf(fd, " *[%d] Client Information: (current client)\n", index++);
|
||||
} else {
|
||||
dprintf(fd, " [%d] Client Information:\n", index++);
|
||||
@@ -1029,17 +990,14 @@ namespace MiscServices {
|
||||
DumpClientInfo(fd, *(it->second));
|
||||
}
|
||||
std::string header[2] = {"Current", "Security"};
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (currentIme[i] != nullptr)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (currentIme[i] != nullptr) {
|
||||
dprintf(fd, "\n * %s IME mImeId = %s\n", header[i].c_str(), Utils::to_utf8(currentIme[i]->mImeId).c_str());
|
||||
KeyboardType *type = currentIme[i]->mTypes.at(currentKbdIndex[i]);
|
||||
dprintf(fd, " %s KeyboardType mHashCode = %d, mLanguage = %s\n", header[i].c_str(),
|
||||
type->getHashCode(), Utils::to_utf8(type->getLanguage()).c_str());
|
||||
|
||||
if (imsCore[i] != nullptr)
|
||||
{
|
||||
if (imsCore[i] != nullptr) {
|
||||
sptr<IRemoteObject> b = imsCore[i]->AsObject();
|
||||
dprintf(fd, " %s IME Service = %s#%p\n", header[i].c_str(),
|
||||
Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr());
|
||||
@@ -1069,8 +1027,7 @@ 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)
|
||||
{
|
||||
if (index < 0 || index > MAX_IME) {
|
||||
dprintf(fd, "\n * PerUserSession::DumpCurrentSession: invalid index\n");
|
||||
}
|
||||
dprintf(fd, "\n * Current Session State :\n");
|
||||
@@ -1123,8 +1080,8 @@ namespace MiscServices {
|
||||
*/
|
||||
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;
|
||||
@@ -1168,10 +1125,8 @@ namespace MiscServices {
|
||||
return nullptr;
|
||||
}
|
||||
int hashCode = currentKbdTypes[typeIndex];
|
||||
for (int i = 0; i < (int)currentIme[imeIndex]->mTypes.size(); i++)
|
||||
{
|
||||
if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode)
|
||||
{
|
||||
for (int i = 0; i < (int)currentIme[imeIndex]->mTypes.size(); i++) {
|
||||
if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode) {
|
||||
return currentIme[imeIndex]->mTypes[i];
|
||||
}
|
||||
}
|
||||
@@ -1197,10 +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;
|
||||
@@ -1208,10 +1161,8 @@ namespace MiscServices {
|
||||
}
|
||||
} else {
|
||||
std::vector<int> hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[imeIndex]->mImeId);
|
||||
for (int i = 0; i < (int)hashCodeList.size(); i++)
|
||||
{
|
||||
if (hashCode == hashCodeList[i])
|
||||
{
|
||||
for (int i = 0; i < (int)hashCodeList.size(); i++) {
|
||||
if (hashCode == hashCodeList[i]) {
|
||||
currentKbdIndex[imeIndex] = i;
|
||||
flag = true;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user