From 3da39a5b98eb6121d7a3c72f1d1833b174526c22 Mon Sep 17 00:00:00 2001 From: gaochao Date: Sat, 9 Nov 2024 10:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E6=BA=90id=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaochao --- dfx/hisysevent_adapter/hisysevent_adapter.cpp | 4 ++-- dfx/hisysevent_adapter/hisysevent_adapter.h | 2 +- frameworks/resmgr/include/res_desc.h | 2 +- frameworks/resmgr/src/res_desc.cpp | 8 ++++---- .../resmgr/src/resource_manager_impl.cpp | 6 +++--- .../test/unittest/common/res_desc_test.cpp | 2 +- .../inner_api/include/resource_manager.h | 2 +- .../include/resource_manager_data_context.h | 2 +- .../include/resource_manager_napi_utils.h | 4 ++-- .../src/resource_manager_napi_async_impl.cpp | 12 +++++------ .../src/resource_manager_napi_sync_impl.cpp | 20 +++++++++---------- .../core/src/resource_manager_napi_utils.cpp | 16 +++++++-------- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/dfx/hisysevent_adapter/hisysevent_adapter.cpp b/dfx/hisysevent_adapter/hisysevent_adapter.cpp index 5a95005..7977e21 100644 --- a/dfx/hisysevent_adapter/hisysevent_adapter.cpp +++ b/dfx/hisysevent_adapter/hisysevent_adapter.cpp @@ -33,7 +33,7 @@ void ReportInitResourceManagerFail(const std::string& bundleName, const std::str } } -void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const std::string& errMsg) +void ReportGetResourceByIdFail(uint32_t resId, const std::string& result, const std::string& errMsg) { int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::GLOBAL_RESMGR, "GET_RES_BY_ID_FAILED", HiSysEventNameSpace::EventType::BEHAVIOR, @@ -42,7 +42,7 @@ void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const s "ERROR_MSG", errMsg); if (ret != 0) { RESMGR_HILOGE(RESMGR_TAG, - "HiSysEventWrite failed! ret %{public}d, resId %{public}d, result %{public}s, errMsg %{public}s.", + "HiSysEventWrite failed! ret %{public}d, resId %{public}u, result %{public}s, errMsg %{public}s.", ret, resId, result.c_str(), errMsg.c_str()); } } diff --git a/dfx/hisysevent_adapter/hisysevent_adapter.h b/dfx/hisysevent_adapter/hisysevent_adapter.h index 0280aed..03c9bc2 100644 --- a/dfx/hisysevent_adapter/hisysevent_adapter.h +++ b/dfx/hisysevent_adapter/hisysevent_adapter.h @@ -23,7 +23,7 @@ namespace Global { namespace Resource { void ReportInitResourceManagerFail(const std::string& bundleName, const std::string& errMsg); -void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const std::string& errMsg); +void ReportGetResourceByIdFail(uint32_t resId, const std::string& result, const std::string& errMsg); void ReportGetResourceByNameFail(const std::string& resName, const std::string& result, const std::string& errMsg); diff --git a/frameworks/resmgr/include/res_desc.h b/frameworks/resmgr/include/res_desc.h index fb4e9bc..bffaf76 100644 --- a/frameworks/resmgr/include/res_desc.h +++ b/frameworks/resmgr/include/res_desc.h @@ -84,7 +84,7 @@ public: * @param id when return true, set id. as sample : 16777225 * @return true: value is ref */ - static bool IsRef(const std::string &value, ResType &resType, int &id); + static bool IsRef(const std::string &value, ResType &resType, uint32_t &id); std::string ToString() const; diff --git a/frameworks/resmgr/src/res_desc.cpp b/frameworks/resmgr/src/res_desc.cpp index 74303cd..e9c8363 100644 --- a/frameworks/resmgr/src/res_desc.cpp +++ b/frameworks/resmgr/src/res_desc.cpp @@ -224,7 +224,7 @@ bool IdItem::HaveParent() const return (values_.size() % 2 == 1); // Taking the remainder of 2 to determine the existence of a parent node } -bool IdItem::IsRef(const std::string &value, ResType &resType, int &id) +bool IdItem::IsRef(const std::string &value, ResType &resType, uint32_t &id) { const char *it = value.c_str(); const char *st = it; @@ -240,11 +240,11 @@ bool IdItem::IsRef(const std::string &value, ResType &resType, int &id) typeStr.assign(it + 1, index - 1); idStr.assign(it + index + 1, value.size() - index); - int idd = atoi(idStr.c_str()); - if (idd <= 0) { + unsigned long tmpId; + if (!Utils::convertToUnsignedLong(idStr, tmpId)) { return false; } - + uint32_t idd = static_cast(tmpId); for (auto iit = resTypeStrList.begin(); iit != resTypeStrList.end(); ++iit) { auto tValue = iit->second; auto type = iit->first; diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp index f39d28f..07a43ba 100644 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -427,7 +427,7 @@ RState ResourceManagerImpl::GetPluralString(const std::shared_ptr } if (haveParent) { // get parent - int id; + uint32_t id; ResType resType; bool isRef = IdItem::IsRef(currItem->values_[0], resType, id); if (!isRef) { @@ -797,7 +797,7 @@ RState ResourceManagerImpl::GetInteger(const std::shared_ptr idItem, int RState ResourceManagerImpl::ProcessReference(const std::string value, std::vector> &idItems) { - int id; + uint32_t id; ResType resType; bool isRef = true; int count = 0; diff --git a/frameworks/resmgr/test/unittest/common/res_desc_test.cpp b/frameworks/resmgr/test/unittest/common/res_desc_test.cpp index ccfa509..dc5ce9b 100644 --- a/frameworks/resmgr/test/unittest/common/res_desc_test.cpp +++ b/frameworks/resmgr/test/unittest/common/res_desc_test.cpp @@ -66,7 +66,7 @@ void ResDescTest::TearDown() HWTEST_F(ResDescTest, ResDescFuncTest001, TestSize.Level1) { std::string str; - int id; + uint32_t id; ResType resType; str.assign("abc"); EXPECT_TRUE(!IdItem::IsRef(str, resType, id)); diff --git a/interfaces/inner_api/include/resource_manager.h b/interfaces/inner_api/include/resource_manager.h index dff6c97..842f788 100644 --- a/interfaces/inner_api/include/resource_manager.h +++ b/interfaces/inner_api/include/resource_manager.h @@ -54,7 +54,7 @@ public: std::string moduleName; /** the resource id in hap */ - int32_t id; + uint32_t id; }; enum class NapiValueType { diff --git a/interfaces/js/innerkits/core/include/resource_manager_data_context.h b/interfaces/js/innerkits/core/include/resource_manager_data_context.h index 4f1c776..34cb24a 100644 --- a/interfaces/js/innerkits/core/include/resource_manager_data_context.h +++ b/interfaces/js/innerkits/core/include/resource_manager_data_context.h @@ -26,7 +26,7 @@ struct ResMgrDataContext { napi_async_work work_; std::string bundleName_; - int32_t resId_; + uint32_t resId_; int32_t param_; std::string path_; diff --git a/interfaces/js/innerkits/core/include/resource_manager_napi_utils.h b/interfaces/js/innerkits/core/include/resource_manager_napi_utils.h index d87eca8..ce94df7 100644 --- a/interfaces/js/innerkits/core/include/resource_manager_napi_utils.h +++ b/interfaces/js/innerkits/core/include/resource_manager_napi_utils.h @@ -58,7 +58,7 @@ public: static std::string GetResNameOrPath(napi_env env, size_t argc, napi_value *argv); - static int GetResId(napi_env env, size_t argc, napi_value *argv); + static uint32_t GetResId(napi_env env, size_t argc, napi_value *argv); static void NapiThrow(napi_env env, int32_t errCode); @@ -66,7 +66,7 @@ public: napi_value &value); static bool GetHapResourceManager(const ResMgrDataContext* dataContext, - std::shared_ptr &resMgr, int32_t &resId); + std::shared_ptr &resMgr, uint32_t &resId); static RState GetIncludeSystem(napi_env env, napi_value value, bool &includeSystem); diff --git a/interfaces/js/innerkits/core/src/resource_manager_napi_async_impl.cpp b/interfaces/js/innerkits/core/src/resource_manager_napi_async_impl.cpp index ff308a9..558b4eb 100644 --- a/interfaces/js/innerkits/core/src/resource_manager_napi_async_impl.cpp +++ b/interfaces/js/innerkits/core/src/resource_manager_napi_async_impl.cpp @@ -406,7 +406,7 @@ napi_value ResourceManagerNapiAsyncImpl::ProcessNoParam(napi_env env, napi_callb auto getStringFunc = [](napi_env env, void* data) { ResMgrDataContext *dataContext = static_cast(data); std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId); if (!ret) { @@ -466,7 +466,7 @@ napi_value ResourceManagerNapiAsyncImpl::GetStringByName(napi_env env, napi_call auto getStringArrayFunc = [](napi_env env, void* data) { ResMgrDataContext *dataContext = static_cast(data); RState state; - int32_t resId = 0; + uint32_t resId = 0; std::shared_ptr resMgr = nullptr; if (dataContext->resId_ != 0 || dataContext->resource_ != nullptr) { bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId); @@ -521,7 +521,7 @@ napi_value ResourceManagerNapiAsyncImpl::GetStringArrayByName(napi_env env, napi auto getMediaFunc = [](napi_env env, void *data) { ResMgrDataContext *dataContext = static_cast(data); std::string path; - int32_t resId = 0; + uint32_t resId = 0; std::shared_ptr resMgr = nullptr; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId); if (!ret) { @@ -565,7 +565,7 @@ auto getMediaBase64Func = [](napi_env env, void *data) { std::string path; RState state; if (dataContext->resId_ != 0 || dataContext->resource_ != nullptr) { - int32_t resId = 0; + uint32_t resId = 0; std::shared_ptr resMgr = nullptr; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId); if (!ret) { @@ -629,7 +629,7 @@ auto getPluralCapFunc = [](napi_env env, void *data) { ResMgrDataContext *dataContext = static_cast(data); RState state; if (dataContext->resId_ != 0 || dataContext->resource_ != nullptr) { - int32_t resId = 0; + uint32_t resId = 0; std::shared_ptr resMgr = nullptr; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId); if (!ret) { @@ -813,7 +813,7 @@ napi_value ResourceManagerNapiAsyncImpl::GetRawFileList(napi_env env, napi_callb auto getColorFunc = [](napi_env env, void* data) { ResMgrDataContext *dataContext = static_cast(data); std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; if (!ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId)) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to GetHapResourceManager in getColorFunc"); diff --git a/interfaces/js/innerkits/core/src/resource_manager_napi_sync_impl.cpp b/interfaces/js/innerkits/core/src/resource_manager_napi_sync_impl.cpp index 709574f..9827393 100644 --- a/interfaces/js/innerkits/core/src/resource_manager_napi_sync_impl.cpp +++ b/interfaces/js/innerkits/core/src/resource_manager_napi_sync_impl.cpp @@ -309,7 +309,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessStrResource(napi_env env, napi_callb std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetStringSync"); @@ -357,7 +357,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessSymbolResource(napi_env env, napi_ca std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetSymbol"); @@ -399,7 +399,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessColorResource(napi_env env, napi_cal std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in ProcessColorResource"); @@ -442,7 +442,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessNumResource(napi_env env, napi_callb std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to ResourceManagerNapiUtils::GetHapResourceManager in GetNumber"); @@ -484,7 +484,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessBoolResource(napi_env env, napi_call std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret2) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetBoolean"); @@ -525,7 +525,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcesstMediaContentBase64Resource(napi_env std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret2) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetMediaContentBase64Sync"); @@ -570,7 +570,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessMediaContentResource(napi_env env, n std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret2) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetMediaContentSync"); @@ -616,7 +616,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessPluralStringValueResource(napi_env e std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret2) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetPluralStringValueSync"); @@ -669,7 +669,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessStringArrayValueResource(napi_env en std::unique_ptr &dataContext) { std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId); if (!ret2) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetStringArrayValueSync"); @@ -729,7 +729,7 @@ napi_value ResourceManagerNapiSyncImpl::GetDrawableDescriptor(napi_env env, napi } std::shared_ptr resMgr = nullptr; - int32_t resId = 0; + uint32_t resId = 0; if (!ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId)) { dataContext->SetErrorMsg("Failed to get GetHapResourceManager in GetDrawableDescriptor", true); return nullptr; diff --git a/interfaces/js/innerkits/core/src/resource_manager_napi_utils.cpp b/interfaces/js/innerkits/core/src/resource_manager_napi_utils.cpp index f1fa29c..3c52835 100644 --- a/interfaces/js/innerkits/core/src/resource_manager_napi_utils.cpp +++ b/interfaces/js/innerkits/core/src/resource_manager_napi_utils.cpp @@ -110,7 +110,7 @@ std::string ResourceManagerNapiUtils::GetResNameOrPath(napi_env env, size_t argc return buf.data(); } -int ResourceManagerNapiUtils::GetResId(napi_env env, size_t argc, napi_value *argv) +uint32_t ResourceManagerNapiUtils::GetResId(napi_env env, size_t argc, napi_value *argv) { if (argc == 0 || argv == nullptr) { return 0; @@ -126,14 +126,14 @@ int ResourceManagerNapiUtils::GetResId(napi_env env, size_t argc, napi_value *ar RESMGR_HILOGE(RESMGR_JS_TAG, "Invalid param, not number"); return 0; } - int resId = 0; - status = napi_get_value_int32(env, argv[ARRAY_SUBCRIPTOR_ZERO], &resId); + int64_t resId = 0; + status = napi_get_value_int64(env, argv[ARRAY_SUBCRIPTOR_ZERO], &resId); if (status != napi_ok) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get id number"); return 0; } - return resId; + return static_cast(resId); } std::string ResourceManagerNapiUtils::FindErrMsg(int32_t errCode) @@ -358,13 +358,13 @@ bool ResourceManagerNapiUtils::GetResourceObjectId(napi_env env, RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resource id number"); return false; } - int32_t resId = 0; - status = napi_get_value_int32(env, id, &resId); + int64_t resId = 0; + status = napi_get_value_int64(env, id, &resId); if (status != napi_ok) { RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resource id value"); return false; } - resourcePtr->id = resId; + resourcePtr->id = static_cast(resId); return true; } @@ -392,7 +392,7 @@ int32_t ResourceManagerNapiUtils::GetResourceObject(napi_env env, } bool ResourceManagerNapiUtils::GetHapResourceManager(const ResMgrDataContext* dataContext, - std::shared_ptr &resMgr, int32_t &resId) + std::shared_ptr &resMgr, uint32_t &resId) { std::shared_ptr resource = dataContext->resource_; // In fa module, resource is null.