From 27d0d728c0a921b2559168ead19fbbb05993314a Mon Sep 17 00:00:00 2001 From: cy7717 Date: Tue, 22 Apr 2025 20:35:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B0=83=E7=94=A8=E4=B8=BA?= =?UTF-8?q?=E5=8D=95=E4=BE=8B=E6=A8=A1=E5=BC=8F=EF=BC=8C=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E6=9E=84=E9=80=A0=E4=B8=8E?= =?UTF-8?q?=E6=9E=90=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- .../src/imf_hisysevent_util.cpp | 5 ++-- services/src/ime_info_inquirer.cpp | 23 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/imf_hisysevent/src/imf_hisysevent_util.cpp b/common/imf_hisysevent/src/imf_hisysevent_util.cpp index ab791650b..9cae6c94a 100644 --- a/common/imf_hisysevent/src/imf_hisysevent_util.cpp +++ b/common/imf_hisysevent/src/imf_hisysevent_util.cpp @@ -22,6 +22,7 @@ #include "hisysevent.h" #include "ipc_skeleton.h" #include "running_process_info.h" +#include "singleton.h" namespace OHOS { namespace MiscServices { using namespace OHOS::AppExecFwk; @@ -117,8 +118,8 @@ std::string ImfHiSysEventUtil::GetAppName(uint64_t fullTokenId) case ATokenTypeEnum::TOKEN_HAP: { if (fullTokenId == IPCSkeleton::GetSelfTokenID()) { RunningProcessInfo info; - AppMgrClient client; - if (client.GetProcessRunningInformation(info) == 0) { + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient != nullptr && appMgrClient->GetProcessRunningInformation(info) == 0) { name = info.processName_; } break; diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 4dbeb1d4b..619d17092 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -15,7 +15,7 @@ #include "ime_info_inquirer.h" #include "app_mgr_client.h" -#include "bundle_mgr_client_impl.h" +#include "bundle_mgr_client.h" #include "full_ime_info_manager.h" #include "input_type_manager.h" #include "iservice_registry.h" @@ -23,6 +23,7 @@ #include "locale_info.h" #include "os_account_adapter.h" #include "parameter.h" +#include "singleton.h" #include "system_ability_definition.h" namespace OHOS { @@ -598,9 +599,9 @@ int32_t ImeInfoInquirer::ParseSubtype(const OHOS::AppExecFwk::ExtensionAbilityIn IMSA_HILOGE("find metadata name: SUBTYPE_PROFILE_METADATA_NAME failed!"); return ErrorCode::ERROR_BAD_PARAMETERS; } - OHOS::AppExecFwk::BundleMgrClientImpl clientImpl; + OHOS::AppExecFwk::BundleMgrClient client; std::vector profiles; - if (!clientImpl.GetResConfigFile(extInfo, iter->name, profiles)) { + if (!client.GetResConfigFile(extInfo, iter->name, profiles)) { IMSA_HILOGE("failed to GetProfileFromExtension!"); return ErrorCode::ERROR_PACKAGE_MANAGER; } @@ -1112,8 +1113,12 @@ std::vector ImeInfoInquirer::GetRunningIme(int32_t userId) { std::vector bundleNames; std::vector infos; - AppMgrClient client; - auto ret = client.GetProcessRunningInfosByUserId(infos, userId); + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient == nullptr) { + IMSA_HILOGE("appMgrClient is nullptr."); + return bundleNames; + } + auto ret = appMgrClient->GetProcessRunningInfosByUserId(infos, userId); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("GetAllRunningProcesses failed, ret: %{public}d!", ret); return bundleNames; @@ -1212,8 +1217,12 @@ std::string ImeInfoInquirer::GetTargetString( bool ImeInfoInquirer::IsInputMethodExtension(pid_t pid) { RunningProcessInfo info; - AppMgrClient client; - client.GetRunningProcessInfoByPid(pid, info); + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient == nullptr) { + IMSA_HILOGE("appMgrClient is nullptr."); + return false; + } + appMgrClient->GetRunningProcessInfoByPid(pid, info); return info.extensionType_ == ExtensionAbilityType::INPUTMETHOD; } } // namespace MiscServices -- Gitee