diff --git a/bundle.json b/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..a710bda5c218affc112a9f352a5823cf393406bf --- /dev/null +++ b/bundle.json @@ -0,0 +1,72 @@ +{ + "name": "@ohos/appexecfwk_lite", + "description": "Bundle installation management frameworks", + "homePage": "https://gitee.com/openharmony", + "version": "3.1", + "license": "Apache License 2.0", + "repository": "https://gitee.com/openharmony/appexecfwk_appexecfwk_lite", + "publishAs": "code-segment", + "segment": { + "destPath": "foundation/appexecfwk/appexecfwk_lite" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "appexecfwk_lite", + "subsystem": "appexecfwk", + "adapted_system_type": [ + "mini" + ], + "rom": "300KB", + "ram": ">2MB", + "deps": { + "components": [ + "aafwk_lite", + "hilog", + "utils_base", + "permission", + "ipc_lite", + "samgr_lite", + "resmgr_lite", + "appverify" + ], + "third_party": [ + "zlib", + "bounds_checking_function", + "cjson" + ] + }, + "build": { + "sub_component": [ + "//foundation/appexecfwk/appexecfwk_lite/services/bundlemgr_lite:appexecfwk_services_lite", + "//foundation/appexecfwk/appexecfwk_lite/frameworks/bundle_lite:appexecfwk_kits_lite" + ], + "inner_kits": [ + { + "header": { + "header_base": "foundation/appexecfwk/appexecfwk_lite/interfaces/innerkits/bundlemgr_lite", + "header_files": [ + "bundle_daemon_interface.h", + "bundle_inner_interface.h", + "bundle_service_interface.h" + ] + }, + "name": "//foundation/appexecfwk/appexecfwk_lite/services/bundlemgr_lite:appexecfwk_services_lite" + }, + { + "header": { + "header_base": "foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "header_files": [ + "ability_info.h", + "appexecfwk_errors.h", + "bundle_info.h", + "element_name.h", + "module_info.h" + ] + }, + "name": "//foundation/appexecfwk/appexecfwk_lite/frameworks/bundle_lite:appexecfwk_kits_lite" + } + ] + } + } +} \ No newline at end of file diff --git a/frameworks/bundle_lite/BUILD.gn b/frameworks/bundle_lite/BUILD.gn index a3892f50516c49d1bd23b060a20973810a3d8759..090f17bae2196e5cf338934b06834ebc0b4b1eb9 100644 --- a/frameworks/bundle_lite/BUILD.gn +++ b/frameworks/bundle_lite/BUILD.gn @@ -26,28 +26,94 @@ lite_component("appexecfwk_kits_lite") { } lite_library("bundle") { - target_type = "shared_library" - sources = [ - "src/ability_info.cpp", - "src/ability_info_utils.cpp", - "src/bundle_callback.cpp", - "src/bundle_callback_utils.cpp", - "src/bundle_info.cpp", - "src/bundle_info_utils.cpp", - "src/bundle_manager.cpp", - "src/bundle_self_callback.cpp", - "src/convert_utils.cpp", - "src/element_name.cpp", - "src/module_info.cpp", - "src/module_info_utils.cpp", - "src/token_generate.cpp", - ] + if (ohos_kernel_type == "liteos_m") { + target_type = "static_library" - deps = [ - "${aafwk_lite_path}/frameworks/want_lite:want", - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//base/security/permission/services/permission_lite/pms_client:pms_client", - ] + sources = [ + "src/ability_info.cpp", + "src/ability_info_utils.cpp", + "src/bundle_info.cpp", + "src/bundle_info_utils.cpp", + "src/element_name.cpp", + "src/module_info.cpp", + "src/module_info_utils.cpp", + "src/slite/bundle_manager.cpp", + "src/slite/bundle_manager_inner.cpp", + "src/slite/bundlems_slite_client.cpp", + ] + + public_deps = [ + "${aafwk_lite_path}/frameworks/want_lite:want", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static", + ] + + include_dirs = [ + "${appexecfwk_lite_path}/services/bundlemgr_lite/include", + "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite/slite", + "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite/slite", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", + "${appexecfwk_lite_path}/utils/bundle_lite", + "${appexecfwk_lite_path}/frameworks/bundle_lite/include", + "//base/security/permission/interfaces/kits/permission_lite", + "//base/security/permission/services/permission_lite/pms/include", + "${aafwk_lite_path}/frameworks/want_lite/include", + "${aafwk_lite_path}/interfaces/kits/want_lite", + "${aafwk_lite_path}/interfaces/kits/ability_lite/slite", + "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/bounds_checking_function/include", + "//utils/native/lite/include", + "//utils/native/lite/memory/include", + "//third_party/cJSON", + ] + } else { + target_type = "shared_library" + + sources = [ + "src/ability_info.cpp", + "src/ability_info_utils.cpp", + "src/bundle_callback.cpp", + "src/bundle_callback_utils.cpp", + "src/bundle_info.cpp", + "src/bundle_info_utils.cpp", + "src/bundle_manager.cpp", + "src/bundle_self_callback.cpp", + "src/convert_utils.cpp", + "src/element_name.cpp", + "src/module_info.cpp", + "src/module_info_utils.cpp", + "src/token_generate.cpp", + ] + + deps = [ + "${aafwk_lite_path}/frameworks/want_lite:want", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//base/security/permission/services/permission_lite/pms_client:pms_client", + ] + + include_dirs = [ + "include", + "//base/security/permission/interfaces/kits/permission_lite", + "//base/security/permission/services/permission_lite/pms/include", + "${aafwk_lite_path}/frameworks/want_lite/include", + "${aafwk_lite_path}/interfaces/kits/want_lite", + "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", + "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", + "${appexecfwk_lite_path}/utils/bundle_lite", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/bounds_checking_function/include", + "//utils/native/lite/include", + "//third_party/cJSON", + ] + + defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ] + } cflags = [ "-fPIC", @@ -55,26 +121,6 @@ lite_library("bundle") { "-Wno-format", ] cflags_cc = cflags - - include_dirs = [ - "include", - "//base/security/permission/interfaces/kits/permission_lite", - "//base/security/permission/services/permission_lite/pms/include", - "${aafwk_lite_path}/frameworks/want_lite/include", - "${aafwk_lite_path}/interfaces/kits/want_lite", - "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", - "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", - "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", - "${appexecfwk_lite_path}/utils/bundle_lite", - "//foundation/communication/ipc_lite/interfaces/kits", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", - "//third_party/bounds_checking_function/include", - "//utils/native/lite/include", - "//third_party/cJSON", - ] - - defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ] } ndk_lib("bundle_notes") { diff --git a/frameworks/bundle_lite/include/bundle_callback_utils.h b/frameworks/bundle_lite/include/bundle_callback_utils.h index 376c90e5259fc25bd27960e12e7deb74a52b759d..ec1031d71392948b4ce0245c7e88fc8be5afe0a8 100755 --- a/frameworks/bundle_lite/include/bundle_callback_utils.h +++ b/frameworks/bundle_lite/include/bundle_callback_utils.h @@ -67,4 +67,9 @@ struct BundleCallbackInfo { BundleStateCallback bundleStateCallback; void *data; }; + +struct ResultOfGetBundleSize { + uint8_t resultCode; + uint32_t bundleSize; +}; #endif // OHOS_BUNDLE_CALLBACK_UTILS_H \ No newline at end of file diff --git a/frameworks/bundle_lite/include/bundle_info_utils.h b/frameworks/bundle_lite/include/bundle_info_utils.h index 6043c2ae4c034203649b6fa841ca69062be8e1b6..92af18583c51fd3cde4e86236818a58115133954 100755 --- a/frameworks/bundle_lite/include/bundle_info_utils.h +++ b/frameworks/bundle_lite/include/bundle_info_utils.h @@ -21,6 +21,7 @@ namespace OHOS { struct BundleInfoUtils { static void CopyBundleInfo(int32_t flags, BundleInfo *des, BundleInfo src); + static void CopyBundleInfoNoReplication(int32_t flags, BundleInfo *des, BundleInfo src); static bool SetBundleInfoBundleName(BundleInfo *bundleInfo, const char *bundleName); static bool SetBundleInfoVendor(BundleInfo *bundleInfo, const char *vendor); static bool SetBundleInfoLabel(BundleInfo *bundleInfo, const char *label); diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index a96f37d3d38b3d9ad17df03ae3b679bb529a44c1..c0c0eb8d86ab566c81f134fd6fe5fdca7890ef30 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -49,6 +49,12 @@ public: uint32_t GetBundleSize(const char *bundleName) const; + bool RegisterInstallerCallback(InstallerCallback installerCallback) const; + + void UpdateBundleInfoList() const; + + uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) const; + private: BundleMsClient() = default; diff --git a/frameworks/bundle_lite/src/bundle_info_utils.cpp b/frameworks/bundle_lite/src/bundle_info_utils.cpp index b166e94066e81524cf79821b234cf427e932abf1..0f891eaf4386a7a8b730f4888ae26a888f4dd9fe 100755 --- a/frameworks/bundle_lite/src/bundle_info_utils.cpp +++ b/frameworks/bundle_lite/src/bundle_info_utils.cpp @@ -84,6 +84,50 @@ void BundleInfoUtils::CopyBundleInfo(int32_t flags, BundleInfo *des, BundleInfo #endif } +void BundleInfoUtils::CopyBundleInfoNoReplication(int32_t flags, BundleInfo *des, BundleInfo src) +{ + if (des == nullptr) { + return; + } + des->bundleName = src.bundleName; + des->label = src.label; + des->versionName = src.versionName; + des->bigIconPath = src.bigIconPath; + des->codePath = src.codePath; + des->dataPath = src.dataPath; + des->vendor = src.vendor; + if (src.numOfModule != 0) { + des->numOfModule = src.numOfModule; + des->moduleInfos = src.moduleInfos; + } + des->isSystemApp = src.isSystemApp; + des->versionCode = src.versionCode; + des->compatibleApi = src.compatibleApi; + des->targetApi = src.targetApi; + des->appId = src.appId; +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER + des->isKeepAlive = src.isKeepAlive; + des->isNativeApp = src.isNativeApp; + des->uid = src.uid; + des->gid = src.gid; + if (flags == GET_BUNDLE_WITH_ABILITIES) { + SetBundleInfoAbilityInfos(des, src.abilityInfos, src.numOfAbility); + } else { + des->abilityInfos = nullptr; + des->numOfAbility = 0; + } +#else + des->smallIconPath = src.smallIconPath; + if (flags == GET_BUNDLE_WITH_ABILITIES) { + if (src.abilityInfo != nullptr) { + des->abilityInfo = src.abilityInfo; + } + } else { + des->abilityInfo = nullptr; + } +#endif +} + bool BundleInfoUtils::SetBundleInfoBundleName(BundleInfo *bundleInfo, const char *bundleName) { if (bundleInfo == nullptr || bundleName == nullptr) { diff --git a/frameworks/bundle_lite/src/bundle_manager.cpp b/frameworks/bundle_lite/src/bundle_manager.cpp index 6386271224749bb42ffcfbd6b75b62f162082c95..2a8aff0cb0e62c9fcf10f9dd763fcac4e8f908af 100755 --- a/frameworks/bundle_lite/src/bundle_manager.cpp +++ b/frameworks/bundle_lite/src/bundle_manager.cpp @@ -43,7 +43,7 @@ constexpr static uint8_t OBJECT_NUMBER_IN_INSTALLATION = 1; constexpr static uint8_t OBJECT_NUMBER_IN_INSTALLATION = 2; #endif -int32 RegisterCallback(BundleStatusCallback *bundleStatusCallback) +int32_t RegisterCallback(BundleStatusCallback *bundleStatusCallback) { if ((bundleStatusCallback == nullptr) || (bundleStatusCallback->callBack == nullptr)) { return ERR_APPEXECFWK_OBJECT_NULL; @@ -57,7 +57,7 @@ int32 RegisterCallback(BundleStatusCallback *bundleStatusCallback) bundleStatusCallback->bundleName, bundleStatusCallback->data); } -int32 UnregisterCallback() +int32_t UnregisterCallback() { return OHOS::BundleCallback::GetInstance().UnregisterBundleStateCallback(); } @@ -224,6 +224,22 @@ static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply) return resultCode; } +static uint8_t DeserializeBundleSize(IOwner owner, IpcIo *reply) +{ + if ((reply == nullptr) || (owner == nullptr)) { + return OHOS_FAILURE; + } + uint8_t resultCode = IpcIoPopUint8(reply); + ResultOfGetBundleSize *info = reinterpret_cast(owner); + if (resultCode != ERR_OK) { + info->resultCode = resultCode; + return resultCode; + } + info->bundleSize = IpcIoPopUint32(reply); + info->resultCode = resultCode; + return resultCode; +} + static uint8_t DeserializeSystemCapabilities(IOwner owner, IpcIo *reply) { if ((reply == nullptr) || (owner == nullptr)) { @@ -300,6 +316,9 @@ static int Notify(IOwner owner, int code, IpcIo *reply) HILOG_INFO(HILOG_MODULE_APP, "BundleManager HasSystemCapability invoke return: %{public}d", *ret); break; } + case GET_BUNDLE_SIZE: { + return DeserializeBundleSize(owner, reply); + } case GET_SYS_CAP: { return DeserializeSystemCapabilities(owner, reply); } @@ -605,6 +624,43 @@ uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len) return ObtainInnerBundleInfos(flags, bundleInfos, len, GET_BUNDLE_INFOS, &ipcIo); } +uint32_t GetBundleSize(const char *bundleName) +{ + if (bundleName == nullptr) { + return 0; + } + if (strlen(bundleName) >= MAX_BUNDLE_NAME) { + return 0; + } + if (CheckSelfPermission(static_cast(PERMISSION_GET_BUNDLE_INFO)) != GRANTED) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get bundle size failed due to permission denied"); + return 0; + } + auto bmsClient = GetBmsClient(); + if (bmsClient == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get bundle size failed due to nullptr bms client"); + return 0; + } + + IpcIo ipcIo; + char data[IPC_IO_DATA_MAX]; + IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); + IpcIoPushString(&ipcIo, bundleName); + if (!IpcIoAvailable(&ipcIo)) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleSize ipc failed"); + return 0; + } + + ResultOfGetBundleSize resultOfGetBundleSize; + int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_SIZE, &ipcIo, &resultOfGetBundleSize, Notify); + if (ret != OHOS_SUCCESS) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleSize invoke failed: %{public}d", ret); + return 0; + } + uint32_t bundleSize = resultOfGetBundleSize.bundleSize; + return bundleSize; +} + uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len) { if ((bundleInfos == nullptr) || (len == nullptr)) { diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index 04c4e1b0827cf76e1f66b4da4ee1092a6d455f73..a2fd4c253e51418a8d1cc9c7e15cd744478b11e7 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -28,4 +28,19 @@ uint32_t GetBundleSize(const char *bundleName) { return OHOS::BundleMsClient::GetInstance().GetBundleSize(bundleName); } + +bool RegisterInstallerCallback(InstallerCallback installerCallback) +{ + return OHOS::BundleMsClient::GetInstance().RegisterInstallerCallback(installerCallback); +} + +void UpdateBundleInfoList(void) +{ + OHOS::BundleMsClient::GetInstance().UpdateBundleInfoList(); +} + +uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) +{ + return OHOS::BundleMsClient::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); +} } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index ba326bc2bc3ad77dd1d9df58ecee398a6cc92a89..fe137067d0303b3f5b878291abcf15166f7d7390 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -83,8 +83,8 @@ bool BundleMsClient::Install(const char *hapPath, const InstallParam *installPar g_bmsbuff->bundleInstallerCallback = installerCallback; Request request = { .msgId = BMS_INSTALL_MSG, - .data = nullptr, .len = 0, + .data = nullptr, .msgValue = 0, }; @@ -118,8 +118,31 @@ bool BundleMsClient::Uninstall (const char *bundleName, const InstallParam *inst g_bmsbuff->bundleInstallerCallback = installerCallback; Request request = { .msgId = BMS_UNINSTALL_MSG, + .len = 0, .data = nullptr, + .msgValue = 0, + }; + int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); + 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, .len = 0, + .data = nullptr, .msgValue = 0, }; int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); @@ -165,4 +188,20 @@ uint32_t BundleMsClient::GetBundleSize (const char *bundleName) const } return bmsProxy_->GetBundleSize(bundleName); } + +void BundleMsClient::UpdateBundleInfoList () const +{ + if (!Initialize()) { + return; + } + bmsProxy_->UpdateBundleInfoList(); +} + +uint8_t BundleMsClient::GetBundleInfosNoReplication (const int flags, BundleInfo **bundleInfos, int32_t *len) const +{ + if (!Initialize()) { + return -1; + } + return bmsProxy_->GetBundleInfosNoReplication(flags, bundleInfos, len); +} } // namespace OHOS diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h index a79850d197da0b7c2528bdfdc4b03b3d666f0008..c5b679ca3aa266b918796abf5c4c40141224c099 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h @@ -40,6 +40,7 @@ enum BmsCmd { QUERY_KEEPALIVE_BUNDLE_INFOS, GET_BUNDLE_INFOS_BY_METADATA, CHECK_SYS_CAP, + GET_BUNDLE_SIZE, GET_SYS_CAP, BMS_INNER_BEGIN, INSTALL = BMS_INNER_BEGIN, // bms install application @@ -59,6 +60,7 @@ struct BmsServerProxy { uint8_t (*GetBundleInfos)(int flags, BundleInfo **bundleInfos, int32_t *len); uint8_t (*QueryKeepAliveBundleInfos)(BundleInfo **bundleInfos, int32_t *len); uint8_t (*GetBundleNameForUid)(int32_t uid, char **bundleName); + uint32_t (*GetBundleSize)(const char *bundleName); }; struct BmsInnerServerProxy { diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index fec629bfa11cbc4daef9d6414ca084cf1599bda1..f385265c6f6c3019e41613686e868c6bcab187dc 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -51,6 +51,9 @@ 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); + void (*UpdateBundleInfoList)(); + uint8_t (*GetBundleInfosNoReplication)(const int flags, BundleInfo **bundleInfos, int32_t *len); }; #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..6fca8947576e44283b02453460072c21de35e9cb 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,35 @@ 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); + +/** + * @brief Update bundleInfo when system language has been changed. + * + */ +void UpdateBundleInfoList(void); + + /** + * @brief Obtains the {@link BundleInfo} of all bundles with no replication in the system. + * + * @param flags Specifies whether each of the obtained {@link BundleInfo} objects can contain {@link AbilityInfo}. + * The value 1 indicates that it can contain {@link AbilityInfo}, and 0 indicates that + * it cannot. + * @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects. + * @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained. + * @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in + * {@link AppexecfwkErrors} otherwise. + * + */ +uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); + #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/kits/bundle_lite/bundle_manager.h b/interfaces/kits/bundle_lite/bundle_manager.h index c55791cab45ca3d7b5fed84e54d7cfe129c35235..39086ae6b95041242cec444df43dd225ba445415 100755 --- a/interfaces/kits/bundle_lite/bundle_manager.h +++ b/interfaces/kits/bundle_lite/bundle_manager.h @@ -94,7 +94,7 @@ int32_t RegisterCallback(BundleStatusCallback *BundleStatusCallback); * @since 1.0 * @version 1.0 */ -int32_t UnregisterCallback(); +int32_t UnregisterCallback(void); /** * @brief Installs or updates an application. @@ -216,6 +216,7 @@ uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInf */ uint8_t GetBundleNameForUid(int32_t uid, char **bundleName); +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER /** * @brief Check if the specify syscap name is supported by the system. * @@ -246,6 +247,17 @@ SystemCapability *GetSystemAvailableCapabilities(); * @version 4 */ void FreeSystemAvailableCapabilitiesInfo(SystemCapability *sysCap); +#endif +/** + * @brief Get bundle size + * + * @param bundleName Indicates the bundle name. + * @return Returns the bundle size (Byte) if this function is successfully called; returns 0 otherwise. + * + * @since 7 + * @version 7 + */ +uint32_t GetBundleSize(const char *bundleName); #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/kits/bundle_lite/module_info.h b/interfaces/kits/bundle_lite/module_info.h index b78c4f024ab1fc46937391e225aa7dd1a24eb5bb..9d6d92636b7104ad7b9f872c256d9f3f4e06f026 100644 --- a/interfaces/kits/bundle_lite/module_info.h +++ b/interfaces/kits/bundle_lite/module_info.h @@ -84,7 +84,7 @@ typedef struct { /** Whether the HAP package is installed while the user is installing the application */ bool isDeliveryInstall; - /** + /** * Pointer to the types of devices that can run the application. The maximum size of the device type array is * {@link DEVICE_TYPE_SIZE}. */ diff --git a/services/bundlemgr_lite/BUILD.gn b/services/bundlemgr_lite/BUILD.gn index 96be3f231afa0c11aacd0ea3549b26453b7e9d09..60bbb54a03176a8a5ec8916b713184f1ae9c2081 100644 --- a/services/bundlemgr_lite/BUILD.gn +++ b/services/bundlemgr_lite/BUILD.gn @@ -17,68 +17,132 @@ config("bundle_config") { cflags_cc = [ "-std=c++14" ] } -shared_library("bundlems") { - configs -= [ "//build/lite/config:language_cpp" ] - configs += [ ":bundle_config" ] +if (ohos_kernel_type == "liteos_m") { + static_library("bundlems") { + sources = [ + "src/bundle_map.cpp", + "src/bundle_mgr_service.cpp", + "src/bundle_mgr_slite_feature.cpp", + "src/bundle_util.cpp", + "src/gt_bundle_extractor.cpp", + "src/gt_bundle_installer.cpp", + "src/gt_bundle_manager_service.cpp", + "src/gt_bundle_parser.cpp", + "src/gt_extractor_util.cpp", + ] + deps = [ + "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static", + "//foundation/ace/ace_engine_lite/frameworks:ace_lite", + "//foundation/distributedschedule/samgr_lite/samgr:samgr", + ] - cflags = [ - "-Wall", - "-Wno-format", - "-Wno-format-extra-args", - ] - cflags_cc = cflags + include_dirs = [ + "${appexecfwk_lite_path}/services/bundlemgr_lite/include", + "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite/slite", + "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite/slite", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", + "${appexecfwk_lite_path}/utils/bundle_lite", + "${appexecfwk_lite_path}/frameworks/bundle_lite/include", + "//base/startup/syspara_lite/interfaces/kits/", + "${aafwk_lite_path}/interfaces/kits/ability_lite/slite", + "${aafwk_lite_path}/services/abilitymgr_lite/include", + "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", + "${aafwk_lite_path}/interfaces/kits/ability_lite", + "${aafwk_lite_path}/interfaces/kits/want_lite", + "${aafwk_lite_path}/frameworks/want_lite/include", + "//base/global/resmgr_lite/interfaces/innerkits/include", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//third_party/jerryscript/jerry-core/api", + "//third_party/jerryscript/jerry-core/include", + "//third_party/cJSON", + "//third_party/zlib", + "//third_party/zlib/contrib/minizip", + "//base/security/permission/interfaces/kits/permission_lite", + "//base/security/permission/services/permission_lite/pms/include", + "//base/security/appverify/interfaces/innerkits/appverify_lite/include", + "//third_party/bounds_checking_function/include", + "//utils/native/lite/include", + "//utils/native/lite/memory/include", + "include", + ] + } + lite_component("appexecfwk_services_lite") { + features = [ ":bundlems" ] + } +} else { + shared_library("bundlems") { + configs -= [ "//build/lite/config:language_cpp" ] + configs += [ ":bundle_config" ] - sources = [ - "src/bundle_daemon_client.cpp", - "src/bundle_extractor.cpp", - "src/bundle_info_creator.cpp", - "src/bundle_inner_feature.cpp", - "src/bundle_installer.cpp", - "src/bundle_manager_service.cpp", - "src/bundle_map.cpp", - "src/bundle_ms_feature.cpp", - "src/bundle_ms_host.cpp", - "src/bundle_parser.cpp", - "src/bundle_res_transform.cpp", - "src/bundle_util.cpp", - "src/extractor_util.cpp", - "src/hap_sign_verify.cpp", - "src/zip_file.cpp", - ] - include_dirs = [ - "//base/global/resmgr_lite/interfaces/innerkits/include", - "${aafwk_lite_path}/services/abilitymgr_lite/include", - "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", - "${aafwk_lite_path}/interfaces/kits/ability_lite", - "${aafwk_lite_path}/interfaces/kits/want_lite", - "${aafwk_lite_path}/frameworks/want_lite/include", - "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", - "${appexecfwk_lite_path}/frameworks/bundle_lite/include", - "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", - "${appexecfwk_lite_path}/utils/bundle_lite", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//third_party/cJSON", - "//third_party/zlib", - "//third_party/zlib/contrib/minizip", - "//base/security/permission/interfaces/kits/permission_lite", - "//base/security/permission/services/permission_lite/pms/include", - "//base/security/appverify/interfaces/innerkits/appverify_lite/include", - "//third_party/bounds_checking_function/include", - "//utils/native/lite/include", - "//utils/native/lite/memory", - "include", - ] + cflags = [ + "-Wall", + "-Wno-format", + "-Wno-format-extra-args", + ] + cflags_cc = cflags - public_deps = [ - "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", - "//base/global/resmgr_lite/frameworks/resmgr_lite:global_resmgr", - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//base/security/appverify/interfaces/innerkits/appverify_lite:verify", - "//build/lite/config/component/cJSON:cjson_shared", - "//build/lite/config/component/zlib:zlib_shared", - "//foundation/distributedschedule/samgr_lite/samgr:samgr", - ] + sources = [ + "src/bundle_daemon_client.cpp", + "src/bundle_extractor.cpp", + "src/bundle_info_creator.cpp", + "src/bundle_inner_feature.cpp", + "src/bundle_installer.cpp", + "src/bundle_manager_service.cpp", + "src/bundle_map.cpp", + "src/bundle_ms_feature.cpp", + "src/bundle_ms_host.cpp", + "src/bundle_parser.cpp", + "src/bundle_res_transform.cpp", + "src/bundle_util.cpp", + "src/extractor_util.cpp", + "src/hap_sign_verify.cpp", + "src/zip_file.cpp", + ] + include_dirs = [ + "//base/global/resmgr_lite/interfaces/innerkits/include", + "${aafwk_lite_path}/services/abilitymgr_lite/include", + "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", + "${aafwk_lite_path}/interfaces/kits/ability_lite", + "${aafwk_lite_path}/interfaces/kits/want_lite", + "${aafwk_lite_path}/frameworks/want_lite/include", + "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", + "${appexecfwk_lite_path}/frameworks/bundle_lite/include", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", + "${appexecfwk_lite_path}/utils/bundle_lite", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//third_party/cJSON", + "//third_party/zlib", + "//third_party/zlib/contrib/minizip", + "//base/security/permission/interfaces/kits/permission_lite", + "//base/security/permission/services/permission_lite/pms/include", + "//base/security/appverify/interfaces/innerkits/appverify_lite/include", + "//third_party/bounds_checking_function/include", + "//utils/native/lite/include", + "//utils/native/lite/memory", + "include", + ] + + public_deps = [ + "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", + "//base/global/resmgr_lite/frameworks/resmgr_lite:global_resmgr", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//base/security/appverify/interfaces/innerkits/appverify_lite:verify", + "//build/lite/config/component/cJSON:cjson_shared", + "//build/lite/config/component/zlib:zlib_shared", + "//foundation/distributedschedule/samgr_lite/samgr:samgr", + ] + } + lite_component("appexecfwk_services_lite") { + features = [ + ":bundlems", + "tools:bm", + "bundle_daemon:bundle_daemon", + ] + } } generate_notice_file("appexecfwk_services_lite_notice_file") { @@ -89,11 +153,3 @@ generate_notice_file("appexecfwk_services_lite_notice_file") { "//third_party/bounds_checking_function", ] } - -lite_component("appexecfwk_services_lite") { - features = [ - ":bundlems", - "tools:bm", - "bundle_daemon:bundle_daemon", - ] -} diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp index 0afce614d5fbf34303796d9c875114e4850b1c36..b48b4982565925b25abe4cf9272e42348ac1d9fd 100755 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp @@ -15,9 +15,9 @@ #include "bundle_daemon_handler.h" +#include #include #include -#include #include "bundle_daemon_log.h" #include "bundle_file_utils.h" diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp index 6422d04001ff54118f3bd9e48ac1530a627a156a..95e7ad34f0a9c150a0d5a987738c672c0382ca49 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp @@ -15,9 +15,9 @@ #include "bundle_file_utils.h" +#include #include #include -#include #include #include diff --git a/services/bundlemgr_lite/include/bundle_common.h b/services/bundlemgr_lite/include/bundle_common.h index 1b0e146e8b48cde4755f69ed0f00895f1226ba5f..076e0799a900ec6611cc2210033c70366821086b 100755 --- a/services/bundlemgr_lite/include/bundle_common.h +++ b/services/bundlemgr_lite/include/bundle_common.h @@ -147,22 +147,22 @@ const uint8_t MAX_VERSION_NAME_LEN = 127; const uint16_t MAX_LABLE_LEN = 255; #else const char DEFAULT_DEVICE_TYPE[] = "fitnessWatch"; -const char INSTALL_PATH[] = "user/ace/run"; -const char DATA_PATH[] = "user/ace/data"; -const char SYSTEM_BUNDLE_PATH[] = "system/ace/sys"; -const char THIRD_SYSTEM_BUNDLE_PATH[] = "system/ace/vendor"; -const char UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON[] = "user/ace/etc/uninstalled_delbundle.json"; -const char THIRD_SYSTEM_BUNDLE_JSON[] = "user/ace/etc/third_system_bundle.json"; -const char JSON_PATH[] = "user/ace/etc/bundles/"; -const char JSON_PATH_NO_SLASH_END[] = "user/ace/etc/bundles"; +const char INSTALL_PATH[] = "/data/user/ace/run"; +const char DATA_PATH[] = "/data/user/ace/data"; +const char SYSTEM_BUNDLE_PATH[] = "/data/system/ace/sys"; +const char THIRD_SYSTEM_BUNDLE_PATH[] = "/data/system/ace/vendor"; +const char UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON[] = "/data/user/ace/etc/uninstalled_delbundle.json"; +const char THIRD_SYSTEM_BUNDLE_JSON[] = "/data/user/ace/etc/third_system_bundle.json"; +const char JSON_PATH[] = "/data/user/ace/etc/bundles/"; +const char JSON_PATH_NO_SLASH_END[] = "/data/user/ace/etc/bundles"; // store bundle permissions for IAM -const char PERMISSIONS_PATH[] = "user/ace/etc/permissions"; +const char PERMISSIONS_PATH[] = "/data/user/ace/etc/permissions"; const char ASSET_JS_PATH[] = "/assets/js/default"; const char ICON_NAME[] = "/icon.bin"; const char SMALL_ICON_NAME[] = "/icon_small.bin"; const char DEFAULT_ICON_SETTING[] = "$media:icon"; const char INSTALL_FILE_SUFFIX[] = ".bin"; -const char TMP_RESOURCE_DIR[] = "user/ace/run/tmpResource"; +const char TMP_RESOURCE_DIR[] = "/data/user/ace/run/tmpResource"; const char RESOURCES_RAW_FILE[] = "/resources/rawfile"; const char RAW_FILE[] = "/rawfile"; const uint16_t READ_SIZE = 1024 * 4; @@ -172,7 +172,7 @@ const uint8_t LONG_LENGTH = 8; const uint16_t MAX_INT = 256; const uint8_t MAX_VERSION_NAME_LEN = 20; const uint8_t MAX_LABLE_LEN = 30; -const uint8_t MAX_THIRD_BUNDLE_NUMBER = 30; +const uint8_t MAX_THIRD_BUNDLE_NUMBER = 50; struct SignatureInfo { char *bundleName; @@ -195,7 +195,11 @@ const char JSON_SUB_KEY_GID[] = "gid"; #endif struct ProfileVersion { +#ifdef __LITEOS_M__ + int32_t versionCode; +#else uint32_t versionCode; +#endif char *versionName; }; diff --git a/services/bundlemgr_lite/include/bundle_extractor.h b/services/bundlemgr_lite/include/bundle_extractor.h index ade31787fca31e8aad53cc0f6cb7fc2900b6918b..cbfec2d753625f7ee08e8912c4c653e2c3258fd7 100755 --- a/services/bundlemgr_lite/include/bundle_extractor.h +++ b/services/bundlemgr_lite/include/bundle_extractor.h @@ -16,7 +16,6 @@ #ifndef OHOS_BUNDLE_EXTRACTOR_H #define OHOS_BUNDLE_EXTRACTOR_H -#include "stdint.h" #include #include diff --git a/services/bundlemgr_lite/include/bundle_installer.h b/services/bundlemgr_lite/include/bundle_installer.h index b9945ff9326ed63b1eecf90a2611ed3a96794f02..db64b2569ac4712913d9583f8976077ecd4be1a8 100755 --- a/services/bundlemgr_lite/include/bundle_installer.h +++ b/services/bundlemgr_lite/include/bundle_installer.h @@ -70,9 +70,9 @@ private: #define CHECK_PRO_RESULT(errcode, bundleInfo, permissions, abilityRes) \ do { \ - if (errcode != ERR_OK) { \ + if ((errcode) != ERR_OK) { \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ - AdapterFree(permissions.permissionTrans); \ + AdapterFree((permissions).permissionTrans); \ AdapterFree(abilityRes); \ return errcode; \ } \ @@ -80,19 +80,19 @@ private: #define CLEAR_INSTALL_ENV(bundleInfo) \ do { \ - if (bundleInfo != nullptr) { \ + if ((bundleInfo) != nullptr) { \ BundleDaemonClient::GetInstance().RemoveInstallDirectory( \ - bundleInfo->codePath, bundleInfo->dataPath, false); \ + (bundleInfo)->codePath, (bundleInfo)->dataPath, false); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ } \ } while (0) #define CHECK_PRO_PART_ROLLBACK(errcode, path, permissions, bundleInfo, abilityRes) \ do { \ - if (errcode != ERR_OK && bundleInfo != nullptr) { \ - BundleDaemonClient::GetInstance().RemoveFile(path.c_str()); \ + if ((errcode) != ERR_OK && (bundleInfo) != nullptr) { \ + BundleDaemonClient::GetInstance().RemoveFile((path).c_str()); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ - AdapterFree(permissions.permissionTrans); \ + AdapterFree((permissions).permissionTrans); \ AdapterFree(abilityRes); \ return errcode; \ } \ @@ -100,11 +100,11 @@ private: #define CHECK_PRO_ROLLBACK(errcode, permissions, bundleInfo, abilityRes, randStr) \ do { \ - if (errcode != ERR_OK && bundleInfo != nullptr) { \ - AdapterFree(permissions.permissionTrans); \ + if ((errcode) != ERR_OK && (bundleInfo) != nullptr) { \ + AdapterFree((permissions).permissionTrans); \ AdapterFree(abilityRes); \ - ManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \ - BundleUtil::DeleteJsonFile(bundleInfo->bundleName, randStr); \ + ManagerService::GetInstance().RemoveBundleInfo((bundleInfo)->bundleName); \ + BundleUtil::DeleteJsonFile((bundleInfo)->bundleName, randStr); \ CLEAR_INSTALL_ENV(bundleInfo); \ return errcode; \ } \ diff --git a/services/bundlemgr_lite/include/bundle_manager_service.h b/services/bundlemgr_lite/include/bundle_manager_service.h index 472762fd8b8047c69a5a39d99968cb59ce403a8f..ec6bb6f52a3cfe2c0311852670d8f2b2f40796a6 100755 --- a/services/bundlemgr_lite/include/bundle_manager_service.h +++ b/services/bundlemgr_lite/include/bundle_manager_service.h @@ -44,6 +44,7 @@ public: bool UpdateBundleInfo(BundleInfo *info); uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len); + uint32_t GetBundleSize(const char *bundleName); std::vector GetServiceId() const; int32_t GenerateUid(const char *bundleName, int8_t bundleStyle); void RecycleUid(const char *bundleName); diff --git a/services/bundlemgr_lite/include/bundle_map.h b/services/bundlemgr_lite/include/bundle_map.h index c68b4c0479c78e54ef5ccaad561ce8a5fd09ad7d..7a72cc1f886ac90c94b7e29925bbc2e3b34bea10 100644 --- a/services/bundlemgr_lite/include/bundle_map.h +++ b/services/bundlemgr_lite/include/bundle_map.h @@ -35,6 +35,7 @@ public: bool Update(BundleInfo *bundleInfo); BundleInfo *Get(const char *bundleName) const; uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; + uint8_t GetBundleInfosNoReplication(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) const; void Erase(const char *bundleName); void EraseAll(); 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..d9ff3bc24c743538f34fe5609057778583985ef2 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -37,6 +37,9 @@ 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 void UpdateBundleInfoList(); + static uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); static BundleMgrSliteFeature *GetInstance() { diff --git a/services/bundlemgr_lite/include/bundle_ms_feature.h b/services/bundlemgr_lite/include/bundle_ms_feature.h index 8a872f3eb79d880e2d22488681467b72ee3261c0..f33cfdbb3b887ca7323b696d9f5661495a50d288 100755 --- a/services/bundlemgr_lite/include/bundle_ms_feature.h +++ b/services/bundlemgr_lite/include/bundle_ms_feature.h @@ -44,6 +44,7 @@ public: static uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len); static uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInfos, int32_t *len); static uint8_t GetBundleNameForUid(int32_t uid, char **bundleName); + static uint32_t GetBundleSize(const char *bundleName); private: BundleMsFeature(); @@ -60,6 +61,7 @@ private: static uint8_t ChangeInnerCallbackServiceId(const uint8_t funcId, IpcIo *req, IpcIo *reply); static uint8_t HasSystemCapability(const uint8_t funcId, IpcIo *req, IpcIo *reply); static uint8_t GetSystemAvailableCapabilities(const uint8_t funcId, IpcIo *req, IpcIo *reply); + static uint8_t GetInnerBundleSize(const uint8_t funcId, IpcIo *req, IpcIo *reply); Identity identity_; static BundleInvokeType BundleMsInvokeFuc[BMS_INNER_BEGIN]; diff --git a/services/bundlemgr_lite/include/bundle_parser.h b/services/bundlemgr_lite/include/bundle_parser.h index 51dfa6637c06dc8033068604ec9d55af89a2251a..6d3e750b73bf30981c2899d60ed3623e5c6f6480 100755 --- a/services/bundlemgr_lite/include/bundle_parser.h +++ b/services/bundlemgr_lite/include/bundle_parser.h @@ -71,14 +71,14 @@ private: #define CHECK_NULL(object, errorCode) \ do { \ - if (object == nullptr) { \ + if ((object) == nullptr) { \ return errorCode; \ } \ } while (0) #define CHECK_LENGTH(length, maxLength, errorCode) \ do { \ - if (length > maxLength) { \ + if ((length) > (maxLength)) { \ return errorCode; \ } \ } while (0) @@ -92,7 +92,7 @@ private: #define CHECK_PARSE_RESULT(errorCode, object, bundleProfile) \ do { \ - if (errorCode != ERR_OK) { \ + if ((errorCode) != ERR_OK) { \ FREE_BUNDLE_PROFILE(bundleProfile); \ cJSON_Delete(object); \ return errorCode; \ @@ -101,9 +101,9 @@ private: #define FREE_BUNDLE_PROFILE(bundleProfile) \ do { \ - AdapterFree(bundleProfile.abilityInfos); \ + AdapterFree((bundleProfile).abilityInfos); \ for (uint8_t i = 0; i < METADATA_SIZE; i++) { \ - AdapterFree(bundleProfile.moduleInfo.metaData[i]); \ + AdapterFree((bundleProfile).moduleInfo.metaData[i]); \ } \ } while (0) } // namespace OHOS diff --git a/services/bundlemgr_lite/include/bundle_util.h b/services/bundlemgr_lite/include/bundle_util.h index 4a2e11c3917f6e655665a915d40d7f9ce453c6a8..b73bf2a28c60ed5284514e394e7b6d443140cdf8 100755 --- a/services/bundlemgr_lite/include/bundle_util.h +++ b/services/bundlemgr_lite/include/bundle_util.h @@ -26,6 +26,11 @@ #endif #include "cJSON.h" +#ifdef __LITEOS_M__ +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#endif + namespace OHOS { class BundleUtil { public: diff --git a/services/bundlemgr_lite/include/bundlems_log.h b/services/bundlemgr_lite/include/bundlems_log.h index 933673cafb2c22485a15dbc0ce8bc71e3e8f1d3e..c5601d4614074ea9c2198a3590987602bf19f936 100755 --- a/services/bundlemgr_lite/include/bundlems_log.h +++ b/services/bundlemgr_lite/include/bundlems_log.h @@ -24,7 +24,7 @@ namespace OHOS { #undef LOG_DOMAIN #define LOG_DOMAIN 0xD001300 -#ifdef APP_PLATFORM_WATCHGT +#ifdef __LITEOS_M__ #ifndef HILOG_DEBUG #define HILOG_DEBUG(mod, format, ...) #endif @@ -64,7 +64,7 @@ namespace OHOS { #define CHECK_NULLPTR_RETURN_PTR(point, name, fmt) \ do { \ - if (point == nullptr) { \ + if ((point) == nullptr) { \ PRINTE(name, fmt); \ return nullptr; \ } \ @@ -72,7 +72,7 @@ namespace OHOS { #define CHECK_NULLPTR_RETURN(point, name, fmt) \ do { \ - if (point == nullptr) { \ + if ((point) == nullptr) { \ PRINTE(name, fmt); \ return; \ } \ @@ -80,7 +80,7 @@ namespace OHOS { #define CHECK_NULLPTR_RETURN_CODE(point, name, fmt, code) \ do { \ - if (point == nullptr) { \ + if ((point) == nullptr) { \ PRINTE(name, fmt); \ return code; \ } \ diff --git a/services/bundlemgr_lite/include/gt_bundle_extractor.h b/services/bundlemgr_lite/include/gt_bundle_extractor.h index 037a1565eab8e2bcc612f4919ccab7ab8641b382..e504de959199ae801ac4fe2cd578320975fc41c2 100644 --- a/services/bundlemgr_lite/include/gt_bundle_extractor.h +++ b/services/bundlemgr_lite/include/gt_bundle_extractor.h @@ -17,7 +17,6 @@ #define OHOS_GT_BUNDLE_EXTRACTOR_H #include "bundle_common.h" -#include "stdint.h" namespace OHOS { class GtBundleExtractor { diff --git a/services/bundlemgr_lite/include/gt_bundle_installer.h b/services/bundlemgr_lite/include/gt_bundle_installer.h index ed558e541c792c9ae8ebaf0372c50a78b7fb5ff5..ed01cc976cdc8952aeb98e9b5cd5c1b547efe81e 100755 --- a/services/bundlemgr_lite/include/gt_bundle_installer.h +++ b/services/bundlemgr_lite/include/gt_bundle_installer.h @@ -19,7 +19,6 @@ #ifdef __cplusplus extern "C" { #endif -#include "generate-bytecode.h" #ifdef __cplusplus } #endif @@ -66,28 +65,27 @@ private: uint8_t AddBundleResList(const char *bundleName, uint32_t labelId, uint32_t iconId); uint8_t MoveRawFileToDataPath(const BundleInfo *bundleInfo); uint8_t TransformJsToBc(const char *codePath, InstallRecord &record); - }; #define FREE_PRO_RESOURCE(fp, permissions, bundleInfo) \ do { \ - if (fp >= 0) { \ + if ((fp) >= 0) { \ close(fp); \ } \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ - UI_Free(permissions.permissionTrans); \ + UI_Free((permissions).permissionTrans); \ } while (0) #define FREE_SIGNATUREINFO(signatureInfo) \ do { \ - AdapterFree(signatureInfo.appId); \ + AdapterFree((signatureInfo).appId); \ AdapterFree(signatureInfo.bundleName); \ BundleUtil::FreeStrArrayMemory(signatureInfo.restricPermission, signatureInfo.restricNum); \ } while (0) #define CHECK_PRO_RESULT(errcode, fp, permissions, bundleInfo, signatureInfo) \ do { \ - if (errcode != ERR_OK) { \ + if ((errcode) != ERR_OK) { \ FREE_PRO_RESOURCE(fp, permissions, bundleInfo); \ FREE_SIGNATUREINFO(signatureInfo); \ return errcode; \ @@ -96,7 +94,7 @@ private: #define CLEAR_INSTALL_ENV(bundleInfo) \ do { \ - if (bundleInfo != nullptr) { \ + if ((bundleInfo) != nullptr) { \ BundleUtil::RemoveDir(bundleInfo->codePath); \ BundleUtil::RemoveDir(bundleInfo->dataPath); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ @@ -105,21 +103,21 @@ private: #define CHECK_PRO_PART_ROLLBACK(errcode, path, permissions, bundleInfo, signatureInfo) \ do { \ - if (errcode != ERR_OK) { \ + if ((errcode) != ERR_OK) { \ BundleUtil::RemoveDir(path); \ AdapterFree(path); \ BundleInfoUtils::FreeBundleInfo(bundleInfo); \ FREE_SIGNATUREINFO(signatureInfo); \ - UI_Free(permissions.permissionTrans); \ + UI_Free((permissions).permissionTrans); \ return errcode; \ } \ } while (0) #define CHECK_PRO_ROLLBACK(errcode, permissions, bundleInfo, signatureInfo, randStr) \ do { \ - if (errcode != ERR_OK && bundleInfo != nullptr) { \ + if ((errcode) != ERR_OK && (bundleInfo) != nullptr) { \ FREE_SIGNATUREINFO(signatureInfo); \ - UI_Free(permissions.permissionTrans); \ + UI_Free((permissions).permissionTrans); \ GtManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \ BundleUtil::DeleteJsonFile(bundleInfo->bundleName, randStr); \ CLEAR_INSTALL_ENV(bundleInfo); \ diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index 4f0564bcce48a2c954372bf0d5449f7e255ab702..a38143838056001794e29d41e33710172c47d364 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -61,6 +61,7 @@ public: uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); + uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); void ScanPackages(); BundleInfo *QueryBundleInfo(const char *bundleName); void RemoveBundleInfo(const char *bundleName); @@ -69,6 +70,7 @@ public: uint32_t GetNumOfThirdBundles(); void RemoveBundleResList(const char *bundleName); void AddBundleResList(const BundleRes *bundleRes); + void UpdateBundleInfoList(); void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process); void AddNumOfThirdBundles(); void ReduceNumOfThirdBundles(); @@ -78,14 +80,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); @@ -95,13 +97,16 @@ private: bool isSystemApp, bool isUpdated, const char *appId); void RemoveSystemAppPathList(List *systemPathList); void ClearSystemBundleInstallMsg(); +#ifdef BC_TRANS_ENABLE void TransformJsToBcWhenRestart(const char *codePath, const char *bundleName); void TransformJsToBc(const char *codePath, const char *bundleJsonPath, cJSON *installRecordObj); +#endif 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); GtBundleInstaller *installer_; BundleMap *bundleMap_; @@ -109,6 +114,7 @@ private: BundleInstallMsg *bundleInstallMsg_; char *jsEngineVer_; uint32_t installedThirdBundleNum_; + List systemPathList_; }; } diff --git a/services/bundlemgr_lite/include/gt_bundle_parser.h b/services/bundlemgr_lite/include/gt_bundle_parser.h index be0443fdbbd01d6d64d68a17bafcf115df1e9669..d3b8d2745fc0e0d5e398d0a4bf60bc733010388d 100644 --- a/services/bundlemgr_lite/include/gt_bundle_parser.h +++ b/services/bundlemgr_lite/include/gt_bundle_parser.h @@ -56,21 +56,21 @@ private: #define CHECK_NULL(object, errorCode) \ do { \ - if (object == nullptr) { \ + if ((object) == nullptr) { \ return errorCode; \ } \ } while (0) #define CHECK_LENGTH(length, maxLength, errorCode) \ do { \ - if (length > maxLength) { \ + if ((length) > (maxLength)) { \ return errorCode; \ } \ } while (0) #define CHECK_IS_TRUE(result, errorCode) \ do { \ - if (!result) { \ + if (!(result)) { \ return errorCode; \ } \ } while (0) @@ -78,20 +78,20 @@ private: #define FREE_BUNDLE_PROFILE(bundleProfile) \ do { \ for (int32_t i = 0; i < METADATA_SIZE; i++) { \ - AdapterFree(bundleProfile.moduleInfo.metaData[i]); \ + AdapterFree((bundleProfile).moduleInfo.metaData[i]); \ } \ } while (0) #define FREE_BUNDLE_RES(bundleRes) \ do { \ - if (bundleRes.abilityRes != nullptr) { \ - AdapterFree(bundleRes.abilityRes); \ + if ((bundleRes).abilityRes != nullptr) { \ + AdapterFree((bundleRes).abilityRes); \ } \ } while (0) #define CHECK_PARSE_RESULT(errorCode, object, bundleProfile, bundleRes) \ do { \ - if (errorCode != ERR_OK) { \ + if ((errorCode) != ERR_OK) { \ FREE_BUNDLE_PROFILE(bundleProfile); \ FREE_BUNDLE_RES(bundleRes); \ cJSON_Delete(object); \ diff --git a/services/bundlemgr_lite/src/bundle_manager_service.cpp b/services/bundlemgr_lite/src/bundle_manager_service.cpp index 169fb03d230b396f3a64edc4fe66d5fcc0fbc6b1..b4e28ab037b39e41623c8553d917b1670410674f 100755 --- a/services/bundlemgr_lite/src/bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/bundle_manager_service.cpp @@ -625,6 +625,25 @@ uint8_t ManagerService::GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, return bundleMap_->GetBundleInfos(flags, bundleInfos, len); } +uint32_t ManagerService::GetBundleSize(const char *bundleName) +{ + if (bundleName == nullptr) { + return 0; + } + BundleInfo *installedInfo = bundleMap_->Get(bundleName); + if (installedInfo == nullptr) { + return 0; + } + char *codePath = installedInfo->codePath; + uint32_t codeBundleSize = BundleUtil::GetFileFolderSize(codePath); + if (codeBundleSize == 0) { + return 0; + } + char *dataPath = installedInfo->dataPath; + uint32_t dataBundleSize = BundleUtil::GetFileFolderSize(dataPath); + HILOG_INFO(HILOG_MODULE_APP, "bundle size is %{public}d\n", codeBundleSize + dataBundleSize); + return codeBundleSize + dataBundleSize; +} std::string ManagerService::GetCodeDirPath() const { diff --git a/services/bundlemgr_lite/src/bundle_map.cpp b/services/bundlemgr_lite/src/bundle_map.cpp index 628ef71736d5d247fd19e05b42d307f041e31ade..767ae113638636f8ec271e951175ad441028b959 100755 --- a/services/bundlemgr_lite/src/bundle_map.cpp +++ b/services/bundlemgr_lite/src/bundle_map.cpp @@ -204,6 +204,39 @@ uint8_t BundleMap::GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32 return ERR_OK; } +uint8_t BundleMap::GetBundleInfosNoReplication(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const +{ + if (bundleInfos == nullptr) { + return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR; + } +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER + MutexAcquire(&g_bundleListMutex, 0); +#else + MutexAcquire(&g_bundleListMutex, BUNDLELIST_MUTEX_TIMEOUT); +#endif + if (bundleInfos_->IsEmpty()) { + MutexRelease(&g_bundleListMutex); + return ERR_APPEXECFWK_QUERY_NO_INFOS; + } + + BundleInfo *infos = reinterpret_cast(AdapterMalloc(sizeof(BundleInfo) * bundleInfos_->Size())); + if (infos == nullptr || memset_s(infos, sizeof(BundleInfo) * bundleInfos_->Size(), 0, + sizeof(BundleInfo) * bundleInfos_->Size()) != EOK) { + AdapterFree(infos); + MutexRelease(&g_bundleListMutex); + return ERR_APPEXECFWK_QUERY_INFOS_INIT_ERROR; + } + *bundleInfos = infos; + + for (auto node = bundleInfos_->Begin(); node != bundleInfos_->End(); node = node->next_) { + BundleInfoUtils::CopyBundleInfoNoReplication(flags, infos++, *(node->value_)); + } + + *len = bundleInfos_->Size(); + MutexRelease(&g_bundleListMutex); + return ERR_OK; +} + uint8_t BundleMap::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) const { if (bundleName == nullptr) { diff --git a/services/bundlemgr_lite/src/bundle_mgr_service.cpp b/services/bundlemgr_lite/src/bundle_mgr_service.cpp index cbad14ab29121f57db26b4bbff5f1bfdfd9a67df..59eddf6b8bb91c2d272be05fcb039142da16e698 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_service.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_service.cpp @@ -38,8 +38,12 @@ static void Init() { SamgrLite *sm = SAMGR_GetInstance(); CHECK_NULLPTR_RETURN(sm, "BundleManagerService", "get samgr error"); +#ifdef __LITEOS_M__ + sm->RegisterService(BundleMgrService::GetInstance()); +#else BOOL result = sm->RegisterService(BundleMgrService::GetInstance()); PRINTI("BundleManagerService", "bms starts %{public}s", result ? "successfully" : "unsuccessfully"); +#endif } SYSEX_SERVICE_INIT(Init); @@ -58,8 +62,8 @@ BOOL BundleMgrService::ServiceInitialize(Service *service, Identity identity) bundleManagerService->identity_ = identity; Request request = { .msgId = BMS_SCAN_PACKAGE_MSG, - .data = nullptr, .len = 0, + .data = nullptr, .msgValue = 0, }; (void) SAMGR_SendRequest(bundleManagerService->GetIdentity(), &request, nullptr); @@ -84,6 +88,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; } @@ -92,7 +98,11 @@ BOOL BundleMgrService::ServiceMessageHandle(Service *service, Request *request) TaskConfig BundleMgrService::GetServiceTaskConfig(Service *service) { +#ifdef __LITEOS_M__ + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK}; +#else TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK}; +#endif return config; } } // namespace OHOS diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index 5b12cff9841c1b5405284a983fd7aaaf9596f714..7fc5cf5d24e2ac094e3f733bffe2b8bf6b4772f8 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -34,6 +34,9 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos, .GetInstallState = BundleMgrSliteFeature::GetInstallState, .GetBundleSize = BundleMgrSliteFeature::GetBundleSize, + .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback, + .UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList, + .GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -118,7 +121,7 @@ uint8_t BundleMgrSliteFeature::GetBundleInfo(const char *bundleName, int32_t fla return OHOS::GtManagerService::GetInstance().GetBundleInfo(bundleName, flags, *bundleInfo); } -uint8_t BundleMgrSliteFeature::GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len) +uint8_t BundleMgrSliteFeature::GetBundleInfos(const int32_t flags, BundleInfo **bundleInfos, int32_t *len) { return OHOS::GtManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len); } @@ -132,4 +135,19 @@ uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName) { return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName); } + +bool BundleMgrSliteFeature::RegisterInstallerCallback(InstallerCallback installerCallback) +{ + return OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(installerCallback); +} + +void BundleMgrSliteFeature::UpdateBundleInfoList() +{ + OHOS::GtManagerService::GetInstance().UpdateBundleInfoList(); +} + +uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) +{ + return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); +} } // namespace OHOS diff --git a/services/bundlemgr_lite/src/bundle_ms_feature.cpp b/services/bundlemgr_lite/src/bundle_ms_feature.cpp index 6edbe6cfcd9db52ea606524292a518bc1e4cc8b1..785545f9a1cf395cc3efee3a9acd0099a70bf0fe 100755 --- a/services/bundlemgr_lite/src/bundle_ms_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_ms_feature.cpp @@ -33,7 +33,9 @@ #include "want_utils.h" namespace OHOS { +#ifdef __LINUX__ constexpr static uint32_t MAX_IPC_STRING_LENGTH = 8192UL; +#endif static BmsImpl g_bmsImpl = { SERVER_IPROXY_IMPL_BEGIN, .Invoke = BundleMsFeature::Invoke, @@ -42,6 +44,7 @@ static BmsImpl g_bmsImpl = { .GetBundleInfos = BundleMsFeature::GetBundleInfos, .QueryKeepAliveBundleInfos = BundleMsFeature::QueryKeepAliveBundleInfos, .GetBundleNameForUid = BundleMsFeature::GetBundleNameForUid, + .GetBundleSize = BundleMsFeature::GetBundleSize, IPROXY_END }; @@ -54,6 +57,7 @@ BundleInvokeType BundleMsFeature::BundleMsInvokeFuc[BMS_INNER_BEGIN] { HandleGetBundleInfos, HandleGetBundleInfos, HasSystemCapability, + GetInnerBundleSize, GetSystemAvailableCapabilities, }; @@ -117,7 +121,7 @@ BOOL BundleMsFeature::OnFeatureMessage(Feature *feature, Request *request) return TRUE; } -void static InnerFreeDataBuff(void *ptr) +static void InnerFreeDataBuff(void *ptr) { if (ptr != nullptr) { cJSON_free(ptr); @@ -248,6 +252,25 @@ uint8_t BundleMsFeature::GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, Ip return OHOS_SUCCESS; } +uint8_t BundleMsFeature::GetInnerBundleSize(const uint8_t funcId, IpcIo *req, IpcIo *reply) +{ + if ((req == nullptr) || (reply == nullptr)) { + return ERR_APPEXECFWK_OBJECT_NULL; + } + size_t size = 0; + uint32_t bundleSize = 0; + char *bundleName = reinterpret_cast(IpcIoPopString(req, &size)); + if (bundleName == nullptr) { + IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); + IpcIoPushUint32(reply, bundleSize); + return OHOS_SUCCESS; + } + bundleSize = GetBundleSize(bundleName); + IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); + IpcIoPushUint32(reply, bundleSize); + return OHOS_SUCCESS; +} + uint8_t BundleMsFeature::HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, IpcIo *reply) { if ((req == nullptr) || (reply == nullptr)) { @@ -427,6 +450,11 @@ uint8_t BundleMsFeature::GetBundleInfos(const int flags, BundleInfo **bundleInfo return OHOS::ManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len); } +uint32_t BundleMsFeature::GetBundleSize(const char *bundleName) +{ + return OHOS::ManagerService::GetInstance().GetBundleSize(bundleName); +} + uint8_t BundleMsFeature::QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len) { if ((bundleInfos == nullptr) || (len == nullptr)) { diff --git a/services/bundlemgr_lite/src/bundle_util.cpp b/services/bundlemgr_lite/src/bundle_util.cpp index 27813a68fca4df3ec6e03f7999689f39d8e8762d..fbf1903536ad1c0ca93b3bf691fbcfc7ab30a369 100755 --- a/services/bundlemgr_lite/src/bundle_util.cpp +++ b/services/bundlemgr_lite/src/bundle_util.cpp @@ -29,21 +29,25 @@ #else #include "adapter.h" #include "bundlems_log.h" +#include "cstdio" #include "dirent.h" #include "fcntl.h" #include "los_tick.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #endif -#include +#include #include "utils.h" namespace OHOS { const char DIGITSTR[] = "0123456789"; const uint8_t MAX_CHARACTER_VALUE = 26; const uint8_t NUM_OF_TYPE = 3; +#ifdef __LITEOS_M__ +const int32_t MAX_JSON_SIZE = 1024 * 64; +#else const uint32_t MAX_JSON_SIZE = 1024 * 64; +#endif /* * path should not include ".." or "./" or ".\0" @@ -197,7 +201,7 @@ uint32_t BundleUtil::GetFileFolderSize(const char *filePath) list->PushFront(Utils::Strdup(filePath)); uint32_t fileFolderSize = 0; - while(!list->IsEmpty()) { + while (!list->IsEmpty()) { char *curPath = list->Front(); if (curPath == nullptr) { break; @@ -242,7 +246,7 @@ uint32_t BundleUtil::GetCurrentFolderSize(const char *dirPath, List* lis continue; } - if (IsFile(filePath)) { + if (!IsDir(filePath)) { if (stat(filePath, &buf) != 0 || buf.st_size <= 0) { fileSize = 0; break; @@ -573,7 +577,7 @@ void BundleUtil::CreateRandStr(char *str, uint32_t len) if (str == nullptr) { return; } -#ifndef APP_PLATFORM_WATCHGT +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER srand(time(NULL)); #else srand(LOS_TickCountGet()); diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index 1750d7712e08f225a2b052f23dcb72e645c04606..5a3f6eb19b891a4f23e6b172c6da907504c5e518 100755 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -185,12 +185,14 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName if (!BundleUtil::CheckRealPath(path)) { return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR; } - +#ifndef __LITEOS_M__ int32_t totalFileSize = APPVERI_GetUnsignedFileLength(path); if (totalFileSize == V_ERR) { return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } - +#else + int32_t totalFileSize = 0; +#endif char *emptyJsPathComp[] = {const_cast(TMP_RESOURCE_DIR), const_cast(ASSET_JS_PATH)}; char *emptyJsPath = BundleUtil::Strscat(emptyJsPathComp, sizeof(emptyJsPathComp) / sizeof(char *)); if (emptyJsPath == nullptr) { @@ -250,7 +252,9 @@ uint8_t GtBundleExtractor::ExtractBundleParam(const char *path, int32_t &fpStart if (errorCode != ERR_OK) { return errorCode; } - +#ifdef __LITEOS_M__ + close(fp); +#endif if (strlen(*bundleName) > MAX_BUNDLE_NAME_LEN || strlen(*bundleName) < MIN_BUNDLE_NAME_LEN) { return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME_LENGTH; } diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 05e5de3eaae94fddc5c9496c43569e9b2c296cf0..1c1bfb37dcccf0813d670e3aaddc4c4253e37c0d 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -25,13 +25,13 @@ extern "C" { #include "appexecfwk_errors.h" #include "bundle_util.h" #include "bundlems_log.h" +#include "cstdio" #include "dirent.h" #include "fcntl.h" #include "global.h" #include "gt_bundle_extractor.h" #include "gt_bundle_manager_service.h" #include "gt_bundle_parser.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #include "utils.h" @@ -105,6 +105,7 @@ uint8_t GtBundleInstaller::PreCheckBundle(const char *path, int32_t &fp, Signatu uint8_t GtBundleInstaller::VerifySignature(const char *path, SignatureInfo &signatureInfo, uint32_t &fileSize, uint8_t bundleStyle) { +#ifndef __LITEOS_M__ VerifyResult verifyResult; // verify signature (void) APPVERI_SetDebugMode(true); @@ -145,6 +146,7 @@ uint8_t GtBundleInstaller::VerifySignature(const char *path, SignatureInfo &sign } } APPVERI_FreeVerifyRst(&verifyResult); +#endif return ERR_OK; } @@ -199,7 +201,8 @@ uint8_t GtBundleInstaller::Install(const char *path, InstallerCallback installer if (errorCode != ERR_OK) { return errorCode; } - (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SIXTH_FINISHED_PROCESS, installerCallback); + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, + 0, BMS_SIXTH_FINISHED_PROCESS, installerCallback); // rename bundle.json if (!RenameJsonFile(installRecord.bundleName, randStr)) { @@ -232,10 +235,20 @@ 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); + (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); - (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_SECOND_FINISHED_PROCESS, installerCallback); + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, + 0, BMS_SECOND_FINISHED_PROCESS, installerCallback); +#ifdef __LITEOS_M__ + fp = open(path, O_RDONLY, S_IREAD); + if (fp < 0) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] process bundle install fp open fail"); + errorCode = ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS; + } + CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); +#endif // parse HarmoyProfile.json, get permissions and bundleInfo errorCode = GtBundleParser::ParseHapProfile(fp, fileSize, permissions, bundleRes, &bundleInfo); CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo); @@ -263,7 +276,8 @@ 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); + (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(); @@ -274,7 +288,8 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra errorCode = TransformJsToBc(tmpCodePath, installRecord); CHECK_PRO_PART_ROLLBACK(errorCode, tmpCodePath, permissions, bundleInfo, signatureInfo); #endif - (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FOURTH_FINISHED_PROCESS, installerCallback); + (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); @@ -284,7 +299,8 @@ 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); - (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, BMS_FIFTH_FINISHED_PROCESS, installerCallback); + (void) GtManagerService::GetInstance().ReportInstallCallback(OPERATION_DOING, 0, + BMS_FIFTH_FINISHED_PROCESS, installerCallback); // store permissions errorCode = StorePermissions(installRecord.bundleName, permissions.permissionTrans, permissions.permNum, isUpdate); @@ -464,6 +480,7 @@ uint8_t GtBundleInstaller::HandleFileAndBackUpRecord(const InstallRecord &record return ERR_OK; } +#ifdef BC_TRANS_ENABLE uint8_t GtBundleInstaller::TransformJsToBc(const char *codePath, InstallRecord &record) { if (codePath == nullptr) { @@ -482,11 +499,10 @@ uint8_t GtBundleInstaller::TransformJsToBc(const char *codePath, InstallRecord & return ERR_APPEXECFWK_INSTALL_FAILED_TRANSFORM_BC_FILE_ERROR; } AdapterFree(jsPath); -#ifdef BC_TRANS_ENABLE record.transformResult = 0; -#endif return ERR_OK; } +#endif uint8_t GtBundleInstaller::UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelId, uint32_t iconId, BundleInfo *bundleInfo, bool isUpdate) @@ -576,11 +592,11 @@ uint8_t GtBundleInstaller::Uninstall(const char *bundleName) if (sprintf_s(bundleJsonPath, PATH_LENGTH, "%s%s%s", JSON_PATH, bundleName, JSON_SUFFIX) < 0) { return ERR_APPEXECFWK_UNINSTALL_FAILED_INTERNAL_ERROR; } - +#ifndef __LITEOS_M__ if (DeletePermissions(const_cast(bundleName)) < 0) { return ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_PERMISSIONS_ERROR; } - +#endif bool res = CheckIsThirdSystemBundle(bundleName); if (!(BundleUtil::RemoveDir(bundleInfo->codePath) && BundleUtil::RemoveDir(bundleInfo->dataPath))) { GtManagerService::GetInstance().RemoveBundleInfo(bundleName); @@ -733,10 +749,12 @@ uint8_t GtBundleInstaller::StorePermissions(const char *bundleName, PermissionTr bool isUpdate) { if (permNum == 0) { +#ifndef __LITEOS_M__ if (isUpdate) { int32_t ret = DeletePermissions(bundleName); HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] delete permissions, result is %d", ret); } +#endif return ERR_OK; } @@ -747,11 +765,12 @@ uint8_t GtBundleInstaller::StorePermissions(const char *bundleName, PermissionTr if (!BundleUtil::IsDir(PERMISSIONS_PATH)) { BundleUtil::MkDirs(PERMISSIONS_PATH); } - +#ifndef __LITEOS_M__ if (SaveOrUpdatePermissions(const_cast(bundleName), permissions, permNum, static_cast(isUpdate)) != 0) { return ERR_APPEXECFWK_INSTALL_FAILED_STORE_PERMISSIONS_ERROR; } +#endif 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 3b0a010aab88c714fcbad42c867ade67415f778b..fc35e022b40da646c8c984329930c6dec82817b9 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -14,7 +14,8 @@ */ #include "gt_bundle_manager_service.h" - +#include "aafwk_event_error_id.h" +#include "aafwk_event_error_code.h" #include "ability_info_utils.h" #include "ability_message_id.h" #include "appexecfwk_errors.h" @@ -23,6 +24,7 @@ #include "bundle_util.h" #include "bundlems_log.h" #include "cmsis_os2.h" +#include "cstdio" #include "dirent.h" #include "fcntl.h" #include "gt_bundle_extractor.h" @@ -30,14 +32,14 @@ #include "gt_extractor_util.h" #include "jerryscript_adapter.h" #include "los_tick.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #include "utils.h" #include "want.h" +using namespace OHOS::ACELite; + 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; @@ -64,15 +66,18 @@ GtManagerService::~GtManagerService() bool GtManagerService::Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback) { + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install start"); if (installer_ == nullptr) { installer_ = new GtBundleInstaller(); } if (hapPath == nullptr) { return false; } +#ifndef __LITEOS_M__ if (installerCallback == nullptr) { return false; } +#endif char *path = reinterpret_cast(AdapterMalloc(strlen(hapPath) + 1)); if (path == nullptr) { return false; @@ -82,6 +87,7 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP return false; } +#ifndef __LITEOS_M__ // delete resource temp dir first (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); // create new bundleInstallMsg @@ -97,14 +103,12 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP uint8_t ret = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName), &(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath), &(bundleInstallMsg_->bigIconPath)); - if (ret != 0) { 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 +123,13 @@ 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(); +#else + uint8_t ret = installer_->Install(path, installerCallback); + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] install ret is %d", ret); +#endif + (void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR); AdapterFree(path); return true; } @@ -136,9 +144,11 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Parsed bundleName to be uninstalled is null"); return false; } +#ifndef __LITEOS_M__ if (installerCallback == nullptr) { return false; } +#endif char *innerBundleName = reinterpret_cast(AdapterMalloc(strlen(bundleName) + 1)); if (innerBundleName == nullptr) { return false; @@ -152,6 +162,7 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins (void) ReportUninstallCallback(OPERATION_DOING, BUNDLE_UNINSTALL_DOING, innerBundleName, BMS_UNINSTALLATION_START, installerCallback); uint8_t ret = installer_->Uninstall(innerBundleName); + HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] uninstall ret is %d", ret); if (ret == 0) { (void) ReportUninstallCallback(ret, BUNDLE_UNINSTALL_OK, innerBundleName, BMS_INSTALLATION_COMPLETED, installerCallback); @@ -176,7 +187,7 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins *installProcess = BMS_INSTALLATION_COMPLETED; return true; } - if (bundleInstallMsg_ == nullptr) { + if (bundleInstallMsg_ == nullptr || bundleInstallMsg_->bundleName == nullptr) { *installState = BUNDLE_INSTALL_FAIL; *installProcess = 0; return true; @@ -247,7 +258,51 @@ uint8_t GtManagerService::GetBundleInfos(const int flags, BundleInfo **bundleInf return bundleMap_->GetBundleInfos(flags, bundleInfos, len); } -void GtManagerService::InstallAllSystemBundle() +uint8_t GtManagerService::GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) +{ + if (bundleMap_ == nullptr) { + return ERR_APPEXECFWK_OBJECT_NULL; + } + return bundleMap_->GetBundleInfosNoReplication(flags, bundleInfos, len); +} + +bool GtManagerService::RegisterInstallerCallback(InstallerCallback installerCallback) +{ +#ifndef __LITEOS_M__ + if (installerCallback == nullptr) { + return false; + } +#endif + InstallPreBundle(systemPathList_, installerCallback); + return true; +} + +void GtManagerService::InstallPreBundle(List systemPathList, InstallerCallback installerCallback) +{ +#ifndef __LITEOS_M__ + if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) { + BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END); + InstallAllSystemBundle(installerCallback); + RemoveSystemAppPathList(&systemPathList); + return; + } +#endif + 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 +317,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() @@ -342,42 +359,43 @@ void GtManagerService::ClearSystemBundleInstallMsg() void GtManagerService::ScanPackages() { +#ifdef BC_TRANS_ENABLE 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(); - return; - } +#endif +#ifdef __LITEOS_M__ + if (!BundleUtil::MkDirs(INSTALL_PATH) || !BundleUtil::MkDirs(DATA_PATH) || + !BundleUtil::MkDirs(JSON_PATH)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ScanPackages mkdirs failed!"); + } + if (!BundleUtil::IsDir(SYSTEM_BUNDLE_PATH)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] system bundle path is not exist, unable to pre install!"); + } +#endif // 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); } - 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_); + +#ifdef __LITEOS_M__ + InstallerCallback installerCallback = nullptr; + RegisterInstallerCallback(installerCallback); +#endif } void GtManagerService::RemoveSystemAppPathList(List *systemPathList) @@ -682,6 +700,47 @@ 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 == nullptr || 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; + } + } +} + +#ifdef BC_TRANS_ENABLE void GtManagerService::TransformJsToBcWhenRestart(const char *codePath, const char *bundleName) { if (codePath == nullptr) { @@ -755,7 +814,9 @@ void GtManagerService::TransformJsToBc(const char *codePath, const char *bundleJ return; } + DisableServiceWdg(); EXECRES result = walk_directory(jsPath); + EnableServiceWdg(); 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); @@ -783,8 +844,9 @@ void GtManagerService::TransformJsToBc(const char *codePath, const char *bundleJ return; } } - (void) BundleUtil::StoreJsonContentToFile(bundleJsonPath, installRecordObj); + (void)BundleUtil::StoreJsonContentToFile(bundleJsonPath, installRecordObj); } +#endif bool GtManagerService::CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object) { @@ -998,7 +1060,7 @@ void GtManagerService::APP_FreeAllAppInfo(const AppInfoList *list) AppInfoList *currentNode = nullptr; AppInfoList *nextNode = nullptr; - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE (currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) { + LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) { if (currentNode != nullptr) { LOS_ListDelete(&(currentNode->appDoubleList)); AdapterFree(currentNode); @@ -1027,7 +1089,7 @@ void SetCurrentBundle(const char *name) } int len = strlen(name); - g_currentBundle = (char *) AdapterMalloc(len + 1); + g_currentBundle = (char *)AdapterMalloc(len + 1); if (g_currentBundle == nullptr || strncpy_s(g_currentBundle, len + 1, name, len) < 0) { AdapterFree(g_currentBundle); } @@ -1043,7 +1105,7 @@ const char *GetCurrentBundle() } int len = strlen(g_currentBundle); - char *bundleName = (char *) AdapterMalloc(len + 1); + char *bundleName = (char *)AdapterMalloc(len + 1); if (bundleName == nullptr || strncpy_s(bundleName, len + 1, g_currentBundle, len) < 0) { AdapterFree(bundleName); MutexRelease(&g_currentBundleMutex); @@ -1053,4 +1115,4 @@ const char *GetCurrentBundle() MutexRelease(&g_currentBundleMutex); return bundleName; } -} \ 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 841118118d0b26dbfc8801547234c2d75d7b1b86..c52fe44a27ff10e435af9928d44332d025e21847 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(); + const char *deviceType = GetDeviceType(); if (deviceType == nullptr) { return false; } @@ -419,7 +419,11 @@ BundleInfo *GtBundleParser::CreateBundleInfo(const char *path, const BundleProfi return nullptr; } // set abilityInfo +#ifdef __LITEOS_M__ + AbilityInfo abilityInfo = {.srcPath = jsPath, .bundleName = bundleInfo->bundleName}; +#else AbilityInfo abilityInfo = {.bundleName = bundleInfo->bundleName, .srcPath = jsPath}; +#endif if (!BundleInfoUtils::SetBundleInfoAbilityInfo(bundleInfo, abilityInfo)) { AdapterFree(abilityInfo.srcPath); BundleInfoUtils::FreeBundleInfo(bundleInfo); @@ -486,7 +490,8 @@ bool GtBundleParser::ConvertIconResToBundleInfo(const char *resPath, uint32_t ic return false; } char *pos = relativeIconPath + strlen(relativeIconPath); - for (; *pos != '/'; pos--) {}; + for (; *pos != '/'; pos--) { + }; *pos = '\0'; char *bigIconPathComp[] = { bundleInfo->codePath, const_cast(ASSETS), relativeIconPath, const_cast(ICON_NAME) @@ -602,7 +607,11 @@ uint8_t GtBundleParser::SaveBundleInfo(const BundleProfile &bundleProfile, const *bundleInfo = nullptr; return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR; } +#ifdef __LITEOS_M__ + AbilityInfo abilityInfo = {.srcPath = jsPath, .bundleName = (*bundleInfo)->bundleName}; +#else AbilityInfo abilityInfo = {.bundleName = (*bundleInfo)->bundleName, .srcPath = jsPath}; +#endif // set abilityInfo if (!BundleInfoUtils::SetBundleInfoAbilityInfo(*bundleInfo, abilityInfo)) { AdapterFree(jsPath); diff --git a/services/bundlemgr_lite/src/gt_extractor_util.cpp b/services/bundlemgr_lite/src/gt_extractor_util.cpp index 02ab2c566996892d3cb321ef7ba8da28adf0f424..3c10d017b55d9f3eb3c91fa0727025516ba24324 100755 --- a/services/bundlemgr_lite/src/gt_extractor_util.cpp +++ b/services/bundlemgr_lite/src/gt_extractor_util.cpp @@ -15,14 +15,14 @@ #include "gt_extractor_util.h" -#include +#include #include "appexecfwk_errors.h" #include "bundle_common.h" #include "bundle_util.h" #include "bundlems_log.h" +#include "cstdio" #include "dirent.h" #include "fcntl.h" -#include "stdio.h" #include "sys/stat.h" #include "unistd.h" #include "utils.h" diff --git a/services/bundlemgr_lite/src/zip_file.cpp b/services/bundlemgr_lite/src/zip_file.cpp index ef9452992822b319db0908554ce89a41ba50af98..cc329ccb4a42b7de05ed6261782cb52928357eee 100755 --- a/services/bundlemgr_lite/src/zip_file.cpp +++ b/services/bundlemgr_lite/src/zip_file.cpp @@ -26,13 +26,13 @@ namespace OHOS { namespace { -#define ZIPPOS_ADD_AND_CHECK_OVERFLOW(first, second, sum) \ -{ \ - if ((second > 0) && (first > (std::numeric_limits::max() - second))) { \ - return false; \ - } \ - sum = first + second; \ -} +#define ZIPPOS_ADD_AND_CHECK_OVERFLOW(first, second, sum) \ + do { \ + if (((second) > 0) && ((first) > (std::numeric_limits::max() - (second)))) { \ + return false; \ + } \ + (sum) = (first) + (second); \ + } while (0) constexpr uint32_t MAX_FILE_NAME = 256; constexpr uint32_t UNZIP_BUFFER_SIZE = 1024; diff --git a/services/bundlemgr_lite/tools/BUILD.gn b/services/bundlemgr_lite/tools/BUILD.gn index a4f827df6675fa9c6b0f369fccb24161ebe318a0..4c9d99af546894bcfb343aeba0ae6afaa6fb20d9 100644 --- a/services/bundlemgr_lite/tools/BUILD.gn +++ b/services/bundlemgr_lite/tools/BUILD.gn @@ -38,6 +38,7 @@ executable("bm") { deps = [ "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//base/startup/syspara_lite/frameworks/parameter:parameter", "//base/security/permission/services/permission_lite/pms_client:pms_client", "//build/lite/config/component/cJSON:cjson_shared", "//foundation/communication/ipc_lite:liteipc_adapter", @@ -48,6 +49,7 @@ executable("bm") { "include", "//base/security/permission/services/permission_lite/pms_client/include", "//base/security/permission/interfaces/innerkits/permission_lite", + "//base/startup/syspara_lite/interfaces/kits", "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", "${aafwk_lite_path}/interfaces/kits/want_lite", "${aafwk_lite_path}/services/abilitymgr_lite/include", diff --git a/services/bundlemgr_lite/tools/src/command_parser.cpp b/services/bundlemgr_lite/tools/src/command_parser.cpp index 97e950d0ff06c084192837042ce119ae3b5555e4..28f9687a56950a62e524b2ff5a384dab561bb33b 100644 --- a/services/bundlemgr_lite/tools/src/command_parser.cpp +++ b/services/bundlemgr_lite/tools/src/command_parser.cpp @@ -30,7 +30,7 @@ #include "convert_utils.h" #include "iproxy_client.h" #include "liteipc_adapter.h" -#include "pms_interface_inner.h" +#include "parameter.h" #include "samgr_lite.h" #include "securec.h" @@ -275,14 +275,15 @@ void CommandParser::RunAsGetUdidCommand(int32_t argc, char *argv[]) const return; } - unsigned char udid[UDID_STRING_LEN + 1] = {0}; + char udid[UDID_STRING_LEN + 1] = {0}; if (memset_s(udid, sizeof(udid), 0, sizeof(udid)) != EOK) { printf("GetUdid error memset\n"); return; } - int ret = RequestDevUdid(udid, sizeof(udid)); + char *devUdid = udid; + int ret = GetDevUdid(devUdid, sizeof(udid)); if (ret == EOK) { - cout << udid << endl; + cout << devUdid << endl; } else { cout << "Get Udid error ret = " << ret << endl; } diff --git a/utils/bundle_lite/aafwk_event_error_code.h b/utils/bundle_lite/aafwk_event_error_code.h new file mode 100644 index 0000000000000000000000000000000000000000..6b2c9591f80033e3ff1b03d2e9bf8d30ef4121a9 --- /dev/null +++ b/utils/bundle_lite/aafwk_event_error_code.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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 UTILS_BUNDLE_LITE_AAFWK_EVENT_ERROR_CODE_H +#define UTILS_BUNDLE_LITE_AAFWK_EVENT_ERROR_CODE_H + +#include "memory_heap.h" +#include "product_adapter.h" +#include "aafwk_event_error_id.h" + +namespace OHOS { +namespace ACELite { +#define APP_EVENT(code1) \ + AafwkEventCodePrint::GetInstance()->AafwkEventPrint(code1, 0) +#define APP_ERRCODE_EXTRA(code1, code2) \ + AafwkEventCodePrint::GetInstance()->AafwkErrorPrint(code1, code2) + +class AafwkEventCodePrint final : public MemoryHeap { +public: + AafwkEventCodePrint() = default; + ~AafwkEventCodePrint() = default; + + static AafwkEventCodePrint *GetInstance() + { + static AafwkEventCodePrint printInstance; + return &printInstance; + } + + void AafwkEventPrint(uint8_t info2, uint8_t info3) + { + ProductAdapter::PrintEventTrace(0, info2, info3); + } + + void AafwkEventPrint(uint8_t info1, uint8_t info2, uint8_t info3) + { + ProductAdapter::PrintEventTrace(info1, info2, info3); + } + + void AafwkErrorPrint(uint8_t info1, uint16_t info2) + { + ProductAdapter::PrintErrCode(info1, info2); + } +}; +} +} +#endif \ No newline at end of file diff --git a/utils/bundle_lite/aafwk_event_error_id.h b/utils/bundle_lite/aafwk_event_error_id.h new file mode 100644 index 0000000000000000000000000000000000000000..9d09de06ec532790fe7b1c126c7cea9d1dd19807 --- /dev/null +++ b/utils/bundle_lite/aafwk_event_error_id.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 UTILS_BUNDLE_LITE_AAFWK_EVENT_ERROR_ID_H +#define UTILS_BUNDLE_LITE_AAFWK_EVENT_ERROR_ID_H + +namespace OHOS { +// event codes +enum { + MT_ACE_APP_START = 0x01, + MT_ACE_APP_ACTIVE, + MT_ACE_APP_BACKGROUND, + MT_ACE_APP_STOP +} AceAppType; + +// start error codes +const int EXCE_ACE_APP_START = 0x01; + +enum { + EXCE_ACE_APP_START_UNKNOWN_BUNDLE_INFO = 0x0, + EXCE_ACE_APP_START_CREATE_TSAK_FAILED = 0x3, + EXCE_ACE_APP_START_LAUNCHER_EXIT_FAILED, + EXCE_ACE_APP_STOP_NO_ABILITY_RUNNING, + EXCE_ACE_APP_STOP_UNKNOWN_ABILITY_TOKEN +} AceAppStartError; + +// scan error codes +const int EXCE_ACE_APP_SCAN = 0x07; + +enum { + EXCE_ACE_APP_SCAN_INVALID_SYSTEM_APP = 0x0, + EXCE_ACE_APP_SCAN_PARSE_JSON_FALIED, + EXCE_ACE_APP_SCAN_PARSE_PROFILE_FALIED, + EXCE_ACE_APP_SCAN_UNKNOWN_BUNDLE_INFO +} AceAppScanError; +} +#endif \ No newline at end of file diff --git a/utils/bundle_lite/adapter.h b/utils/bundle_lite/adapter.h index 0f53edb9dcb0aa64185fbf127eb1bf6c608cd282..2039c89301474c3001c57adbd7114eec8fb9fea4 100755 --- a/utils/bundle_lite/adapter.h +++ b/utils/bundle_lite/adapter.h @@ -22,7 +22,7 @@ #define EXTERNC #endif -#ifndef APP_PLATFORM_WATCHGT +#ifndef __LITEOS_M__ // memory operator define #include @@ -32,8 +32,8 @@ #define AdapterMalloc(a) malloc(a) #define AdapterFree(a) \ do { \ - if (a != nullptr) { \ - (void) free((void *)a); \ + if ((a) != nullptr) { \ + (void) free((void *)(a)); \ a = nullptr; \ } \ } while (0) @@ -43,7 +43,7 @@ #define MutexAcquire(a, b) pthread_mutex_lock(a) #define MutexRelease(a) pthread_mutex_unlock(a) -#else // APP_PLATFORM_WATCHGT +#else // __LITEOS_M__ #include "stdint.h" #include "ohos_mem_pool.h" @@ -76,8 +76,6 @@ const unsigned int RETRY_TIMES = 10; } \ } while (0) -#define APP_ERRCODE_EXTRA(code1, code2) -#define APP_EVENT(code1) #define RecordAbiityInfoEvt(code1) #define MutexDelete(a) osMutexDelete(a) #define MutexAcquire(a, b) osMutexAcquire(a, b)