mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-23 06:40:06 +00:00
commit
8fa439821c
@ -51,7 +51,8 @@
|
||||
"data_share",
|
||||
"resource_schedule_service",
|
||||
"memmgr",
|
||||
"hicollie"
|
||||
"hicollie",
|
||||
"resource_management"
|
||||
],
|
||||
"third_party": [
|
||||
"cJSON"
|
||||
|
@ -110,6 +110,7 @@ enum {
|
||||
ERROR_CMD_LISTENER_ERROR = 41,
|
||||
ERROR_SYSTEM_CMD_CHANNEL_ERROR = 42,
|
||||
ERROR_INVALID_PRIVATE_COMMAND = 43,
|
||||
ERROR_OS_ACCOUNT = 44,
|
||||
};
|
||||
}; // namespace ErrorCode
|
||||
|
||||
|
@ -33,6 +33,11 @@ enum {
|
||||
MSG_ID_USER_REMOVED, // a user removed
|
||||
MSG_ID_PACKAGE_REMOVED, // a package is removed
|
||||
MSG_ID_BUNDLE_SCAN_FINISHED, // bundle scan finished, ready to create data share helper
|
||||
MSG_ID_PACKAGE_ADDED,
|
||||
MSG_ID_PACKAGE_CHANGED,
|
||||
MSG_ID_SYS_LANGUAGE_CHANGED,
|
||||
MSG_ID_OS_ACCOUNT_STARTED,
|
||||
MSG_ID_BOOT_COMPLETED,
|
||||
MSG_ID_SELECT_BY_RANGE,
|
||||
MSG_ID_SELECT_BY_MOVEMENT,
|
||||
MSG_ID_HANDLE_EXTEND_ACTION,
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#ifndef INPUTMETHOD_IMF_INPUT_METHOD_PROPERTY_H
|
||||
#define INPUTMETHOD_IMF_INPUT_METHOD_PROPERTY_H
|
||||
@ -41,6 +42,12 @@ struct SubProperty {
|
||||
std::string icon; // the icon of subtype
|
||||
int32_t iconId = 0; // the icon id of subtype
|
||||
};
|
||||
|
||||
struct FullImeInfo {
|
||||
uint32_t tokenId{ 0 };
|
||||
Property prop;
|
||||
std::vector<SubProperty> subProps;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -59,6 +59,7 @@ ohos_shared_library("inputmethod_service") {
|
||||
"${inputmethod_path}/services/adapter/wms_connection_monitor/src/wms_connection_observer.cpp",
|
||||
"${inputmethod_path}/services/identity_checker/src/identity_checker_impl.cpp",
|
||||
"src/freeze_manager.cpp",
|
||||
"src/full_ime_info_manager.cpp",
|
||||
"src/im_common_event_manager.cpp",
|
||||
"src/ime_cfg_manager.cpp",
|
||||
"src/ime_info_inquirer.cpp",
|
||||
@ -99,12 +100,14 @@ ohos_shared_library("inputmethod_service") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"i18n:intl_util",
|
||||
"init:libbeget_proxy",
|
||||
"init:libbegetutil",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_single",
|
||||
"memmgr:memmgrclient",
|
||||
"os_account:os_account_innerkits",
|
||||
"resource_management:global_resmgr",
|
||||
"resource_schedule_service:ressched_client",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
@ -145,6 +148,7 @@ ohos_static_library("inputmethod_service_static") {
|
||||
"adapter/wms_connection_monitor/src/wms_connection_observer.cpp",
|
||||
"identity_checker/src/identity_checker_impl.cpp",
|
||||
"src/freeze_manager.cpp",
|
||||
"src/full_ime_info_manager.cpp",
|
||||
"src/im_common_event_manager.cpp",
|
||||
"src/ime_cfg_manager.cpp",
|
||||
"src/ime_info_inquirer.cpp",
|
||||
@ -181,12 +185,14 @@ ohos_static_library("inputmethod_service_static") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"i18n:intl_util",
|
||||
"init:libbeget_proxy",
|
||||
"init:libbegetutil",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_single",
|
||||
"memmgr:memmgrclient",
|
||||
"os_account:os_account_innerkits",
|
||||
"resource_management:global_resmgr",
|
||||
"resource_schedule_service:ressched_client",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "system_language_observer.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "message.h"
|
||||
#include "message_handler.h"
|
||||
#include "parameter.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -44,6 +46,11 @@ void SystemLanguageObserver::OnChange(const char *key, const char *value, void *
|
||||
if (handler_ != nullptr) {
|
||||
handler_();
|
||||
}
|
||||
Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_SYS_LANGUAGE_CHANGED, nullptr);
|
||||
if (msg == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageHandler::Instance()->SendMessage(msg);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
51
services/include/full_ime_info_manager.h
Normal file
51
services/include/full_ime_info_manager.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SERVICES_INCLUDE_FULL_IME_INFO_MANAGER_H
|
||||
#define SERVICES_INCLUDE_FULL_IME_INFO_MANAGER_H
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
|
||||
#include "input_method_property.h"
|
||||
#include "timer.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
|
||||
class FullImeInfoManager {
|
||||
public:
|
||||
static FullImeInfoManager &GetInstance();
|
||||
int32_t Init(); // osAccount start/bundle scan finished/regular update
|
||||
int32_t Add(int32_t userId); // user switched
|
||||
int32_t Update(); // language change
|
||||
int32_t Delete(int32_t userId); // user removed
|
||||
int32_t Add(int32_t userId, const std::string &bundleName); // package added
|
||||
int32_t Delete(int32_t userId, const std::string &bundleName); // package removed
|
||||
int32_t Update(int32_t userId, const std::string &bundleName); // package changed
|
||||
std::vector<FullImeInfo> Get(int32_t userId);
|
||||
std::string Get(int32_t userId, uint32_t tokenId);
|
||||
bool Has(int32_t userId, const std::string &bundleName);
|
||||
|
||||
private:
|
||||
FullImeInfoManager();
|
||||
~FullImeInfoManager();
|
||||
std::mutex lock_;
|
||||
std::map<int32_t, std::vector<FullImeInfo>> fullImeInfos_;
|
||||
Utils::Timer timer_{ "imeInfoCacheInitTimer" };
|
||||
uint32_t timerId_{ 0 };
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_FULL_IME_INFO_MANAGER_H
|
@ -39,7 +39,7 @@ public:
|
||||
ImCommonEventManager();
|
||||
~ImCommonEventManager();
|
||||
static sptr<ImCommonEventManager> GetInstance();
|
||||
bool SubscribeEvent(const std::string &event);
|
||||
bool SubscribeEvent();
|
||||
bool SubscribeKeyboardEvent(KeyHandle handle);
|
||||
bool SubscribeWindowManagerService(FocusHandle handle, Handler inputHandler);
|
||||
bool SubscribeMemMgrService(const Handler &handler);
|
||||
@ -55,10 +55,14 @@ public:
|
||||
void StartUser(const EventFwk::CommonEventData &data);
|
||||
void RemoveUser(const EventFwk::CommonEventData &data);
|
||||
void OnBundleScanFinished(const EventFwk::CommonEventData &data);
|
||||
void AddPackage(const EventFwk::CommonEventData &data);
|
||||
void ChangePackage(const EventFwk::CommonEventData &data);
|
||||
void HandleBootCompleted(const EventFwk::CommonEventData &data);
|
||||
|
||||
private:
|
||||
using EventListenerFunc = std::function<void(EventSubscriber *that, const EventFwk::CommonEventData &data)>;
|
||||
std::map<std::string, EventListenerFunc> EventManagerFunc_;
|
||||
void HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data);
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "bundle_mgr_proxy.h"
|
||||
#include "element_name.h"
|
||||
#include "enable_ime_data_parser.h"
|
||||
@ -30,6 +29,7 @@
|
||||
#include "input_method_property.h"
|
||||
#include "input_method_status.h"
|
||||
#include "refbase.h"
|
||||
#include "resource_manager.h"
|
||||
#include "sys_cfg_parser.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -80,7 +80,8 @@ public:
|
||||
static ImeInfoInquirer &GetInstance();
|
||||
std::string GetDumpInfo(int32_t userId);
|
||||
std::shared_ptr<ImeNativeCfg> GetImeToStart(int32_t userId);
|
||||
std::shared_ptr<Property> GetImeByBundleName(int32_t userId, const std::string &bundleName);
|
||||
std::shared_ptr<Property> GetImeProperty(
|
||||
int32_t userId, const std::string &bundleName, const std::string &extName = "");
|
||||
std::shared_ptr<Property> GetCurrentInputMethod(int32_t userId);
|
||||
std::shared_ptr<SubProperty> GetCurrentSubtype(int32_t userId);
|
||||
std::shared_ptr<ImeInfo> GetImeInfo(int32_t userId, const std::string &bundleName, const std::string &subName);
|
||||
@ -100,6 +101,11 @@ public:
|
||||
bool IsEnableInputMethod();
|
||||
bool IsEnableSecurityMode();
|
||||
void InitSystemConfig();
|
||||
ImeNativeCfg GetDefaultIme();
|
||||
int32_t QueryFullImeInfo(std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &imeInfos);
|
||||
int32_t QueryFullImeInfo(int32_t userId, std::vector<FullImeInfo> &imeInfos);
|
||||
int32_t GetFullImeInfo(int32_t userId, const std::string &bundleName, FullImeInfo &imeInfo);
|
||||
bool IsInputMethod(int32_t userId, const std::string &bundleName);
|
||||
|
||||
private:
|
||||
ImeInfoInquirer() = default;
|
||||
@ -107,7 +113,6 @@ private:
|
||||
OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr();
|
||||
void InitCache(int32_t userId);
|
||||
SubProperty GetExtends(const std::vector<OHOS::AppExecFwk::Metadata> &metaData);
|
||||
ImeNativeCfg GetDefaultIme();
|
||||
std::string GetStringById(const std::string &bundleName, const std::string &moduleName, const int32_t labelId,
|
||||
const int32_t userId);
|
||||
std::shared_ptr<ImeInfo> GetImeInfoFromCache(const int32_t userId, const std::string &bundleName,
|
||||
@ -134,6 +139,9 @@ private:
|
||||
bool ParseSubtypeProfile(const std::vector<std::string> &profiles, SubtypeCfg &subtypeCfg);
|
||||
void CovertToLanguage(const std::string &locale, std::string &language);
|
||||
bool QueryImeExtInfos(const int32_t userId, std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &infos);
|
||||
std::shared_ptr<Global::Resource::ResourceManager> GetResMgr(const std::string &resourcePath);
|
||||
int32_t GetFullImeInfo(
|
||||
int32_t userId, const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, FullImeInfo &imeInfo);
|
||||
|
||||
SystemConfig systemConfig_;
|
||||
std::mutex currentImeInfoLock_;
|
||||
|
@ -104,9 +104,10 @@ private:
|
||||
void StopInputService();
|
||||
int32_t OnUserStarted(const Message *msg);
|
||||
int32_t OnUserRemoved(const Message *msg);
|
||||
int32_t OnPackageRemoved(const Message *msg);
|
||||
int32_t HandlePackageEvent(const Message *msg);
|
||||
int32_t OnPackageRemoved(int32_t userId, const std::string &packageName);
|
||||
int32_t OnDisplayOptionalInputMethod();
|
||||
void StartUserIdListener();
|
||||
void SubscribeCommonEvent();
|
||||
bool IsNeedSwitch(const std::string &bundleName, const std::string &subName);
|
||||
int32_t CheckSwitchPermission(const SwitchInfo &switchInfo, SwitchTrigger trigger);
|
||||
bool IsStartInputTypePermitted();
|
||||
|
198
services/src/full_ime_info_manager.cpp
Normal file
198
services/src/full_ime_info_manager.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "full_ime_info_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common_timer_errors.h"
|
||||
#include "ime_info_inquirer.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
constexpr uint32_t TIMER_TASK_INTERNAL = 3600000; // updated hourly
|
||||
FullImeInfoManager::~FullImeInfoManager()
|
||||
{
|
||||
timer_.Unregister(timerId_);
|
||||
timer_.Shutdown(false);
|
||||
fullImeInfos_.clear();
|
||||
}
|
||||
|
||||
FullImeInfoManager::FullImeInfoManager()
|
||||
{
|
||||
uint32_t ret = timer_.Setup();
|
||||
if (ret != Utils::TIMER_ERR_OK) {
|
||||
IMSA_HILOGE("failed to create timer");
|
||||
return;
|
||||
}
|
||||
timerId_ = timer_.Register([this]() { Init(); }, TIMER_TASK_INTERNAL, false);
|
||||
}
|
||||
|
||||
FullImeInfoManager &FullImeInfoManager::GetInstance()
|
||||
{
|
||||
static FullImeInfoManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Init()
|
||||
{
|
||||
std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> fullImeInfos;
|
||||
auto ret = ImeInfoInquirer::GetInstance().QueryFullImeInfo(fullImeInfos);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGW("failed to QueryFullImeInfo, ret:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
fullImeInfos_.clear();
|
||||
for (const auto &infos : fullImeInfos) {
|
||||
fullImeInfos_.insert_or_assign(infos.first, infos.second);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Add(int32_t userId)
|
||||
{
|
||||
std::vector<FullImeInfo> infos;
|
||||
auto ret = ImeInfoInquirer::GetInstance().QueryFullImeInfo(userId, infos);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("failed to QueryFullImeInfo, userId:%{public}d, ret:%{public}d", userId, ret);
|
||||
return ret;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
fullImeInfos_.insert_or_assign(userId, infos);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Update()
|
||||
{
|
||||
auto ret = Init();
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
fullImeInfos_.clear();
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Delete(int32_t userId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
fullImeInfos_.erase(userId);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Add(int32_t userId, const std::string &bundleName)
|
||||
{
|
||||
FullImeInfo info;
|
||||
auto ret = ImeInfoInquirer::GetInstance().GetFullImeInfo(userId, bundleName, info);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("failed to GetFullImeInfo, userId:%{public}d, bundleName:%{public}s, ret:%{public}d", userId,
|
||||
bundleName.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
auto it = fullImeInfos_.find(userId);
|
||||
if (it == fullImeInfos_.end()) {
|
||||
fullImeInfos_.insert({ userId, { info } });
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
auto iter = std::find_if(it->second.begin(), it->second.end(),
|
||||
[&bundleName](const FullImeInfo &info) { return bundleName == info.prop.name; });
|
||||
if (iter != it->second.end()) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
it->second.push_back(info);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Delete(int32_t userId, const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
auto it = fullImeInfos_.find(userId);
|
||||
if (it == fullImeInfos_.end()) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
auto iter = std::find_if(it->second.begin(), it->second.end(),
|
||||
[&bundleName](const FullImeInfo &info) { return bundleName == info.prop.name; });
|
||||
if (iter == it->second.end()) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
it->second.erase(iter);
|
||||
if (it->second.empty()) {
|
||||
fullImeInfos_.erase(it->first);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t FullImeInfoManager::Update(int32_t userId, const std::string &bundleName)
|
||||
{
|
||||
FullImeInfo info;
|
||||
auto ret = ImeInfoInquirer::GetInstance().GetFullImeInfo(userId, bundleName, info);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("failed to GetFullImeInfo failed, userId:%{public}d, bundleName:%{public}s, ret:%{public}d",
|
||||
userId, bundleName.c_str(), ret);
|
||||
return ErrorCode::ERROR_PACKAGE_MANAGER;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
auto it = fullImeInfos_.find(userId);
|
||||
if (it == fullImeInfos_.end()) {
|
||||
fullImeInfos_.insert({ userId, { info } });
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
auto iter = std::find_if(it->second.begin(), it->second.end(),
|
||||
[&bundleName](const FullImeInfo &info) { return bundleName == info.prop.name; });
|
||||
if (iter != it->second.end()) {
|
||||
it->second.erase(iter);
|
||||
}
|
||||
it->second.push_back(info);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
std::vector<FullImeInfo> FullImeInfoManager::Get(int32_t userId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
auto it = fullImeInfos_.find(userId);
|
||||
if (it == fullImeInfos_.end()) {
|
||||
return {};
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool FullImeInfoManager::Has(int32_t userId, const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
auto it = fullImeInfos_.find(userId);
|
||||
if (it == fullImeInfos_.end()) {
|
||||
return false;
|
||||
}
|
||||
auto iter = std::find_if(it->second.begin(), it->second.end(),
|
||||
[&bundleName](const FullImeInfo &info) { return bundleName == info.prop.name; });
|
||||
return iter != it->second.end();
|
||||
}
|
||||
|
||||
std::string FullImeInfoManager::Get(int32_t userId, uint32_t tokenId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(lock_);
|
||||
auto it = fullImeInfos_.find(userId);
|
||||
if (it == fullImeInfos_.end()) {
|
||||
return "";
|
||||
}
|
||||
auto iter = std::find_if(
|
||||
it->second.begin(), it->second.end(), [&tokenId](const FullImeInfo &info) { return tokenId == info.tokenId; });
|
||||
if (iter == it->second.end()) {
|
||||
return "";
|
||||
}
|
||||
return (*iter).prop.name;
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "full_ime_info_manager.h"
|
||||
#include "global.h"
|
||||
#include "ime_info_inquirer.h"
|
||||
#include "ipc_skeleton.h"
|
||||
@ -34,6 +35,7 @@ using namespace OHOS::EventFwk;
|
||||
constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
|
||||
constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
|
||||
constexpr const char *COMMON_EVENT_PARAM_PANEL_RECT = "panelRect";
|
||||
constexpr int32_t INVALID_USER_ID = -1;
|
||||
ImCommonEventManager::ImCommonEventManager()
|
||||
{
|
||||
}
|
||||
@ -54,13 +56,16 @@ sptr<ImCommonEventManager> ImCommonEventManager::GetInstance()
|
||||
return instance_;
|
||||
}
|
||||
|
||||
bool ImCommonEventManager::SubscribeEvent(const std::string &event)
|
||||
bool ImCommonEventManager::SubscribeEvent()
|
||||
{
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(event);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
|
||||
|
||||
EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
|
||||
@ -176,6 +181,11 @@ bool ImCommonEventManager::SubscribeAccountManagerService(Handler handler)
|
||||
if (handler != nullptr) {
|
||||
handler();
|
||||
}
|
||||
Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_OS_ACCOUNT_STARTED, nullptr);
|
||||
if (msg == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageHandler::Instance()->SendMessage(msg);
|
||||
});
|
||||
if (listener == nullptr) {
|
||||
IMSA_HILOGE("failed to create listener!");
|
||||
@ -213,6 +223,18 @@ ImCommonEventManager::EventSubscriber::EventSubscriber(const EventFwk::CommonEve
|
||||
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
|
||||
return that->OnBundleScanFinished(data);
|
||||
};
|
||||
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED] =
|
||||
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
|
||||
return that->AddPackage(data);
|
||||
};
|
||||
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED] =
|
||||
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
|
||||
return that->ChangePackage(data);
|
||||
};
|
||||
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED] =
|
||||
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
|
||||
return that->HandleBootCompleted(data);
|
||||
};
|
||||
}
|
||||
|
||||
void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data)
|
||||
@ -264,24 +286,66 @@ void ImCommonEventManager::EventSubscriber::RemoveUser(const CommonEventData &da
|
||||
}
|
||||
|
||||
void ImCommonEventManager::EventSubscriber::RemovePackage(const CommonEventData &data)
|
||||
{
|
||||
HandlePackageEvent(MessageID::MSG_ID_PACKAGE_REMOVED, data);
|
||||
}
|
||||
|
||||
void ImCommonEventManager::EventSubscriber::AddPackage(const EventFwk::CommonEventData &data)
|
||||
{
|
||||
HandlePackageEvent(MessageID::MSG_ID_PACKAGE_ADDED, data);
|
||||
}
|
||||
|
||||
void ImCommonEventManager::EventSubscriber::ChangePackage(const EventFwk::CommonEventData &data)
|
||||
{
|
||||
HandlePackageEvent(MessageID::MSG_ID_PACKAGE_CHANGED, data);
|
||||
}
|
||||
|
||||
void ImCommonEventManager::EventSubscriber::HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data)
|
||||
{
|
||||
auto const &want = data.GetWant();
|
||||
auto element = want.GetElement();
|
||||
std::string bundleName = element.GetBundleName();
|
||||
int32_t userId = want.GetIntParam("userId", 0);
|
||||
IMSA_HILOGD("ImCommonEventManager::RemovePackage, bundleName: %{public}s, userId: %{public}d", bundleName.c_str(),
|
||||
userId);
|
||||
int32_t userId = want.GetIntParam("userId", INVALID_USER_ID);
|
||||
if (userId == INVALID_USER_ID) {
|
||||
IMSA_HILOGE("invalid user id, messageId:%{public}d", messageId);
|
||||
return;
|
||||
}
|
||||
IMSA_HILOGD(
|
||||
"messageId:%{public}d, bundleName:%{public}s, userId:%{public}d", messageId, bundleName.c_str(), userId);
|
||||
if (messageId == MessageID::MSG_ID_PACKAGE_REMOVED) {
|
||||
if (!FullImeInfoManager::GetInstance().Has(userId, bundleName)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!ImeInfoInquirer::GetInstance().IsInputMethod(userId, bundleName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
MessageParcel *parcel = new (std::nothrow) MessageParcel();
|
||||
if (parcel == nullptr) {
|
||||
IMSA_HILOGE("parcel is nullptr!");
|
||||
IMSA_HILOGE("parcel is nullptr");
|
||||
return;
|
||||
}
|
||||
if (!ITypesUtil::Marshal(*parcel, userId, bundleName)) {
|
||||
IMSA_HILOGE("failed to write message parcel");
|
||||
IMSA_HILOGE("Failed to write message parcel");
|
||||
delete parcel;
|
||||
return;
|
||||
}
|
||||
Message *msg = new Message(MessageID::MSG_ID_PACKAGE_REMOVED, parcel);
|
||||
Message *msg = new (std::nothrow) Message(messageId, parcel);
|
||||
if (msg == nullptr) {
|
||||
IMSA_HILOGE("failed to create Message");
|
||||
delete parcel;
|
||||
return;
|
||||
}
|
||||
MessageHandler::Instance()->SendMessage(msg);
|
||||
}
|
||||
|
||||
void ImCommonEventManager::EventSubscriber::HandleBootCompleted(const EventFwk::CommonEventData &data)
|
||||
{
|
||||
Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_BOOT_COMPLETED, nullptr);
|
||||
if (msg == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageHandler::Instance()->SendMessage(msg);
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,17 @@
|
||||
#include "application_info.h"
|
||||
#include "bundle_mgr_client_impl.h"
|
||||
#include "file_operator.h"
|
||||
#include "full_ime_info_manager.h"
|
||||
#include "global.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ime_cfg_manager.h"
|
||||
#include "input_method_info.h"
|
||||
#include "input_type_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "locale_config.h"
|
||||
#include "locale_info.h"
|
||||
#include "os_account_info.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "parameter.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability.h"
|
||||
@ -36,6 +41,8 @@ namespace OHOS {
|
||||
namespace MiscServices {
|
||||
namespace {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace Global::Resource;
|
||||
using namespace AccountSA;
|
||||
constexpr const char *SUBTYPE_PROFILE_METADATA_NAME = "ohos.extension.input_method";
|
||||
constexpr uint32_t SUBTYPE_PROFILE_NUM = 1;
|
||||
constexpr const char *DEFAULT_IME_KEY = "persist.sys.default_ime";
|
||||
@ -298,6 +305,15 @@ int32_t ImeInfoInquirer::ListInputMethod(int32_t userId, InputMethodStatus statu
|
||||
int32_t ImeInfoInquirer::ListInputMethod(const int32_t userId, std::vector<Property> &props)
|
||||
{
|
||||
IMSA_HILOGD("userId: %{public}d.", userId);
|
||||
auto infos = FullImeInfoManager::GetInstance().Get(userId);
|
||||
for (const auto &info : infos) {
|
||||
props.push_back(info.prop);
|
||||
}
|
||||
if (!props.empty()) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
IMSA_HILOGD("%{public}d get all prop form bms.", userId);
|
||||
std::vector<ExtensionAbilityInfo> extensionInfos;
|
||||
if (!QueryImeExtInfos(userId, extensionInfos)) {
|
||||
IMSA_HILOGE("failed to QueryImeExtInfos!");
|
||||
@ -309,10 +325,19 @@ int32_t ImeInfoInquirer::ListInputMethod(const int32_t userId, std::vector<Prope
|
||||
if (it != props.end()) {
|
||||
continue;
|
||||
}
|
||||
std::string label;
|
||||
std::string resPath = extension.hapPath.empty() ? extension.resourcePath : extension.hapPath;
|
||||
auto resMgr = GetResMgr(resPath);
|
||||
if (resMgr != nullptr) {
|
||||
auto errValue = resMgr->GetStringById(extension.applicationInfo.labelId, label);
|
||||
if (errValue != RState::SUCCESS) {
|
||||
IMSA_HILOGE("GetStringById failed, bundleName:%{public}s, id:%{public}d", extension.bundleName.c_str(),
|
||||
extension.applicationInfo.labelId);
|
||||
}
|
||||
}
|
||||
props.push_back({ .name = extension.bundleName,
|
||||
.id = extension.name,
|
||||
.label =
|
||||
GetStringById(extension.bundleName, extension.moduleName, extension.applicationInfo.labelId, userId),
|
||||
.label = label,
|
||||
.labelId = extension.applicationInfo.labelId,
|
||||
.iconId = extension.applicationInfo.iconId });
|
||||
}
|
||||
@ -335,10 +360,8 @@ int32_t ImeInfoInquirer::ListEnabledInputMethod(const int32_t userId, std::vecto
|
||||
IMSA_HILOGE("get enable data failed");
|
||||
return ret;
|
||||
}
|
||||
auto info = GetDefaultImeInfo(userId);
|
||||
if (info != nullptr) {
|
||||
enableVec.insert(enableVec.begin(), info->prop.name);
|
||||
}
|
||||
auto info = GetDefaultIme();
|
||||
enableVec.insert(enableVec.begin(), info.bundleName);
|
||||
|
||||
auto newEnd = std::remove_if(props.begin(), props.end(), [&enableVec](const auto &prop) {
|
||||
return std::find(enableVec.begin(), enableVec.end(), prop.name) == enableVec.end();
|
||||
@ -368,10 +391,8 @@ int32_t ImeInfoInquirer::ListDisabledInputMethod(const int32_t userId, std::vect
|
||||
IMSA_HILOGE("get enable data failed");
|
||||
return ret;
|
||||
}
|
||||
auto info = GetDefaultImeInfo(userId);
|
||||
if (info != nullptr) {
|
||||
enableVec.insert(enableVec.begin(), info->prop.name);
|
||||
}
|
||||
auto info = GetDefaultIme();
|
||||
enableVec.insert(enableVec.begin(), info.bundleName);
|
||||
|
||||
auto newEnd = std::remove_if(props.begin(), props.end(), [&enableVec](const auto &prop) {
|
||||
return std::find(enableVec.begin(), enableVec.end(), prop.name) != enableVec.end();
|
||||
@ -412,6 +433,15 @@ int32_t ImeInfoInquirer::ListInputMethodSubtype(int32_t userId, const std::strin
|
||||
std::vector<SubProperty> &subProps)
|
||||
{
|
||||
IMSA_HILOGD("userId: %{public}d, bundleName: %{public}s.", userId, bundleName.c_str());
|
||||
auto infos = FullImeInfoManager::GetInstance().Get(userId);
|
||||
auto it = std::find_if(
|
||||
infos.begin(), infos.end(), [&bundleName](const FullImeInfo &info) { return info.prop.name == bundleName; });
|
||||
if (it != infos.end()) {
|
||||
subProps = (*it).subProps;
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
IMSA_HILOGD("%{public}d get %{public}s all subProp form bms.", userId, bundleName.c_str());
|
||||
std::vector<ExtensionAbilityInfo> extInfos;
|
||||
auto ret = GetExtInfosByBundleName(userId, bundleName, extInfos);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
@ -539,6 +569,9 @@ int32_t ImeInfoInquirer::ListInputMethodSubtype(const int32_t userId, const Exte
|
||||
IMSA_HILOGE("failed to parse subtype!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string resPath = extInfo.hapPath.empty() ? extInfo.resourcePath : extInfo.hapPath;
|
||||
auto resMgr = GetResMgr(resPath);
|
||||
IMSA_HILOGD("subtypes size: %{public}zu.", subtypes.size());
|
||||
for (const auto &subtype : subtypes) {
|
||||
// subtype which provides a particular input type should not appear in the subtype list
|
||||
@ -554,7 +587,13 @@ int32_t ImeInfoInquirer::ListInputMethodSubtype(const int32_t userId, const Exte
|
||||
auto pos = subProp.label.find(':');
|
||||
if (pos != std::string::npos && pos + 1 < subProp.label.size()) {
|
||||
subProp.labelId = atoi(subProp.label.substr(pos + 1).c_str());
|
||||
subProp.label = GetStringById(extInfo.bundleName, extInfo.moduleName, subProp.labelId, userId);
|
||||
}
|
||||
if (resMgr != nullptr) {
|
||||
auto errValue = resMgr->GetStringById(subProp.labelId, subProp.label);
|
||||
if (errValue != RState::SUCCESS) {
|
||||
IMSA_HILOGE("GetStringById failed, bundleName:%{public}s, id:%{public}d.", extInfo.bundleName.c_str(),
|
||||
subProp.labelId);
|
||||
}
|
||||
}
|
||||
pos = subProp.icon.find(':');
|
||||
if (pos != std::string::npos && pos + 1 < subProp.icon.size()) {
|
||||
@ -641,7 +680,8 @@ SubProperty ImeInfoInquirer::GetExtends(const std::vector<Metadata> &metaData)
|
||||
return property;
|
||||
}
|
||||
|
||||
std::shared_ptr<Property> ImeInfoInquirer::GetImeByBundleName(int32_t userId, const std::string &bundleName)
|
||||
std::shared_ptr<Property> ImeInfoInquirer::GetImeProperty(
|
||||
int32_t userId, const std::string &bundleName, const std::string &extName)
|
||||
{
|
||||
IMSA_HILOGD("start, bundleName: %{public}s", bundleName.c_str());
|
||||
std::vector<AppExecFwk::ExtensionAbilityInfo> extInfos;
|
||||
@ -651,8 +691,9 @@ std::shared_ptr<Property> ImeInfoInquirer::GetImeByBundleName(int32_t userId, co
|
||||
return nullptr;
|
||||
}
|
||||
Property prop = { .name = extInfos[0].bundleName,
|
||||
.id = extInfos[0].name,
|
||||
.label = extInfos[0].applicationInfo.label,
|
||||
.id = extName.empty() ? extInfos[0].name : extName,
|
||||
.label =
|
||||
GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, userId),
|
||||
.labelId = extInfos[0].applicationInfo.labelId,
|
||||
.iconId = extInfos[0].applicationInfo.iconId };
|
||||
return std::make_shared<Property>(prop);
|
||||
@ -662,26 +703,38 @@ std::shared_ptr<Property> ImeInfoInquirer::GetCurrentInputMethod(int32_t userId)
|
||||
{
|
||||
auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId);
|
||||
IMSA_HILOGD("currentIme: %{public}s.", currentImeCfg->imeId.c_str());
|
||||
std::vector<AppExecFwk::ExtensionAbilityInfo> extInfos;
|
||||
auto ret = ImeInfoInquirer::GetInstance().GetExtInfosByBundleName(userId, currentImeCfg->bundleName, extInfos);
|
||||
if (ret != ErrorCode::NO_ERROR || extInfos.empty()) {
|
||||
IMSA_HILOGE("userId: %{public}d getExtInfosByBundleName %{public}s failed!", userId,
|
||||
currentImeCfg->bundleName.c_str());
|
||||
return nullptr;
|
||||
auto infos = FullImeInfoManager::GetInstance().Get(userId);
|
||||
auto it = std::find_if(infos.begin(), infos.end(),
|
||||
[¤tImeCfg](const FullImeInfo &info) { return info.prop.name == currentImeCfg->bundleName; });
|
||||
if (it != infos.end()) {
|
||||
auto prop = std::make_shared<Property>((*it).prop);
|
||||
prop->id = currentImeCfg->extName;
|
||||
return prop;
|
||||
}
|
||||
Property prop = { .name = extInfos[0].bundleName,
|
||||
.id = currentImeCfg->extName, // if old ime, the extInfos[0].name maybe not same with currentImeExtName
|
||||
.label =
|
||||
GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, userId),
|
||||
.labelId = extInfos[0].applicationInfo.labelId,
|
||||
.iconId = extInfos[0].applicationInfo.iconId };
|
||||
return std::make_shared<Property>(prop);
|
||||
|
||||
IMSA_HILOGD("%{public}d get %{public}s prop form bms.", userId, currentImeCfg->bundleName.c_str());
|
||||
return GetImeProperty(userId, currentImeCfg->bundleName, currentImeCfg->extName);
|
||||
}
|
||||
|
||||
std::shared_ptr<SubProperty> ImeInfoInquirer::GetCurrentSubtype(int32_t userId)
|
||||
{
|
||||
auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId);
|
||||
IMSA_HILOGD("currentIme: %{public}s.", currentIme->imeId.c_str());
|
||||
auto infos = FullImeInfoManager::GetInstance().Get(userId);
|
||||
auto it = std::find_if(infos.begin(), infos.end(),
|
||||
[¤tIme](const FullImeInfo &info) { return info.prop.name == currentIme->bundleName; });
|
||||
if (it != infos.end() && !it->subProps.empty()) {
|
||||
auto iter = std::find_if(it->subProps.begin(), it->subProps.end(),
|
||||
[¤tIme](const SubProperty &subProp) { return subProp.id == currentIme->subName; });
|
||||
if (iter != it->subProps.end()) {
|
||||
return std::make_shared<SubProperty>(*iter);
|
||||
}
|
||||
IMSA_HILOGW("subtype %{public}s not found.", currentIme->subName.c_str());
|
||||
return std::make_shared<SubProperty>(it->subProps[0]);
|
||||
}
|
||||
|
||||
IMSA_HILOGD("%{public}d get [%{public}s, %{public}s] form bms.", userId, currentIme->bundleName.c_str(),
|
||||
currentIme->subName.c_str());
|
||||
std::vector<ExtensionAbilityInfo> extInfos;
|
||||
auto ret = GetExtInfosByBundleName(userId, currentIme->bundleName, extInfos);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
@ -770,23 +823,31 @@ int32_t ImeInfoInquirer::GetInputMethodConfig(const int32_t userId, AppExecFwk::
|
||||
int32_t ImeInfoInquirer::GetDefaultInputMethod(const int32_t userId, std::shared_ptr<Property> &prop, bool isBrief)
|
||||
{
|
||||
IMSA_HILOGD("userId: %{public}d.", userId);
|
||||
if (isBrief) {
|
||||
IMSA_HILOGD("GetDefaultInputMethod from ime.");
|
||||
auto defaultIme = GetDefaultImeCfgProp();
|
||||
if (defaultIme == nullptr) {
|
||||
IMSA_HILOGE("defaultIme is nullptr!");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
prop = std::make_shared<Property>(*defaultIme);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
auto imeInfo = GetDefaultImeInfo(userId);
|
||||
if (imeInfo == nullptr) {
|
||||
IMSA_HILOGE("imeInfo is nullptr!");
|
||||
auto defaultIme = GetDefaultImeCfgProp();
|
||||
if (defaultIme == nullptr) {
|
||||
IMSA_HILOGE("abnormal default ime cfg.");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
IMSA_HILOGD("getDefaultInputMethod name: %{public}s.", imeInfo->prop.name.c_str());
|
||||
prop = std::make_shared<Property>(imeInfo->prop);
|
||||
auto infos = FullImeInfoManager::GetInstance().Get(userId);
|
||||
auto it = std::find_if(infos.begin(), infos.end(),
|
||||
[&defaultIme](const FullImeInfo &info) { return info.prop.name == defaultIme->name; });
|
||||
if (it != infos.end()) {
|
||||
prop = std::make_shared<Property>((*it).prop);
|
||||
prop->id = defaultIme->id;
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
IMSA_HILOGD("%{public}d get %{public}s form bms.", userId, defaultIme->name.c_str());
|
||||
if (isBrief) {
|
||||
IMSA_HILOGD("get brief info.");
|
||||
if (prop == nullptr) {
|
||||
prop = std::make_shared<Property>();
|
||||
}
|
||||
prop->name = defaultIme->name;
|
||||
prop->id = defaultIme->id;
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
prop = GetImeProperty(userId, defaultIme->name, defaultIme->id);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@ -907,5 +968,143 @@ std::shared_ptr<Property> ImeInfoInquirer::GetDefaultImeCfgProp()
|
||||
defaultIme->id = ime.extName;
|
||||
return defaultIme;
|
||||
}
|
||||
|
||||
std::shared_ptr<ResourceManager> ImeInfoInquirer::GetResMgr(const std::string &resourcePath)
|
||||
{
|
||||
if (resourcePath.empty()) {
|
||||
IMSA_HILOGE("resourcePath is empty.");
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<ResourceManager> resMgr(CreateResourceManager());
|
||||
if (resMgr == nullptr) {
|
||||
IMSA_HILOGE("resMgr is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
resMgr->AddResource(resourcePath.c_str());
|
||||
std::unique_ptr<ResConfig> resConfig(CreateResConfig());
|
||||
if (resConfig == nullptr) {
|
||||
IMSA_HILOGE("resConfig is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
std::map<std::string, std::string> configs;
|
||||
OHOS::Global::I18n::LocaleInfo locale(Global::I18n::LocaleConfig::GetSystemLocale(), configs);
|
||||
resConfig->SetLocaleInfo(locale.GetLanguage().c_str(), locale.GetScript().c_str(), locale.GetRegion().c_str());
|
||||
resMgr->UpdateResConfig(*resConfig);
|
||||
return resMgr;
|
||||
}
|
||||
|
||||
int32_t ImeInfoInquirer::QueryFullImeInfo(std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &fullImeInfos)
|
||||
{
|
||||
std::vector<int32_t> userIds;
|
||||
auto ret = OsAccountManager::QueryActiveOsAccountIds(userIds);
|
||||
if (ret != ErrorCode::NO_ERROR || userIds.empty()) {
|
||||
return ErrorCode::ERROR_OS_ACCOUNT;
|
||||
}
|
||||
for (auto &userId : userIds) {
|
||||
std::vector<FullImeInfo> infos;
|
||||
auto errNo = QueryFullImeInfo(userId, infos);
|
||||
if (errNo != ErrorCode::NO_ERROR) {
|
||||
continue;
|
||||
}
|
||||
fullImeInfos.emplace_back(userId, infos);
|
||||
}
|
||||
if (fullImeInfos.empty()) {
|
||||
return ErrorCode::ERROR_PACKAGE_MANAGER;
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t ImeInfoInquirer::QueryFullImeInfo(int32_t userId, std::vector<FullImeInfo> &imeInfo)
|
||||
{
|
||||
std::vector<ExtensionAbilityInfo> extInfos;
|
||||
auto ret = ImeInfoInquirer::GetInstance().QueryImeExtInfos(userId, extInfos);
|
||||
if (!ret || extInfos.empty()) {
|
||||
IMSA_HILOGE("%{public}d QueryImeExtInfos failed.", userId);
|
||||
return ErrorCode::ERROR_PACKAGE_MANAGER;
|
||||
}
|
||||
std::map<std::string, std::vector<ExtensionAbilityInfo>> tempExtInfos;
|
||||
for (const auto &extInfo : extInfos) {
|
||||
auto it = tempExtInfos.find(extInfo.bundleName);
|
||||
if (it != tempExtInfos.end()) {
|
||||
it->second.push_back(extInfo);
|
||||
continue;
|
||||
}
|
||||
tempExtInfos.insert({ extInfo.bundleName, { extInfo } });
|
||||
}
|
||||
|
||||
for (const auto &extInfo : tempExtInfos) {
|
||||
FullImeInfo info;
|
||||
auto errNo = GetFullImeInfo(userId, extInfo.second, info);
|
||||
if (errNo != ErrorCode::NO_ERROR) {
|
||||
return errNo;
|
||||
}
|
||||
imeInfo.push_back(info);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t ImeInfoInquirer::GetFullImeInfo(int32_t userId, const std::string &bundleName, FullImeInfo &imeInfo)
|
||||
{
|
||||
auto bmg = GetBundleMgr();
|
||||
if (bmg == nullptr) {
|
||||
return ErrorCode::ERROR_PACKAGE_MANAGER;
|
||||
}
|
||||
BundleInfo bundleInfo;
|
||||
auto ret = bmg->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, userId);
|
||||
if (!ret) {
|
||||
IMSA_HILOGE("[%{public}d,%{public}s] GetBundleInfo failed.", userId, bundleName.c_str());
|
||||
return ErrorCode::ERROR_PACKAGE_MANAGER;
|
||||
}
|
||||
std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> extInfos;
|
||||
for (const auto &extInfo : bundleInfo.extensionInfos) {
|
||||
if (extInfo.type != ExtensionAbilityType::INPUTMETHOD) {
|
||||
continue;
|
||||
}
|
||||
extInfos.push_back(extInfo);
|
||||
}
|
||||
return GetFullImeInfo(userId, extInfos, imeInfo);
|
||||
}
|
||||
|
||||
int32_t ImeInfoInquirer::GetFullImeInfo(
|
||||
int32_t userId, const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, FullImeInfo &imeInfo)
|
||||
{
|
||||
if (extInfos.empty()) {
|
||||
return ErrorCode::ERROR_PACKAGE_MANAGER;
|
||||
}
|
||||
auto isNewIme = IsNewExtInfos(extInfos);
|
||||
auto ret = isNewIme ? ListInputMethodSubtype(userId, extInfos[0], imeInfo.subProps)
|
||||
: ListInputMethodSubtype(userId, extInfos, imeInfo.subProps);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGE("[%{public}d,%{public}s] list Subtype failed.", userId, extInfos[0].bundleName.c_str());
|
||||
return ret;
|
||||
}
|
||||
imeInfo.tokenId = extInfos[0].applicationInfo.accessTokenId;
|
||||
imeInfo.prop.name = extInfos[0].bundleName;
|
||||
imeInfo.prop.id = extInfos[0].name;
|
||||
imeInfo.prop.label =
|
||||
GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, userId);
|
||||
imeInfo.prop.labelId = extInfos[0].applicationInfo.labelId;
|
||||
imeInfo.prop.iconId = extInfos[0].applicationInfo.iconId;
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
bool ImeInfoInquirer::IsInputMethod(int32_t userId, const std::string &bundleName)
|
||||
{
|
||||
auto bmg = GetBundleMgr();
|
||||
if (bmg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
BundleInfo bundleInfo;
|
||||
auto ret = bmg->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, userId);
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
for (const auto &extInfo : bundleInfo.extensionInfos) {
|
||||
if (extInfo.type == ExtensionAbilityType::INPUTMETHOD) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
@ -22,6 +22,7 @@
|
||||
#include "combination_key.h"
|
||||
#include "common_event_support.h"
|
||||
#include "errors.h"
|
||||
#include "full_ime_info_manager.h"
|
||||
#include "global.h"
|
||||
#include "im_common_event_manager.h"
|
||||
#include "ime_cfg_manager.h"
|
||||
@ -282,17 +283,17 @@ void InputMethodSystemAbility::Initialize()
|
||||
isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled();
|
||||
}
|
||||
|
||||
void InputMethodSystemAbility::StartUserIdListener()
|
||||
void InputMethodSystemAbility::SubscribeCommonEvent()
|
||||
{
|
||||
sptr<ImCommonEventManager> imCommonEventManager = ImCommonEventManager::GetInstance();
|
||||
bool isSuccess = imCommonEventManager->SubscribeEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
|
||||
bool isSuccess = imCommonEventManager->SubscribeEvent();
|
||||
if (isSuccess) {
|
||||
IMSA_HILOGI("initialize subscribe service event success.");
|
||||
return;
|
||||
}
|
||||
|
||||
IMSA_HILOGE("failed, try again 10s later");
|
||||
auto callback = [this]() { StartUserIdListener(); };
|
||||
auto callback = [this]() { SubscribeCommonEvent(); };
|
||||
serviceHandler_->PostTask(callback, INIT_INTERVAL);
|
||||
}
|
||||
|
||||
@ -783,7 +784,7 @@ int32_t InputMethodSystemAbility::SwitchInputType(const SwitchInfo &switchInfo)
|
||||
}
|
||||
IMSA_HILOGD("need to switch ime: %{public}s|%{public}s.", switchInfo.bundleName.c_str(),
|
||||
switchInfo.subName.c_str());
|
||||
auto targetImeProperty = ImeInfoInquirer::GetInstance().GetImeByBundleName(userId_, switchInfo.bundleName);
|
||||
auto targetImeProperty = ImeInfoInquirer::GetInstance().GetImeProperty(userId_, switchInfo.bundleName);
|
||||
if (targetImeProperty == nullptr) {
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
@ -882,16 +883,28 @@ void InputMethodSystemAbility::WorkThread()
|
||||
OnUserRemoved(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_PACKAGE_REMOVED: {
|
||||
OnPackageRemoved(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_HIDE_KEYBOARD_SELF: {
|
||||
userSession_->OnHideSoftKeyBoardSelf();
|
||||
break;
|
||||
}
|
||||
case MSG_ID_BUNDLE_SCAN_FINISHED: {
|
||||
RegisterDataShareObserver();
|
||||
FullImeInfoManager::GetInstance().Init();
|
||||
break;
|
||||
}
|
||||
case MSG_ID_PACKAGE_ADDED:
|
||||
case MSG_ID_PACKAGE_CHANGED:
|
||||
case MSG_ID_PACKAGE_REMOVED: {
|
||||
HandlePackageEvent(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_SYS_LANGUAGE_CHANGED: {
|
||||
FullImeInfoManager::GetInstance().Update();
|
||||
break;
|
||||
}
|
||||
case MSG_ID_BOOT_COMPLETED:
|
||||
case MSG_ID_OS_ACCOUNT_STARTED: {
|
||||
FullImeInfoManager::GetInstance().Init();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -911,15 +924,16 @@ void InputMethodSystemAbility::WorkThread()
|
||||
*/
|
||||
int32_t InputMethodSystemAbility::OnUserStarted(const Message *msg)
|
||||
{
|
||||
// if scb enable, deal when receive wmsConnected.
|
||||
if (isScbEnable_) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
if (msg->msgContent_ == nullptr) {
|
||||
IMSA_HILOGE("msgContent_ is nullptr.");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
auto newUserId = msg->msgContent_->ReadInt32();
|
||||
FullImeInfoManager::GetInstance().Add(newUserId);
|
||||
// if scb enable, deal when receive wmsConnected.
|
||||
if (isScbEnable_) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
if (newUserId == userId_) {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
@ -937,6 +951,32 @@ int32_t InputMethodSystemAbility::OnUserRemoved(const Message *msg)
|
||||
auto userId = msg->msgContent_->ReadInt32();
|
||||
IMSA_HILOGI("start: %{public}d", userId);
|
||||
ImeCfgManager::GetInstance().DeleteImeCfg(userId);
|
||||
FullImeInfoManager::GetInstance().Delete(userId);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbility::HandlePackageEvent(const Message *msg)
|
||||
{
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
if (data == nullptr) {
|
||||
IMSA_HILOGD("data is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t userId = 0;
|
||||
std::string packageName;
|
||||
if (!ITypesUtil::Unmarshal(*data, userId, packageName)) {
|
||||
IMSA_HILOGE("Failed to read message parcel");
|
||||
return ErrorCode::ERROR_EX_PARCELABLE;
|
||||
}
|
||||
if (msg->msgId_ == MSG_ID_PACKAGE_CHANGED) {
|
||||
return FullImeInfoManager::GetInstance().Update(userId, packageName);
|
||||
}
|
||||
if (msg->msgId_ == MSG_ID_PACKAGE_ADDED) {
|
||||
return FullImeInfoManager::GetInstance().Add(userId, packageName);
|
||||
}
|
||||
if (msg->msgId_ == MSG_ID_PACKAGE_REMOVED) {
|
||||
return OnPackageRemoved(userId, packageName);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@ -948,19 +988,9 @@ int32_t InputMethodSystemAbility::OnUserRemoved(const Message *msg)
|
||||
* \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked
|
||||
* \return ErrorCode::ERROR_BAD_PARAMETERS bad parameter
|
||||
*/
|
||||
int32_t InputMethodSystemAbility::OnPackageRemoved(const Message *msg)
|
||||
int32_t InputMethodSystemAbility::OnPackageRemoved(int32_t userId, const std::string &packageName)
|
||||
{
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
if (data == nullptr) {
|
||||
IMSA_HILOGD("data is nullptr.");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t userId = 0;
|
||||
std::string packageName;
|
||||
if (!ITypesUtil::Unmarshal(*data, userId, packageName)) {
|
||||
IMSA_HILOGE("failed to read message parcel");
|
||||
return ErrorCode::ERROR_EX_PARCELABLE;
|
||||
}
|
||||
FullImeInfoManager::GetInstance().Delete(userId, packageName);
|
||||
// if the app that doesn't belong to current user is removed, ignore it
|
||||
if (userId != userId_) {
|
||||
IMSA_HILOGD("userId: %{public}d, currentUserId: %{public}d.", userId, userId_);
|
||||
@ -1155,7 +1185,7 @@ void InputMethodSystemAbility::InitMonitors()
|
||||
{
|
||||
int32_t ret = InitAccountMonitor();
|
||||
IMSA_HILOGI("init account monitor, ret: %{public}d.", ret);
|
||||
StartUserIdListener();
|
||||
SubscribeCommonEvent();
|
||||
ret = InitMemMgrMonitor();
|
||||
IMSA_HILOGI("init MemMgr monitor, ret: %{public}d.", ret);
|
||||
ret = InitKeyEventMonitor();
|
||||
@ -1305,8 +1335,12 @@ int32_t InputMethodSystemAbility::GetSecurityMode(int32_t &security)
|
||||
security = static_cast<int32_t>(SecurityMode::FULL);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
auto callBundleName = identityChecker_->GetBundleNameByToken(IPCSkeleton::GetCallingTokenID());
|
||||
SecurityMode mode = SecurityModeParser::GetInstance()->GetSecurityMode(callBundleName, userId_);
|
||||
auto bundleName = FullImeInfoManager::GetInstance().Get(userId_, IPCSkeleton::GetCallingTokenID());
|
||||
if (bundleName.empty()) {
|
||||
bundleName = identityChecker_->GetBundleNameByToken(IPCSkeleton::GetCallingTokenID());
|
||||
IMSA_HILOGW("%{public}s tokenId not find.", bundleName.c_str());
|
||||
}
|
||||
SecurityMode mode = SecurityModeParser::GetInstance()->GetSecurityMode(bundleName, userId_);
|
||||
security = static_cast<int32_t>(mode);
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ void ImfSaStubFuzzUtil::Initialize()
|
||||
DelayedSingleton<InputMethodSystemAbility>::GetInstance()->state_ = ServiceRunningState::STATE_RUNNING;
|
||||
ImeCfgManager::GetInstance().Init();
|
||||
DelayedSingleton<InputMethodSystemAbility>::GetInstance()->userSession_->UpdateCurrentUserId(USER_ID);
|
||||
DelayedSingleton<InputMethodSystemAbility>::GetInstance()->StartUserIdListener();
|
||||
DelayedSingleton<InputMethodSystemAbility>::GetInstance()->SubscribeCommonEvent();
|
||||
int32_t ret = DelayedSingleton<InputMethodSystemAbility>::GetInstance()->InitKeyEventMonitor();
|
||||
IMSA_HILOGI("init KeyEvent monitor %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed");
|
||||
ret = DelayedSingleton<InputMethodSystemAbility>::GetInstance()->InitWmsMonitor();
|
||||
|
@ -121,49 +121,6 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_GetExtends, TestSize.Level0)
|
||||
EXPECT_EQ(subProperty.icon, "icon");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SA_TestOnPackageRemoved
|
||||
* @tc.desc: SA_TestOnPackageRemoved
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnPackageRemoved, TestSize.Level0)
|
||||
{
|
||||
// msg is nullptr
|
||||
auto *msg = new Message(MessageID::MSG_ID_PACKAGE_REMOVED, nullptr);
|
||||
auto ret = service_->OnPackageRemoved(msg);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
|
||||
MessageHandler::Instance()->SendMessage(msg);
|
||||
|
||||
// PARCELABLE failed
|
||||
MessageParcel *parcel1 = new (std::nothrow) MessageParcel();
|
||||
auto bundleName = "testBundleName1";
|
||||
parcel1->WriteString(bundleName);
|
||||
auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel1);
|
||||
auto ret1 = service_->OnPackageRemoved(msg1.get());
|
||||
EXPECT_EQ(ret1, ErrorCode::ERROR_EX_PARCELABLE);
|
||||
|
||||
// userId is not same
|
||||
auto parcel2 = new (std::nothrow) MessageParcel();
|
||||
auto userId = 50;
|
||||
service_->userId_ = 60;
|
||||
parcel2->WriteInt32(userId);
|
||||
parcel2->WriteString(bundleName);
|
||||
auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel2);
|
||||
auto ret2 = service_->OnPackageRemoved(msg2.get());
|
||||
EXPECT_EQ(ret2, ErrorCode::NO_ERROR);
|
||||
|
||||
//remove bundle not current ime
|
||||
auto parcel3 = new (std::nothrow) MessageParcel();
|
||||
service_->userId_ = userId;
|
||||
ImeCfgManager::GetInstance().imeConfigs_.push_back({ 60, "testBundleName/testExtName", "testSubName" });
|
||||
parcel3->WriteInt32(userId);
|
||||
parcel3->WriteString(bundleName);
|
||||
auto msg3 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel3);
|
||||
auto ret3 = service_->OnPackageRemoved(msg3.get());
|
||||
EXPECT_EQ(ret3, ErrorCode::NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SA_TestOnUserStarted
|
||||
* @tc.desc: SA_TestOnUserStarted.
|
||||
@ -177,7 +134,7 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnUserStarted, TestSize.Level0)
|
||||
MessageParcel *parcel = nullptr;
|
||||
auto msg = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel);
|
||||
auto ret = service_->OnUserStarted(msg.get());
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
|
||||
|
||||
// msg is nullptr
|
||||
service_->isScbEnable_ = false;
|
||||
|
Loading…
Reference in New Issue
Block a user