diff --git a/frameworks/innerkitsimpl/utils/include/image_utils.h b/frameworks/innerkitsimpl/utils/include/image_utils.h index 45fce12f05e27af6b85516e2848bac623005520d..fd8261b66f315288e2998894e2b972bbb527bccc 100644 --- a/frameworks/innerkitsimpl/utils/include/image_utils.h +++ b/frameworks/innerkitsimpl/utils/include/image_utils.h @@ -162,6 +162,7 @@ private: static uint32_t SaveDataToFile(const std::string& fileName, const char* data, const size_t& totalSize); static std::string GetLocalTime(); static std::string GetPixelMapName(PixelMap* pixelMap); + static int32_t GetAPIVersionInner(); }; } // namespace Media } // namespace OHOS diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index f33ae97c7bdba12913088cab2bf9ce3aa497f21e..3d6e8b04201e6fad6fcedb566582ba93def214a3 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "__config" #include "image_log.h" @@ -1156,6 +1157,17 @@ std::string ImageUtils::GetEncodedHeifFormat() int32_t ImageUtils::GetAPIVersion() { #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) + static std::atomic apiVersion = GetAPIVersionInner(); + if (apiVersion.load() <= 0) { + apiVersion.store(GetAPIVersionInner()); + } + return apiVersion.load(); +#endif +} + +int32_t ImageUtils::GetAPIVersionInner() +{ +#if !defined(CROSS_PLATFORM) uint32_t targetVersion = 0; auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) {