diff --git a/frameworks/native/ability/native/js_service_extension.cpp b/frameworks/native/ability/native/js_service_extension.cpp index c972121bea46859edaadc389e3a344a9134eb041..efd1e8c8fa4a9ec000947bc7ea3da566de0e1e98 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 07d53e3a72bfcdcd45aaaed019a49ddf7bdede23..c2371bf1e9facc5dadfb5aee2fc91bf952f43af5 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;