mirror of
https://github.com/openharmony/bundlemanager_bundle_framework_lite.git
synced 2026-07-19 12:13:04 -04:00
IssueNo:#I45HUE
Description:change priv-app install callback Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia <wangdengjia@huawei.com> Change-Id: I802a1bf73706657726cfe4e0716aeb1a111cb3af Signed-off-by: wangdengjia <wangdengjia@huawei.com>
This commit is contained in:
@@ -49,6 +49,8 @@ public:
|
||||
|
||||
uint32_t GetBundleSize(const char *bundleName) const;
|
||||
|
||||
bool RegisterInstallerCallback(InstallerCallback installerCallback) const;
|
||||
|
||||
private:
|
||||
BundleMsClient() = default;
|
||||
|
||||
|
||||
@@ -28,4 +28,9 @@ uint32_t GetBundleSize(const char *bundleName)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().GetBundleSize(bundleName);
|
||||
}
|
||||
|
||||
bool RegisterInstallerCallback(InstallerCallback installerCallback)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().RegisterInstallerCallback(installerCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,29 @@ bool BundleMsClient::Uninstall (const char *bundleName, const InstallParam *inst
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
bool BundleMsClient::RegisterInstallerCallback (InstallerCallback installerCallback) const
|
||||
{
|
||||
BundleMgrService *service = BundleMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (installerCallback == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (g_bmsbuff == nullptr) {
|
||||
g_bmsbuff = reinterpret_cast<Bmsbuff *>(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff)));
|
||||
}
|
||||
g_bmsbuff->bundleInstallerCallback = installerCallback;
|
||||
Request request = {
|
||||
.msgId = BMS_REGISTER_CALLBACK_MSG,
|
||||
.data = nullptr,
|
||||
.len = 0,
|
||||
.msgValue = 0,
|
||||
};
|
||||
int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
uint8_t BundleMsClient::QueryAbilityInfo (const Want *want, AbilityInfo *abilityInfo) const
|
||||
{
|
||||
if (!Initialize()) {
|
||||
|
||||
@@ -51,6 +51,7 @@ struct BmsSliteInterface {
|
||||
uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess);
|
||||
uint32_t (*GetBundleSize)(const char *bundleName);
|
||||
bool (*RegisterInstallerCallback)(InstallerCallback installerCallback);
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bundle_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@@ -64,6 +66,15 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t
|
||||
*/
|
||||
uint32_t GetBundleSize(const char *bundleName);
|
||||
|
||||
/**
|
||||
* @brief Register installer callback.
|
||||
*
|
||||
* @param installerCallback Indicates the installer callback.
|
||||
* @return Returns success or failure.
|
||||
*
|
||||
*/
|
||||
bool RegisterInstallerCallback(InstallerCallback installerCallback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
|
||||
static uint32_t GetBundleSize (const char *bundleName);
|
||||
static bool RegisterInstallerCallback(InstallerCallback installerCallback);
|
||||
|
||||
static BundleMgrSliteFeature *GetInstance()
|
||||
{
|
||||
|
||||
@@ -78,14 +78,14 @@ public:
|
||||
uint8_t process, InstallerCallback installerCallback);
|
||||
bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
|
||||
uint32_t GetBundleSize(const char *bundleName);
|
||||
bool RegisterInstallerCallback(InstallerCallback installerCallback);
|
||||
|
||||
private:
|
||||
GtManagerService();
|
||||
~GtManagerService();
|
||||
void ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInstalledApp *> *systemPathList);
|
||||
void ScanThirdApp(const char *appDir, const List<ToBeInstalledApp *> *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<ToBeInstalledApp *> *systemPathList,
|
||||
int32_t versionCode, uint8_t scanFlag);
|
||||
@@ -102,6 +102,7 @@ private:
|
||||
void APP_QueryAppInfo(const char *appDir, AppInfoList *list);
|
||||
void APP_InsertAppInfo(char *filePath, AppInfoList *list);
|
||||
void APP_FreeAllAppInfo(const AppInfoList *list);
|
||||
void InstallPreBundle(List<ToBeInstalledApp *> systemPathList, InstallerCallback installerCallback);
|
||||
|
||||
GtBundleInstaller *installer_;
|
||||
BundleMap *bundleMap_;
|
||||
@@ -109,6 +110,7 @@ private:
|
||||
BundleInstallMsg *bundleInstallMsg_;
|
||||
char *jsEngineVer_;
|
||||
uint32_t installedThirdBundleNum_;
|
||||
List<ToBeInstalledApp *> systemPathList_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ BOOL BundleMgrService::ServiceMessageHandle(Service *service, Request *request)
|
||||
g_bmsbuff->bundleInstallerCallback);
|
||||
} else if (request->msgId == BMS_SCAN_PACKAGE_MSG) {
|
||||
OHOS::GtManagerService::GetInstance().ScanPackages();
|
||||
} else if (request->msgId == BMS_REGISTER_CALLBACK_MSG) {
|
||||
OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(g_bmsbuff->bundleInstallerCallback);
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
|
||||
.GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos,
|
||||
.GetInstallState = BundleMgrSliteFeature::GetInstallState,
|
||||
.GetBundleSize = BundleMgrSliteFeature::GetBundleSize,
|
||||
.RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback,
|
||||
DEFAULT_IUNKNOWN_ENTRY_END
|
||||
};
|
||||
|
||||
@@ -132,4 +133,9 @@ uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName)
|
||||
{
|
||||
return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName);
|
||||
}
|
||||
|
||||
bool BundleMgrSliteFeature::RegisterInstallerCallback(InstallerCallback installerCallback)
|
||||
{
|
||||
return OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(installerCallback);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
const uint8_t PAIR_VALUE = 2;
|
||||
const uint8_t OPERATION_DOING = 200;
|
||||
const uint8_t BMS_INSTALLATION_START = 101;
|
||||
const uint8_t BMS_UNINSTALLATION_START = 104;
|
||||
@@ -102,9 +101,8 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
|
||||
char *name = strchr(path, '/');
|
||||
bundleInstallMsg_->bundleName = Utils::Strdup(name + 1);
|
||||
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback);
|
||||
// delete resource temp dir
|
||||
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
|
||||
ClearSystemBundleInstallMsg();
|
||||
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
|
||||
AdapterFree(path);
|
||||
return false;
|
||||
}
|
||||
@@ -119,9 +117,9 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
|
||||
} else {
|
||||
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback);
|
||||
}
|
||||
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
|
||||
SetCurrentBundle(nullptr);
|
||||
ClearSystemBundleInstallMsg();
|
||||
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
|
||||
AdapterFree(path);
|
||||
return true;
|
||||
}
|
||||
@@ -247,7 +245,39 @@ uint8_t GtManagerService::GetBundleInfos(const int flags, BundleInfo **bundleInf
|
||||
return bundleMap_->GetBundleInfos(flags, bundleInfos, len);
|
||||
}
|
||||
|
||||
void GtManagerService::InstallAllSystemBundle()
|
||||
bool GtManagerService::RegisterInstallerCallback(InstallerCallback installerCallback)
|
||||
{
|
||||
if (installerCallback == nullptr) {
|
||||
return false;
|
||||
}
|
||||
InstallPreBundle(systemPathList_, installerCallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GtManagerService::InstallPreBundle(List<ToBeInstalledApp *> systemPathList, InstallerCallback installerCallback)
|
||||
{
|
||||
if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) {
|
||||
BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END);
|
||||
InstallAllSystemBundle(installerCallback);
|
||||
RemoveSystemAppPathList(&systemPathList);
|
||||
return;
|
||||
}
|
||||
for (auto node = systemPathList.Begin(); node != systemPathList.End(); node = node->next_) {
|
||||
ToBeInstalledApp *toBeInstalledApp = node->value_;
|
||||
if (toBeInstalledApp->isUpdated) {
|
||||
(void) ReloadBundleInfo(toBeInstalledApp->installedPath, toBeInstalledApp->appId,
|
||||
toBeInstalledApp->isSystemApp);
|
||||
}
|
||||
if (!BundleUtil::IsFile(toBeInstalledApp->path) ||
|
||||
!BundleUtil::EndWith(toBeInstalledApp->path, INSTALL_FILE_SUFFIX)) {
|
||||
return;
|
||||
}
|
||||
(void) Install(toBeInstalledApp->path, nullptr, installerCallback);
|
||||
}
|
||||
RemoveSystemAppPathList(&systemPathList);
|
||||
}
|
||||
|
||||
void GtManagerService::InstallAllSystemBundle(InstallerCallback installerCallback)
|
||||
{
|
||||
AppInfoList *list = GtManagerService::APP_InitAllAppInfo();
|
||||
if (list == nullptr) {
|
||||
@@ -262,54 +292,16 @@ void GtManagerService::InstallAllSystemBundle()
|
||||
(strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) {
|
||||
continue;
|
||||
}
|
||||
InstallSystemBundle(((AppInfoList *)currentNode)->filePath);
|
||||
|
||||
if (!BundleUtil::IsFile(((AppInfoList *)currentNode)->filePath) ||
|
||||
!BundleUtil::EndWith(((AppInfoList *)currentNode)->filePath, INSTALL_FILE_SUFFIX)) {
|
||||
return;
|
||||
}
|
||||
(void) Install(((AppInfoList *)currentNode)->filePath, nullptr, installerCallback);
|
||||
}
|
||||
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<BundleInstallMsg *>(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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void GtManagerService::ClearSystemBundleInstallMsg()
|
||||
{
|
||||
if (bundleInstallMsg_ == nullptr) {
|
||||
@@ -348,11 +340,6 @@ void GtManagerService::ScanPackages()
|
||||
if (jsEngineVer_ == nullptr) {
|
||||
HILOG_WARN(HILOG_MODULE_AAFWK, "[BMS] get jsEngine version fail when restart!");
|
||||
}
|
||||
if (!BundleUtil::IsDir(JSON_PATH_NO_SLASH_END)) {
|
||||
BundleUtil::MkDirs(JSON_PATH_NO_SLASH_END);
|
||||
InstallAllSystemBundle();
|
||||
return;
|
||||
}
|
||||
|
||||
// get third system bundle uninstall record
|
||||
cJSON *uninstallRecord = BundleUtil::GetJsonStream(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON);
|
||||
@@ -360,24 +347,14 @@ void GtManagerService::ScanPackages()
|
||||
(void) unlink(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON);
|
||||
}
|
||||
|
||||
List<ToBeInstalledApp *> systemPathList;
|
||||
// scan system apps and third system apps
|
||||
ScanSystemApp(uninstallRecord, &systemPathList);
|
||||
ScanSystemApp(uninstallRecord, &systemPathList_);
|
||||
if (uninstallRecord != nullptr) {
|
||||
cJSON_Delete(uninstallRecord);
|
||||
}
|
||||
|
||||
// scan third apps
|
||||
ScanThirdApp(INSTALL_PATH, &systemPathList);
|
||||
// install new system app or app which is to be updated
|
||||
for (auto node = systemPathList.Begin(); node != systemPathList.End(); node = node->next_) {
|
||||
ToBeInstalledApp *toBeInstalledApp = node->value_;
|
||||
if (toBeInstalledApp->isUpdated) {
|
||||
(void) ReloadBundleInfo(toBeInstalledApp->installedPath, toBeInstalledApp->appId,
|
||||
toBeInstalledApp->isSystemApp);
|
||||
}
|
||||
InstallSystemBundle(toBeInstalledApp->path);
|
||||
}
|
||||
RemoveSystemAppPathList(&systemPathList);
|
||||
ScanThirdApp(INSTALL_PATH, &systemPathList_);
|
||||
}
|
||||
|
||||
void GtManagerService::RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemPathList)
|
||||
@@ -893,7 +870,7 @@ int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, uint8_t insta
|
||||
return -1;
|
||||
}
|
||||
bundleInstallMsg->installState = static_cast<InstallState>(installState);
|
||||
bundleInstallMsg->bundleName = bundleName;
|
||||
bundleInstallMsg->bundleName = Utils::Strdup(bundleName);
|
||||
bundleInstallMsg->installProcess = process;
|
||||
(*installerCallback)(errCode, bundleInstallMsg);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user