mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-18 17:24:37 -04:00
@@ -22,11 +22,13 @@ namespace OHOS {
|
||||
public:
|
||||
ParaHandle() = default;
|
||||
virtual ~ParaHandle() = default;
|
||||
static bool SetDefaultIme(const std::string &imeName);
|
||||
static std::string GetDefaultIme();
|
||||
static bool SetDefaultIme(int32_t userId, const std::string &imeName);
|
||||
static std::string GetDefaultIme(int32_t userId);
|
||||
private:
|
||||
static const char *DEFAULT_IME;
|
||||
static const char *DEFAULT_IME_KEY;
|
||||
static const char *DEFAULT_IME_NAME;
|
||||
static constexpr int CONFIG_LEN = 128;
|
||||
static const int32_t main_userId = 100;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,20 +17,32 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
const char *ParaHandle::DEFAULT_IME = "persist.sys.default_ime";
|
||||
bool ParaHandle::SetDefaultIme(const std::string &imeName)
|
||||
const char *ParaHandle::DEFAULT_IME_KEY = "persist.sys.default_ime";
|
||||
const char *ParaHandle::DEFAULT_IME_NAME = "com.example.kikakeyboard/com.example.kikakeyboard.ServiceExtAbility";
|
||||
bool ParaHandle::SetDefaultIme(int32_t userId, const std::string &imeName)
|
||||
{
|
||||
return SetParameter(DEFAULT_IME, imeName.data()) == 0;
|
||||
if (userId != main_userId) {
|
||||
return SetParameter(DEFAULT_IME_KEY + userId, imeName.data()) == 0;
|
||||
} else {
|
||||
return SetParameter(DEFAULT_IME_KEY, imeName.data()) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ParaHandle::GetDefaultIme()
|
||||
std::string ParaHandle::GetDefaultIme(int32_t userId)
|
||||
{
|
||||
char value[CONFIG_LEN];
|
||||
int code = GetParameter(DEFAULT_IME, "", value, CONFIG_LEN);
|
||||
int code = 0;
|
||||
if (userId != main_userId) {
|
||||
code = GetParameter(DEFAULT_IME_KEY + userId, "", value, CONFIG_LEN);
|
||||
} else {
|
||||
code = GetParameter(DEFAULT_IME_KEY, "", value, CONFIG_LEN);
|
||||
}
|
||||
if (code > 0) {
|
||||
return value;
|
||||
}
|
||||
return "";
|
||||
|
||||
SetDefaultIme(userId, DEFAULT_IME_NAME);
|
||||
return DEFAULT_IME_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace MiscServices {
|
||||
}
|
||||
IMSA_HILOGI("Publish ErrorCode::NO_ERROR.");
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme();
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme(userId_);
|
||||
StartInputService(defaultIme);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
@@ -547,6 +547,9 @@ namespace MiscServices {
|
||||
IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS));
|
||||
return ErrorCode::ERROR_BAD_PARAMETERS;
|
||||
}
|
||||
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme(userId_);
|
||||
StopInputService(defaultIme);
|
||||
int32_t userId = msg->msgContent_->ReadInt32();
|
||||
userId_ = userId;
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnUserStarted userId = %{public}u", userId);
|
||||
@@ -563,10 +566,8 @@ namespace MiscServices {
|
||||
|
||||
userSettings.insert(std::pair<int32_t, PerUserSetting*>(userId, setting));
|
||||
userSessions.insert(std::pair<int32_t, PerUserSession*>(userId, session));
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme();
|
||||
defaultIme = ParaHandle::GetDefaultIme(userId_);
|
||||
StartInputService(defaultIme);
|
||||
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnUserStarted End...[%d]\n", userId);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -855,7 +856,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnDisplayOptionalInputMethod has no ime");
|
||||
return;
|
||||
}
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme();
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme(userId_);
|
||||
std::string params = "";
|
||||
std::vector<InputMethodProperty*>::iterator it;
|
||||
for (it = properties.begin(); it < properties.end(); ++it) {
|
||||
@@ -894,11 +895,11 @@ namespace MiscServices {
|
||||
[this](int32_t id, const std::string& event, const std::string& params) {
|
||||
IMSA_HILOGI("Dialog callback: %{public}s, %{public}s", event.c_str(), params.c_str());
|
||||
if (event == "EVENT_CHANGE_IME") {
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme();
|
||||
std::string defaultIme = ParaHandle::GetDefaultIme(userId_);
|
||||
if (defaultIme != params) {
|
||||
StopInputService(defaultIme);
|
||||
StartInputService(params);
|
||||
ParaHandle::SetDefaultIme(params);
|
||||
ParaHandle::SetDefaultIme(userId_, params);
|
||||
}
|
||||
Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id);
|
||||
} else if (event == "EVENT_START_IME_SETTING") {
|
||||
|
||||
Reference in New Issue
Block a user