diff --git a/frameworks/resmgr_lite/BUILD.gn b/frameworks/resmgr_lite/BUILD.gn index 9b0dcf263ff5f597addfe4eece8c949f1e35467f..f2e3c539cc34cd2088b1260e1a56c2f3acda0a56 100644 --- a/frameworks/resmgr_lite/BUILD.gn +++ b/frameworks/resmgr_lite/BUILD.gn @@ -82,7 +82,10 @@ if (defined(ohos_lite)) { static_library("global_resmgr") { sources = global_sources public_configs = [ ":global_resmgr_config" ] - deps = [ "//third_party/bounds_checking_function:libsec_static" ] + deps = [ + "//third_party/bounds_checking_function:libsec_static", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static", + ] } } else { shared_library("global_resmgr") { diff --git a/frameworks/resmgr_lite/src/global.c b/frameworks/resmgr_lite/src/global.c index 4b0e73f6630bfe0d6a51f56befb523bc47dde147..a7466c022527ecd770e38992f1db7a7af4cd1bd0 100644 --- a/frameworks/resmgr_lite/src/global.c +++ b/frameworks/resmgr_lite/src/global.c @@ -24,6 +24,7 @@ #include #include "global_utils.h" +#include "hilog_wrapper.h" /* * locale format as below, use '-' or '_' to link, e.g. en_Latn_US @@ -151,6 +152,7 @@ static int32_t GLOBAL_GetValueByIdInternal(uint32_t id, const char *path, const char realResourcePath[PATH_MAX] = {'\0'}; GlobalUtilsImpl *utilsImpl = GetGlobalUtilsImpl(); if (utilsImpl->CheckFilePath(path, realResourcePath, PATH_MAX) == MC_FAILURE) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "GLOBAL_GetValueByIdInternal failed to check file %s", path); return MC_FAILURE; } @@ -158,10 +160,12 @@ static int32_t GLOBAL_GetValueByIdInternal(uint32_t id, const char *path, const IdHeader idHeader = {0, NULL}; int32_t file = open(realResourcePath, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH); if (file < 0) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "GLOBAL_GetValueByIdInternal failed to open %s", realResourcePath); return MC_FAILURE; } int32_t ret = utilsImpl->GetIdHeaderByOffset(file, idHeaderOffset, &idHeader); if (ret != MC_SUCCESS) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to git id header by offset %lu", idHeaderOffset); close(file); return ret; } @@ -172,12 +176,15 @@ static int32_t GLOBAL_GetValueByIdInternal(uint32_t id, const char *path, const if (idHeader.idParams[i].id == id) { ret = utilsImpl->GetIdItem(file, idHeader.idParams[i].offset, &idItem); if (ret != MC_SUCCESS) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to get idiItem"); close(file); free(idHeader.idParams); return ret; } *value = (char *)malloc(idItem.valueLen); if (*value == NULL || strcpy_s(*value, idItem.valueLen, idItem.value) != EOK) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, + // "GLOBAL_GetValueByIdInternal failed to copy id item value %s", idItem.value); close(file); free(idHeader.idParams); FreeIdItem(&idItem); @@ -197,12 +204,14 @@ static int32_t GLOBAL_GetValueByIdInternal(uint32_t id, const char *path, const int32_t GLOBAL_GetValueById(uint32_t id, const char *path, char **value) { if (path == NULL || path[0] == '\0' || value == NULL) { + HILOG_ERROR("GLOBAL_GetValueById input params invalid"); return MC_FAILURE; } char tempLocale[MAX_LOCALE_LENGTH] = {'\0'}; int32_t ret = strcpy_s(tempLocale, MAX_LOCALE_LENGTH, g_locale); if (ret != EOK) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "GLOBAL_GetValueById failed to copy g_locale %s", g_locale); return MC_FAILURE; } @@ -212,6 +221,8 @@ int32_t GLOBAL_GetValueById(uint32_t id, const char *path, char **value) return MC_SUCCESS; } } + //HILOG_ERROR(HILOG_MODULE_HIVIEW, + // "fail get value by id: %lu, path: %s, tempLocale: %s", id, path, tempLocale); return MC_FAILURE; } diff --git a/frameworks/resmgr_lite/src/global.cpp b/frameworks/resmgr_lite/src/global.cpp index a66a833c61b74deb8c38d8a27b851f5b02f12ae5..a30d2a96a535e41f6399bd02d83a4c4dcb23e655 100644 --- a/frameworks/resmgr_lite/src/global.cpp +++ b/frameworks/resmgr_lite/src/global.cpp @@ -120,6 +120,7 @@ int32_t GLOBAL_GetRegion(char *region, uint8_t len) int32_t GetValue(const IdItem *idItem, char **value) { if (idItem == nullptr) { + HILOG_ERROR("GetValue idItem is null"); return SYS_ERROR; } if (idItem->isArray_) { @@ -130,6 +131,7 @@ int32_t GetValue(const IdItem *idItem, char **value) ret.append("]"); *value = static_cast(malloc(ret.size() + 1)); if (*value == nullptr || strcpy_s(*value, ret.size() + 1, ret.c_str()) != EOK) { + HILOG_ERROR("GetValue copy ret failed"); FreeValue(value); return SYS_ERROR; } @@ -137,6 +139,7 @@ int32_t GetValue(const IdItem *idItem, char **value) } else { *value = static_cast(malloc(idItem->valueLen_ + 1)); if (*value == nullptr || strcpy_s(*value, idItem->valueLen_ + 1, idItem->value_.c_str()) != EOK) { + HILOG_ERROR("GetValue copy idItem value failed"); FreeValue(value); return SYS_ERROR; } @@ -171,6 +174,7 @@ int32_t GLOBAL_GetValueById(uint32_t id, const char *path, char **value) auto idItem = hapManager.FindResourceById(id); if (idItem == nullptr) { + HILOG_ERROR("GLOBAL_GetValueById FindResourceById error. path: %s, id: %u", path, id); return OBJ_NOT_FOUND; } diff --git a/frameworks/resmgr_lite/src/global_utils.c b/frameworks/resmgr_lite/src/global_utils.c index ecd778d4666d36447c42934f5196ca15d588d869..88ec7c87c66544040fd798b1f843dbedf1315a39 100644 --- a/frameworks/resmgr_lite/src/global_utils.c +++ b/frameworks/resmgr_lite/src/global_utils.c @@ -27,6 +27,8 @@ #include #include +#include "hilog_wrapper.h" + #define MAX_ID_ITEM_NUM 0x7F #define MAX_RES_CONFIG_NUM 0xFFFF #define MAX_ITEM_LENGTH 0xFF @@ -258,6 +260,7 @@ static uint32_t FindOffsetByAllParam(char **resConfig, const Key *keys, uint32_t static uint32_t GetIdHeaderOffsetByCount(char **resConfig, const Key *keys, uint32_t configNum, int32_t count) { if (resConfig == NULL || keys == NULL) { + HILOG_ERROR("GetIdHeaderOffsetByCount resConfig or keys is null"); return INVALID_OFFSET; } uint32_t offset = INVALID_OFFSET; @@ -294,12 +297,14 @@ static void FreeKeyParams(Key *keys, int32_t count) static int32_t GetKeyParams(int32_t file, Key *keys, uint32_t resConfigNum) { if (file < 0 || keys == NULL) { + HILOG_ERROR("GetKeyParams file negative or keys is null"); return MC_FAILURE; } g_defaultIdHeaderOffset = INVALID_OFFSET; for (uint32_t i = 0; i < resConfigNum; ++i) { int seekRet = lseek(file, INDEX_DEFAULT_OFFSET, SEEK_CUR); // skip the "KEYS" header if (seekRet < 0) { + HILOG_ERROR("GetKeyParams file %ld seek failed, seekRet: %d", file, seekRet); FreeKeyParams(keys, i); return MC_FAILURE; } @@ -310,11 +315,13 @@ static int32_t GetKeyParams(int32_t file, Key *keys, uint32_t resConfigNum) continue; } if (keys[i].keysCount > KEY_TYPE_MAX) { + HILOG_ERROR("GetKeyParams keysCount %lu invalid, i: %lu", keys[i].keysCount, i); FreeKeyParams(keys, i); return MC_FAILURE; } keys[i].keyParams = (KeyParam *)malloc(sizeof(KeyParam) * keys[i].keysCount); if (keys[i].keyParams == NULL) { + HILOG_ERROR("GetKeyParams keyParams is null, i: %lu", i); FreeKeyParams(keys, i); return MC_FAILURE; } @@ -329,21 +336,26 @@ static int32_t GetKeyParams(int32_t file, Key *keys, uint32_t resConfigNum) static int32_t CheckFilePath(const char *path, char *realResourcePath, int32_t length) { if (length > PATH_MAX || length < 0) { + HILOG_ERROR("CheckFilePath length %ld invalid", length); return MC_FAILURE; } #if (defined(_WIN32) || defined(_WIN64)) if (!PathCanonicalizeA((char*)path, realResourcePath)) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "CheckFilePath path %s canonicalize failed", path); return MC_FAILURE; } return MC_SUCCESS; #elif defined(I18N_PRODUCT) int ret = strcpy_s(realResourcePath, PATH_MAX, path); if (ret != 0) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "CheckFilePath path %s copy failed", path); return MC_FAILURE; } return MC_SUCCESS; #else if (realpath(path, realResourcePath) == NULL) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, + // "CheckFilePath path %s realpath failed, realResourcePath %s", path, realResourcePath); return MC_FAILURE; } return MC_SUCCESS; @@ -353,35 +365,43 @@ static int32_t CheckFilePath(const char *path, char *realResourcePath, int32_t l static uint32_t GetOffsetByLocale(const char *path, const char *locale, uint32_t length) { if (path == NULL || strlen(path) == 0 || locale == NULL || length == 0) { + HILOG_ERROR("GetOffsetByLocale input params invalid"); return INVALID_OFFSET; } char realResourcePath[PATH_MAX] = {0}; if (CheckFilePath(path, realResourcePath, PATH_MAX) == MC_FAILURE) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "GetOffsetByLocale check file path %s failed", path); return INVALID_OFFSET; } int32_t file = open(realResourcePath, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH); if (file < 0) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "GetOffsetByLocale open file %s failed", realResourcePath); return INVALID_OFFSET; } int seekRet = lseek(file, RES_CONFIG_NUM_OFFSET, SEEK_SET); // goto resConfigNum index, now is fixed at 132 if (seekRet < 0) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, "GetOffsetByLocale file %s seek failed", realResourcePath); close(file); return INVALID_OFFSET; } uint32_t resConfigNum = GetDefaultOffsetValue(file); if (resConfigNum == 0 || resConfigNum > MAX_RES_CONFIG_NUM) { + //HILOG_ERROR(HILOG_MODULE_HIVIEW, + // "GetOffsetByLocale %s get offset failed resConfigNum:%lu", realResourcePath, resConfigNum); close(file); return INVALID_OFFSET; } int size = sizeof(Key) * resConfigNum; Key *keys = (Key *)malloc(size); if (keys == NULL) { + HILOG_ERROR("GetOffsetByLocale keys is null, resConfigNum: %lu", resConfigNum); close(file); return INVALID_OFFSET; } (void)memset_s(keys, size, 0, size); int32_t ret = GetKeyParams(file, keys, resConfigNum); if (ret != MC_SUCCESS) { + HILOG_ERROR("GetOffsetByLocale get key params failed, ret: %ld", ret); close(file); free(keys); return INVALID_OFFSET; @@ -399,11 +419,13 @@ static uint32_t GetOffsetByLocale(const char *path, const char *locale, uint32_t static uint32_t GetDefaultOffsetValue(int32_t file) { if (file < 0) { + HILOG_ERROR("GetDefaultOffsetValue file %ld negative", file); return 0; } uint8_t cache[INDEX_DEFAULT_OFFSET] = {0}; int32_t ret = read(file, cache, INDEX_DEFAULT_OFFSET); if (ret != INDEX_DEFAULT_OFFSET) { + HILOG_ERROR("GetDefaultOffsetValue %ld read failed, ret: %ld", file, ret); return 0; } return ConvertUint8ArrayToUint32(cache, INDEX_DEFAULT_OFFSET); @@ -425,12 +447,14 @@ static uint32_t GetKeyValue(int32_t file) static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) { if (offset == INVALID_OFFSET || file == -1 || idItem == NULL) { + HILOG_ERROR("GetIdItem input params invalid"); return MC_FAILURE; } uint8_t defaultCache[INDEX_DEFAULT_OFFSET] = {0}; uint8_t lengthCache[VALUE_LENGTH_OFFSET] = {0}; int seekRet = lseek(file, offset, SEEK_SET); if (seekRet < 0) { + HILOG_ERROR("GetIdItem file %ld seek failed, seekRet: %d", file, seekRet); return MC_FAILURE; } (void)read(file, defaultCache, INDEX_DEFAULT_OFFSET); @@ -445,11 +469,13 @@ static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) (void)read(file, lengthCache, VALUE_LENGTH_OFFSET); idItem->valueLen = (uint16_t)ConvertUint8ArrayToUint32(lengthCache, VALUE_LENGTH_OFFSET); if (idItem->valueLen == 0 || idItem->valueLen > MAX_ITEM_LENGTH) { + HILOG_ERROR("GetIdItem idItem valueLen %u invalid", idItem->valueLen); return MC_FAILURE; } idItem->value = (char *)malloc(idItem->valueLen); if (idItem->value == NULL) { + HILOG_ERROR("GetIdItem idItem value is null"); return MC_FAILURE; } (void)memset_s(idItem->value, idItem->valueLen, 0, idItem->valueLen); @@ -458,6 +484,7 @@ static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) (void)read(file, lengthCache, VALUE_LENGTH_OFFSET); idItem->nameLen = (uint16_t)ConvertUint8ArrayToUint32(lengthCache, VALUE_LENGTH_OFFSET); if (idItem->nameLen == 0 || idItem->nameLen > MAX_ITEM_LENGTH) { + HILOG_ERROR("GetIdItem idItem nameLen %u invalid", idItem->nameLen); free(idItem->value); idItem->value = NULL; return MC_FAILURE; @@ -465,10 +492,13 @@ static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) idItem->name = (char *)malloc(idItem->nameLen); if (idItem->name == NULL) { + HILOG_ERROR("GetIdItem idItem name is null"); free(idItem->value); idItem->value = NULL; return MC_FAILURE; } + //HILOG_INFO(HILOG_MODULE_HIVIEW, + // "GetIdItem file:%ld, name:%s, nameLen:%u", file, idItem->name, idItem->nameLen); (void)memset_s(idItem->name, idItem->nameLen, 0, idItem->nameLen); (void)read(file, idItem->name, idItem->nameLen); @@ -496,18 +526,22 @@ static uint32_t GetIdHeaderOffsetByLocale(const char *locale, const Key *keys, u static int32_t GetIdHeaderByOffset(int32_t file, uint32_t offset, IdHeader *idHeader) { if (file == -1 || offset == INVALID_OFFSET || idHeader == NULL) { + HILOG_ERROR("GetIdHeaderByOffset input params invalid"); return MC_FAILURE; } (void)lseek(file, (int32_t)offset + INDEX_DEFAULT_OFFSET, SEEK_SET); // skip the "IDSS" header idHeader->count = GetDefaultOffsetValue(file); if (idHeader->count == 0 || idHeader->count > MAX_ID_ITEM_NUM) { + HILOG_ERROR("GetIdHeaderByOffset idHeader count %lu invalid", idHeader->count); return MC_FAILURE; } idHeader->idParams = (IdParam *)malloc(sizeof(IdParam) * idHeader->count); if (idHeader->idParams == NULL) { + HILOG_ERROR("GetIdHeaderByOffset idHeader idParams is null, idHeader->count: %lu", idHeader->count); return MC_FAILURE; } + HILOG_INFO("GetIdHeaderByOffset file: %ld, idHeader->count: %lu", file, idHeader->count); for (uint32_t i = 0; i < idHeader->count; i++) { idHeader->idParams[i].id = GetDefaultOffsetValue(file); idHeader->idParams[i].offset = GetDefaultOffsetValue(file);