From 071e23e9bc446b635372d53af6bbc35dba66e19b Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Fri, 26 Nov 2021 10:02:48 +0800 Subject: [PATCH] IssueNo:#I4JV8A Description:add insert pre app info list Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia Change-Id: I1df32ba33961c4a63f081f3ac927a51fccc99660 Signed-off-by: wangdengjia --- .../include/bundlems_slite_client.h | 6 + .../src/slite/bundle_manager_inner.cpp | 15 +++ .../src/slite/bundlems_slite_client.cpp | 24 ++++ .../bundlemgr_lite/bundle_service_interface.h | 3 + .../bundlemgr_lite/slite/bundle_install_msg.h | 32 +++++ .../include/bundle_mgr_slite_feature.h | 3 + .../include/gt_bundle_manager_service.h | 16 +-- .../src/bundle_mgr_slite_feature.cpp | 18 +++ .../src/gt_bundle_manager_service.cpp | 119 ++++++++++-------- 9 files changed, 171 insertions(+), 65 deletions(-) diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index c0c0eb8..63ddbc5 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -55,6 +55,12 @@ public: uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) const; + PreAppList *InitPreAppInfo(void) const; + + void InsertPreAppInfo(const char *filePath, PreAppList *list) const; + + void SetPreAppInfo(PreAppList *list) 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 a2fd4c2..cbae834 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -43,4 +43,19 @@ uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, i { return OHOS::BundleMsClient::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); } + +PreAppList *InitPreAppInfo(void) +{ + return OHOS::BundleMsClient::GetInstance().InitPreAppInfo(); +} + +void InsertPreAppInfo(const char *filePath, PreAppList *list) +{ + OHOS::BundleMsClient::GetInstance().InsertPreAppInfo(filePath, list); +} + +void SetPreAppInfo(PreAppList *list) +{ + OHOS::BundleMsClient::GetInstance().SetPreAppInfo(list); +} } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index 667af82..7b6d44b 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -204,4 +204,28 @@ uint8_t BundleMsClient::GetBundleInfosNoReplication (const int flags, BundleInfo } return bmsProxy_->GetBundleInfosNoReplication(flags, bundleInfos, len); } + +PreAppList *BundleMsClient::InitPreAppInfo () const +{ + if (!Initialize()) { + return nullptr; + } + return bmsProxy_->InitPreAppInfo(); +} + +void BundleMsClient::InsertPreAppInfo (const char *filePath, PreAppList *list) const +{ + if (!Initialize()) { + return; + } + bmsProxy_->InsertPreAppInfo(filePath, list); +} + +void BundleMsClient::SetPreAppInfo(PreAppList *list) const +{ + if (!Initialize()) { + return; + } + bmsProxy_->SetPreAppInfo(list); +} } // namespace OHOS diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index f385265..5e632f4 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -54,6 +54,9 @@ struct BmsSliteInterface { bool (*RegisterInstallerCallback)(InstallerCallback installerCallback); void (*UpdateBundleInfoList)(); uint8_t (*GetBundleInfosNoReplication)(const int flags, BundleInfo **bundleInfos, int32_t *len); + PreAppList *(*InitPreAppInfo)(void); + void (*InsertPreAppInfo)(const char *filePath, PreAppList *list); + void (*SetPreAppInfo)(PreAppList *list); }; #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 6fca894..81b4ea3 100644 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -19,6 +19,7 @@ #include #include "bundle_manager.h" +#include "los_list.h" #ifdef __cplusplus #if __cplusplus @@ -26,6 +27,7 @@ extern "C" { #endif #endif /* __cplusplus */ +#define MAX_APP_FILE_PATH_LEN 100 typedef enum { BUNDLE_INSTALL_DOING = 0, BUNDLE_INSTALL_OK = 1, @@ -44,6 +46,11 @@ typedef struct { uint8_t installProcess; } BundleInstallMsg; +typedef struct { + LOS_DL_LIST appDoubleList; + char filePath[MAX_APP_FILE_PATH_LEN]; +} PreAppList; + /** * @brief Get the install state and install process of the bundle. * @@ -95,6 +102,31 @@ void UpdateBundleInfoList(void); */ uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); +/** + * @brief Initializing preset application information. + * + * @return Returns an empty PreAppList. + * + */ +PreAppList *InitPreAppInfo(void); + +/** + * @brief Insert preset application information to the list. + * + * @param filePath Indicates the file path of the preconfigured application. + * @param list Indicates the inserted list. + * + */ +void InsertPreAppInfo(const char *filePath, PreAppList *list); + +/** + * @brief Setting the preset application list. + * + * @param list Indicates the preset application list. + * + */ +void SetPreAppInfo(PreAppList *list); + #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 d9ff3bc..75d0ccc 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -40,6 +40,9 @@ public: static bool RegisterInstallerCallback(InstallerCallback installerCallback); static void UpdateBundleInfoList(); static uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); + static PreAppList *InitPreAppInfo(); + static void InsertPreAppInfo(const char *filePath, PreAppList *list); + static void SetPreAppInfo(PreAppList *list); 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 68f9de3..afab0d8 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -26,11 +26,9 @@ #include "install_param.h" #include "bundle_install_msg.h" #include "bundle_manager.h" -#include "los_list.h" #include "ohos_types.h" namespace OHOS { -#define MAX_APP_FILE_PATH_LEN 100 struct ToBeInstalledApp { bool isSystemApp; bool isUpdated; @@ -38,10 +36,6 @@ struct ToBeInstalledApp { char *installedPath; char *appId; }; -struct AppInfoList { - LOS_DL_LIST appDoubleList; - char filePath[MAX_APP_FILE_PATH_LEN]; -}; typedef enum { BUNDLE_INSTALL, @@ -81,6 +75,9 @@ public: bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); uint32_t GetBundleSize(const char *bundleName); bool RegisterInstallerCallback(InstallerCallback installerCallback); + PreAppList *InitPreAppInfo(void); + void InsertPreAppInfo(const char *filePath, PreAppList *list); + void SetPreAppInfo(PreAppList *list); private: GtManagerService(); @@ -100,11 +97,9 @@ private: 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); void InstallPreBundle(List systemPathList, InstallerCallback installerCallback); + void QueryPreAppInfo(const char *appDir, PreAppList *list); + void FreePreAppInfo(const PreAppList *list); GtBundleInstaller *installer_; BundleMap *bundleMap_; @@ -113,6 +108,7 @@ private: char *jsEngineVer_; uint32_t installedThirdBundleNum_; List systemPathList_; + PreAppList *preAppList_; }; } diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 5772f79..202df91 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -37,6 +37,9 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback, .UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList, .GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication, + .InitPreAppInfo = BundleMgrSliteFeature::InitPreAppInfo, + .InsertPreAppInfo = BundleMgrSliteFeature::InsertPreAppInfo, + .SetPreAppInfo = BundleMgrSliteFeature::SetPreAppInfo, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -150,4 +153,19 @@ uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, Bund { return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); } + +PreAppList *BundleMgrSliteFeature::InitPreAppInfo() +{ + return OHOS::GtManagerService::GetInstance().InitPreAppInfo(); +} + +void BundleMgrSliteFeature::InsertPreAppInfo(const char *filePath, PreAppList *list) +{ + OHOS::GtManagerService::GetInstance().InsertPreAppInfo(filePath, list); +} + +void BundleMgrSliteFeature::SetPreAppInfo(PreAppList *list) +{ + OHOS::GtManagerService::GetInstance().SetPreAppInfo(list); +} } // 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 5947505..3ef6224 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -50,6 +50,7 @@ GtManagerService::GtManagerService() bundleInstallMsg_ = nullptr; jsEngineVer_ = nullptr; installedThirdBundleNum_ = 0; + preAppList_ = nullptr; } GtManagerService::~GtManagerService() @@ -267,6 +268,21 @@ bool GtManagerService::RegisterInstallerCallback(InstallerCallback installerCall void GtManagerService::InstallPreBundle(List systemPathList, InstallerCallback installerCallback) { + // get third system bundle uninstall record + cJSON *uninstallRecord = BundleUtil::GetJsonStream(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); + if (uninstallRecord == nullptr) { + (void) unlink(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); + } + + // scan system apps and third system apps + ScanSystemApp(uninstallRecord, &systemPathList_); + if (uninstallRecord != nullptr) { + cJSON_Delete(uninstallRecord); + } + + // scan third apps + ScanThirdApp(INSTALL_PATH, &systemPathList_); + if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) { BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END); InstallAllSystemBundle(installerCallback); @@ -275,14 +291,15 @@ void GtManagerService::InstallPreBundle(List systemPathList, } for (auto node = systemPathList.Begin(); node != systemPathList.End(); node = node->next_) { ToBeInstalledApp *toBeInstalledApp = node->value_; + if (!BundleUtil::IsFile(toBeInstalledApp->path) || + !BundleUtil::EndWith(toBeInstalledApp->path, INSTALL_FILE_SUFFIX)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Pre install file path is invalid"); + continue; + } 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); @@ -290,27 +307,28 @@ void GtManagerService::InstallPreBundle(List systemPathList, void GtManagerService::InstallAllSystemBundle(InstallerCallback installerCallback) { - AppInfoList *list = GtManagerService::APP_InitAllAppInfo(); + PreAppList *list = preAppList_; if (list == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] InstallAllSystemBundle InitAllAppInfo fail, list is nullptr"); return; } - AppInfoList *currentNode = nullptr; - AppInfoList *nextNode = nullptr; - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) { - if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) || - (strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) { + PreAppList *currentNode = nullptr; + PreAppList *nextNode = nullptr; + LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, PreAppList, appDoubleList) { + if ((strcmp(((PreAppList *)currentNode)->filePath, ".") == 0) || + (strcmp(((PreAppList *)currentNode)->filePath, "..") == 0)) { continue; } - if (!BundleUtil::IsFile(((AppInfoList *)currentNode)->filePath) || - !BundleUtil::EndWith(((AppInfoList *)currentNode)->filePath, INSTALL_FILE_SUFFIX)) { + if (!BundleUtil::IsFile(((PreAppList *)currentNode)->filePath) || + !BundleUtil::EndWith(((PreAppList *)currentNode)->filePath, INSTALL_FILE_SUFFIX)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Install all system bundle file path is invalid"); return; } - (void) Install(((AppInfoList *)currentNode)->filePath, nullptr, installerCallback); + (void) Install(((PreAppList *)currentNode)->filePath, nullptr, installerCallback); } - GtManagerService::APP_FreeAllAppInfo(list); + GtManagerService::FreePreAppInfo(list); } void GtManagerService::ClearSystemBundleInstallMsg() @@ -351,21 +369,6 @@ void GtManagerService::ScanPackages() if (jsEngineVer_ == nullptr) { HILOG_WARN(HILOG_MODULE_AAFWK, "[BMS] get jsEngine version fail when restart!"); } - - // get third system bundle uninstall record - cJSON *uninstallRecord = BundleUtil::GetJsonStream(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); - if (uninstallRecord == nullptr) { - (void) unlink(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON); - } - - // scan system apps and third system apps - ScanSystemApp(uninstallRecord, &systemPathList_); - if (uninstallRecord != nullptr) { - cJSON_Delete(uninstallRecord); - } - - // scan third apps - ScanThirdApp(INSTALL_PATH, &systemPathList_); } void GtManagerService::RemoveSystemAppPathList(List *systemPathList) @@ -385,7 +388,7 @@ void GtManagerService::RemoveSystemAppPathList(List *systemP void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List *systemPathList) { - AppInfoList *list = GtManagerService::APP_InitAllAppInfo(); + PreAppList *list = preAppList_; if (list == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ScanSystemApp InitAllAppInfo fail, list is nullptr"); return; @@ -394,25 +397,25 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, ListappDoubleList, AppInfoList, appDoubleList) { - if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) || - (strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) { + LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, PreAppList, appDoubleList) { + if ((strcmp(((PreAppList *)currentNode)->filePath, ".") == 0) || + (strcmp(((PreAppList *)currentNode)->filePath, "..") == 0)) { continue; } - if (BundleUtil::StartWith(((AppInfoList *)currentNode)->filePath, SYSTEM_BUNDLE_PATH)) { + if (BundleUtil::StartWith(((PreAppList *)currentNode)->filePath, SYSTEM_BUNDLE_PATH)) { scanFlag = SYSTEM_APP_FLAG; - } else if (BundleUtil::StartWith(((AppInfoList *)currentNode)->filePath, THIRD_SYSTEM_BUNDLE_PATH)) { + } else if (BundleUtil::StartWith(((PreAppList *)currentNode)->filePath, THIRD_SYSTEM_BUNDLE_PATH)) { scanFlag = THIRD_SYSTEM_APP_FLAG; } else { continue; // skip third app } // scan system app - bool res = CheckSystemBundleIsValid(((AppInfoList *)currentNode)->filePath, &bundleName, versionCode); + bool res = CheckSystemBundleIsValid(((PreAppList *)currentNode)->filePath, &bundleName, versionCode); if (!res) { APP_ERRCODE_EXTRA(EXCE_ACE_APP_SCAN, EXCE_ACE_APP_SCAN_INVALID_SYSTEM_APP); AdapterFree(bundleName); @@ -426,11 +429,11 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, ListfilePath, bundleName, + ReloadEntireBundleInfo(((PreAppList *)currentNode)->filePath, bundleName, systemPathList, versionCode, scanFlag); AdapterFree(bundleName); } - GtManagerService::APP_FreeAllAppInfo(list); + GtManagerService::FreePreAppInfo(list); } void GtManagerService::ScanThirdApp(const char *appDir, const List *systemPathList) @@ -929,26 +932,23 @@ int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, uint8_t insta return 0; } -AppInfoList *GtManagerService::APP_InitAllAppInfo() +PreAppList *GtManagerService::InitPreAppInfo() { - AppInfoList *list = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList)); + PreAppList *list = (PreAppList *)AdapterMalloc(sizeof(PreAppList)); if (list == nullptr) { return nullptr; } - if (memset_s(list, sizeof(AppInfoList), 0, sizeof(AppInfoList)) != EOK) { + if (memset_s(list, sizeof(PreAppList), 0, sizeof(PreAppList)) != EOK) { AdapterFree(list); return nullptr; } LOS_ListInit(&list->appDoubleList); - - APP_QueryAppInfo(SYSTEM_BUNDLE_PATH, list); - APP_QueryAppInfo(THIRD_SYSTEM_BUNDLE_PATH, list); return list; } -void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list) +void GtManagerService::QueryPreAppInfo(const char *appDir, PreAppList *list) { struct dirent *ent = nullptr; if (appDir == nullptr) { @@ -989,24 +989,24 @@ void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list) continue; } - APP_InsertAppInfo(appPath, (AppInfoList *)&list->appDoubleList); + InsertPreAppInfo(appPath, (PreAppList *)&list->appDoubleList); AdapterFree(appPath); } AdapterFree(fileName); } -void GtManagerService::APP_InsertAppInfo(char *filePath, AppInfoList *list) +void GtManagerService::InsertPreAppInfo(const char *filePath, PreAppList *list) { if ((filePath == nullptr) || (list == nullptr)) { return; } - AppInfoList *app = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList)); + PreAppList *app = (PreAppList *)AdapterMalloc(sizeof(PreAppList)); if (app == nullptr) { return; } - if (memset_s(app, sizeof(AppInfoList), 0, sizeof(AppInfoList)) != 0) { + if (memset_s(app, sizeof(PreAppList), 0, sizeof(PreAppList)) != 0) { AdapterFree(app); return; } @@ -1020,15 +1020,24 @@ void GtManagerService::APP_InsertAppInfo(char *filePath, AppInfoList *list) return; } -void GtManagerService::APP_FreeAllAppInfo(const AppInfoList *list) +void GtManagerService::SetPreAppInfo(PreAppList *list) +{ + if (list == nullptr) { + return; + } + preAppList_ = list; + return; +} + +void GtManagerService::FreePreAppInfo(const PreAppList *list) { if (list == nullptr) { return; } - AppInfoList *currentNode = nullptr; - AppInfoList *nextNode = nullptr; - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) { + PreAppList *currentNode = nullptr; + PreAppList *nextNode = nullptr; + LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, PreAppList, appDoubleList) { if (currentNode != nullptr) { LOS_ListDelete(&(currentNode->appDoubleList)); AdapterFree(currentNode);