diff --git a/services/bundlemgr_lite/include/bundle_app_info.h b/services/bundlemgr_lite/include/bundle_app_info.h index 0dc83125382a2d8a1d8f3fca40c3e50cbf5fdd1f..ad8027df6918b0ca65dc713bd580b2ff54f3bd48 100755 --- a/services/bundlemgr_lite/include/bundle_app_info.h +++ b/services/bundlemgr_lite/include/bundle_app_info.h @@ -46,13 +46,6 @@ typedef struct { uint8 installProcess; } BundleInstallMsg; -/** - * add for app market - */ -int BundleCallbackFunc(unsigned char operationResult, const char *bundleName, unsigned char errorcode); - -int ReportSystemBundleInstallProcess(unsigned char process, const char *bundleName, unsigned char installState); - #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 99afc09073e31dde47dbd5f8ed13b2de2c2604d2..e25e70ac538bcd1cce321b4fea8df5354cd97ea1 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_service.h +++ b/services/bundlemgr_lite/include/bundle_mgr_service.h @@ -23,6 +23,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; class BundleMgrService : public Service { public: diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index 4abded1d2cf0b0e835cdfc8e62e03115e9866a7f..2e0c1dabf358abee89f884484a0b5be04d4663a9 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -37,7 +37,7 @@ public: GtBundleInstaller() = default; ~GtBundleInstaller() = default; - uint8_t Install(const char *path); + uint8_t Install(const char *path, char* &resultBundleName); uint8_t Uninstall(const char *bundleName); int8_t getInstallationProgress(const char *bundleName); private: diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 65cef81fa4a679b488adb3f6ac15f02461be8277..8a607fee027e853a739d0de14734e0d7e3c29b88 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -30,11 +30,17 @@ #include "ohos_types.h" namespace OHOS { +#define MAX_APP_FILE_PATH_LEN 100 struct ToBeInstalledApp { bool isSystemApp; bool isUpdated; char *path; char *installedPath; + char *appId; +}; +struct AppInfoList { + LOS_DL_LIST appDoubleList; + char filePath[MAX_APP_FILE_PATH_LEN]; }; class GtManagerService { @@ -55,13 +61,9 @@ public: void RemoveBundleInfo(const char *bundleName); void AddBundleInfo(BundleInfo *info); bool UpdateBundleInfo(BundleInfo *info); - char *GetAppIdByBundleName(const char *bundleName); - uint32_t GetVersionCodeByBundlePath(const char *path, unsigned char *versionCode, uint8_t length); uint32_t GetNumOfThirdBundles(); void RemoveBundleResList(const char *bundleName); void AddBundleResList(const BundleRes *bundleRes); - void UpdateBundleInfoList(); - int32_t ReportSystemBundleInstallProcess(uint8_t process, const char *bundleName, uint8_t installState); void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process); void AddNumOfThirdBundles(); void ReduceNumOfThirdBundles(); @@ -80,12 +82,16 @@ private: bool CheckSystemBundleIsValid(const char *appPath, char **bundleName, int32_t &versionCode); bool CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object); void AddSystemAppPathList(const char *installedPath, const char *path, List *systemPathList, - bool isSystemApp, bool isUpdated); + bool isSystemApp, bool isUpdated, const char *appId); void RemoveSystemAppPathList(List *systemPathList); void ClearSystemBundleInstallMsg(); void TransformJsToBcWhenRestart(const char *codePath, const char *bundleName); void TransformJsToBc(const char *codePath, const char *bundleJsonPath, cJSON *installRecordObj); bool IsSystemBundleInstalledPath(const char *appPath, const List *systemPathList); + AppInfoList *APP_InitAllAppInfo(void); + void APP_QueryAppInfo(const char *appDir, AppInfoList *list); + void APP_InsertAppInfo(char *filePath, AppInfoList *list); + void APP_FreeAllAppInfo(const AppInfoList *list); GtBundleInstaller *installer_; BundleMap *bundleMap_; @@ -97,16 +103,6 @@ private: } extern "C" { -#define JS_FILE_PATH_FLASH_LIGHT "system/ace/sys/flashlight.bin" -#define JS_FILE_PATH_HEALTH_ECG "system/ace/sys/health_ecg.bin" -#define MAX_APP_FILE_PATH_LEN 100 -typedef struct { - LOS_DL_LIST appDoubleList; - char filePath[MAX_APP_FILE_PATH_LEN]; -} AppInfoList; - -AppInfoList *APP_InitAllAppInfo(void); -void APP_FreeAllAppInfo(const AppInfoList *list); void EnableServiceWdg(void); void DisableServiceWdg(void); } diff --git a/services/bundlemgr_lite/src/bundle_mgr_service.cpp b/services/bundlemgr_lite/src/bundle_mgr_service.cpp index 5228cfa166ee7eecbc73a067253f258413ae4bfe..c4440fc07c8d8a17b62e36630ab2116944f1682c 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_service.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_service.cpp @@ -40,7 +40,6 @@ static void Init() CHECK_NULLPTR_RETURN(sm, "BundleManagerService", "get samgr error"); BOOL result = sm->RegisterService(BundleMgrService::GetInstance()); PRINTI("BundleManagerService", "bms starts %{public}s", result ? "successfully" : "unsuccessfully"); - OHOS::GtManagerService::GetInstance().ScanPackages(); } SYSEX_SERVICE_INIT(Init); @@ -57,6 +56,13 @@ BOOL BundleMgrService::ServiceInitialize(Service *service, Identity identity) } BundleMgrService *bundleManagerService = static_cast(service); bundleManagerService->identity_ = identity; + Request request = { + .msgId = BMS_SCAN_PACKAGE_MSG, + .data = nullptr, + .len = 0, + .msgValue = 0, + }; + (void) SAMGR_SendRequest(bundleManagerService->GetIdentity(), &request, nullptr); return TRUE; } @@ -67,15 +73,14 @@ Identity *BundleMgrService::GetIdentity() BOOL BundleMgrService::ServiceMessageHandle(Service *service, Request *request) { - if (request == nullptr || g_bmsbuff == nullptr) { - return FALSE; - } if (request->msgId == BMS_INSTALL_MSG) { OHOS::GtManagerService::GetInstance().Install(g_bmsbuff->bundleParameter, nullptr, g_bmsbuff->bundleInstallerCallback); } else if (request->msgId == BMS_UNINSTALL_MSG) { OHOS::GtManagerService::GetInstance().Uninstall(g_bmsbuff->bundleParameter, nullptr, g_bmsbuff->bundleInstallerCallback); + } else if (request->msgId == BMS_SCAN_PACKAGE_MSG) { + OHOS::GtManagerService::GetInstance().ScanPackages(); } return TRUE; } diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 28e756837f69622121bccc69958ef491b1605b6a..53c4ac82377a10051b4b8530b825db76483ff4d5 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -157,8 +157,12 @@ uint8_t GtBundleInstaller::SwitchErrorCode(int32_t errorCode) } } -uint8_t GtBundleInstaller::Install(const char *path) +uint8_t GtBundleInstaller::Install(const char *path, char* &resultBundleName) { + if (installationProgress_.bundleName != nullptr) { + AdapterFree(installationProgress_.bundleName); + installationProgress_.bundleName = nullptr; + } if (path == nullptr) { return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR; } @@ -193,6 +197,8 @@ uint8_t GtBundleInstaller::Install(const char *path) if (errorCode != ERR_OK) { return errorCode; } + resultBundleName = Utils::Strdup(installRecord.bundleName); + // rename bundle.json if (!RenameJsonFile(installRecord.bundleName, randStr)) { BundleInfo *bundleInfo = GtManagerService::GetInstance().QueryBundleInfo(installRecord.bundleName); @@ -238,9 +244,6 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra // parse HarmoyProfile.json, get permissions and bundleInfo errorCode = GtBundleParser::ParseHapProfile(fp, fileSize, permissions, bundleRes, &bundleInfo); CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); - if (installationProgress_.bundleName != nullptr) { - AdapterFree(installationProgress_.bundleName); - } installationProgress_.bundleName = Utils::Strdup(bundleInfo->bundleName); installationProgress_.installStateLabel = BMS_FIRST_FINISHED_PROCESS; // terminate current runing app @@ -284,6 +287,10 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra AdapterFree(tmpCodePath); CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); + // 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; errorCode = UpdateBundleInfo(bundleStyle, labelId, iconId, bundleInfo, isUpdate); CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr); diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index 034f31a1707fb1f834e86a1121deb4736ee23778..03d27ec657215bbca7724d3ddd251e841c3c9a68 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -40,6 +40,7 @@ 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; @@ -83,9 +84,6 @@ void SetCurrentBundle(const char *name) bool GtManagerService::Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback) { - if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) { - BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END); - } if (installer_ == nullptr) { installer_ = new GtBundleInstaller(); } @@ -107,11 +105,16 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP AdapterFree(path); return false; } + char *resultMessage = Utils::Strdup(name); + if (installerCallback != nullptr) { + (*installerCallback)(OPERATION_DOING, resultMessage + 1); + } + char *resultBundleName = nullptr; DisableServiceWdg(); - uint8_t ret = installer_->Install(path); + uint8_t ret = installer_->Install(path, resultBundleName); EnableServiceWdg(); if (installerCallback != nullptr) { - (*installerCallback)(ret, nullptr); + (*installerCallback)(ret, resultBundleName); } AdapterFree(path); return true; @@ -135,12 +138,15 @@ 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); + } uint8_t bResult = installer_->Uninstall(innerBundleName); if (installerCallback != nullptr) { - (*installerCallback)(bResult, nullptr); + (*installerCallback)(bResult, innerBundleName); } SetCurrentBundle(nullptr); - AdapterFree(innerBundleName); return true; } @@ -181,7 +187,7 @@ uint8_t GtManagerService::GetBundleInfos(const int flags, BundleInfo **bundleInf void GtManagerService::InstallAllSystemBundle() { - AppInfoList *list = APP_InitAllAppInfo(); + AppInfoList *list = GtManagerService::APP_InitAllAppInfo(); if (list == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] InstallAllSystemBundle InitAllAppInfo fail, list is nullptr"); return; @@ -196,7 +202,7 @@ void GtManagerService::InstallAllSystemBundle() } InstallSystemBundle(((AppInfoList *)currentNode)->filePath); } - APP_FreeAllAppInfo(list); + GtManagerService::APP_FreeAllAppInfo(list); } void GtManagerService::InstallSystemBundle(const char *systemAppPath) @@ -230,14 +236,13 @@ void GtManagerService::InstallSystemBundle(const char *systemAppPath) ClearSystemBundleInstallMsg(); return; } - uint8_t result = installer_->Install(systemAppPath); + char *resultBundleName = nullptr; + DisableServiceWdg(); + uint8_t result = installer_->Install(systemAppPath, resultBundleName); + EnableServiceWdg(); + AdapterFree(resultBundleName); SetCurrentBundle(nullptr); HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install system result is %d", result); - if (result != ERR_OK) { - ReportSystemBundleInstallProcess(0, nullptr, BUNDLE_INSTALL_FAIL); - } else { - ReportSystemBundleInstallProcess(FINISHED_PROCESS, nullptr, BUNDLE_INSTALL_OK); - } // delete resource temp dir ClearSystemBundleInstallMsg(); (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); @@ -277,6 +282,7 @@ void GtManagerService::ScanPackages() { if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) { BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END); + InstallAllSystemBundle(); return; } @@ -297,6 +303,10 @@ void GtManagerService::ScanPackages() // 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); @@ -312,13 +322,14 @@ void GtManagerService::RemoveSystemAppPathList(List *systemP ToBeInstalledApp *toBeInstalledApp = node->value_; AdapterFree(toBeInstalledApp->installedPath); AdapterFree(toBeInstalledApp->path); + AdapterFree(toBeInstalledApp->appId); UI_Free(toBeInstalledApp); } } void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List *systemPathList) { - AppInfoList *list = APP_InitAllAppInfo(); + AppInfoList *list = GtManagerService::APP_InitAllAppInfo(); if (list == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ScanSystemApp InitAllAppInfo fail, list is nullptr"); return; @@ -363,7 +374,7 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List *systemPathList) @@ -478,13 +489,13 @@ void GtManagerService::ReloadEntireBundleInfo(const char *appPath, const char *b bool isSystemApp = (scanFlag == SYSTEM_APP_FLAG); if (scanFlag != THIRD_APP_FLAG) { if (!res) { - AddSystemAppPathList(nullptr, appPath, systemPathList, isSystemApp, false); + AddSystemAppPathList(nullptr, appPath, systemPathList, isSystemApp, false, appId); AdapterFree(appId); AdapterFree(codePath); return; } if (oldVersionCode < versionCode) { - AddSystemAppPathList(codePath, appPath, systemPathList, isSystemApp, true); + AddSystemAppPathList(codePath, appPath, systemPathList, isSystemApp, true, appId); AdapterFree(appId); AdapterFree(codePath); return; @@ -510,7 +521,7 @@ void GtManagerService::ReloadEntireBundleInfo(const char *appPath, const char *b } void GtManagerService::AddSystemAppPathList(const char *installedPath, const char *path, - List *systemPathList, bool isSystemApp, bool isUpdated) + List *systemPathList, bool isSystemApp, bool isUpdated, const char *appId) { if (path == nullptr || systemPathList == nullptr) { return; @@ -525,6 +536,7 @@ void GtManagerService::AddSystemAppPathList(const char *installedPath, const cha toBeInstalledApp->path = Utils::Strdup(path); toBeInstalledApp->isSystemApp = isSystemApp; toBeInstalledApp->isUpdated = isUpdated; + toBeInstalledApp->appId = Utils::Strdup(appId); systemPathList->PushBack(toBeInstalledApp); } @@ -603,46 +615,6 @@ void GtManagerService::RemoveBundleResList(const char *bundleName) } } -void GtManagerService::UpdateBundleInfoList() -{ - if (bundleResList_ == nullptr) { - return; - } - - for (auto node = bundleResList_->Begin(); node != bundleResList_->End(); node = node->next_) { - BundleRes *res = node->value_; - if (res->bundleName == nullptr || res->abilityRes == nullptr) { - continue; - } - - BundleInfo *bundleInfo = bundleMap_->Get(res->bundleName); - if (bundleInfo == nullptr) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] get no bundleInfo when change bundle res!"); - continue; - } - - int32_t len = strlen(INSTALL_PATH) + 1 + strlen(res->bundleName); - char *path = reinterpret_cast(UI_Malloc(len + 1)); - if (path == nullptr) { - continue; - } - - if (sprintf_s(path, len + 1, "%s/%s", INSTALL_PATH, res->bundleName) < 0) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] change bundle res failed! because sprintf_s fail"); - UI_Free(path); - continue; - } - - uint8_t errorCode = GtBundleParser::ConvertResInfoToBundleInfo(path, res->abilityRes->labelId, - res->abilityRes->iconId, bundleInfo); - UI_Free(path); - if (errorCode != ERR_OK) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] change bundle res failed! errorCode is %d", errorCode); - return; - } - } -} - void GtManagerService::TransformJsToBcWhenRestart(const char *codePath, const char *bundleName) { if (codePath == nullptr) { @@ -795,50 +767,6 @@ bool GtManagerService::UpdateBundleInfo(BundleInfo *info) return bundleMap_->Update(info); } -char *GtManagerService::GetAppIdByBundleName(const char *bundleName) -{ - if (bundleName == nullptr) { - return nullptr; - } - BundleInfo bundleInfo; - if (GetBundleInfo(bundleName, 0, bundleInfo) != ERR_OK) { - return nullptr; - } - return BundleUtil::GetValueFromBundleJson(bundleName, JSON_SUB_KEY_APPID); -} - -uint32_t GtManagerService::GetVersionCodeByBundlePath(const char *path, unsigned char *versionCode, uint8_t length) -{ - if (!BundleUtil::IsFile(path) || versionCode == nullptr || length == 0) { - return 0; - } - - char *bundleName = nullptr; - int32_t code = -1; - if (!GtBundleParser::ParseBundleAttr(path, &bundleName, code)) { - AdapterFree(bundleName); - return 0; - } - AdapterFree(bundleName); - // convert number to char - uint8_t versionCodeLen = 0; - while (code != 0) { - if (versionCodeLen == length - 1) { - return 0; - } - versionCode[versionCodeLen++] = code % MAX_SINGLE_DIGIT_VALUE + ZERO_ASCII_NUM; - code /= MAX_SINGLE_DIGIT_VALUE; - } - versionCode[versionCodeLen] = '\0'; - // pre-post conversion - for (uint8_t j = 0; j < versionCodeLen / PAIR_VALUE; j++) { - versionCode[j] = versionCode[j] + versionCode[versionCodeLen - 1 - j]; - versionCode[versionCodeLen - 1 - j] = versionCode[j] - versionCode[versionCodeLen - 1 - j]; - versionCode[j] = versionCode[j] - versionCode[versionCodeLen - 1 - j]; - } - return versionCodeLen; -} - uint32_t GtManagerService::GetNumOfThirdBundles() { return installedThirdBundleNum_; @@ -869,66 +797,132 @@ void GtManagerService::SendBundleListChangedToLauncher(BundleState state, const } } -int32_t GtManagerService::ReportSystemBundleInstallProcess(uint8_t process, const char *bundleName, - uint8_t installState) +int8_t GtManagerService::GetInstallState(const char *bundleName) const { - if (systemBundleInstallMsg_ == nullptr) { - return -1; + BundleInfo *installedInfo = bundleMap_->Get(bundleName); + if (installedInfo != nullptr) { + return BMS_INSTALLATION_COMPLETED; + } + return installer_->getInstallationProgress(bundleName); +} + +AppInfoList *GtManagerService::APP_InitAllAppInfo() +{ + AppInfoList *list = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList)); + if (list == nullptr) { + return nullptr; } - BundleInstallMsg *bundleInstallMsg = reinterpret_cast(SvrMalloc(sizeof(BundleInstallMsg))); - if (bundleInstallMsg == nullptr) { - return -1; + if (memset_s(list, sizeof(AppInfoList), 0, sizeof(AppInfoList)) != EOK) { + AdapterFree(list); + return nullptr; } - bundleInstallMsg->installState = static_cast(installState); - bundleInstallMsg->installProcess = process; - bundleInstallMsg->label = systemBundleInstallMsg_->label; - bundleInstallMsg->bundleName = systemBundleInstallMsg_->bundleName; - bundleInstallMsg->smallIconPath = systemBundleInstallMsg_->smallIconPath; - bundleInstallMsg->bigIconPath = systemBundleInstallMsg_->bigIconPath; - return 0; + + LOS_ListInit(&list->appDoubleList); + + APP_QueryAppInfo(SYSTEM_BUNDLE_PATH, list); + APP_QueryAppInfo(THIRD_SYSTEM_BUNDLE_PATH, list); + return list; } -void GtManagerService::ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process) +void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list) { - if (bundleName == nullptr) { + struct dirent *ent = nullptr; + if (appDir == nullptr) { return; } - if (bundleStyle == THIRD_APP_FLAG) { - (void) BundleCallbackFunc(process, bundleName, 0); - } else { - (void) ReportSystemBundleInstallProcess(process, bundleName, BUNDLE_INSTALL_DOING); + + DIR *dir = opendir(appDir); + if (dir == nullptr) { + return; } -} + char *fileName = reinterpret_cast(AdapterMalloc(MAX_NAME_LEN + 1)); + while ((ent = readdir(dir)) != nullptr) { + if (memset_s(fileName, MAX_NAME_LEN + 1, 0, MAX_NAME_LEN + 1) != EOK) { + break; + } -int8_t GtManagerService::GetInstallState(const char *bundleName) const -{ - BundleInfo *installedInfo = bundleMap_->Get(bundleName); - if (installedInfo != nullptr) { - return BMS_INSTALLATION_COMPLETED; + if (strcpy_s(fileName, MAX_NAME_LEN + 1, ent->d_name) != 0) { + break; + } + + if ((strcmp(fileName, ".") == 0) || (strcmp(fileName, "..")) == 0) { + continue; + } + + int32_t len = strlen(appDir) + 1 + strlen(fileName) + 1; + char *appPath = reinterpret_cast(AdapterMalloc(len)); + if (appPath == nullptr) { + break; + } + + if (sprintf_s(appPath, len, "%s/%s", appDir, fileName) < 0) { + AdapterFree(appPath); + break; + } + + if (!BundleUtil::IsFile(appPath)) { + AdapterFree(appPath); + continue; + } + + APP_InsertAppInfo(appPath, (AppInfoList *)&list->appDoubleList); + AdapterFree(appPath); } - return installer_->getInstallationProgress(bundleName); + AdapterFree(fileName); } -} // namespace OHOS -extern "C" { -static char *g_currentBundle = nullptr; -const int32_t BUNDLENAME_MUTEX_TIMEOUT = 2000; -static osMutexId_t g_currentBundleMutex; -char *GetAppIdByBundleName(const char *bundleName) +void GtManagerService::APP_InsertAppInfo(char *filePath, AppInfoList *list) { - return OHOS::GtManagerService::GetInstance().GetAppIdByBundleName(bundleName); -} + if ((filePath == nullptr) || (list == nullptr)) { + return; + } -uint32_t GetVersionCodeByBundlePath(const char *path, unsigned char *versionCode, uint8_t length) -{ - return OHOS::GtManagerService::GetInstance().GetVersionCodeByBundlePath(path, versionCode, length); + AppInfoList *app = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList)); + if (app == nullptr) { + return; + } + + if (memset_s(app, sizeof(AppInfoList), 0, sizeof(AppInfoList)) != 0) { + AdapterFree(app); + return; + } + + if (memcpy_s(app->filePath, sizeof(app->filePath), filePath, strnlen(filePath, MAX_APP_FILE_PATH_LEN)) != 0) { + AdapterFree(app); + return; + } + + LOS_ListTailInsert(&list->appDoubleList, &app->appDoubleList); + return; } -void UpdateBundleInfoList() +void GtManagerService::APP_FreeAllAppInfo(const AppInfoList *list) { - OHOS::GtManagerService::GetInstance().UpdateBundleInfoList(); + if (list == nullptr) { + return; + } + + AppInfoList *currentNode = nullptr; + AppInfoList *nextNode = nullptr; + LOS_DL_LIST_FOR_EACH_ENTRY_SAFE (currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) { + if (currentNode != nullptr) { + LOS_ListDelete(&(currentNode->appDoubleList)); + AdapterFree(currentNode); + currentNode = nullptr; + } + } + + if (list != nullptr) { + AdapterFree(list); + } + return; } +} // namespace OHOS +extern "C" { +static char *g_currentBundle = nullptr; +const int32_t BUNDLENAME_MUTEX_TIMEOUT = 2000; +static osMutexId_t g_currentBundleMutex; void SetCurrentBundle(const char *name) { @@ -966,29 +960,4 @@ const char *GetCurrentBundle() MutexRelease(&g_currentBundleMutex); return bundleName; } - -int ReportSystemBundleInstallProcess(unsigned char process, const char *bundleName, unsigned char installState) -{ - return 0; -} - -int BundleCallbackFunc(unsigned char operationResult, const char *bundleName, unsigned char errorcode) -{ - return 0; -} - -void ScanPackages() -{ - OHOS::GtManagerService::GetInstance().ScanPackages(); -} - -AppInfoList *APP_InitAllAppInfo() -{ - return nullptr; -} - -void APP_FreeAllAppInfo(const AppInfoList *list) -{ - return; -} } \ No newline at end of file diff --git a/services/bundlemgr_lite/src/gt_bundle_parser.cpp b/services/bundlemgr_lite/src/gt_bundle_parser.cpp index 1d206cbbd223eb397c10be3edbf1c63a17f3d27e..13942c760c7b616dc27523d6e00810e4c8dcc6ee 100755 --- a/services/bundlemgr_lite/src/gt_bundle_parser.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_parser.cpp @@ -450,14 +450,14 @@ uint8_t GtBundleParser::ConvertResInfoToBundleInfo(const char *path, uint32_t la if (labelId != 0) { char *label = nullptr; if (GLOBAL_GetValueById(labelId, resPath, &label) != 0) { - AdapterFree(label); + Free(label); AdapterFree(resPath); return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_LABEL_RES_ERROR; } // release label memory first AdapterFree(bundleInfo->label); bundleInfo->label = Utils::Strdup(label); - AdapterFree(label); + Free(label); if (bundleInfo->label == nullptr) { AdapterFree(resPath); return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; @@ -496,16 +496,16 @@ bool GtBundleParser::ConvertIconResToBundleInfo(const char *resPath, uint32_t ic }; char *bigIconPath = BundleUtil::Strscat(bigIconPathComp, sizeof(bigIconPathComp) / sizeof(char *)); if (bigIconPath == nullptr) { - AdapterFree(relativeIconPath); + Free(relativeIconPath); return false; } char *smallIconPath = BundleUtil::Strscat(smallIconPathComp, sizeof(smallIconPathComp) / sizeof(char *)); if (smallIconPath == nullptr) { - AdapterFree(relativeIconPath); + Free(relativeIconPath); AdapterFree(bigIconPath); return false; } - AdapterFree(relativeIconPath); + Free(relativeIconPath); if (!BundleUtil::IsFile(bigIconPath) || !BundleUtil::IsFile(smallIconPath)) { AdapterFree(bigIconPath); AdapterFree(smallIconPath); diff --git a/utils/bundle_lite/adapter.h b/utils/bundle_lite/adapter.h index d43f9753fc349ff4dd20e21b73d4243ec384ca58..ac6c370df8efa9b50d5ada9a00c381ba2a849844 100755 --- a/utils/bundle_lite/adapter.h +++ b/utils/bundle_lite/adapter.h @@ -67,6 +67,15 @@ const unsigned int RETRY_TIMES = 10; } \ } while (0) +#define Malloc(a) malloc(a) +#define Free(a) \ + do { \ + if (a != nullptr) { \ + (void) free((void *)a); \ + a = nullptr; \ + } \ + } while (0) + #define APP_ERRCODE_EXTRA(code1, code2) #define APP_EVENT(code1) #define RecordAbiityInfoEvt(code1)