From 94efbeae7505692872e3e84e8e53510c6221596e Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Wed, 23 Jun 2021 11:17:15 +0800 Subject: [PATCH 1/7] IssueNo:#I3WWHK Description:Add uninstall state interface. Sig:startup Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia --- .../include/bundlems_slite_client.h | 2 + .../src/slite/bundle_manager_inner.cpp | 5 ++ .../src/slite/bundlems_slite_client.cpp | 8 +++ .../bundlemgr_lite/bundle_service_interface.h | 1 + .../bundlemgr_lite/slite/bundle_install_msg.h | 16 +++++ .../include/bundle_mgr_slite_feature.h | 1 + .../include/gt_bundle_installer.h | 2 - .../include/gt_bundle_manager_service.h | 9 +++ .../src/bundle_mgr_slite_feature.cpp | 6 ++ .../src/gt_bundle_installer.cpp | 1 + .../src/gt_bundle_manager_service.cpp | 66 +++++++++++++++---- 11 files changed, 102 insertions(+), 15 deletions(-) diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 7c8ceb9..8e5d9ec 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -47,6 +47,8 @@ public: bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) const; + bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) const; + private: BundleMsClient() = default; diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index cf3b4a5..853b04e 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -23,4 +23,9 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t { return OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName, installState, installProcess); } + +bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) +{ + return OHOS::BundleMsClient::GetInstance().GetUninstallState(bundleName, uninstallState); +} } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index 6b210ed..60a7185 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -157,4 +157,12 @@ bool BundleMsClient::GetInstallState (const char *bundleName, InstallState *inst } return bmsProxy_->GetInstallState(bundleName, installState, installProcess); } + +bool BundleMsClient::GetUninstallState (const char *bundleName, UninstallState *uninstallState) const +{ + if (!Initialize()) { + return false; + } + return bmsProxy_->GetUninstallState(bundleName, uninstallState); +} } // namespace OHOS diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index 74f516f..271375a 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -50,6 +50,7 @@ struct BmsSliteInterface { uint8_t (*GetBundleInfo)(const char *bundleName, int32_t flags, BundleInfo *bundleInfo); uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len); bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess); + bool (*GetUninstallState)(const char *bundleName, UninstallState *uninstallState); }; #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h index 48dc255..552a04a 100644 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -39,6 +39,12 @@ typedef struct { uint8_t installProcess; } BundleInstallMsg; +typedef enum { + BUNDLE_UNINSTALL_DOING = 0, + BUNDLE_UNINSTALL_OK = 1, + BUNDLE_UNINSTALL_FAIL = 2 +} UninstallState; + /** * @brief Get the install state and install process of the bundle. * @@ -52,6 +58,16 @@ typedef struct { */ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); +/** + * @brief Get the uninstall state and uninstall state of the bundle. + * + * @param bundleName Indicates the name of the bundle. + * @param uninstallState Obtains uninstall state. + * @return Returns success or not. + * + */ +bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); + #ifdef __cplusplus #if __cplusplus } diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index 0955f9e..6bdfe1b 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -36,6 +36,7 @@ public: static uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo); static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len); static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); + static bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); static BundleMgrSliteFeature *GetInstance() { diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index 5d2a7e7..9e3a750 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -16,8 +16,6 @@ #ifndef OHOS_GT_BUNDLE_INSTALLER_H #define OHOS_GT_BUNDLE_INSTALLER_H -#include "generate-bytecode.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 321c080..ff09786 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -49,6 +49,11 @@ typedef enum { BUNDLE_UPDATE, } BundleState; +typedef struct { + char *bundleName; + UninstallState uninstallState; +} BundleUninstallMsg; + class GtManagerService { public: static GtManagerService &GetInstance() @@ -75,7 +80,10 @@ public: void ReduceNumOfThirdBundles(); int32_t ReportInstallCallback(uint8_t errCode, uint8_t installState, uint8_t process, InstallerCallback installerCallback); + int32_t ReportUninstallCallback(uint8_t errCode, char *bundleName, + uint8_t process, InstallerCallback installerCallback); bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); + bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); private: GtManagerService(); @@ -105,6 +113,7 @@ private: BundleMap *bundleMap_; List *bundleResList_; BundleInstallMsg *bundleInstallMsg_; + BundleUninstallMsg *bundleUninstallMsg_; char *jsEngineVer_; uint32_t installedThirdBundleNum_; }; diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 0734c40..4a019ee 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -33,6 +33,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .GetBundleInfo = BundleMgrSliteFeature::GetBundleInfo, .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos, .GetInstallState = BundleMgrSliteFeature::GetInstallState, + .GetUninstallState = BundleMgrSliteFeature::GetUninstallState, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -126,4 +127,9 @@ bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState { return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess); } + +bool BundleMgrSliteFeature::GetUninstallState(const char *bundleName, UninstallState *uninstallState) +{ + return OHOS::GtManagerService::GetInstance().GetUninstallState(bundleName, uninstallState); +} } // namespace OHOS diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 1295121..3815bf3 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -18,6 +18,7 @@ #ifdef __cplusplus extern "C" { +#include "generate-bytecode.h" #endif #ifdef __cplusplus } diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 3948e9a..6f4e0d7 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -25,7 +25,6 @@ #include "cmsis_os2.h" #include "dirent.h" #include "fcntl.h" -#include "generate-bytecode.h" #include "gt_bundle_extractor.h" #include "gt_bundle_parser.h" #include "gt_extractor_util.h" @@ -50,6 +49,7 @@ GtManagerService::GtManagerService() bundleResList_ = new List(); bundleMap_ = BundleMap::GetInstance(); bundleInstallMsg_ = nullptr; + bundleUninstallMsg_ = nullptr; jsEngineVer_ = nullptr; installedThirdBundleNum_ = 0; } @@ -111,9 +111,9 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP uint8_t ret = installer_->Install(path, installerCallback); EnableServiceWdg(); if (ret == 0) { - (void) ReportInstallCallback(ret, 1, BMS_INSTALLATION_COMPLETED, installerCallback); + (void) ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback); } else { - (void) ReportInstallCallback(ret, 2, BMS_INSTALLATION_COMPLETED, installerCallback); + (void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback); } (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); SetCurrentBundle(nullptr); @@ -144,21 +144,31 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins return false; } SetCurrentBundle(innerBundleName); - bundleInstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); - if (bundleInstallMsg_ == nullptr) { + + bundleUninstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleUninstallMsg))); + if (bundleUninstallMsg_ == nullptr) { return false; } - if (memset_s(bundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { - AdapterFree(bundleInstallMsg_); + if (memset_s(bundleUninstallMsg_, sizeof(BundleUninstallMsg), 0, sizeof(BundleUninstallMsg)) != EOK) { + AdapterFree(bundleUninstallMsg_); return false; } - bundleInstallMsg_->bundleName = Utils::Strdup(innerBundleName); - (void) ReportInstallCallback(OPERATION_DOING, 0, BMS_UNINSTALLATION_START, installerCallback); + bundleUninstallMsg_->bundleName = innerBundleName; + bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_DOING; + + (void) ReportUninstallCallback(OPERATION_DOING, innerBundleName, BMS_UNINSTALLATION_START, installerCallback); uint8_t ret = installer_->Uninstall(innerBundleName); - (void) ReportInstallCallback(ret, 0, BMS_INSTALLATION_COMPLETED, installerCallback); - ClearSystemBundleInstallMsg(); + if (ret == 0) { + bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_OK; + } else { + bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_FAIL; + } + (void) ReportUninstallCallback(ret, innerBundleName, BMS_INSTALLATION_COMPLETED, installerCallback); + SetCurrentBundle(nullptr); AdapterFree(innerBundleName); + AdapterFree(bundleUninstallMsg_); + bundleUninstallMsg_ = nullptr; return true; } @@ -170,7 +180,7 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins *installProcess = BMS_INSTALLATION_COMPLETED; return true; } - if (bundleName == bundleInstallMsg_->bundleName) { + if (strcmp(bundleName, bundleInstallMsg_->bundleName) == 0) { *installState = bundleInstallMsg_->installState; *installProcess = bundleInstallMsg_->installProcess; return true; @@ -180,6 +190,21 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins return true; } +bool GtManagerService::GetUninstallState(const char *bundleName, UninstallState *uninstallState) +{ + BundleInfo *uninstalledInfo = bundleMap_->Get(bundleName); + if (uninstalledInfo == nullptr) { + *uninstallState = BUNDLE_UNINSTALL_OK; + return true; + } + if (strcmp(bundleName, bundleUninstallMsg_->bundleName) == 0) { + *uninstallState = bundleUninstallMsg_->uninstallState; + return true; + } + *uninstallState = BUNDLE_UNINSTALL_DOING; + return true; +} + uint8_t GtManagerService::QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo) { if (want->element == nullptr) { @@ -847,11 +872,26 @@ int32_t GtManagerService::ReportInstallCallback(uint8_t errCode, uint8_t install bundleInstallMsg->bundleName = bundleInstallMsg_->bundleName; bundleInstallMsg->smallIconPath = bundleInstallMsg_->smallIconPath; bundleInstallMsg->bigIconPath = bundleInstallMsg_->bigIconPath; - (*installerCallback)(errCode, bundleInstallMsg); return 0; } +int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, char *bundleName, + uint8_t process, InstallerCallback installerCallback) +{ + if (installerCallback == nullptr) { + return -1; + } + BundleInstallMsg *bundleUninstallMsg = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (bundleUninstallMsg == nullptr) { + return -1; + } + bundleUninstallMsg->bundleName = bundleName; + bundleUninstallMsg->installProcess = process; + (*installerCallback)(errCode, bundleUninstallMsg); + return 0; +} + AppInfoList *GtManagerService::APP_InitAllAppInfo() { AppInfoList *list = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList)); -- Gitee From 1d9560b5ef262e3874aaaa2ee14aa913c26c1a79 Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Fri, 2 Jul 2021 15:02:36 +0800 Subject: [PATCH 2/7] IssueNo:#I3O061 Description:Add transform bytecode. Sig:startup Feature or Bugfix:Feature Binary Source:No --- .../bundlemgr_lite/include/gt_bundle_installer.h | 1 + .../bundlemgr_lite/src/gt_bundle_installer.cpp | 9 +++++++-- .../src/gt_bundle_manager_service.cpp | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index 9e3a750..ed558e5 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -19,6 +19,7 @@ #ifdef __cplusplus extern "C" { #endif +#include "generate-bytecode.h" #ifdef __cplusplus } #endif diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 3815bf3..69eeefc 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -18,7 +18,6 @@ #ifdef __cplusplus extern "C" { -#include "generate-bytecode.h" #endif #ifdef __cplusplus } @@ -235,12 +234,12 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra BundleInfo *bundleInfo = nullptr; (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FIRST_FINISHED_PROCESS, installerCallback); uint8_t errorCode = PreCheckBundle(path, fp, signatureInfo, fileSize, bundleStyle); + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SECOND_FINISHED_PROCESS, installerCallback); CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); // parse HarmoyProfile.json, get permissions and bundleInfo errorCode = GtBundleParser::ParseHapProfile(fp, fileSize, permissions, bundleRes, &bundleInfo); CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); SetCurrentBundle(bundleInfo->bundleName); - (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SECOND_FINISHED_PROCESS, installerCallback); // terminate current runing app uint32_t labelId = (bundleRes.abilityRes != nullptr) ? bundleRes.abilityRes->labelId : 0; uint32_t iconId = (bundleRes.abilityRes != nullptr) ? bundleRes.abilityRes->iconId : 0; @@ -471,6 +470,12 @@ uint8_t GtBundleInstaller::TransformJsToBc(const char *codePath, InstallRecord & if (jsPath == nullptr) { return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } + EXECRES result = walk_directory(jsPath); + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] transform js to bc when install, result is %d", result); + if (result != EXCE_ACE_JERRY_EXEC_OK) { + AdapterFree(jsPath); + return ERR_APPEXECFWK_INSTALL_FAILED_TRANSFORM_BC_FILE_ERROR; + } AdapterFree(jsPath); #ifdef BC_TRANS_ENABLE record.transformResult = 0; diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 6f4e0d7..6c655ca 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -28,6 +28,7 @@ #include "gt_bundle_extractor.h" #include "gt_bundle_parser.h" #include "gt_extractor_util.h" +#include "jerryscript_adapter.h" #include "los_tick.h" #include "stdio.h" #include "sys/stat.h" @@ -335,6 +336,12 @@ void GtManagerService::ClearSystemBundleInstallMsg() void GtManagerService::ScanPackages() { + JerryBmsPsRamMemInit(); + bms_task_context_init(); + jsEngineVer_ = get_jerry_version_no(); + if (jsEngineVer_ == nullptr) { + HILOG_WARN(HILOG_MODULE_AAFWK, "[BMS] get jsEngine version fail when restart!"); + } if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) { BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END); InstallAllSystemBundle(); @@ -742,6 +749,14 @@ void GtManagerService::TransformJsToBc(const char *codePath, const char *bundleJ return; } + EXECRES result = walk_directory(jsPath); + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] transform js to bc, result is %d", result); + if (result != EXCE_ACE_JERRY_EXEC_OK) { + result = walk_del_bytecode(jsPath); + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] delete byte code, result is %d", result); + AdapterFree(jsPath); + return; + } AdapterFree(jsPath); cJSON *resultObj = cJSON_CreateNumber(0); -- Gitee From efe2371e72b1f1db9285bb2526ce03ae0ccaf75a Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Wed, 7 Jul 2021 16:35:04 +0800 Subject: [PATCH 3/7] IssueNo:#I3ZJ0J Description:Add interface non null judgment Sig:startup Feature or Bugfix:Bugfix Binary Source:No --- .../include/gt_bundle_manager_service.h | 1 - .../src/gt_bundle_manager_service.cpp | 24 +++++++------------ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index ff09786..48b7afc 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -67,7 +67,6 @@ public: uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); void ScanPackages(); - void SendBundleListChangedToLauncher(BundleState state, const char *bundleName); BundleInfo *QueryBundleInfo(const char *bundleName); void RemoveBundleInfo(const char *bundleName); void AddBundleInfo(BundleInfo *info); diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 6c655ca..a0865ff 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -38,7 +38,6 @@ namespace OHOS { const uint8_t PAIR_VALUE = 2; -const uint8_t FINISHED_PROCESS = 100; const uint8_t OPERATION_DOING = 200; const uint8_t BMS_INSTALLATION_START = 101; const uint8_t BMS_UNINSTALLATION_START = 104; @@ -175,12 +174,20 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins bool GtManagerService::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) { + if (bundleName == nullptr) { + retrun false; + } BundleInfo *installedInfo = bundleMap_->Get(bundleName); if (installedInfo != nullptr) { *installState = BUNDLE_INSTALL_OK; *installProcess = BMS_INSTALLATION_COMPLETED; return true; } + if (bundleInstallMsg_ == nullptr) { + *installState = BUNDLE_INSTALL_FAIL; + *installProcess = 0; + return true; + } if (strcmp(bundleName, bundleInstallMsg_->bundleName) == 0) { *installState = bundleInstallMsg_->installState; *installProcess = bundleInstallMsg_->installProcess; @@ -851,21 +858,6 @@ void GtManagerService::ReduceNumOfThirdBundles() installedThirdBundleNum_--; } -void GtManagerService::SendBundleListChangedToLauncher(BundleState state, const char *bundleName) -{ - if (bundleName == nullptr) { - return; - } - char *innerBundleName = reinterpret_cast(SvrMalloc(strlen(bundleName) + 1)); - if (innerBundleName == nullptr) { - return; - } - if (strncpy_s(innerBundleName, strlen(bundleName) + 1, bundleName, strlen(bundleName)) != EOK) { - SvrFree(innerBundleName); - return; - } -} - int32_t GtManagerService::ReportInstallCallback(uint8_t errCode, uint8_t installState, uint8_t process, InstallerCallback installerCallback) { -- Gitee From 6c29916d2e4a610f7007fb2c5afad48658b7f9ae Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Thu, 8 Jul 2021 18:13:45 +0800 Subject: [PATCH 4/7] IssueNo:#I3ZQBA Description:change error Sig:startup Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia --- services/bundlemgr_lite/src/gt_bundle_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index a0865ff..4d9e534 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -175,7 +175,7 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins bool GtManagerService::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) { if (bundleName == nullptr) { - retrun false; + return false; } BundleInfo *installedInfo = bundleMap_->Get(bundleName); if (installedInfo != nullptr) { -- Gitee From e295f5dc9d7b9b82cdf13247b82b9edfecbed90e Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Mon, 19 Jul 2021 20:18:29 +0800 Subject: [PATCH 5/7] IssueNo:#I3XCB5 Description:add get file folder size interface Sig:startup Feature or Bugfix:Feature Binary Source:No Signed-off-by: wangdengjia --- .../include/bundlems_slite_client.h | 2 + .../src/slite/bundle_manager_inner.cpp | 5 ++ .../src/slite/bundlems_slite_client.cpp | 8 ++ .../bundlemgr_lite/bundle_service_interface.h | 1 + .../bundlemgr_lite/slite/bundle_install_msg.h | 9 +++ .../include/bundle_mgr_slite_feature.h | 1 + services/bundlemgr_lite/include/bundle_util.h | 2 + .../include/gt_bundle_extractor.h | 2 +- .../include/gt_bundle_manager_service.h | 1 + .../src/bundle_mgr_slite_feature.cpp | 6 ++ services/bundlemgr_lite/src/bundle_util.cpp | 74 +++++++++++++++++++ .../src/gt_bundle_extractor.cpp | 20 ++--- .../src/gt_bundle_manager_service.cpp | 36 +++++++-- 13 files changed, 151 insertions(+), 16 deletions(-) diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 8e5d9ec..2c92dd4 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -49,6 +49,8 @@ public: bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) const; + uint32_t GetBundleSize(const char *bundleName) const; + private: BundleMsClient() = default; diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index 853b04e..23e0083 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -28,4 +28,9 @@ bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) { return OHOS::BundleMsClient::GetInstance().GetUninstallState(bundleName, uninstallState); } + +uint32_t GetBundleSize(const char *bundleName) +{ + return OHOS::BundleMsClient::GetInstance().GetBundleSize(bundleName); +} } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index 60a7185..e8f0d77 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -165,4 +165,12 @@ bool BundleMsClient::GetUninstallState (const char *bundleName, UninstallState * } return bmsProxy_->GetUninstallState(bundleName, uninstallState); } + +uint32_t BundleMsClient::GetBundleSize (const char *bundleName) const +{ + if (!Initialize()) { + return -1; + } + return bmsProxy_->GetBundleSize(bundleName); +} } // namespace OHOS diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index 271375a..064633e 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -51,6 +51,7 @@ struct BmsSliteInterface { uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len); bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess); bool (*GetUninstallState)(const char *bundleName, UninstallState *uninstallState); + uint32_t (*GetBundleSize)(const char *bundleName); }; #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h index 552a04a..a4f844d 100644 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -68,6 +68,15 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t */ bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); +/** + * @brief Get the bundle size. + * + * @param bundleName Indicates the name of the bundle. + * @return Returns bundle size or returns 0 if get bundle size failed. + * + */ +uint32_t GetBundleSize(const char *bundleName); + #ifdef __cplusplus #if __cplusplus } diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index 6bdfe1b..3008e5b 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -37,6 +37,7 @@ public: static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len); static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); static bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); + static uint32_t GetBundleSize (const char *bundleName); static BundleMgrSliteFeature *GetInstance() { diff --git a/services/bundlemgr_lite/include/bundle_util.h b/services/bundlemgr_lite/include/bundle_util.h index 890c763..4a2e11c 100755 --- a/services/bundlemgr_lite/include/bundle_util.h +++ b/services/bundlemgr_lite/include/bundle_util.h @@ -36,6 +36,8 @@ public: static bool StartWith(const char *str, const char *subStr); static cJSON *GetJsonStream(const char *path); static uint32_t GetFileSize(const char *filePath); + static uint32_t GetFileFolderSize(const char *filePath); + static uint32_t GetCurrentFolderSize(const char *dirPath, List* list); static cJSON *ConvertInstallRecordToJson(const InstallRecord &installRecord); static char *GetValueFromBundleJson(const char *bundleName, const char *key); static int32_t GetValueFromBundleJson(const char *bundleName, const char *key, int32_t defaultValue); diff --git a/services/bundlemgr_lite/include/gt_bundle_extractor.h b/services/bundlemgr_lite/include/gt_bundle_extractor.h index abc321b..037a156 100644 --- a/services/bundlemgr_lite/include/gt_bundle_extractor.h +++ b/services/bundlemgr_lite/include/gt_bundle_extractor.h @@ -26,7 +26,7 @@ public: uint8_t bundleStyle); static char *ExtractHapProfile(int32_t fp, uint32_t totalFileSize); static uint8_t ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName); - static bool ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath, + static uint8_t ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath, char **bigIconPath); private: static uint8_t ExtractFileDataPos(int32_t fp, uint64_t &filePos); diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 48b7afc..8cbecf4 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -83,6 +83,7 @@ public: uint8_t process, InstallerCallback installerCallback); bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); + uint32_t GetBundleSize(const char *bundleName); private: GtManagerService(); diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 4a019ee..2fcbcd5 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -34,6 +34,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos, .GetInstallState = BundleMgrSliteFeature::GetInstallState, .GetUninstallState = BundleMgrSliteFeature::GetUninstallState, + .GetBundleSize = BundleMgrSliteFeature::GetBundleSize, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -132,4 +133,9 @@ bool BundleMgrSliteFeature::GetUninstallState(const char *bundleName, UninstallS { return OHOS::GtManagerService::GetInstance().GetUninstallState(bundleName, uninstallState); } + +uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName) +{ + return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName); +} } // namespace OHOS diff --git a/services/bundlemgr_lite/src/bundle_util.cpp b/services/bundlemgr_lite/src/bundle_util.cpp index 7458161..27813a6 100755 --- a/services/bundlemgr_lite/src/bundle_util.cpp +++ b/services/bundlemgr_lite/src/bundle_util.cpp @@ -182,6 +182,80 @@ uint32_t BundleUtil::GetFileSize(const char *filePath) return fileInfo.st_size; } +uint32_t BundleUtil::GetFileFolderSize(const char *filePath) +{ + if (!CheckRealPath(filePath)) { + return 0; + } + List* list = new (std::nothrow)List(); + if (list == nullptr) { +#ifdef APP_PLATFORM_WATCHGT + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] GetFolderSize failed, list is null"); +#endif + return 0; + } + + list->PushFront(Utils::Strdup(filePath)); + uint32_t fileFolderSize = 0; + while(!list->IsEmpty()) { + char *curPath = list->Front(); + if (curPath == nullptr) { + break; + } + fileFolderSize += GetCurrentFolderSize(curPath, list); + list->PopFront(); + AdapterFree(curPath); + } + + if (!list->IsEmpty()) { +#ifdef APP_PLATFORM_WATCHGT + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] After get folder size, list is still not empty"); +#endif + for (auto node = list->Begin(); node != list->End(); node = node->next_) { + AdapterFree(node->value_); + } + } + delete list; + return fileFolderSize; +} + +uint32_t BundleUtil::GetCurrentFolderSize(const char *dirPath, List* list) +{ + DIR *dir = nullptr; + if ((dir = opendir(dirPath)) == nullptr) { + return 0; + } + dirent *dp = nullptr; + char filePath[PATH_LENGTH] = { 0 }; + struct stat buf = { 0 }; + uint32_t fileSize = 0; + while ((dp = readdir(dir)) != nullptr) { + if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..")) == 0) { + continue; + } + + if (memset_s(filePath, PATH_LENGTH, 0, PATH_LENGTH) != EOK) { + continue; + } + + if (sprintf_s(filePath, PATH_LENGTH, "%s/%s", dirPath, dp->d_name) < 0) { + continue; + } + + if (IsFile(filePath)) { + if (stat(filePath, &buf) != 0 || buf.st_size <= 0) { + fileSize = 0; + break; + } + fileSize += buf.st_size; + } else { + list->PushBack(Utils::Strdup(filePath)); + } + } + closedir(dir); + return fileSize; +} + void BundleUtil::DeleteJsonFile(const char *bundleName, const char *randStr) { if (bundleName == nullptr || randStr == nullptr) { diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index 35280c2..1750d77 100755 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -179,45 +179,45 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32 return true; } -bool GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath, +uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath, char **bigIconPath) { if (!BundleUtil::CheckRealPath(path)) { - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR; } int32_t totalFileSize = APPVERI_GetUnsignedFileLength(path); if (totalFileSize == V_ERR) { - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } char *emptyJsPathComp[] = {const_cast(TMP_RESOURCE_DIR), const_cast(ASSET_JS_PATH)}; char *emptyJsPath = BundleUtil::Strscat(emptyJsPathComp, sizeof(emptyJsPathComp) / sizeof(char *)); if (emptyJsPath == nullptr) { - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } if (!BundleUtil::MkDirs(emptyJsPath)) { AdapterFree(emptyJsPath); - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_CREATE_DATA_DIR_ERROR; } AdapterFree(emptyJsPath); int32_t fp = open(path, O_RDONLY, S_IREAD | S_IWRITE); if (fp < 0) { - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS; } // extractor config.json、 resources dir and resources.index in TMP_RESOURCE_DIR if (!ExtractResourceFile(TMP_RESOURCE_DIR, fp, static_cast(totalFileSize))) { close(fp); - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR; } close(fp); // get bundleName、 label、 smallIconPath and bigIconPath from bundleInfo BundleRes bundleRes = { 0 }; BundleInfo *bundleInfo = GtBundleParser::ParseHapProfile(TMP_RESOURCE_DIR, &bundleRes); if (bundleInfo == nullptr) { - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR; } if (bundleRes.abilityRes != nullptr) { AdapterFree(bundleRes.abilityRes); @@ -228,10 +228,10 @@ bool GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, c *bigIconPath = Utils::Strdup(bundleInfo->bigIconPath); if (*bundleName == nullptr || *label == nullptr || *smallIconPath == nullptr || *bigIconPath == nullptr) { BundleInfoUtils::FreeBundleInfo(bundleInfo); - return false; + return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR; } BundleInfoUtils::FreeBundleInfo(bundleInfo); - return true; + return ERR_OK; } uint8_t GtBundleExtractor::ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName) diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 4d9e534..86f97cc 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -95,20 +95,25 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP return false; } // set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_ - bool isSuccess = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName), + uint8_t ret = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName), &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), &(bundleInstallMsg_->bigIconPath)); - if (!isSuccess) { + + if (ret != 0) { + char *name = strchr(path, '/'); + bundleInstallMsg_->bundleName = Utils::Strdup(name + 1); + (void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback); // delete resource temp dir (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); ClearSystemBundleInstallMsg(); + AdapterFree(path); return false; } SetCurrentBundle(bundleInstallMsg_->bundleName); (void) ReportInstallCallback(OPERATION_DOING, 0, BMS_INSTALLATION_START, installerCallback); DisableServiceWdg(); - uint8_t ret = installer_->Install(path, installerCallback); + ret = installer_->Install(path, installerCallback); EnableServiceWdg(); if (ret == 0) { (void) ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback); @@ -198,6 +203,27 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins return true; } +uint32_t GtManagerService::GetBundleSize(const char *bundleName) +{ + if (bundleName == nullptr) { + return 0; + } + BundleInfo *installedInfo = bundleMap_->Get(bundleName); + if (installedInfo == nullptr) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] failed to get bundle size because the bundle does not exist!"); + return 0; + } + char *codePath = installedInfo->codePath; + uint32_t codeBundleSize = BundleUtil::GetFileFolderSize(codePath); + if (codeBundleSize == 0) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] failed to get code bundle size!"); + return 0; + } + char *dataPath = installedInfo->dataPath; + uint32_t dataBundleSize = BundleUtil::GetFileFolderSize(dataPath); + return codeBundleSize + dataBundleSize; +} + bool GtManagerService::GetUninstallState(const char *bundleName, UninstallState *uninstallState) { BundleInfo *uninstalledInfo = bundleMap_->Get(bundleName); @@ -290,10 +316,10 @@ void GtManagerService::InstallSystemBundle(const char *systemAppPath) return; } // set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_ - bool ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(bundleInstallMsg_->bundleName), + uint8_t ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(bundleInstallMsg_->bundleName), &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), &(bundleInstallMsg_->bigIconPath)); - if (!ret) { + if (ret != 0) { // delete resource temp dir (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); ClearSystemBundleInstallMsg(); -- Gitee From 00b975ead98ecf86133fe56546b564233e25216a Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Tue, 27 Jul 2021 20:22:47 +0800 Subject: [PATCH 6/7] IssueNo:#I42NRY Description:add bms permissions code Sig:startup Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia --- services/bundlemgr_lite/src/gt_bundle_installer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 69eeefc..05e5de3 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -234,8 +234,8 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra BundleInfo *bundleInfo = nullptr; (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FIRST_FINISHED_PROCESS, installerCallback); uint8_t errorCode = PreCheckBundle(path, fp, signatureInfo, fileSize, bundleStyle); - (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SECOND_FINISHED_PROCESS, installerCallback); CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SECOND_FINISHED_PROCESS, installerCallback); // parse HarmoyProfile.json, get permissions and bundleInfo errorCode = GtBundleParser::ParseHapProfile(fp, fileSize, permissions, bundleRes, &bundleInfo); CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); @@ -285,6 +285,11 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra errorCode = MoveRawFileToDataPath(bundleInfo); CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FIFTH_FINISHED_PROCESS, installerCallback); + // store permissions + errorCode = StorePermissions(installRecord.bundleName, permissions.permissionTrans, permissions.permNum, + isUpdate); + CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); + // update bundle Info errorCode = UpdateBundleInfo(bundleStyle, labelId, iconId, bundleInfo, isUpdate); CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); // free memory @@ -572,6 +577,10 @@ uint8_t GtBundleInstaller::Uninstall(const char *bundleName) return ERR_APPEXECFWK_UNINSTALL_FAILED_INTERNAL_ERROR; } + if (DeletePermissions(const_cast(bundleName)) < 0) { + return ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_PERMISSIONS_ERROR; + } + bool res = CheckIsThirdSystemBundle(bundleName); if (!(BundleUtil::RemoveDir(bundleInfo->codePath) && BundleUtil::RemoveDir(bundleInfo->dataPath))) { GtManagerService::GetInstance().RemoveBundleInfo(bundleName); -- Gitee From 48d3cefb77cf48b27a32acc7e38e98b4b49d70bc Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Mon, 9 Aug 2021 11:13:52 +0800 Subject: [PATCH 7/7] IssueNo:#I44HOB Description:change uninstall callback Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia --- .../include/bundlems_slite_client.h | 2 - .../src/slite/bundle_manager_inner.cpp | 5 -- .../src/slite/bundlems_slite_client.cpp | 8 --- .../bundlemgr_lite/bundle_service_interface.h | 1 - .../bundlemgr_lite/slite/bundle_install_msg.h | 21 ++------ .../include/bundle_mgr_slite_feature.h | 1 - .../include/gt_bundle_manager_service.h | 9 +--- .../src/bundle_mgr_slite_feature.cpp | 6 --- .../src/gt_bundle_manager_service.cpp | 52 +++++-------------- 9 files changed, 18 insertions(+), 87 deletions(-) diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 2c92dd4..a96f37d 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -47,8 +47,6 @@ public: bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) const; - bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) const; - uint32_t GetBundleSize(const char *bundleName) const; private: diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index 23e0083..04c4e1b 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -24,11 +24,6 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t return OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName, installState, installProcess); } -bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) -{ - return OHOS::BundleMsClient::GetInstance().GetUninstallState(bundleName, uninstallState); -} - uint32_t GetBundleSize(const char *bundleName) { return OHOS::BundleMsClient::GetInstance().GetBundleSize(bundleName); diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index e8f0d77..ba326bc 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -158,14 +158,6 @@ bool BundleMsClient::GetInstallState (const char *bundleName, InstallState *inst return bmsProxy_->GetInstallState(bundleName, installState, installProcess); } -bool BundleMsClient::GetUninstallState (const char *bundleName, UninstallState *uninstallState) const -{ - if (!Initialize()) { - return false; - } - return bmsProxy_->GetUninstallState(bundleName, uninstallState); -} - uint32_t BundleMsClient::GetBundleSize (const char *bundleName) const { if (!Initialize()) { diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index 064633e..fec629b 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -50,7 +50,6 @@ struct BmsSliteInterface { uint8_t (*GetBundleInfo)(const char *bundleName, int32_t flags, BundleInfo *bundleInfo); uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len); bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess); - bool (*GetUninstallState)(const char *bundleName, UninstallState *uninstallState); uint32_t (*GetBundleSize)(const char *bundleName); }; #ifdef __cplusplus diff --git a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h index a4f844d..77523d5 100644 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -27,7 +27,10 @@ extern "C" { typedef enum { BUNDLE_INSTALL_DOING = 0, BUNDLE_INSTALL_OK = 1, - BUNDLE_INSTALL_FAIL = 2 + BUNDLE_INSTALL_FAIL = 2, + BUNDLE_UNINSTALL_DOING = 3, + BUNDLE_UNINSTALL_OK = 4, + BUNDLE_UNINSTALL_FAIL = 5 } InstallState; typedef struct { @@ -39,12 +42,6 @@ typedef struct { uint8_t installProcess; } BundleInstallMsg; -typedef enum { - BUNDLE_UNINSTALL_DOING = 0, - BUNDLE_UNINSTALL_OK = 1, - BUNDLE_UNINSTALL_FAIL = 2 -} UninstallState; - /** * @brief Get the install state and install process of the bundle. * @@ -58,16 +55,6 @@ typedef enum { */ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); -/** - * @brief Get the uninstall state and uninstall state of the bundle. - * - * @param bundleName Indicates the name of the bundle. - * @param uninstallState Obtains uninstall state. - * @return Returns success or not. - * - */ -bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); - /** * @brief Get the bundle size. * diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index 3008e5b..b81bdf4 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -36,7 +36,6 @@ public: static uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo); static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len); static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); - static bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); static uint32_t GetBundleSize (const char *bundleName); static BundleMgrSliteFeature *GetInstance() diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 8cbecf4..4f0564b 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -49,11 +49,6 @@ typedef enum { BUNDLE_UPDATE, } BundleState; -typedef struct { - char *bundleName; - UninstallState uninstallState; -} BundleUninstallMsg; - class GtManagerService { public: static GtManagerService &GetInstance() @@ -79,10 +74,9 @@ public: void ReduceNumOfThirdBundles(); int32_t ReportInstallCallback(uint8_t errCode, uint8_t installState, uint8_t process, InstallerCallback installerCallback); - int32_t ReportUninstallCallback(uint8_t errCode, char *bundleName, + int32_t ReportUninstallCallback(uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process, InstallerCallback installerCallback); bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); - bool GetUninstallState(const char *bundleName, UninstallState *uninstallState); uint32_t GetBundleSize(const char *bundleName); private: @@ -113,7 +107,6 @@ private: BundleMap *bundleMap_; List *bundleResList_; BundleInstallMsg *bundleInstallMsg_; - BundleUninstallMsg *bundleUninstallMsg_; char *jsEngineVer_; uint32_t installedThirdBundleNum_; }; diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 2fcbcd5..5b12cff 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -33,7 +33,6 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .GetBundleInfo = BundleMgrSliteFeature::GetBundleInfo, .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos, .GetInstallState = BundleMgrSliteFeature::GetInstallState, - .GetUninstallState = BundleMgrSliteFeature::GetUninstallState, .GetBundleSize = BundleMgrSliteFeature::GetBundleSize, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -129,11 +128,6 @@ bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess); } -bool BundleMgrSliteFeature::GetUninstallState(const char *bundleName, UninstallState *uninstallState) -{ - return OHOS::GtManagerService::GetInstance().GetUninstallState(bundleName, uninstallState); -} - uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName) { return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName); diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 86f97cc..3b0a010 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -49,7 +49,6 @@ GtManagerService::GtManagerService() bundleResList_ = new List(); bundleMap_ = BundleMap::GetInstance(); bundleInstallMsg_ = nullptr; - bundleUninstallMsg_ = nullptr; jsEngineVer_ = nullptr; installedThirdBundleNum_ = 0; } @@ -150,30 +149,19 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins } SetCurrentBundle(innerBundleName); - bundleUninstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleUninstallMsg))); - if (bundleUninstallMsg_ == nullptr) { - return false; - } - if (memset_s(bundleUninstallMsg_, sizeof(BundleUninstallMsg), 0, sizeof(BundleUninstallMsg)) != EOK) { - AdapterFree(bundleUninstallMsg_); - return false; - } - bundleUninstallMsg_->bundleName = innerBundleName; - bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_DOING; - - (void) ReportUninstallCallback(OPERATION_DOING, innerBundleName, BMS_UNINSTALLATION_START, installerCallback); + (void) ReportUninstallCallback(OPERATION_DOING, BUNDLE_UNINSTALL_DOING, innerBundleName, + BMS_UNINSTALLATION_START, installerCallback); uint8_t ret = installer_->Uninstall(innerBundleName); if (ret == 0) { - bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_OK; + (void) ReportUninstallCallback(ret, BUNDLE_UNINSTALL_OK, innerBundleName, + BMS_INSTALLATION_COMPLETED, installerCallback); } else { - bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_FAIL; + (void) ReportUninstallCallback(ret, BUNDLE_UNINSTALL_FAIL, innerBundleName, + BMS_INSTALLATION_COMPLETED, installerCallback); } - (void) ReportUninstallCallback(ret, innerBundleName, BMS_INSTALLATION_COMPLETED, installerCallback); SetCurrentBundle(nullptr); AdapterFree(innerBundleName); - AdapterFree(bundleUninstallMsg_); - bundleUninstallMsg_ = nullptr; return true; } @@ -224,21 +212,6 @@ uint32_t GtManagerService::GetBundleSize(const char *bundleName) return codeBundleSize + dataBundleSize; } -bool GtManagerService::GetUninstallState(const char *bundleName, UninstallState *uninstallState) -{ - BundleInfo *uninstalledInfo = bundleMap_->Get(bundleName); - if (uninstalledInfo == nullptr) { - *uninstallState = BUNDLE_UNINSTALL_OK; - return true; - } - if (strcmp(bundleName, bundleUninstallMsg_->bundleName) == 0) { - *uninstallState = bundleUninstallMsg_->uninstallState; - return true; - } - *uninstallState = BUNDLE_UNINSTALL_DOING; - return true; -} - uint8_t GtManagerService::QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo) { if (want->element == nullptr) { @@ -909,19 +882,20 @@ int32_t GtManagerService::ReportInstallCallback(uint8_t errCode, uint8_t install return 0; } -int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, char *bundleName, +int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process, InstallerCallback installerCallback) { if (installerCallback == nullptr) { return -1; } - BundleInstallMsg *bundleUninstallMsg = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); - if (bundleUninstallMsg == nullptr) { + BundleInstallMsg *bundleInstallMsg = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (bundleInstallMsg == nullptr) { return -1; } - bundleUninstallMsg->bundleName = bundleName; - bundleUninstallMsg->installProcess = process; - (*installerCallback)(errCode, bundleUninstallMsg); + bundleInstallMsg->installState = static_cast(installState); + bundleInstallMsg->bundleName = bundleName; + bundleInstallMsg->installProcess = process; + (*installerCallback)(errCode, bundleInstallMsg); return 0; } -- Gitee