t①常驻内存优化将常量从.h文件移动到.cpp中并去掉static;②编译选项改为-Oz;③string改为char;④特殊子类型和普通输入法流程合一 Signed-off-by:白光成 <baiguangcheng2@h-partners.com>

Signed-off-by: 白光成 <baiguangcheng2@h-partners.com>
This commit is contained in:
白光成 2025-01-14 17:53:45 +08:00
parent abba95d079
commit 624a3e770f
12 changed files with 39 additions and 35 deletions

View File

@ -50,7 +50,7 @@ ohos_shared_library("inputmethod_service") {
"-fvisibility-inlines-hidden",
"-fdata-sections",
"-ffunction-sections",
"-Os",
"-Oz",
"-Wno-c99-designator",
]
sources = [
@ -151,7 +151,7 @@ ohos_static_library("inputmethod_service_static") {
cflags_cc = [
"-fdata-sections",
"-ffunction-sections",
"-Os",
"-Oz",
]
sources = [
"${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp",

View File

@ -32,10 +32,11 @@ namespace OHOS {
namespace MiscServices {
constexpr const char *SETTING_COLUMN_KEYWORD = "KEYWORD";
constexpr const char *SETTING_COLUMN_VALUE = "VALUE";
const std::string SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/"
constexpr const char *SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/"
"SETTINGSDATA?Proxy=true";
const std::string SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
const std::string SETTINGS_USER_DATA_URI = "datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_";
constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
constexpr const char *SETTINGS_USER_DATA_URI = "datashare:///com.ohos.settingsdata/"
"entry/settingsdata/USER_SETTINGATA_";
struct UserImeConfig : public Serializable {
std::string userId;
std::vector<std::string> identities;

View File

@ -72,8 +72,8 @@ int32_t SettingsDataUtils::RegisterObserver(const sptr<SettingsDataObserver> &ob
return ErrorCode::ERROR_NULL_POINTER;
}
auto uri = GenerateTargetUri(SETTING_URI_PROXY, observer->GetKey());
auto helper = SettingsDataUtils::CreateDataShareHelper(SETTING_URI_PROXY);
auto uri = GenerateTargetUri(std::string(SETTING_URI_PROXY), observer->GetKey());
auto helper = SettingsDataUtils::CreateDataShareHelper(std::string(SETTING_URI_PROXY));
if (helper == nullptr) {
IMSA_HILOGE("helper is nullptr!");
return ErrorCode::ERROR_NULL_POINTER;
@ -89,8 +89,8 @@ int32_t SettingsDataUtils::RegisterObserver(const sptr<SettingsDataObserver> &ob
int32_t SettingsDataUtils::UnregisterObserver(const sptr<SettingsDataObserver> &observer)
{
auto uri = GenerateTargetUri(SETTING_URI_PROXY, observer->GetKey());
auto helper = SettingsDataUtils::CreateDataShareHelper(SETTING_URI_PROXY);
auto uri = GenerateTargetUri(std::string(SETTING_URI_PROXY), observer->GetKey());
auto helper = SettingsDataUtils::CreateDataShareHelper(std::string(SETTING_URI_PROXY));
if (helper == nullptr) {
return ErrorCode::ERROR_ENABLE_IME;
}
@ -108,7 +108,7 @@ std::shared_ptr<DataShare::DataShareHelper> SettingsDataUtils::CreateDataShareHe
return nullptr;
}
auto helper = DataShare::DataShareHelper::Creator(remoteObj_, uriProxy, SETTINGS_DATA_EXT_URI);
auto helper = DataShare::DataShareHelper::Creator(remoteObj_, uriProxy, std::string(SETTINGS_DATA_EXT_URI));
if (helper == nullptr) {
IMSA_HILOGE("create helper failed, uri: %{public}s!", uriProxy.c_str());
return nullptr;
@ -229,7 +229,7 @@ bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName)
}
const char *settingKey = "settings.inputmethod.enable_ime";
std::string settingValue = "";
GetStringValue(SETTING_URI_PROXY, settingKey, settingValue);
GetStringValue(std::string(SETTING_URI_PROXY), settingKey, settingValue);
IMSA_HILOGI("settingValue: %{public}s", settingValue.c_str());
std::string value = "";
if (settingValue == "") {
@ -238,7 +238,7 @@ bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName)
value = SetSettingValues(settingValue, bundleName);
}
IMSA_HILOGI("value: %{public}s", value.c_str());
return SetStringValue(SETTING_URI_PROXY, settingKey, value);
return SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value);
}
std::vector<std::string> SettingsDataUtils::split(const std::string &text, char delim)

View File

@ -34,7 +34,6 @@ public:
static std::string GetRealPath(const char *path);
private:
static constexpr int32_t SUCCESS = 0;
static std::string Read(const std::string &path, const std::string &key);
};
} // namespace MiscServices

View File

@ -24,6 +24,7 @@
#include "global.h"
namespace OHOS {
namespace MiscServices {
constexpr int32_t SUCCESS = 0;
bool FileOperator::Create(const std::string &path, mode_t mode)
{
auto ret = mkdir(path.c_str(), mode);

View File

@ -150,9 +150,6 @@ private:
int32_t InitAccountMonitor();
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
int32_t userId_;
static constexpr const char *SELECT_DIALOG_ACTION = "action.system.inputmethodchoose";
static constexpr const char *SELECT_DIALOG_HAP = "com.ohos.inputmethodchoosedialog";
static constexpr const char *SELECT_DIALOG_ABILITY = "InputMethod";
bool stop_ = false;
void InitMonitors();
int32_t InitKeyEventMonitor();

View File

@ -167,14 +167,11 @@ private:
int32_t userId_; // the id of the user to whom the object is linking
std::recursive_mutex mtx;
std::map<sptr<IRemoteObject>, std::shared_ptr<InputClientInfo>> mapClients_;
static const int MAX_RESTART_NUM = 3;
static const int IME_RESET_TIME_OUT = 3;
#ifdef IMF_ON_DEMAND_START_STOP_SA_ENABLE
static const int MAX_IME_START_TIME = 2000;
#else
static const int MAX_IME_START_TIME = 1500;
#endif
static constexpr int32_t MAX_RESTART_TASKS = 2;
std::mutex clientLock_;
sptr<IInputClient> currentClient_; // the current input client
std::mutex resetLock;

View File

@ -126,7 +126,6 @@ public:
static bool ParseDefaultFullIme(std::vector<DefaultFullImeInfo> &defaultFullImeList);
private:
static constexpr const char *SYS_CFG_FILE_PATH = "etc/inputmethod/inputmethod_framework_config.json";
static std::string GetSysCfgContent(const std::string &key);
};
} // namespace MiscServices

View File

@ -23,7 +23,7 @@
namespace OHOS {
namespace MiscServices {
const std::string INPUT_METHOD_SERVICE_SA_NAME = "inputmethod_service";
constexpr const char *INPUT_METHOD_SERVICE_SA_NAME = "inputmethod_service";
constexpr const char *STOP_TASK_NAME = "ReportStop";
constexpr std::int32_t DELAY_TIME = 3000L;
std::shared_ptr<AppExecFwk::EventHandler> FreezeManager::eventHandler_ = nullptr;
@ -98,7 +98,7 @@ void FreezeManager::ReportRss(bool shouldFreeze, pid_t pid)
auto status = shouldFreeze ? ResourceSchedule::ResType::SaControlAppStatus::SA_STOP_APP
: ResourceSchedule::ResType::SaControlAppStatus::SA_START_APP;
std::unordered_map<std::string, std::string> payload = { { "saId", std::to_string(INPUT_METHOD_SYSTEM_ABILITY_ID) },
{ "saName", INPUT_METHOD_SERVICE_SA_NAME },
{ "saName", std::string(INPUT_METHOD_SERVICE_SA_NAME) },
{ "extensionType", std::to_string(static_cast<int32_t>(AppExecFwk::ExtensionAbilityType::INPUTMETHOD)) },
{ "pid", std::to_string(pid) } };
IMSA_HILOGD("report RSS should freeze: %{public}d.", shouldFreeze);

View File

@ -62,11 +62,14 @@ using namespace Security::AccessToken;
REGISTER_SYSTEM_ABILITY_BY_ID(InputMethodSystemAbility, INPUT_METHOD_SYSTEM_ABILITY_ID, true);
constexpr std::int32_t INIT_INTERVAL = 10000L;
constexpr const char *UNDEFINED = "undefined";
static const std::string PERMISSION_CONNECT_IME_ABILITY = "ohos.permission.CONNECT_IME_ABILITY";
static const char *PERMISSION_CONNECT_IME_ABILITY = "ohos.permission.CONNECT_IME_ABILITY";
std::shared_ptr<AppExecFwk::EventHandler> InputMethodSystemAbility::serviceHandler_;
constexpr uint32_t START_SA_TIMEOUT = 6; // 6s
constexpr const char *SELECT_DIALOG_ACTION = "action.system.inputmethodchoose";
constexpr const char *SELECT_DIALOG_HAP = "com.ohos.inputmethodchoosedialog";
constexpr const char *SELECT_DIALOG_ABILITY = "InputMethod";
#ifdef IMF_ON_DEMAND_START_STOP_SA_ENABLE
const std::string UNLOAD_SA_TASK = "unloadInputMethodSaTask";
constexpr const char *UNLOAD_SA_TASK = "unloadInputMethodSaTask";
constexpr int64_t DELAY_UNLOAD_SA_TIME = 20000; // 20s
constexpr int32_t REFUSE_UNLOAD_DELAY_TIME = 1000; // 1s
#endif
@ -123,10 +126,10 @@ void InputMethodSystemAbility::ResetDelayUnloadTask(uint32_t code)
return;
}
serviceHandler_->RemoveTask(UNLOAD_SA_TASK);
serviceHandler_->RemoveTask(std::string(UNLOAD_SA_TASK));
IMSA_HILOGD("post unload task");
lastPostTime = GetTickCount();
bool ret = serviceHandler_->PostTask(task, UNLOAD_SA_TASK, DELAY_UNLOAD_SA_TIME);
bool ret = serviceHandler_->PostTask(task, std::string(UNLOAD_SA_TASK), DELAY_UNLOAD_SA_TIME);
if (!ret) {
IMSA_HILOGE("post unload task fail code:%{public}u", code);
}
@ -542,7 +545,7 @@ int32_t InputMethodSystemAbility::RequestShowInput()
{
AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID();
if (!identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId) &&
!identityChecker_->HasPermission(tokenId, PERMISSION_CONNECT_IME_ABILITY)) {
!identityChecker_->HasPermission(tokenId, std::string(PERMISSION_CONNECT_IME_ABILITY))) {
return ErrorCode::ERROR_STATUS_PERMISSION_DENIED;
}
auto userId = GetCallingUserId();
@ -559,7 +562,7 @@ int32_t InputMethodSystemAbility::RequestHideInput()
AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID();
auto pid = IPCSkeleton::GetCallingPid();
if (!identityChecker_->IsFocused(pid, tokenId) &&
!identityChecker_->HasPermission(tokenId, PERMISSION_CONNECT_IME_ABILITY)) {
!identityChecker_->HasPermission(tokenId, std::string(PERMISSION_CONNECT_IME_ABILITY))) {
return ErrorCode::ERROR_STATUS_PERMISSION_DENIED;
}
auto userId = GetCallingUserId();
@ -617,7 +620,7 @@ int32_t InputMethodSystemAbility::HideCurrentInput()
if (identityChecker_->IsBroker(tokenId)) {
return session->OnHideCurrentInput();
}
if (!identityChecker_->HasPermission(tokenId, PERMISSION_CONNECT_IME_ABILITY)) {
if (!identityChecker_->HasPermission(tokenId, std::string(PERMISSION_CONNECT_IME_ABILITY))) {
return ErrorCode::ERROR_STATUS_PERMISSION_DENIED;
}
return session->OnHideCurrentInput();
@ -635,7 +638,7 @@ int32_t InputMethodSystemAbility::ShowCurrentInput()
if (identityChecker_->IsBroker(tokenId)) {
return session->OnShowCurrentInput();
}
if (!identityChecker_->HasPermission(tokenId, PERMISSION_CONNECT_IME_ABILITY)) {
if (!identityChecker_->HasPermission(tokenId, std::string(PERMISSION_CONNECT_IME_ABILITY))) {
return ErrorCode::ERROR_STATUS_PERMISSION_DENIED;
}
return session->OnShowCurrentInput();
@ -1730,7 +1733,8 @@ int32_t InputMethodSystemAbility::CheckEnableAndSwitchPermission()
IMSA_HILOGE("not native sa!");
return ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION;
}
if (!identityChecker_->HasPermission(IPCSkeleton::GetCallingTokenID(), PERMISSION_CONNECT_IME_ABILITY)) {
if (!identityChecker_->HasPermission(IPCSkeleton::GetCallingTokenID(),
std::string(PERMISSION_CONNECT_IME_ABILITY))) {
IMSA_HILOGE("have not PERMISSION_CONNECT_IME_ABILITY!");
return ErrorCode::ERROR_STATUS_PERMISSION_DENIED;
}
@ -1752,7 +1756,8 @@ int32_t InputMethodSystemAbility::CheckSwitchPermission(int32_t userId, const Sw
IMSA_HILOGE("not system app!");
return ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION;
}
if (!identityChecker_->HasPermission(IPCSkeleton::GetCallingTokenID(), PERMISSION_CONNECT_IME_ABILITY)) {
if (!identityChecker_->HasPermission(IPCSkeleton::GetCallingTokenID(),
std::string(PERMISSION_CONNECT_IME_ABILITY))) {
IMSA_HILOGE("have not PERMISSION_CONNECT_IME_ABILITY!");
return ErrorCode::ERROR_STATUS_PERMISSION_DENIED;
}
@ -1760,7 +1765,8 @@ int32_t InputMethodSystemAbility::CheckSwitchPermission(int32_t userId, const Sw
}
if (trigger == SwitchTrigger::CURRENT_IME) {
// PERMISSION_CONNECT_IME_ABILITY check temporarily reserved for application adaptation, will be deleted soon
if (identityChecker_->HasPermission(IPCSkeleton::GetCallingTokenID(), PERMISSION_CONNECT_IME_ABILITY)) {
if (identityChecker_->HasPermission(IPCSkeleton::GetCallingTokenID(),
std::string(PERMISSION_CONNECT_IME_ABILITY))) {
return ErrorCode::NO_ERROR;
}
IMSA_HILOGE("have not PERMISSION_CONNECT_IME_ABILITY!");
@ -1789,7 +1795,7 @@ bool InputMethodSystemAbility::IsStartInputTypePermitted(int32_t userId)
if (identityChecker_->IsBundleNameValid(tokenId, defaultIme->prop.name)) {
return true;
}
if (identityChecker_->HasPermission(tokenId, PERMISSION_CONNECT_IME_ABILITY)) {
if (identityChecker_->HasPermission(tokenId, std::string(PERMISSION_CONNECT_IME_ABILITY))) {
return true;
}
auto session = UserSessionManager::GetInstance().GetUserSession(userId);
@ -1803,7 +1809,7 @@ bool InputMethodSystemAbility::IsStartInputTypePermitted(int32_t userId)
int32_t InputMethodSystemAbility::ConnectSystemCmd(const sptr<IRemoteObject> &channel, sptr<IRemoteObject> &agent)
{
auto tokenId = IPCSkeleton::GetCallingTokenID();
if (!identityChecker_->HasPermission(tokenId, PERMISSION_CONNECT_IME_ABILITY)) {
if (!identityChecker_->HasPermission(tokenId, std::string(PERMISSION_CONNECT_IME_ABILITY))) {
IMSA_HILOGE("have not PERMISSION_CONNECT_IME_ABILITY!");
return ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION;
}

View File

@ -52,6 +52,9 @@ constexpr const char *STRICT_MODE = "strictMode";
constexpr const char *ISOLATED_SANDBOX = "isolatedSandbox";
constexpr uint32_t CHECK_IME_RUNNING_RETRY_INTERVAL = 60;
constexpr uint32_t CHECK_IME_RUNNING_RETRY_TIMES = 10;
constexpr int32_t MAX_RESTART_NUM = 3;
constexpr int32_t IME_RESET_TIME_OUT = 3;
constexpr int32_t MAX_RESTART_TASKS = 2;
PerUserSession::PerUserSession(int userId) : userId_(userId) { }
PerUserSession::PerUserSession(int32_t userId, const std::shared_ptr<AppExecFwk::EventHandler> &eventHandler)

View File

@ -21,6 +21,7 @@
#include "global.h"
namespace OHOS {
namespace MiscServices {
constexpr const char *SYS_CFG_FILE_PATH = "etc/inputmethod/inputmethod_framework_config.json";
bool SysCfgParser::ParseSystemConfig(SystemConfig &systemConfig)
{
auto content = GetSysCfgContent(GET_NAME(systemConfig));