From d1bd37286dcfeceec83c10fb723bef10d5bb1ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=8F=9E=E9=A3=8E?= Date: Thu, 10 Mar 2022 09:26:25 +0000 Subject: [PATCH 1/3] Description:code quality. Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No #I4X9CB; Signed-off-by: wuluofeng --- interfaces/kits/bundle_lite/bundle_manager.h | 14 +++++++++- .../bundlemgr_lite/include/bundle_extractor.h | 2 +- .../bundlemgr_lite/include/bundle_installer.h | 22 ++++++++-------- .../bundlemgr_lite/include/bundle_parser.h | 10 +++---- .../bundlemgr_lite/include/bundlems_log.h | 6 ++--- .../include/gt_bundle_installer.h | 26 +++++++++---------- .../bundlemgr_lite/include/gt_bundle_parser.h | 14 +++++----- .../bundlemgr_lite/src/bundle_ms_feature.cpp | 2 +- services/bundlemgr_lite/src/bundle_util.cpp | 4 +-- .../src/gt_bundle_installer.cpp | 2 +- .../src/gt_bundle_manager_service.cpp | 2 +- .../bundlemgr_lite/src/gt_extractor_util.cpp | 4 +-- services/bundlemgr_lite/src/zip_file.cpp | 4 +-- utils/bundle_lite/adapter.h | 4 +-- 14 files changed, 64 insertions(+), 52 deletions(-) diff --git a/interfaces/kits/bundle_lite/bundle_manager.h b/interfaces/kits/bundle_lite/bundle_manager.h index c55791c..39086ae 100755 --- a/interfaces/kits/bundle_lite/bundle_manager.h +++ b/interfaces/kits/bundle_lite/bundle_manager.h @@ -94,7 +94,7 @@ int32_t RegisterCallback(BundleStatusCallback *BundleStatusCallback); * @since 1.0 * @version 1.0 */ -int32_t UnregisterCallback(); +int32_t UnregisterCallback(void); /** * @brief Installs or updates an application. @@ -216,6 +216,7 @@ uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInf */ uint8_t GetBundleNameForUid(int32_t uid, char **bundleName); +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER /** * @brief Check if the specify syscap name is supported by the system. * @@ -246,6 +247,17 @@ SystemCapability *GetSystemAvailableCapabilities(); * @version 4 */ void FreeSystemAvailableCapabilitiesInfo(SystemCapability *sysCap); +#endif +/** + * @brief Get bundle size + * + * @param bundleName Indicates the bundle name. + * @return Returns the bundle size (Byte) if this function is successfully called; returns 0 otherwise. + * + * @since 7 + * @version 7 + */ +uint32_t GetBundleSize(const char *bundleName); #ifdef __cplusplus #if __cplusplus } diff --git a/services/bundlemgr_lite/include/bundle_extractor.h b/services/bundlemgr_lite/include/bundle_extractor.h index ade3178..9e969ac 100755 --- a/services/bundlemgr_lite/include/bundle_extractor.h +++ b/services/bundlemgr_lite/include/bundle_extractor.h @@ -16,9 +16,9 @@ #ifndef OHOS_BUNDLE_EXTRACTOR_H #define OHOS_BUNDLE_EXTRACTOR_H -#include "stdint.h" #include #include +#include "stdint.h" namespace OHOS { class BundleExtractor { diff --git a/services/bundlemgr_lite/include/bundle_installer.h b/services/bundlemgr_lite/include/bundle_installer.h index b9945ff..c1991e8 100755 --- a/services/bundlemgr_lite/include/bundle_installer.h +++ b/services/bundlemgr_lite/include/bundle_installer.h @@ -70,9 +70,9 @@ private: #define CHECK_PRO_RESULT(errcode, bundleInfo, permissions, abilityRes) \ do { \ - if (errcode != ERR_OK) { \ + if ((errcode) != ERR_OK) { \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ - AdapterFree(permissions.permissionTrans); \ + AdapterFree((permissions).permissionTrans); \ AdapterFree(abilityRes); \ return errcode; \ } \ @@ -80,19 +80,19 @@ private: #define CLEAR_INSTALL_ENV(bundleInfo) \ do { \ - if (bundleInfo != nullptr) { \ + if ((bundleInfo) != nullptr) { \ BundleDaemonClient::GetInstance().RemoveInstallDirectory( \ - bundleInfo->codePath, bundleInfo->dataPath, false); \ + (bundleInfo)->codePath, (bundleInfo)->dataPath, false); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ } \ } while (0) #define CHECK_PRO_PART_ROLLBACK(errcode, path, permissions, bundleInfo, abilityRes) \ do { \ - if (errcode != ERR_OK && bundleInfo != nullptr) { \ - BundleDaemonClient::GetInstance().RemoveFile(path.c_str()); \ + if ((errcode) != ERR_OK && (bundleInfo) != nullptr) { \ + BundleDaemonClient::GetInstance().RemoveFile((path).c_str()); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ - AdapterFree(permissions.permissionTrans); \ + AdapterFree((permissions).permissionTrans); \ AdapterFree(abilityRes); \ return errcode; \ } \ @@ -100,11 +100,11 @@ private: #define CHECK_PRO_ROLLBACK(errcode, permissions, bundleInfo, abilityRes, randStr) \ do { \ - if (errcode != ERR_OK && bundleInfo != nullptr) { \ - AdapterFree(permissions.permissionTrans); \ + if ((errcode) != ERR_OK && (bundleInfo) != nullptr) { \ + AdapterFree((permissions).permissionTrans); \ AdapterFree(abilityRes); \ - ManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \ - BundleUtil::DeleteJsonFile(bundleInfo->bundleName, randStr); \ + ManagerService::GetInstance().RemoveBundleInfo((bundleInfo)->bundleName); \ + BundleUtil::DeleteJsonFile((bundleInfo)->bundleName, randStr); \ CLEAR_INSTALL_ENV(bundleInfo); \ return errcode; \ } \ diff --git a/services/bundlemgr_lite/include/bundle_parser.h b/services/bundlemgr_lite/include/bundle_parser.h index 51dfa66..4011af8 100755 --- a/services/bundlemgr_lite/include/bundle_parser.h +++ b/services/bundlemgr_lite/include/bundle_parser.h @@ -71,14 +71,14 @@ private: #define CHECK_NULL(object, errorCode) \ do { \ - if (object == nullptr) { \ + if ((object) == nullptr) { \ return errorCode; \ } \ } while (0) #define CHECK_LENGTH(length, maxLength, errorCode) \ do { \ - if (length > maxLength) { \ + if ((length) > (maxLength)) { \ return errorCode; \ } \ } while (0) @@ -92,7 +92,7 @@ private: #define CHECK_PARSE_RESULT(errorCode, object, bundleProfile) \ do { \ - if (errorCode != ERR_OK) { \ + if ((errorCode) != ERR_OK) { \ FREE_BUNDLE_PROFILE(bundleProfile); \ cJSON_Delete(object); \ return errorCode; \ @@ -101,9 +101,9 @@ private: #define FREE_BUNDLE_PROFILE(bundleProfile) \ do { \ - AdapterFree(bundleProfile.abilityInfos); \ + AdapterFree((bundleProfile).abilityInfos); \ for (uint8_t i = 0; i < METADATA_SIZE; i++) { \ - AdapterFree(bundleProfile.moduleInfo.metaData[i]); \ + AdapterFree((bundleProfile).moduleInfo.metaData[i]);\ } \ } while (0) } // namespace OHOS diff --git a/services/bundlemgr_lite/include/bundlems_log.h b/services/bundlemgr_lite/include/bundlems_log.h index 933673c..2f4fde2 100755 --- a/services/bundlemgr_lite/include/bundlems_log.h +++ b/services/bundlemgr_lite/include/bundlems_log.h @@ -64,7 +64,7 @@ namespace OHOS { #define CHECK_NULLPTR_RETURN_PTR(point, name, fmt) \ do { \ - if (point == nullptr) { \ + if ((point) == nullptr) { \ PRINTE(name, fmt); \ return nullptr; \ } \ @@ -72,7 +72,7 @@ namespace OHOS { #define CHECK_NULLPTR_RETURN(point, name, fmt) \ do { \ - if (point == nullptr) { \ + if ((point) == nullptr) { \ PRINTE(name, fmt); \ return; \ } \ @@ -80,7 +80,7 @@ namespace OHOS { #define CHECK_NULLPTR_RETURN_CODE(point, name, fmt, code) \ do { \ - if (point == nullptr) { \ + if ((point) == nullptr) { \ PRINTE(name, fmt); \ return code; \ } \ diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index ed558e5..c076487 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -75,19 +75,19 @@ private: close(fp); \ } \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ - UI_Free(permissions.permissionTrans); \ + UI_Free((permissions).permissionTrans); \ } while (0) -#define FREE_SIGNATUREINFO(signatureInfo) \ - do { \ - AdapterFree(signatureInfo.appId); \ - AdapterFree(signatureInfo.bundleName); \ - BundleUtil::FreeStrArrayMemory(signatureInfo.restricPermission, signatureInfo.restricNum); \ +#define FREE_SIGNATUREINFO(signatureInfo) \ + do { \ + AdapterFree(signatureInfo.appId); \ + AdapterFree(signatureInfo.bundleName); \ + BundleUtil::FreeStrArrayMemory((signatureInfo).restricPermission, (signatureInfo).restricNum); \ } while (0) #define CHECK_PRO_RESULT(errcode, fp, permissions, bundleInfo, signatureInfo) \ do { \ - if (errcode != ERR_OK) { \ + if ((errcode) != ERR_OK) { \ FREE_PRO_RESOURCE(fp, permissions, bundleInfo); \ FREE_SIGNATUREINFO(signatureInfo); \ return errcode; \ @@ -97,31 +97,31 @@ private: #define CLEAR_INSTALL_ENV(bundleInfo) \ do { \ if (bundleInfo != nullptr) { \ - BundleUtil::RemoveDir(bundleInfo->codePath); \ - BundleUtil::RemoveDir(bundleInfo->dataPath); \ + BundleUtil::RemoveDir((bundleInfo)->codePath); \ + BundleUtil::RemoveDir((bundleInfo)->dataPath); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ } \ } while (0) #define CHECK_PRO_PART_ROLLBACK(errcode, path, permissions, bundleInfo, signatureInfo) \ do { \ - if (errcode != ERR_OK) { \ + if ((errcode) != ERR_OK) { \ BundleUtil::RemoveDir(path); \ AdapterFree(path); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ FREE_SIGNATUREINFO(signatureInfo); \ - UI_Free(permissions.permissionTrans); \ + UI_Free((permissions).permissionTrans); \ return errcode; \ } \ } while (0) #define CHECK_PRO_ROLLBACK(errcode, permissions, bundleInfo, signatureInfo, randStr) \ do { \ - if (errcode != ERR_OK && bundleInfo != nullptr) { \ + if ((errcode) != ERR_OK && (bundleInfo) != nullptr) { \ FREE_SIGNATUREINFO(signatureInfo); \ UI_Free(permissions.permissionTrans); \ GtManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \ - BundleUtil::DeleteJsonFile(bundleInfo->bundleName, randStr); \ + BundleUtil::DeleteJsonFile((bundleInfo)->bundleName, randStr); \ CLEAR_INSTALL_ENV(bundleInfo); \ return errcode; \ } \ diff --git a/services/bundlemgr_lite/include/gt_bundle_parser.h b/services/bundlemgr_lite/include/gt_bundle_parser.h index be0443f..807f6b4 100644 --- a/services/bundlemgr_lite/include/gt_bundle_parser.h +++ b/services/bundlemgr_lite/include/gt_bundle_parser.h @@ -56,21 +56,21 @@ private: #define CHECK_NULL(object, errorCode) \ do { \ - if (object == nullptr) { \ + if ((object) == nullptr) { \ return errorCode; \ } \ } while (0) #define CHECK_LENGTH(length, maxLength, errorCode) \ do { \ - if (length > maxLength) { \ + if ((length) > (maxLength)) { \ return errorCode; \ } \ } while (0) #define CHECK_IS_TRUE(result, errorCode) \ do { \ - if (!result) { \ + if (!(result)) { \ return errorCode; \ } \ } while (0) @@ -78,20 +78,20 @@ private: #define FREE_BUNDLE_PROFILE(bundleProfile) \ do { \ for (int32_t i = 0; i < METADATA_SIZE; i++) { \ - AdapterFree(bundleProfile.moduleInfo.metaData[i]); \ + AdapterFree((bundleProfile).moduleInfo.metaData[i]); \ } \ } while (0) #define FREE_BUNDLE_RES(bundleRes) \ do { \ - if (bundleRes.abilityRes != nullptr) { \ - AdapterFree(bundleRes.abilityRes); \ + if ((bundleRes).abilityRes != nullptr) { \ + AdapterFree((bundleRes).abilityRes); \ } \ } while (0) #define CHECK_PARSE_RESULT(errorCode, object, bundleProfile, bundleRes) \ do { \ - if (errorCode != ERR_OK) { \ + if ((errorCode) != ERR_OK) { \ FREE_BUNDLE_PROFILE(bundleProfile); \ FREE_BUNDLE_RES(bundleRes); \ cJSON_Delete(object); \ diff --git a/services/bundlemgr_lite/src/bundle_ms_feature.cpp b/services/bundlemgr_lite/src/bundle_ms_feature.cpp index 6edbe6c..e94e85a 100755 --- a/services/bundlemgr_lite/src/bundle_ms_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_ms_feature.cpp @@ -117,7 +117,7 @@ BOOL BundleMsFeature::OnFeatureMessage(Feature *feature, Request *request) return TRUE; } -void static InnerFreeDataBuff(void *ptr) +static void InnerFreeDataBuff(void *ptr) { if (ptr != nullptr) { cJSON_free(ptr); diff --git a/services/bundlemgr_lite/src/bundle_util.cpp b/services/bundlemgr_lite/src/bundle_util.cpp index 7458161..aaa4b57 100755 --- a/services/bundlemgr_lite/src/bundle_util.cpp +++ b/services/bundlemgr_lite/src/bundle_util.cpp @@ -27,16 +27,16 @@ #include #include "bundle_daemon_client.h" #else +#include #include "adapter.h" #include "bundlems_log.h" #include "dirent.h" #include "fcntl.h" #include "los_tick.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #endif -#include +#include #include "utils.h" namespace OHOS { diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 69eeefc..29ec26e 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -22,6 +22,7 @@ extern "C" { #ifdef __cplusplus } #endif +#include #include "appexecfwk_errors.h" #include "bundle_util.h" #include "bundlems_log.h" @@ -31,7 +32,6 @@ extern "C" { #include "gt_bundle_extractor.h" #include "gt_bundle_manager_service.h" #include "gt_bundle_parser.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #include "utils.h" diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 4d9e534..f144658 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -15,6 +15,7 @@ #include "gt_bundle_manager_service.h" +#include #include "ability_info_utils.h" #include "ability_message_id.h" #include "appexecfwk_errors.h" @@ -30,7 +31,6 @@ #include "gt_extractor_util.h" #include "jerryscript_adapter.h" #include "los_tick.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #include "utils.h" diff --git a/services/bundlemgr_lite/src/gt_extractor_util.cpp b/services/bundlemgr_lite/src/gt_extractor_util.cpp index 02ab2c5..9ab5c72 100755 --- a/services/bundlemgr_lite/src/gt_extractor_util.cpp +++ b/services/bundlemgr_lite/src/gt_extractor_util.cpp @@ -15,14 +15,14 @@ #include "gt_extractor_util.h" -#include +#include +#include #include "appexecfwk_errors.h" #include "bundle_common.h" #include "bundle_util.h" #include "bundlems_log.h" #include "dirent.h" #include "fcntl.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #include "utils.h" diff --git a/services/bundlemgr_lite/src/zip_file.cpp b/services/bundlemgr_lite/src/zip_file.cpp index ef94529..8e06a13 100755 --- a/services/bundlemgr_lite/src/zip_file.cpp +++ b/services/bundlemgr_lite/src/zip_file.cpp @@ -28,10 +28,10 @@ namespace OHOS { namespace { #define ZIPPOS_ADD_AND_CHECK_OVERFLOW(first, second, sum) \ { \ - if ((second > 0) && (first > (std::numeric_limits::max() - second))) { \ + if (((second) > 0) && ((first) > (std::numeric_limits::max() - (second)))) {\ return false; \ } \ - sum = first + second; \ + (sum) = (first) + (second); \ } constexpr uint32_t MAX_FILE_NAME = 256; diff --git a/utils/bundle_lite/adapter.h b/utils/bundle_lite/adapter.h index 0f53edb..2ecd038 100755 --- a/utils/bundle_lite/adapter.h +++ b/utils/bundle_lite/adapter.h @@ -32,8 +32,8 @@ #define AdapterMalloc(a) malloc(a) #define AdapterFree(a) \ do { \ - if (a != nullptr) { \ - (void) free((void *)a); \ + if ((a) != nullptr) { \ + (void) free((void *)(a)); \ a = nullptr; \ } \ } while (0) -- Gitee From e46b15fe075666caf2d1f9a818da7f2a213acac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=8F=9E=E9=A3=8E?= Date: Thu, 10 Mar 2022 10:01:11 +0000 Subject: [PATCH 2/3] Description:code quality. Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No #I4X9CB; Signed-off-by: wuluofeng --- services/bundlemgr_lite/include/bundle_parser.h | 12 ++++++------ services/bundlemgr_lite/src/zip_file.cpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/services/bundlemgr_lite/include/bundle_parser.h b/services/bundlemgr_lite/include/bundle_parser.h index 4011af8..4c29d58 100755 --- a/services/bundlemgr_lite/include/bundle_parser.h +++ b/services/bundlemgr_lite/include/bundle_parser.h @@ -99,12 +99,12 @@ private: } \ } while (0) -#define FREE_BUNDLE_PROFILE(bundleProfile) \ - do { \ - AdapterFree((bundleProfile).abilityInfos); \ - for (uint8_t i = 0; i < METADATA_SIZE; i++) { \ - AdapterFree((bundleProfile).moduleInfo.metaData[i]);\ - } \ +#define FREE_BUNDLE_PROFILE(bundleProfile) \ + do { \ + AdapterFree((bundleProfile).abilityInfos); \ + for (uint8_t i = 0; i < METADATA_SIZE; i++) { \ + AdapterFree((bundleProfile).moduleInfo.metaData[i]); \ + } \ } while (0) } // namespace OHOS #endif // OHOS_BUNDLE_PARSER_H diff --git a/services/bundlemgr_lite/src/zip_file.cpp b/services/bundlemgr_lite/src/zip_file.cpp index 8e06a13..294518c 100755 --- a/services/bundlemgr_lite/src/zip_file.cpp +++ b/services/bundlemgr_lite/src/zip_file.cpp @@ -26,12 +26,12 @@ namespace OHOS { namespace { -#define ZIPPOS_ADD_AND_CHECK_OVERFLOW(first, second, sum) \ -{ \ - if (((second) > 0) && ((first) > (std::numeric_limits::max() - (second)))) {\ - return false; \ - } \ - (sum) = (first) + (second); \ +#define ZIPPOS_ADD_AND_CHECK_OVERFLOW(first, second, sum) \ +{ \ + if (((second) > 0) && ((first) > (std::numeric_limits::max() - (second)))) { \ + return false; \ + } \ + (sum) = (first) + (second); \ } constexpr uint32_t MAX_FILE_NAME = 256; -- Gitee From 6f17b596807defa14a9730d626053e078c7eff4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=8F=9E=E9=A3=8E?= Date: Tue, 15 Mar 2022 02:02:41 +0000 Subject: [PATCH 3/3] Description:code quality. Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No #I4X9CB; Signed-off-by: wuluofeng --- services/bundlemgr_lite/include/gt_bundle_installer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index c076487..098d386 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -121,7 +121,7 @@ private: FREE_SIGNATUREINFO(signatureInfo); \ UI_Free(permissions.permissionTrans); \ GtManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \ - BundleUtil::DeleteJsonFile((bundleInfo)->bundleName, randStr); \ + BundleUtil::DeleteJsonFile((bundleInfo)->bundleName, randStr); \ CLEAR_INSTALL_ENV(bundleInfo); \ return errcode; \ } \ -- Gitee