From 0a641f95b86d7fd63cf5799aeb4647eded039731 Mon Sep 17 00:00:00 2001 From: kaiju Date: Fri, 25 Jul 2025 14:59:27 +0800 Subject: [PATCH] fix: get bundleName from config Signed-off-by: kaiju Change-Id: Icd0d765984bec6105c0625c95db477e7089286ea --- services/context/inc/widget_context.h | 1 + services/context/inc/widget_json.h | 7 ++- services/context/src/widget_context.cpp | 11 +++- services/context/src/widget_json.cpp | 67 +++++++++++++++++++++---- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/services/context/inc/widget_context.h b/services/context/inc/widget_context.h index 1f1be28a6..0f42bf3d5 100644 --- a/services/context/inc/widget_context.h +++ b/services/context/inc/widget_context.h @@ -169,6 +169,7 @@ private: uint32_t onResultTimerId_ {0}; uint32_t onTipTimerId_ {0}; ResultInfo resultInfo_{0}; + nlohmann::json jsonBuf_ = {}; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/context/inc/widget_json.h b/services/context/inc/widget_json.h index ca5466492..b5ddf41f0 100644 --- a/services/context/inc/widget_json.h +++ b/services/context/inc/widget_json.h @@ -52,8 +52,11 @@ struct WidgetNotice { }; void to_json(nlohmann::json &jsonNotice, const WidgetNotice ¬ice); void from_json(const nlohmann::json &jsonNotice, WidgetNotice ¬ice); -bool GetProcessName(std::vector &processName); -bool GetFollowCallerList(std::vector &processName); +void LoadConfigJsonBuffer(nlohmann::json &jsonBuf); +bool GetProcessName(nlohmann::json &jsonBuf, std::vector &processName); +bool GetFollowCallerList(nlohmann::json &jsonBuf, std::vector &processName); +bool GetSceneboardBundleName(nlohmann::json &jsonBuf, std::string &processName); +bool GetSceneboardAbilityName(nlohmann::json &jsonBuf, std::string &processName); // WidgetCommand struct WidgetCommand { diff --git a/services/context/src/widget_context.cpp b/services/context/src/widget_context.cpp index 41bd350ba..74612a3f2 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -78,6 +78,7 @@ WidgetContext::WidgetContext(uint64_t contextId, const ContextFactory::AuthWidge if (!para.isBackgroundApplication) { SubscribeAppState(callerCallback_, contextId_); } + LoadConfigJsonBuffer(jsonBuf_); } WidgetContext::~WidgetContext() @@ -485,7 +486,7 @@ bool WidgetContext::IsInFollowCallerList() IAM_LOGI("productName is %{public}s.", productName.c_str()); std::vector processName; - if (!GetFollowCallerList(processName)) { + if (!GetFollowCallerList(jsonBuf_, processName)) { IAM_LOGE("GetFollowCallerList error"); return false; } @@ -512,7 +513,7 @@ void WidgetContext::SetSysDialogZOrder(WidgetCmdParameters &widgetCmdParameters) IAM_LOGI("the screen is currently locked, set zOrder"); widgetCmdParameters.sysDialogZOrder = SYSDIALOG_ZORDER_UPPER; } - if (!GetProcessName(processName)) { + if (!GetProcessName(jsonBuf_, processName)) { IAM_LOGE("getProcessName error"); return; } @@ -562,6 +563,12 @@ bool WidgetContext::ConnectExtension(const WidgetRotatePara &widgetRotatePara) AAFwk::Want want; std::string bundleName = "com.ohos.systemui"; std::string abilityName = "com.ohos.systemui.dialog"; + if (!GetSceneboardBundleName(jsonBuf_, bundleName)) { + IAM_LOGI("GetSceneboardBundleName error"); + } + if (!GetSceneboardAbilityName(jsonBuf_, abilityName)) { + IAM_LOGI("GetSceneboardAbilityName error"); + } want.SetElementName(bundleName, abilityName); auto ret = ConnectExtensionAbility(want, commandData); if (ret != ERR_OK) { diff --git a/services/context/src/widget_json.cpp b/services/context/src/widget_json.cpp index 535948f81..440972065 100644 --- a/services/context/src/widget_json.cpp +++ b/services/context/src/widget_json.cpp @@ -87,6 +87,8 @@ const std::string JSON_CMD_EXTRA_INFO = "extraInfo"; constexpr const char *AUTH_WIDGE_CONFIG_SUFFIX = "etc/auth_widget/auth_widget_config.json"; const std::string SHWO_WITH_LEVEL_2_WINDOW = "show_with_level_2_window"; const std::string FOLLOW_CALLER_WINDOW_WHEN_FOLDED = "follow_caller_window_when_folded"; +const std::string SCENEBOARD_BUNDLE_NAME = "sceneboard_bundle_name"; +const std::string SCENEBOARD_ABILITY_NAME = "sceneboard_ability_name"; const uint32_t DISABLE_ROTATE = 0; const uint32_t MAX_ERR_BUF_LEN = 256; @@ -194,6 +196,10 @@ bool GetStringArrayFromJson(const nlohmann::json &jsonObject, std::vector &exemptedBundleInfos, const std::string &key) { + if (jsonObject.is_null()) { + IAM_LOGE("jsonObject is null"); + return false; + } if (jsonObject.is_array() && !jsonObject.is_discarded()) { for (const auto &object : jsonObject) { if (!object.is_object()) { @@ -211,6 +217,30 @@ bool GetStringArrayFromJson(const nlohmann::json &jsonObject, IAM_LOGE("getStringArrayFromJson error"); return false; } + +bool GetStringFromJson(const nlohmann::json &jsonObject, std::string &exemptedBundleInfo, + const std::string &key) +{ + if (jsonObject.is_null()) { + IAM_LOGE("jsonObject is null"); + return false; + } + if (jsonObject.is_array() && !jsonObject.is_discarded()) { + for (const auto &object : jsonObject) { + if (!object.is_object()) { + IAM_LOGE("is not object"); + return false; + } + const auto &objectEnd = object.end(); + if (object.find(key) != objectEnd) { + exemptedBundleInfo = object.at(key).get(); + return true; + } + } + } + IAM_LOGE("getStringFromJson error"); + return false; +} } // utils @@ -407,31 +437,48 @@ std::string GetConfigRealPath() return configPath; } -bool GetProcessName(std::vector &processName) +void LoadConfigJsonBuffer(nlohmann::json &jsonBuf) { - IAM_LOGI("enter"); - nlohmann::json jsonBuf; + IAM_LOGI("LoadConfig start"); std::string configPath = GetConfigRealPath(); if (!ReadFileIntoJson(configPath, jsonBuf)) { IAM_LOGE("ReadFileIntoJson failed"); + } +} + +bool GetSceneboardBundleName(nlohmann::json &jsonBuf, std::string &processName) +{ + IAM_LOGI("enter"); + if (!GetStringFromJson(jsonBuf, processName, SCENEBOARD_BUNDLE_NAME)) { + IAM_LOGE("GetStringFromJson failed"); return false; } - if (!GetStringArrayFromJson(jsonBuf, processName, SHWO_WITH_LEVEL_2_WINDOW)) { - IAM_LOGE("GetStringArrayFromJson failed"); + return true; +} + +bool GetSceneboardAbilityName(nlohmann::json &jsonBuf, std::string &processName) +{ + IAM_LOGI("enter"); + if (!GetStringFromJson(jsonBuf, processName, SCENEBOARD_ABILITY_NAME)) { + IAM_LOGE("GetStringFromJson failed"); return false; } return true; } -bool GetFollowCallerList(std::vector &processName) +bool GetProcessName(nlohmann::json &jsonBuf, std::vector &processName) { IAM_LOGI("enter"); - nlohmann::json jsonBuf; - std::string configPath = GetConfigRealPath(); - if (!ReadFileIntoJson(configPath, jsonBuf)) { - IAM_LOGE("Path to realPath failed"); + if (!GetStringArrayFromJson(jsonBuf, processName, SHWO_WITH_LEVEL_2_WINDOW)) { + IAM_LOGE("GetStringArrayFromJson failed"); return false; } + return true; +} + +bool GetFollowCallerList(nlohmann::json &jsonBuf, std::vector &processName) +{ + IAM_LOGI("enter"); if (!GetStringArrayFromJson(jsonBuf, processName, FOLLOW_CALLER_WINDOW_WHEN_FOLDED)) { IAM_LOGE("GetStringArrayFromJson failed"); return false; -- Gitee