diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md new file mode 100644 index 0000000000000000000000000000000000000000..651e02cef6e623d3385eb4c83d633d73e141cd56 --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE.zh-CN.md @@ -0,0 +1,11 @@ +### 该问题是怎么引起的? + + + +### 重现步骤 + + + +### 报错信息 + + diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100644 index 0000000000000000000000000000000000000000..dd9a0f04c7616fc9722fc857dc6ed6d499b2c201 --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,12 @@ +### 相关的Issue + + +### 原因(目的、解决的问题等) + + +### 描述(做了什么,变更了什么) + + +### 测试用例(新增、改动、可能影响的功能) + + diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 7c8ceb9c481ffff8409d50926250b101e419ea70..8e5d9ecf0bc8931cad6c93c661172b36737d58a3 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 cf3b4a5357ec5390e04b10943cff75e9e8881c01..853b04e503672acdb2eda87ef398e38682944d36 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 6b210ed5645d486933ecfc9183b40ebe0e35b25d..60a7185aa4458a8d773629cecb637dcee4393ea0 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 74f516f62f84dfea6cbac8570ff9402caba6231e..271375a9dfaa4c4fc7c7d997c98e0c9e2cae900e 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 48dc2552afbffc10646564f67079dc4edd7e129c..552a04ad31e991a95f255a8b1ac2f0b6ffea4fcd 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 0955f9e67aa942af111148e950f1b9327c7d3783..6bdfe1b81f88f060fa1bf4549d4fcf8c71af8b00 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 5d2a7e701fc9e78397a470f91197fa7bddf79581..ed558e541c792c9ae8ebaf0372c50a78b7fb5ff5 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -16,11 +16,10 @@ #ifndef OHOS_GT_BUNDLE_INSTALLER_H #define OHOS_GT_BUNDLE_INSTALLER_H -#include "generate-bytecode.h" - #ifdef __cplusplus extern "C" { #endif +#include "generate-bytecode.h" #ifdef __cplusplus } #endif diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 321c080babe74dd48fae8941073c9f94ade7280b..48b7afcc2c529f5703b540a455aca8c35b78a057 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() @@ -62,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); @@ -75,7 +79,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 +112,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 0734c40e8a2aa3fef155dc14f21c57c72204fd26..4a019ee71175d7a389605cbe9775e720b649b7fe 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/bundle_util.cpp b/services/bundlemgr_lite/src/bundle_util.cpp index 745816180b3f29306e264befbd96437a8059a4a2..2afa9fb9658b03d2ac0c3900bab1a9a49c0c3f1a 100755 --- a/services/bundlemgr_lite/src/bundle_util.cpp +++ b/services/bundlemgr_lite/src/bundle_util.cpp @@ -504,6 +504,14 @@ void BundleUtil::CreateRandStr(char *str, uint32_t len) #else srand(LOS_TickCountGet()); #endif + + int fd; + fd = open("/dev/random", O_RDONLY); + if (fd > 0) { + read(fd, &r, sizeof(int)); + } + close(fd); + uint32_t i; for (i = 0; i < len - 1; ++i) { switch ((rand() % NUM_OF_TYPE)) { diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 1295121d88561e49da81d758d7a6a91ab6f9e9cf..69eeefcd9b7d94ebcd3e7dbe29b2ff93c20b3a2d 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -234,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; @@ -470,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 3948e9af11c5d8d112bbb301951d9e8f560da909..4d9e53477c7b7138fb5d0ea3696519ccf682a059 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -25,10 +25,10 @@ #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" +#include "jerryscript_adapter.h" #include "los_tick.h" #include "stdio.h" #include "sys/stat.h" @@ -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; @@ -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,33 +144,51 @@ 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; } bool GtManagerService::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) { + if (bundleName == nullptr) { + return false; + } BundleInfo *installedInfo = bundleMap_->Get(bundleName); if (installedInfo != nullptr) { *installState = BUNDLE_INSTALL_OK; *installProcess = BMS_INSTALLATION_COMPLETED; return true; } - if (bundleName == bundleInstallMsg_->bundleName) { + if (bundleInstallMsg_ == nullptr) { + *installState = BUNDLE_INSTALL_FAIL; + *installProcess = 0; + return true; + } + if (strcmp(bundleName, bundleInstallMsg_->bundleName) == 0) { *installState = bundleInstallMsg_->installState; *installProcess = bundleInstallMsg_->installProcess; return true; @@ -180,6 +198,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) { @@ -310,6 +343,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(); @@ -717,6 +756,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); @@ -811,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) { @@ -847,11 +879,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)); diff --git a/services/bundlemgr_lite/src/gt_bundle_parser.cpp b/services/bundlemgr_lite/src/gt_bundle_parser.cpp index 841118118d0b26dbfc8801547234c2d75d7b1b86..13942c760c7b616dc27523d6e00810e4c8dcc6ee 100755 --- a/services/bundlemgr_lite/src/gt_bundle_parser.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_parser.cpp @@ -312,7 +312,7 @@ bool GtBundleParser::CheckDeviceTypeIsValid(const cJSON *deviceTypeObject) return false; } - const char const *deviceType = GetDeviceType(); + char const *deviceType = GetProductType(); if (deviceType == nullptr) { return false; }