mirror of
https://github.com/openharmony/bundlemanager_bundle_framework_lite.git
synced 2026-07-19 12:13:04 -04:00
@@ -60,9 +60,6 @@ bool BundleMsClient::Initialize() const
|
||||
bool BundleMsClient::Install(const char *hapPath, const InstallParam *installParam,
|
||||
InstallerCallback installerCallback) const
|
||||
{
|
||||
if (g_bmsbuff == nullptr) {
|
||||
g_bmsbuff = reinterpret_cast<Bmsbuff *>(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff)));
|
||||
}
|
||||
BundleMgrService *service = BundleMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return false;
|
||||
@@ -70,22 +67,20 @@ bool BundleMsClient::Install(const char *hapPath, const InstallParam *installPar
|
||||
if (hapPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memset_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, 0, MAX_PATH_LEN) != 0) {
|
||||
return false;
|
||||
}
|
||||
int len = strlen(hapPath);
|
||||
if (len >= MAX_PATH_LEN) {
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, hapPath, len + 1) != 0) {
|
||||
Bmsbuff *data = static_cast<Bmsbuff *>(AdapterMalloc(sizeof(Bmsbuff)));
|
||||
if (memcpy_s(data->bundleParameter, MAX_PATH_LEN, hapPath, len + 1) != 0) {
|
||||
AdapterFree(data);
|
||||
return false;
|
||||
}
|
||||
g_bmsbuff->bundleInstallerCallback = installerCallback;
|
||||
data->bundleInstallerCallback = installerCallback;
|
||||
Request request = {
|
||||
.msgId = BMS_INSTALL_MSG,
|
||||
.len = 0,
|
||||
.data = nullptr,
|
||||
.len = sizeof(Bmsbuff),
|
||||
.data = data,
|
||||
.msgValue = 0,
|
||||
};
|
||||
|
||||
@@ -103,24 +98,20 @@ bool BundleMsClient::Uninstall (const char *bundleName, const InstallParam *inst
|
||||
if (bundleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (g_bmsbuff == nullptr) {
|
||||
g_bmsbuff = reinterpret_cast<Bmsbuff *>(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff)));
|
||||
}
|
||||
if (memset_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, 0, MAX_PATH_LEN) != 0) {
|
||||
return false;
|
||||
}
|
||||
int len = strlen(bundleName);
|
||||
if (len >= MAX_PATH_LEN) {
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, bundleName, len + 1) != 0) {
|
||||
Bmsbuff *data = static_cast<Bmsbuff *>(AdapterMalloc(sizeof(Bmsbuff)));
|
||||
if (memcpy_s(data->bundleParameter, MAX_PATH_LEN, bundleName, len + 1) != 0) {
|
||||
AdapterFree(data);
|
||||
return false;
|
||||
}
|
||||
g_bmsbuff->bundleInstallerCallback = installerCallback;
|
||||
data->bundleInstallerCallback = installerCallback;
|
||||
Request request = {
|
||||
.msgId = BMS_UNINSTALL_MSG,
|
||||
.len = 0,
|
||||
.data = nullptr,
|
||||
.len = sizeof(Bmsbuff),
|
||||
.data = data,
|
||||
.msgValue = 0,
|
||||
};
|
||||
int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
|
||||
@@ -86,12 +86,20 @@ BOOL BundleMgrService::ServiceMessageHandle(Service *service, Request *request)
|
||||
if (request == nullptr) {
|
||||
return FALSE;
|
||||
}
|
||||
if (request->msgId == BMS_INSTALL_MSG && g_bmsbuff != nullptr) {
|
||||
OHOS::GtManagerService::GetInstance().Install(g_bmsbuff->bundleParameter, nullptr,
|
||||
g_bmsbuff->bundleInstallerCallback);
|
||||
} else if (request->msgId == BMS_UNINSTALL_MSG && g_bmsbuff != nullptr) {
|
||||
OHOS::GtManagerService::GetInstance().Uninstall(g_bmsbuff->bundleParameter, nullptr,
|
||||
g_bmsbuff->bundleInstallerCallback);
|
||||
if (request->msgId == BMS_INSTALL_MSG) {
|
||||
Bmsbuff *data = static_cast<Bmsbuff *>(request->data);
|
||||
OHOS::GtManagerService::GetInstance().Install(data->bundleParameter, nullptr,
|
||||
data->bundleInstallerCallback);
|
||||
AdapterFree(request->data);
|
||||
request->data = nullptr;
|
||||
request->len = 0;
|
||||
} else if (request->msgId == BMS_UNINSTALL_MSG) {
|
||||
Bmsbuff *data = static_cast<Bmsbuff *>(request->data);
|
||||
OHOS::GtManagerService::GetInstance().Uninstall(data->bundleParameter, nullptr,
|
||||
data->bundleInstallerCallback);
|
||||
AdapterFree(request->data);
|
||||
request->data = nullptr;
|
||||
request->len = 0;
|
||||
} else if (request->msgId == BMS_SCAN_PACKAGE_MSG) {
|
||||
OHOS::GtManagerService::GetInstance().ScanPackages();
|
||||
} else if (request->msgId == BMS_REGISTER_CALLBACK_MSG && g_bmsbuff != nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user