diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index a96f37d3d38b3d9ad17df03ae3b679bb529a44c1..4e11f9ec95d168525fc3c886c01d1ad15e4c288a 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -49,6 +49,8 @@ public: uint32_t GetBundleSize(const char *bundleName) const; + bool RegisterInstallerCallback(InstallerCallback installerCallback) 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 04c4e1b0827cf76e1f66b4da4ee1092a6d455f73..4d0f549388737c44c730d8b568f02bfba8c3ce55 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 @@ uint32_t GetBundleSize(const char *bundleName) { return OHOS::BundleMsClient::GetInstance().GetBundleSize(bundleName); } + +bool RegisterInstallerCallback(InstallerCallback installerCallback) +{ + return OHOS::BundleMsClient::GetInstance().RegisterInstallerCallback(installerCallback); +} } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index ba326bc2bc3ad77dd1d9df58ecee398a6cc92a89..94607332464eb3312ccfc968fc40dfd38a7d6a0a 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -126,6 +126,29 @@ bool BundleMsClient::Uninstall (const char *bundleName, const InstallParam *inst return ret == ERR_OK; } +bool BundleMsClient::RegisterInstallerCallback (InstallerCallback installerCallback) const +{ + BundleMgrService *service = BundleMgrService::GetInstance(); + if (service == nullptr) { + return false; + } + if (installerCallback == nullptr) { + return false; + } + if (g_bmsbuff == nullptr) { + g_bmsbuff = reinterpret_cast(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff))); + } + g_bmsbuff->bundleInstallerCallback = installerCallback; + Request request = { + .msgId = BMS_REGISTER_CALLBACK_MSG, + .data = nullptr, + .len = 0, + .msgValue = 0, + }; + int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); + return ret == ERR_OK; +} + uint8_t BundleMsClient::QueryAbilityInfo (const Want *want, AbilityInfo *abilityInfo) const { if (!Initialize()) { diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index fec629bfa11cbc4daef9d6414ca084cf1599bda1..537a014a584e3b9e85a44a94dab02d26f1b8e4ec 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); uint32_t (*GetBundleSize)(const char *bundleName); + bool (*RegisterInstallerCallback)(InstallerCallback installerCallback); }; #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 77523d537267542afb783e07fc9514465f0aba6a..48c9e486191ee62f137f2ccfd1c353bda8b7e555 100644 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -18,6 +18,8 @@ #include +#include "bundle_manager.h" + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -64,6 +66,15 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t */ uint32_t GetBundleSize(const char *bundleName); +/** + * @brief Register installer callback. + * + * @param installerCallback Indicates the installer callback. + * @return Returns success or failure. + * + */ +bool RegisterInstallerCallback(InstallerCallback installerCallback); + #ifdef __cplusplus #if __cplusplus } diff --git a/services/bundlemgr_lite/include/bundle_mgr_service.h b/services/bundlemgr_lite/include/bundle_mgr_service.h index e25e70ac538bcd1cce321b4fea8df5354cd97ea1..7bbcc5a8e2f4fbc965b34de6ed67d6ebaadbab4a 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_service.h +++ b/services/bundlemgr_lite/include/bundle_mgr_service.h @@ -24,6 +24,7 @@ namespace OHOS { const unsigned int BMS_INSTALL_MSG = 100; const unsigned int BMS_UNINSTALL_MSG = 101; const unsigned int BMS_SCAN_PACKAGE_MSG = 102; +const unsigned int BMS_REGISTER_CALLBACK_MSG = 103; class BundleMgrService : public Service { public: diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index b81bdf48025f42bc005e1ed61535f4deaf843b91..51f7c464f543e9a8b2f9223a5db83875df4b2dcf 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 uint32_t GetBundleSize (const char *bundleName); + static bool RegisterInstallerCallback(InstallerCallback installerCallback); 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 4f0564bcce48a2c954372bf0d5449f7e255ab702..07912931de1f63e81fc39fd3dd2c4d0872b1c8c2 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -78,14 +78,14 @@ public: uint8_t process, InstallerCallback installerCallback); bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); uint32_t GetBundleSize(const char *bundleName); + bool RegisterInstallerCallback(InstallerCallback installerCallback); private: GtManagerService(); ~GtManagerService(); void ScanSystemApp(const cJSON *uninstallRecord, List *systemPathList); void ScanThirdApp(const char *appDir, const List *systemPathList); - void InstallAllSystemBundle(); - void InstallSystemBundle(const char *systemAppPath); + void InstallAllSystemBundle(InstallerCallback installerCallback); bool ReloadBundleInfo(const char *profileDir, const char *appId, bool isSystemApp); void ReloadEntireBundleInfo(const char *appPath, const char *bundleName, List *systemPathList, int32_t versionCode, uint8_t scanFlag); @@ -102,6 +102,7 @@ private: void APP_QueryAppInfo(const char *appDir, AppInfoList *list); void APP_InsertAppInfo(char *filePath, AppInfoList *list); void APP_FreeAllAppInfo(const AppInfoList *list); + void InstallPreBundle(List systemPathList, InstallerCallback installerCallback); GtBundleInstaller *installer_; BundleMap *bundleMap_; @@ -109,6 +110,7 @@ private: BundleInstallMsg *bundleInstallMsg_; char *jsEngineVer_; uint32_t installedThirdBundleNum_; + List systemPathList_; }; } diff --git a/services/bundlemgr_lite/src/bundle_mgr_service.cpp b/services/bundlemgr_lite/src/bundle_mgr_service.cpp index cbad14ab29121f57db26b4bbff5f1bfdfd9a67df..d58b112d7ce0e4cce6687e33c89d09ef77f64e24 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_service.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_service.cpp @@ -84,6 +84,8 @@ BOOL BundleMgrService::ServiceMessageHandle(Service *service, Request *request) g_bmsbuff->bundleInstallerCallback); } else if (request->msgId == BMS_SCAN_PACKAGE_MSG) { OHOS::GtManagerService::GetInstance().ScanPackages(); + } else if (request->msgId == BMS_REGISTER_CALLBACK_MSG) { + OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(g_bmsbuff->bundleInstallerCallback); } else { return FALSE; } diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 5b12cff9841c1b5405284a983fd7aaaf9596f714..10873b9d72680042d279c338b283700745e5c828 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, .GetBundleSize = BundleMgrSliteFeature::GetBundleSize, + .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -132,4 +133,9 @@ uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName) { return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName); } + +bool BundleMgrSliteFeature::RegisterInstallerCallback(InstallerCallback installerCallback) +{ + return OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(installerCallback); +} } // namespace OHOS diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 3b0a010aab88c714fcbad42c867ade67415f778b..9375e09a40b7d2e4a7789f78c8a27c2f47d2d7ea 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -37,7 +37,6 @@ #include "want.h" namespace OHOS { -const uint8_t PAIR_VALUE = 2; const uint8_t OPERATION_DOING = 200; const uint8_t BMS_INSTALLATION_START = 101; const uint8_t BMS_UNINSTALLATION_START = 104; @@ -102,9 +101,8 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP 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(); + (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); AdapterFree(path); return false; } @@ -119,9 +117,9 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP } else { (void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback); } - (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); SetCurrentBundle(nullptr); ClearSystemBundleInstallMsg(); + (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); AdapterFree(path); return true; } @@ -247,7 +245,39 @@ uint8_t GtManagerService::GetBundleInfos(const int flags, BundleInfo **bundleInf return bundleMap_->GetBundleInfos(flags, bundleInfos, len); } -void GtManagerService::InstallAllSystemBundle() +bool GtManagerService::RegisterInstallerCallback(InstallerCallback installerCallback) +{ + if (installerCallback == nullptr) { + return false; + } + InstallPreBundle(systemPathList_, installerCallback); + return true; +} + +void GtManagerService::InstallPreBundle(List systemPathList, InstallerCallback installerCallback) +{ + if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) { + BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END); + InstallAllSystemBundle(installerCallback); + RemoveSystemAppPathList(&systemPathList); + return; + } + for (auto node = systemPathList.Begin(); node != systemPathList.End(); node = node->next_) { + ToBeInstalledApp *toBeInstalledApp = node->value_; + if (toBeInstalledApp->isUpdated) { + (void) ReloadBundleInfo(toBeInstalledApp->installedPath, toBeInstalledApp->appId, + toBeInstalledApp->isSystemApp); + } + if (!BundleUtil::IsFile(toBeInstalledApp->path) || + !BundleUtil::EndWith(toBeInstalledApp->path, INSTALL_FILE_SUFFIX)) { + return; + } + (void) Install(toBeInstalledApp->path, nullptr, installerCallback); + } + RemoveSystemAppPathList(&systemPathList); +} + +void GtManagerService::InstallAllSystemBundle(InstallerCallback installerCallback) { AppInfoList *list = GtManagerService::APP_InitAllAppInfo(); if (list == nullptr) { @@ -262,52 +292,14 @@ void GtManagerService::InstallAllSystemBundle() (strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) { continue; } - InstallSystemBundle(((AppInfoList *)currentNode)->filePath); - } - GtManagerService::APP_FreeAllAppInfo(list); -} - -void GtManagerService::InstallSystemBundle(const char *systemAppPath) -{ - if (installer_ == nullptr) { - return; - } - if (!BundleUtil::IsFile(systemAppPath) || !BundleUtil::EndWith(systemAppPath, INSTALL_FILE_SUFFIX)) { - return; - } - - // delete resource temp dir first - (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); - // create new bundleInstallMsg - bundleInstallMsg_ = reinterpret_cast(AdapterMalloc(sizeof(BundleInstallMsg))); - if (bundleInstallMsg_ == nullptr) { - return; - } - if (memset_s(bundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) { - AdapterFree(bundleInstallMsg_); - return; - } - // set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_ - uint8_t ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(bundleInstallMsg_->bundleName), - &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), - &(bundleInstallMsg_->bigIconPath)); - if (ret != 0) { - // delete resource temp dir - (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); - ClearSystemBundleInstallMsg(); - return; + if (!BundleUtil::IsFile(((AppInfoList *)currentNode)->filePath) || + !BundleUtil::EndWith(((AppInfoList *)currentNode)->filePath, INSTALL_FILE_SUFFIX)) { + return; + } + (void) Install(((AppInfoList *)currentNode)->filePath, nullptr, installerCallback); } - - InstallerCallback installerCallback = nullptr; - DisableServiceWdg(); - uint8_t result = installer_->Install(systemAppPath, installerCallback); - EnableServiceWdg(); - SetCurrentBundle(nullptr); - HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install system result is %d", result); - // delete resource temp dir - ClearSystemBundleInstallMsg(); - (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); + GtManagerService::APP_FreeAllAppInfo(list); } void GtManagerService::ClearSystemBundleInstallMsg() @@ -348,11 +340,6 @@ void GtManagerService::ScanPackages() 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(); - return; - } // get third system bundle uninstall record cJSON *uninstallRecord = BundleUtil::GetJsonStream(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); @@ -360,24 +347,14 @@ void GtManagerService::ScanPackages() (void) unlink(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); } - List systemPathList; // scan system apps and third system apps - ScanSystemApp(uninstallRecord, &systemPathList); + ScanSystemApp(uninstallRecord, &systemPathList_); if (uninstallRecord != nullptr) { cJSON_Delete(uninstallRecord); } + // scan third apps - ScanThirdApp(INSTALL_PATH, &systemPathList); - // install new system app or app which is to be updated - for (auto node = systemPathList.Begin(); node != systemPathList.End(); node = node->next_) { - ToBeInstalledApp *toBeInstalledApp = node->value_; - if (toBeInstalledApp->isUpdated) { - (void) ReloadBundleInfo(toBeInstalledApp->installedPath, toBeInstalledApp->appId, - toBeInstalledApp->isSystemApp); - } - InstallSystemBundle(toBeInstalledApp->path); - } - RemoveSystemAppPathList(&systemPathList); + ScanThirdApp(INSTALL_PATH, &systemPathList_); } void GtManagerService::RemoveSystemAppPathList(List *systemPathList) @@ -893,7 +870,7 @@ int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, uint8_t insta return -1; } bundleInstallMsg->installState = static_cast(installState); - bundleInstallMsg->bundleName = bundleName; + bundleInstallMsg->bundleName = Utils::Strdup(bundleName); bundleInstallMsg->installProcess = process; (*installerCallback)(errCode, bundleInstallMsg); return 0;