From ecd05b6424e619e4f1731f06deb3865b64220681 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Fri, 15 Aug 2025 10:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Estart=E6=97=B6initDisplayConf?= =?UTF-8?q?ig=E5=89=8D=E5=AF=B9ScreenDensity=E5=B7=B2set=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang_hao_zheng Change-Id: I657165add81331fc8a47a6caeeb4d161aa5a68c3 --- .../ability/native/js_service_extension.cpp | 17 ++++++++++++++++- .../ability/native/js_service_extension.h | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frameworks/native/ability/native/js_service_extension.cpp b/frameworks/native/ability/native/js_service_extension.cpp index c972121bea4..efd1e8c8fa4 100644 --- a/frameworks/native/ability/native/js_service_extension.cpp +++ b/frameworks/native/ability/native/js_service_extension.cpp @@ -299,6 +299,18 @@ void JsServiceExtension::BindContext(napi_env env, napi_value obj) TAG_LOGD(AAFwkTag::SERVICE_EXT, "end"); } +bool JsServiceExtension::HasScreenDensityBeenSet(std::shared_ptr resourceManager) +{ + TAG_LOGD(AAFwkTag::ABILITY, "call HasScreenDensityBeenSet"); + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + if (resConfig == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "null resConfig"); + return false; + } + resourceManager->GetResConfig(*resConfig); + return resConfig->GetScreenDensityDpi() != Global::Resource::ScreenDensity::SCREEN_DENSITY_NOT_SET; +} + void JsServiceExtension::OnStart(const AAFwk::Want &want) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -312,7 +324,10 @@ void JsServiceExtension::OnStart(const AAFwk::Want &want) displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, displayId); TAG_LOGD(AAFwkTag::SERVICE_EXT, "displayId %{public}d", displayId); auto configUtils = std::make_shared(); - configUtils->InitDisplayConfig(displayId, context->GetConfiguration(), context->GetResourceManager()); + if (!HasScreenDensityBeenSet(context->GetResourceManager())) { + TAG_LOGD(AAFwkTag::ABILITY, "call InitDisplayConfig"); + configUtils->InitDisplayConfig(displayId, context->GetConfiguration(), context->GetResourceManager()); + } #endif //SUPPORT_GRAPHICS } diff --git a/interfaces/kits/native/ability/native/js_service_extension.h b/interfaces/kits/native/ability/native/js_service_extension.h index 07d53e3a72b..c2371bf1e9f 100644 --- a/interfaces/kits/native/ability/native/js_service_extension.h +++ b/interfaces/kits/native/ability/native/js_service_extension.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_RUNTIME_JS_SERVICE_EXTENSION_H #include "configuration.h" +#include "configuration_utils.h" #include "insight_intent_execute_param.h" #include "insight_intent_execute_result.h" #include "insight_intent_executor_info.h" @@ -182,6 +183,8 @@ private: void AddLifecycleEventForJSCall(const std::string &eventStr); + bool HasScreenDensityBeenSet(std::shared_ptr resourceManager); + JsRuntime& jsRuntime_; std::unique_ptr jsObj_; std::shared_ptr shellContextRef_ = nullptr; -- Gitee