From 348cfc9ad4e52ede4f50670e3c12338041f886a9 Mon Sep 17 00:00:00 2001 From: kaiju Date: Thu, 24 Jul 2025 16:33:48 +0800 Subject: [PATCH] fix:get bundleName from config Signed-off-by: kaiju Change-Id: I3e0dee84d9483cf7ffd186115735e6a9127d3b4c --- services/context/inc/widget_json.h | 2 + services/context/src/widget_context.cpp | 6 +++ services/context/src/widget_json.cpp | 54 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/services/context/inc/widget_json.h b/services/context/inc/widget_json.h index ca5466492..eb8fd3d5e 100644 --- a/services/context/inc/widget_json.h +++ b/services/context/inc/widget_json.h @@ -54,6 +54,8 @@ 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); +bool GetSceneboardBundleName(std::string &processName); +bool GetSceneboardAbilityName(std::string &processName); // WidgetCommand struct WidgetCommand { diff --git a/services/context/src/widget_context.cpp b/services/context/src/widget_context.cpp index 41bd350ba..b13c883c4 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -562,6 +562,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(bundleName)) { + IAM_LOGE("GetSceneboardBundleName error"); + } + if (!GetSceneboardAbilityName(abilityName)) { + IAM_LOGE("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..dbbf36f99 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; @@ -211,6 +213,26 @@ 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_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("getStringArrayFromJson error"); + return false; +} } // utils @@ -439,6 +461,38 @@ bool GetFollowCallerList(std::vector &processName) return true; } +bool GetSceneboardBundleName(std::string &processName) +{ + IAM_LOGI("enter"); + nlohmann::json jsonBuf; + std::string configPath = GetConfigRealPath(); + if (!ReadFileIntoJson(configPath, jsonBuf)) { + IAM_LOGE("Path to realPath failed"); + return false; + } + if (!GetStringFromJson(jsonBuf, processName, SCENEBOARD_BUNDLE_NAME)) { + IAM_LOGE("GetStringFromJson failed"); + return false; + } + return true; +} + +bool GetSceneboardAbilityName(std::string &processName) +{ + IAM_LOGI("enter"); + nlohmann::json jsonBuf; + std::string configPath = GetConfigRealPath(); + if (!ReadFileIntoJson(configPath, jsonBuf)) { + IAM_LOGE("Path to realPath failed"); + return false; + } + if (!GetStringFromJson(jsonBuf, processName, SCENEBOARD_ABILITY_NAME)) { + IAM_LOGE("GetStringFromJson failed"); + return false; + } + return true; +} + void to_json(nlohmann::json &jsonCommand, const WidgetCommand &command) { GetJsonCmd(jsonCommand, command); -- Gitee