From 55498b3664727275d78dd03523002283b9335bd6 Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Tue, 8 Jun 2021 17:44:13 +0800 Subject: [PATCH] IssueNo:#I3TGYE Description:Add function Sig:startup Feature or Bugfix:Bugfix Binary Source:No --- .../include/bundlems_slite_client.h | 5 +- .../src/slite/bundle_manager_inner.cpp | 5 +- .../src/slite/bundlems_slite_client.cpp | 6 +- .../bundlemgr_lite/bundle_service_interface.h | 3 +- .../bundlemgr_lite/slite/bundle_install_msg.h | 116 ++++++----- .../slite/bundle_manager_inner.h | 24 --- .../include/bundle_mgr_slite_feature.h | 2 +- .../include/gt_bundle_installer.h | 7 +- .../include/gt_bundle_manager_service.h | 16 +- .../src/bundle_mgr_slite_feature.cpp | 5 +- .../src/gt_bundle_extractor.cpp | 1 - .../src/gt_bundle_installer.cpp | 57 +++--- .../src/gt_bundle_manager_service.cpp | 191 +++++++++++------- utils/bundle_lite/adapter.h | 6 +- 14 files changed, 242 insertions(+), 202 deletions(-) rename services/bundlemgr_lite/include/bundle_app_info.h => interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h (64%) mode change 100755 => 100644 diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 559b956..7c8ceb9 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -19,6 +19,7 @@ #include "iproxy_client.h" #include "nocopyable.h" #include "want.h" +#include "bundle_install_msg.h" #include "bundle_service_interface.h" namespace OHOS { @@ -44,7 +45,7 @@ public: uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; - int8_t GetInstallState(const char *bundleName) const; + bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) const; private: BundleMsClient() = default; @@ -55,4 +56,4 @@ private: }; } // namespace OHOS -#endif // OHOS_BUNDLEMS_SLITE_CLIENT_H +#endif // OHOS_BUNDLEMS_SLITE_CLIENT_H \ No newline at end of file diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index a9e01bb..cf3b4a5 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -15,11 +15,12 @@ #include "bundle_manager_inner.h" +#include "bundle_install_msg.h" #include "bundlems_slite_client.h" extern "C" { -int GetInstallState(const char *bundleName) +bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) { - return OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName); + return OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName, installState, installProcess); } } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index 9fd6d3a..6b210ed 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -150,11 +150,11 @@ uint8_t BundleMsClient::GetBundleInfos (int32_t flags, BundleInfo **bundleInfos, return bmsProxy_->GetBundleInfos(flags, bundleInfos, len); } -int8_t BundleMsClient::GetInstallState (const char *bundleName) const +bool BundleMsClient::GetInstallState (const char *bundleName, InstallState *installState, uint8_t *installProcess) const { if (!Initialize()) { - return -1; + return false; } - return bmsProxy_->GetInstallState(bundleName); + return bmsProxy_->GetInstallState(bundleName, installState, installProcess); } } // namespace OHOS diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index b56facc..74f516f 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -22,6 +22,7 @@ #include "install_param.h" #include "bundle_manager.h" #include "bundle_info.h" +#include "bundle_install_msg.h" #ifdef __cplusplus #if __cplusplus @@ -48,7 +49,7 @@ struct BmsSliteInterface { uint8_t (*QueryAbilityInfo)(const Want *want, AbilityInfo *abilityInfo); uint8_t (*GetBundleInfo)(const char *bundleName, int32_t flags, BundleInfo *bundleInfo); uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len); - int8_t (*GetInstallState)(const char *bundleName); + bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess); }; #ifdef __cplusplus #if __cplusplus diff --git a/services/bundlemgr_lite/include/bundle_app_info.h b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h old mode 100755 new mode 100644 similarity index 64% rename from services/bundlemgr_lite/include/bundle_app_info.h rename to interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h index ad8027d..48dc255 --- a/services/bundlemgr_lite/include/bundle_app_info.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -1,55 +1,61 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BUNDLE_APP_INFO_H -#define BUNDLE_APP_INFO_H - -#include "ohos_types.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -typedef enum { - BUNDLE_INSTALL_DOING = 0, - BUNDLE_INSTALL_OK = 1, - BUNDLE_INSTALL_FAIL = 2 -} InstallState; - -/* update bundle state to UI task */ -typedef enum { - BUNDLE_INSTALL, - BUNDLE_UNINSTALL, - BUNDLE_UPDATE, -} BundleState; - -typedef struct { - char *bundleName; - char *label; - char *smallIconPath; - char *bigIconPath; - InstallState installState; - uint8 installProcess; -} BundleInstallMsg; - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* BUNDLE_APP_INFO_H */ \ No newline at end of file +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_BUNDLE_INSTALL_MSG_H +#define OHOS_BUNDLE_INSTALL_MSG_H + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +typedef enum { + BUNDLE_INSTALL_DOING = 0, + BUNDLE_INSTALL_OK = 1, + BUNDLE_INSTALL_FAIL = 2 +} InstallState; + +typedef struct { + char *bundleName; + char *label; + char *smallIconPath; + char *bigIconPath; + InstallState installState; + uint8_t installProcess; +} BundleInstallMsg; + +/** + * @brief Get the install state and install process of the bundle. + * + * @param bundleName Indicates the name of the bundle. + * @param installState Obtains install state. + * @param installProcess Obtains install process. + * @return Returns success or not. + * + * @since 4.0 + * @version 4.0 + */ +bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ +#endif /* OHOS_BUNDLE_INSTALL_MSG_H */ +/** @} */ \ No newline at end of file diff --git a/interfaces/innerkits/bundlemgr_lite/slite/bundle_manager_inner.h b/interfaces/innerkits/bundlemgr_lite/slite/bundle_manager_inner.h index 7aa47e8..05975a5 100755 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_manager_inner.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_manager_inner.h @@ -25,30 +25,6 @@ extern "C" { #endif #endif /* __cplusplus */ -typedef enum { - BMS_NOT_INSTALLED = -1, - BMS_FIRST_FINISHED_PROCESS = 55, - BMS_THIRD_FINISHED_PROCESS = 90, - BMS_FOUR_FINISHED_PROCESS = 95, - BMS_INSTALLATION_COMPLETED = 100 -} InstallStateLabel; - -typedef struct { - InstallStateLabel installStateLabel; - char *bundleName; -} InstallationProgress; - -/** - * @brief Get the install state of the bundle. - * - * @param bundleName Indicates the name of the bundle. - * @return Returns the install state of the bundle. - * - * @since 4.0 - * @version 4.0 - */ -int GetInstallState(const char *bundleName); - /** * @brief Install a simulated bundle for the native ability . * diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index a2af158..0955f9e 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -35,7 +35,7 @@ public: static uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); 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 int8_t GetInstallState(const char *bundleName); + static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); static BundleMgrSliteFeature *GetInstance() { diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index 2e0c1da..5d2a7e7 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -28,6 +28,7 @@ extern "C" { #include "bundle_common.h" #include "bundle_info.h" #include "bundle_info_utils.h" +#include "bundle_manager.h" #include "bundle_manager_inner.h" #include "stdint.h" @@ -37,14 +38,13 @@ public: GtBundleInstaller() = default; ~GtBundleInstaller() = default; - uint8_t Install(const char *path, char* &resultBundleName); + uint8_t Install(const char *path, InstallerCallback installerCallback); uint8_t Uninstall(const char *bundleName); - int8_t getInstallationProgress(const char *bundleName); private: uint8_t PreCheckBundle(const char *path, int32_t &fp, SignatureInfo &signatureInfo, uint32_t &fileSize, uint8_t bundleStyle); uint8_t ProcessBundleInstall(const char *path, const char *randStr, InstallRecord &installRecord, - uint8_t bundleStyle); + uint8_t bundleStyle, InstallerCallback installerCallback); uint8_t HandleFileAndBackUpRecord(const InstallRecord &record, const char *tmpPath, const char *randStr, const char *dataPath, bool isUpdate); uint8_t UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelId, uint32_t iconId, BundleInfo *bundleInfo, @@ -68,7 +68,6 @@ private: uint8_t MoveRawFileToDataPath(const BundleInfo *bundleInfo); uint8_t TransformJsToBc(const char *codePath, InstallRecord &record); - InstallationProgress installationProgress_; }; #define FREE_PRO_RESOURCE(fp, permissions, bundleInfo) \ diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 8a607fe..321c080 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -17,7 +17,6 @@ #define OHOS_GT_BUNDLE_MANAGER_SERVICE_H #include "adapter.h" -#include "bundle_app_info.h" #include "bundle_info.h" #include "bundle_map.h" #include "cJSON.h" @@ -25,6 +24,7 @@ #include "stdint.h" #include "want.h" #include "install_param.h" +#include "bundle_install_msg.h" #include "bundle_manager.h" #include "los_list.h" #include "ohos_types.h" @@ -43,6 +43,12 @@ struct AppInfoList { char filePath[MAX_APP_FILE_PATH_LEN]; }; +typedef enum { + BUNDLE_INSTALL, + BUNDLE_UNINSTALL, + BUNDLE_UPDATE, +} BundleState; + class GtManagerService { public: static GtManagerService &GetInstance() @@ -67,7 +73,9 @@ public: void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process); void AddNumOfThirdBundles(); void ReduceNumOfThirdBundles(); - int8_t GetInstallState(const char *bundleName) const; + int32_t ReportInstallCallback(uint8_t errCode, uint8_t installState, + uint8_t process, InstallerCallback installerCallback); + bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); private: GtManagerService(); @@ -96,7 +104,7 @@ private: GtBundleInstaller *installer_; BundleMap *bundleMap_; List *bundleResList_; - BundleInstallMsg *systemBundleInstallMsg_; + BundleInstallMsg *bundleInstallMsg_; char *jsEngineVer_; uint32_t installedThirdBundleNum_; }; @@ -105,6 +113,8 @@ private: extern "C" { void EnableServiceWdg(void); void DisableServiceWdg(void); +void SetCurrentBundle(const char *name); +const char *GetCurrentBundle(); } #endif // OHOS_GT_BUNDLE_MANAGER_SERVICE_H \ No newline at end of file diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index db24e15..0734c40 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -32,6 +32,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .QueryAbilityInfo = BundleMgrSliteFeature::QueryAbilityInfo, .GetBundleInfo = BundleMgrSliteFeature::GetBundleInfo, .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos, + .GetInstallState = BundleMgrSliteFeature::GetInstallState, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -121,8 +122,8 @@ uint8_t BundleMgrSliteFeature::GetBundleInfos(const int flags, BundleInfo **bund return OHOS::GtManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len); } -int8_t BundleMgrSliteFeature::GetInstallState(const char *bundleName) +bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) { - return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName); + return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess); } } // namespace OHOS diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index 53dc004..35280c2 100755 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -24,7 +24,6 @@ extern "C" { #endif #include "adapter.h" #include "appexecfwk_errors.h" -#include "bundle_app_info.h" #include "bundle_util.h" #include "bundlems_log.h" #include "fcntl.h" diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 88beac1..b42584d 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -23,7 +23,6 @@ extern "C" { } #endif #include "appexecfwk_errors.h" -#include "bundle_app_info.h" #include "bundle_util.h" #include "bundlems_log.h" #include "dirent.h" @@ -39,6 +38,13 @@ extern "C" { namespace OHOS { const char MATCHED_ALL_STR[] = ".*"; +const uint8_t OPERATION_DOING = 200; +const uint8_t BMS_FIRST_FINISHED_PROCESS = 10; +const uint8_t BMS_SECOND_FINISHED_PROCESS = 50; +const uint8_t BMS_THIRD_FINISHED_PROCESS = 60; +const uint8_t BMS_FOURTH_FINISHED_PROCESS = 70; +const uint8_t BMS_FIFTH_FINISHED_PROCESS = 80; +const uint8_t BMS_SIXTH_FINISHED_PROCESS = 90; const uint8_t RADN_NUM = 16; uint8_t GtBundleInstaller::PreCheckBundle(const char *path, int32_t &fp, SignatureInfo &signatureInfo, @@ -157,12 +163,8 @@ uint8_t GtBundleInstaller::SwitchErrorCode(int32_t errorCode) } } -uint8_t GtBundleInstaller::Install(const char *path, char* &resultBundleName) +uint8_t GtBundleInstaller::Install(const char *path, InstallerCallback installerCallback) { - if (installationProgress_.bundleName != nullptr) { - AdapterFree(installationProgress_.bundleName); - installationProgress_.bundleName = nullptr; - } if (path == nullptr) { return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR; } @@ -193,10 +195,11 @@ uint8_t GtBundleInstaller::Install(const char *path, char* &resultBundleName) return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } - uint8_t errorCode = ProcessBundleInstall(path, randStr, installRecord, bundleStyle); + uint8_t errorCode = ProcessBundleInstall(path, randStr, installRecord, bundleStyle, installerCallback); if (errorCode != ERR_OK) { return errorCode; } + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SIXTH_FINISHED_PROCESS, installerCallback); // rename bundle.json if (!RenameJsonFile(installRecord.bundleName, randStr)) { @@ -216,16 +219,8 @@ uint8_t GtBundleInstaller::Install(const char *path, char* &resultBundleName) return ERR_OK; } -int8_t GtBundleInstaller::getInstallationProgress(const char *bundleName) -{ - if (strcmp(installationProgress_.bundleName, bundleName) == 0) { - return installationProgress_.installStateLabel; - } - return BMS_NOT_INSTALLED; -} - uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *randStr, InstallRecord &installRecord, - uint8_t bundleStyle) + uint8_t bundleStyle, InstallerCallback installerCallback) { SignatureInfo signatureInfo; signatureInfo = {.bundleName = nullptr, .appId = nullptr, .restricPermission = nullptr, .restricNum = 0}; @@ -237,14 +232,14 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra .bundleName = nullptr, .moduleDescriptionId = 0, .abilityRes = nullptr, .totalNumOfAbilityRes = 0 }; BundleInfo *bundleInfo = nullptr; - + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FIRST_FINISHED_PROCESS, installerCallback); uint8_t errorCode = PreCheckBundle(path, fp, signatureInfo, fileSize, bundleStyle); 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); - installationProgress_.bundleName = Utils::Strdup(bundleInfo->bundleName); - installationProgress_.installStateLabel = BMS_FIRST_FINISHED_PROCESS; + 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; @@ -268,6 +263,7 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra errorCode = GtBundleExtractor::ExtractHap(tmpCodePath, installRecord.bundleName, fp, fileSize, bundleStyle); close(fp); CHECK_PRO_PART_ROLLBACK(errorCode, tmpCodePath, permissions, bundleInfo, signatureInfo); + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_THIRD_FINISHED_PROCESS, installerCallback); // get js engine version #ifdef BC_TRANS_ENABLE char *jsEngineVersion = get_jerry_version_no(); @@ -278,8 +274,7 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra errorCode = TransformJsToBc(tmpCodePath, installRecord); CHECK_PRO_PART_ROLLBACK(errorCode, tmpCodePath, permissions, bundleInfo, signatureInfo); #endif - - installationProgress_.installStateLabel = BMS_THIRD_FINISHED_PROCESS; + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FOURTH_FINISHED_PROCESS, installerCallback); // rename install path and record install infomation bool isUpdate = GtManagerService::GetInstance().QueryBundleInfo(installRecord.bundleName) != nullptr; errorCode = HandleFileAndBackUpRecord(installRecord, tmpCodePath, randStr, bundleInfo->dataPath, isUpdate); @@ -289,8 +284,9 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra // move rawfile to data path when rawfile is exists errorCode = MoveRawFileToDataPath(bundleInfo); CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); - - installationProgress_.installStateLabel = BMS_FOUR_FINISHED_PROCESS; + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FIFTH_FINISHED_PROCESS, installerCallback); + errorCode = StorePermissions(installRecord.bundleName, permissions.permissionTrans, permissions.permNum, + isUpdate); errorCode = UpdateBundleInfo(bundleStyle, labelId, iconId, bundleInfo, isUpdate); CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); // free memory @@ -508,7 +504,6 @@ uint8_t GtBundleInstaller::UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelI } else { bundleInfo->isSystemApp = false; GtManagerService::GetInstance().AddBundleInfo(bundleInfo); - GtManagerService::GetInstance().SendBundleListChangedToLauncher(BUNDLE_INSTALL, bundleInfo->bundleName); } } else { BundleInfo *oldBundleInfo = GtManagerService::GetInstance().QueryBundleInfo(bundleInfo->bundleName); @@ -520,7 +515,6 @@ uint8_t GtBundleInstaller::UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelI if (!GtManagerService::GetInstance().UpdateBundleInfo(bundleInfo)) { return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } - GtManagerService::GetInstance().SendBundleListChangedToLauncher(BUNDLE_UPDATE, bundleInfo->bundleName); } // update bundle res list return AddBundleResList(bundleInfo->bundleName, labelId, iconId); @@ -574,6 +568,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); @@ -581,7 +579,6 @@ uint8_t GtBundleInstaller::Uninstall(const char *bundleName) if (!res) { GtManagerService::GetInstance().ReduceNumOfThirdBundles(); } - GtManagerService::GetInstance().SendBundleListChangedToLauncher(BUNDLE_UNINSTALL, bundleName); return ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_DIRS_ERROR; } @@ -591,7 +588,6 @@ uint8_t GtBundleInstaller::Uninstall(const char *bundleName) GtManagerService::GetInstance().ReduceNumOfThirdBundles(); } if (unlink(bundleJsonPath) < 0) { - GtManagerService::GetInstance().SendBundleListChangedToLauncher(BUNDLE_UNINSTALL, bundleName); return ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_RECORD_INFO_ERROR; } @@ -599,7 +595,6 @@ uint8_t GtBundleInstaller::Uninstall(const char *bundleName) RecordThirdSystemBundle(bundleName, UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); } - GtManagerService::GetInstance().SendBundleListChangedToLauncher(BUNDLE_UNINSTALL, bundleName); return ERR_OK; } @@ -730,6 +725,7 @@ uint8_t GtBundleInstaller::StorePermissions(const char *bundleName, PermissionTr { if (permNum == 0) { if (isUpdate) { + int32_t ret = DeletePermissions(bundleName); HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] delete permissions, result is %d", ret); } return ERR_OK; @@ -742,6 +738,11 @@ uint8_t GtBundleInstaller::StorePermissions(const char *bundleName, PermissionTr if (!BundleUtil::IsDir(PERMISSIONS_PATH)) { BundleUtil::MkDirs(PERMISSIONS_PATH); } + + if (SaveOrUpdatePermissions(const_cast(bundleName), permissions, permNum, + static_cast(isUpdate)) != 0) { + return ERR_APPEXECFWK_INSTALL_FAILED_STORE_PERMISSIONS_ERROR; + } return ERR_OK; } diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 82d589a..3948e9a 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -18,7 +18,6 @@ #include "ability_info_utils.h" #include "ability_message_id.h" #include "appexecfwk_errors.h" -#include "bundle_app_info.h" #include "bundle_common.h" #include "bundle_message_id.h" #include "bundle_util.h" @@ -41,17 +40,16 @@ namespace OHOS { const uint8_t PAIR_VALUE = 2; const uint8_t FINISHED_PROCESS = 100; const uint8_t OPERATION_DOING = 200; - -static char *g_currentBundle = nullptr; -const int32_t BUNDLENAME_MUTEX_TIMEOUT = 2000; -static osMutexId_t g_currentBundleMutex; +const uint8_t BMS_INSTALLATION_START = 101; +const uint8_t BMS_UNINSTALLATION_START = 104; +const uint8_t BMS_INSTALLATION_COMPLETED = 100; GtManagerService::GtManagerService() { installer_ = new GtBundleInstaller(); bundleResList_ = new List(); bundleMap_ = BundleMap::GetInstance(); - systemBundleInstallMsg_ = nullptr; + bundleInstallMsg_ = nullptr; jsEngineVer_ = nullptr; installedThirdBundleNum_ = 0; } @@ -64,23 +62,6 @@ GtManagerService::~GtManagerService() bundleResList_ = nullptr; } -void SetCurrentBundle(const char *name) -{ - MutexAcquire(&g_currentBundleMutex, BUNDLENAME_MUTEX_TIMEOUT); - AdapterFree(g_currentBundle); - if (name == nullptr) { - MutexRelease(&g_currentBundleMutex); - return; - } - - int len = strlen(name); - g_currentBundle = (char *) AdapterMalloc(len + 1); - if (g_currentBundle == nullptr || strncpy_s(g_currentBundle, len + 1, name, len) < 0) { - AdapterFree(g_currentBundle); - } - MutexRelease(&g_currentBundleMutex); -} - bool GtManagerService::Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback) { @@ -90,6 +71,9 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP if (hapPath == nullptr) { return false; } + if (installerCallback == nullptr) { + return false; + } char *path = reinterpret_cast(AdapterMalloc(strlen(hapPath) + 1)); if (path == nullptr) { return false; @@ -99,24 +83,41 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP return false; } - char *name = strrchr(path, '/'); - if (name == nullptr) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Parsed install path is null"); - AdapterFree(path); + // delete resource temp dir first + (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); + // create new bundleInstallMsg + bundleInstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (bundleInstallMsg_ == nullptr) { + return false; + } + if (memset_s(bundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { + AdapterFree(bundleInstallMsg_); return false; } - char *resultMessage = Utils::Strdup(name); - char *retMessage = Utils::Strdup(name); - if (installerCallback != nullptr) { - (*installerCallback)(OPERATION_DOING, resultMessage + 1); + // set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_ + bool isSuccess = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName), + &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), + &(bundleInstallMsg_->bigIconPath)); + if (!isSuccess) { + // delete resource temp dir + (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); + ClearSystemBundleInstallMsg(); + return false; } - char *resultBundleName = nullptr; + + SetCurrentBundle(bundleInstallMsg_->bundleName); + (void) ReportInstallCallback(OPERATION_DOING, 0, BMS_INSTALLATION_START, installerCallback); DisableServiceWdg(); - uint8_t ret = installer_->Install(path, resultBundleName); + uint8_t ret = installer_->Install(path, installerCallback); EnableServiceWdg(); - if (installerCallback != nullptr) { - (*installerCallback)(ret, retMessage + 1); + if (ret == 0) { + (void) ReportInstallCallback(ret, 1, BMS_INSTALLATION_COMPLETED, installerCallback); + } else { + (void) ReportInstallCallback(ret, 2, BMS_INSTALLATION_COMPLETED, installerCallback); } + (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); + SetCurrentBundle(nullptr); + ClearSystemBundleInstallMsg(); AdapterFree(path); return true; } @@ -131,6 +132,9 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Parsed bundleName to be uninstalled is null"); return false; } + if (installerCallback == nullptr) { + return false; + } char *innerBundleName = reinterpret_cast(AdapterMalloc(strlen(bundleName) + 1)); if (innerBundleName == nullptr) { return false; @@ -139,15 +143,40 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins AdapterFree(innerBundleName); return false; } - char *resultMessage = Utils::Strdup(innerBundleName); - if (installerCallback != nullptr) { - (*installerCallback)(OPERATION_DOING, resultMessage); + SetCurrentBundle(innerBundleName); + bundleInstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (bundleInstallMsg_ == nullptr) { + return false; } - uint8_t bResult = installer_->Uninstall(innerBundleName); - if (installerCallback != nullptr) { - (*installerCallback)(bResult, innerBundleName); + if (memset_s(bundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { + AdapterFree(bundleInstallMsg_); + return false; } + bundleInstallMsg_->bundleName = Utils::Strdup(innerBundleName); + (void) ReportInstallCallback(OPERATION_DOING, 0, BMS_UNINSTALLATION_START, installerCallback); + uint8_t ret = installer_->Uninstall(innerBundleName); + (void) ReportInstallCallback(ret, 0, BMS_INSTALLATION_COMPLETED, installerCallback); + ClearSystemBundleInstallMsg(); SetCurrentBundle(nullptr); + AdapterFree(innerBundleName); + return true; +} + +bool GtManagerService::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) +{ + BundleInfo *installedInfo = bundleMap_->Get(bundleName); + if (installedInfo != nullptr) { + *installState = BUNDLE_INSTALL_OK; + *installProcess = BMS_INSTALLATION_COMPLETED; + return true; + } + if (bundleName == bundleInstallMsg_->bundleName) { + *installState = bundleInstallMsg_->installState; + *installProcess = bundleInstallMsg_->installProcess; + return true; + } + *installState = BUNDLE_INSTALL_FAIL; + *installProcess = 0; return true; } @@ -219,29 +248,29 @@ void GtManagerService::InstallSystemBundle(const char *systemAppPath) // delete resource temp dir first (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); // create new bundleInstallMsg - systemBundleInstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); - if (systemBundleInstallMsg_ == nullptr) { + bundleInstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (bundleInstallMsg_ == nullptr) { return; } - if (memset_s(systemBundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { - AdapterFree(systemBundleInstallMsg_); + if (memset_s(bundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { + AdapterFree(bundleInstallMsg_); return; } - // set bundleName、label、smallIconPath、bigIconPath in systemBundleInstallMsg_ - bool ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(systemBundleInstallMsg_->bundleName), - &(systemBundleInstallMsg_->label), &(systemBundleInstallMsg_->smallIconPath), - &(systemBundleInstallMsg_->bigIconPath)); + // set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_ + bool ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(bundleInstallMsg_->bundleName), + &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), + &(bundleInstallMsg_->bigIconPath)); if (!ret) { // delete resource temp dir (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); ClearSystemBundleInstallMsg(); return; } - char *resultBundleName = nullptr; + + InstallerCallback installerCallback = nullptr; DisableServiceWdg(); - uint8_t result = installer_->Install(systemAppPath, resultBundleName); + uint8_t result = installer_->Install(systemAppPath, installerCallback); EnableServiceWdg(); - AdapterFree(resultBundleName); SetCurrentBundle(nullptr); HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install system result is %d", result); // delete resource temp dir @@ -251,32 +280,32 @@ void GtManagerService::InstallSystemBundle(const char *systemAppPath) void GtManagerService::ClearSystemBundleInstallMsg() { - if (systemBundleInstallMsg_ == nullptr) { + if (bundleInstallMsg_ == nullptr) { return; } - if (systemBundleInstallMsg_->bundleName != nullptr) { - AdapterFree(systemBundleInstallMsg_->bundleName); - systemBundleInstallMsg_->bundleName = nullptr; + if (bundleInstallMsg_->bundleName != nullptr) { + AdapterFree(bundleInstallMsg_->bundleName); + bundleInstallMsg_->bundleName = nullptr; } - if (systemBundleInstallMsg_->label != nullptr) { - AdapterFree(systemBundleInstallMsg_->label); - systemBundleInstallMsg_->label = nullptr; + if (bundleInstallMsg_->label != nullptr) { + AdapterFree(bundleInstallMsg_->label); + bundleInstallMsg_->label = nullptr; } - if (systemBundleInstallMsg_->smallIconPath != nullptr) { - AdapterFree(systemBundleInstallMsg_->smallIconPath); - systemBundleInstallMsg_->smallIconPath = nullptr; + if (bundleInstallMsg_->smallIconPath != nullptr) { + AdapterFree(bundleInstallMsg_->smallIconPath); + bundleInstallMsg_->smallIconPath = nullptr; } - if (systemBundleInstallMsg_->bigIconPath != nullptr) { - AdapterFree(systemBundleInstallMsg_->bigIconPath); - systemBundleInstallMsg_->bigIconPath = nullptr; + if (bundleInstallMsg_->bigIconPath != nullptr) { + AdapterFree(bundleInstallMsg_->bigIconPath); + bundleInstallMsg_->bigIconPath = nullptr; } - AdapterFree(systemBundleInstallMsg_); - systemBundleInstallMsg_ = nullptr; + AdapterFree(bundleInstallMsg_); + bundleInstallMsg_ = nullptr; } void GtManagerService::ScanPackages() @@ -573,7 +602,6 @@ bool GtManagerService::ReloadBundleInfo(const char *profileDir, const char *appI bundleRes->bundleName = bundleInfo->bundleName; AddBundleResList(bundleRes); } - SendBundleListChangedToLauncher(BUNDLE_UPDATE, bundleInfo->bundleName); return true; } AdapterFree(bundleRes->abilityRes); @@ -798,13 +826,30 @@ void GtManagerService::SendBundleListChangedToLauncher(BundleState state, const } } -int8_t GtManagerService::GetInstallState(const char *bundleName) const +int32_t GtManagerService::ReportInstallCallback(uint8_t errCode, uint8_t installState, + uint8_t process, InstallerCallback installerCallback) { - BundleInfo *installedInfo = bundleMap_->Get(bundleName); - if (installedInfo != nullptr) { - return BMS_INSTALLATION_COMPLETED; + if (bundleInstallMsg_ == nullptr) { + return -1; } - return installer_->getInstallationProgress(bundleName); + if (installerCallback == nullptr) { + return -1; + } + BundleInstallMsg *bundleInstallMsg = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); + if (bundleInstallMsg == nullptr) { + return -1; + } + bundleInstallMsg_->installState = static_cast(installState); + bundleInstallMsg_->installProcess = process; + bundleInstallMsg->installState = bundleInstallMsg_->installState; + bundleInstallMsg->installProcess = bundleInstallMsg_->installProcess; + bundleInstallMsg->label = bundleInstallMsg_->label; + bundleInstallMsg->bundleName = bundleInstallMsg_->bundleName; + bundleInstallMsg->smallIconPath = bundleInstallMsg_->smallIconPath; + bundleInstallMsg->bigIconPath = bundleInstallMsg_->bigIconPath; + + (*installerCallback)(errCode, bundleInstallMsg); + return 0; } AppInfoList *GtManagerService::APP_InitAllAppInfo() diff --git a/utils/bundle_lite/adapter.h b/utils/bundle_lite/adapter.h index ac6c370..0f53edb 100755 --- a/utils/bundle_lite/adapter.h +++ b/utils/bundle_lite/adapter.h @@ -79,9 +79,9 @@ const unsigned int RETRY_TIMES = 10; #define APP_ERRCODE_EXTRA(code1, code2) #define APP_EVENT(code1) #define RecordAbiityInfoEvt(code1) -#define MutexDelete(a) -#define MutexAcquire(a, b) -#define MutexRelease(a) +#define MutexDelete(a) osMutexDelete(a) +#define MutexAcquire(a, b) osMutexAcquire(a, b) +#define MutexRelease(a) osMutexRelease(a) #define SvrFree AdapterFree #define SvrMalloc AdapterMalloc -- Gitee