IssueNo:#I3WWHK

Description:Add uninstall state interface.
Sig:startup
Feature or Bugfix:Bugfix
Binary Source:No
This commit is contained in:
wangdengjia
2021-06-23 11:17:15 +08:00
parent 97cb3ae0ba
commit 895859c7ed
11 changed files with 102 additions and 15 deletions
@@ -47,6 +47,8 @@ public:
bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess) const;
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) const;
private:
BundleMsClient() = default;
@@ -23,4 +23,9 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t
{
return OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName, installState, installProcess);
}
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState)
{
return OHOS::BundleMsClient::GetInstance().GetUninstallState(bundleName, uninstallState);
}
}
@@ -157,4 +157,12 @@ bool BundleMsClient::GetInstallState (const char *bundleName, InstallState *inst
}
return bmsProxy_->GetInstallState(bundleName, installState, installProcess);
}
bool BundleMsClient::GetUninstallState (const char *bundleName, UninstallState *uninstallState) const
{
if (!Initialize()) {
return false;
}
return bmsProxy_->GetUninstallState(bundleName, uninstallState);
}
} // namespace OHOS
@@ -50,6 +50,7 @@ struct BmsSliteInterface {
uint8_t (*GetBundleInfo)(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess);
bool (*GetUninstallState)(const char *bundleName, UninstallState *uninstallState);
};
#ifdef __cplusplus
#if __cplusplus
@@ -39,6 +39,12 @@ typedef struct {
uint8_t installProcess;
} BundleInstallMsg;
typedef enum {
BUNDLE_UNINSTALL_DOING = 0,
BUNDLE_UNINSTALL_OK = 1,
BUNDLE_UNINSTALL_FAIL = 2
} UninstallState;
/**
* @brief Get the install state and install process of the bundle.
*
@@ -52,6 +58,16 @@ typedef struct {
*/
bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
/**
* @brief Get the uninstall state and uninstall state of the bundle.
*
* @param bundleName Indicates the name of the bundle.
* @param uninstallState Obtains uninstall state.
* @return Returns success or not.
*
*/
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState);
#ifdef __cplusplus
#if __cplusplus
}
@@ -36,6 +36,7 @@ public:
static uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
static bool GetUninstallState(const char *bundleName, UninstallState *uninstallState);
static BundleMgrSliteFeature *GetInstance()
{
@@ -16,8 +16,6 @@
#ifndef OHOS_GT_BUNDLE_INSTALLER_H
#define OHOS_GT_BUNDLE_INSTALLER_H
#include "generate-bytecode.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -49,6 +49,11 @@ typedef enum {
BUNDLE_UPDATE,
} BundleState;
typedef struct {
char *bundleName;
UninstallState uninstallState;
} BundleUninstallMsg;
class GtManagerService {
public:
static GtManagerService &GetInstance()
@@ -75,7 +80,10 @@ public:
void ReduceNumOfThirdBundles();
int32_t ReportInstallCallback(uint8_t errCode, uint8_t installState,
uint8_t process, InstallerCallback installerCallback);
int32_t ReportUninstallCallback(uint8_t errCode, char *bundleName,
uint8_t process, InstallerCallback installerCallback);
bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState);
private:
GtManagerService();
@@ -105,6 +113,7 @@ private:
BundleMap *bundleMap_;
List<BundleRes *> *bundleResList_;
BundleInstallMsg *bundleInstallMsg_;
BundleUninstallMsg *bundleUninstallMsg_;
char *jsEngineVer_;
uint32_t installedThirdBundleNum_;
};
@@ -33,6 +33,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
.GetBundleInfo = BundleMgrSliteFeature::GetBundleInfo,
.GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos,
.GetInstallState = BundleMgrSliteFeature::GetInstallState,
.GetUninstallState = BundleMgrSliteFeature::GetUninstallState,
DEFAULT_IUNKNOWN_ENTRY_END
};
@@ -126,4 +127,9 @@ bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState
{
return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess);
}
bool BundleMgrSliteFeature::GetUninstallState(const char *bundleName, UninstallState *uninstallState)
{
return OHOS::GtManagerService::GetInstance().GetUninstallState(bundleName, uninstallState);
}
} // namespace OHOS
@@ -18,6 +18,7 @@
#ifdef __cplusplus
extern "C" {
#include "generate-bytecode.h"
#endif
#ifdef __cplusplus
}
@@ -25,7 +25,6 @@
#include "cmsis_os2.h"
#include "dirent.h"
#include "fcntl.h"
#include "generate-bytecode.h"
#include "gt_bundle_extractor.h"
#include "gt_bundle_parser.h"
#include "gt_extractor_util.h"
@@ -50,6 +49,7 @@ GtManagerService::GtManagerService()
bundleResList_ = new List<BundleRes *>();
bundleMap_ = BundleMap::GetInstance();
bundleInstallMsg_ = nullptr;
bundleUninstallMsg_ = nullptr;
jsEngineVer_ = nullptr;
installedThirdBundleNum_ = 0;
}
@@ -111,9 +111,9 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
uint8_t ret = installer_->Install(path, installerCallback);
EnableServiceWdg();
if (ret == 0) {
(void) ReportInstallCallback(ret, 1, BMS_INSTALLATION_COMPLETED, installerCallback);
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback);
} else {
(void) ReportInstallCallback(ret, 2, BMS_INSTALLATION_COMPLETED, installerCallback);
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback);
}
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
SetCurrentBundle(nullptr);
@@ -144,21 +144,31 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins
return false;
}
SetCurrentBundle(innerBundleName);
bundleInstallMsg_ = reinterpret_cast<BundleInstallMsg *>(AdapterMalloc(sizeof(BundleInstallMsg)));
if (bundleInstallMsg_ == nullptr) {
bundleUninstallMsg_ = reinterpret_cast<BundleUninstallMsg *>(AdapterMalloc(sizeof(BundleUninstallMsg)));
if (bundleUninstallMsg_ == nullptr) {
return false;
}
if (memset_s(bundleInstallMsg_, sizeof(BundleInstallMsg), 0, sizeof(BundleInstallMsg)) != EOK) {
AdapterFree(bundleInstallMsg_);
if (memset_s(bundleUninstallMsg_, sizeof(BundleUninstallMsg), 0, sizeof(BundleUninstallMsg)) != EOK) {
AdapterFree(bundleUninstallMsg_);
return false;
}
bundleInstallMsg_->bundleName = Utils::Strdup(innerBundleName);
(void) ReportInstallCallback(OPERATION_DOING, 0, BMS_UNINSTALLATION_START, installerCallback);
bundleUninstallMsg_->bundleName = innerBundleName;
bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_DOING;
(void) ReportUninstallCallback(OPERATION_DOING, innerBundleName, BMS_UNINSTALLATION_START, installerCallback);
uint8_t ret = installer_->Uninstall(innerBundleName);
(void) ReportInstallCallback(ret, 0, BMS_INSTALLATION_COMPLETED, installerCallback);
ClearSystemBundleInstallMsg();
if (ret == 0) {
bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_OK;
} else {
bundleUninstallMsg_->uninstallState = BUNDLE_UNINSTALL_FAIL;
}
(void) ReportUninstallCallback(ret, innerBundleName, BMS_INSTALLATION_COMPLETED, installerCallback);
SetCurrentBundle(nullptr);
AdapterFree(innerBundleName);
AdapterFree(bundleUninstallMsg_);
bundleUninstallMsg_ = nullptr;
return true;
}
@@ -170,7 +180,7 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins
*installProcess = BMS_INSTALLATION_COMPLETED;
return true;
}
if (bundleName == bundleInstallMsg_->bundleName) {
if (strcmp(bundleName, bundleInstallMsg_->bundleName) == 0) {
*installState = bundleInstallMsg_->installState;
*installProcess = bundleInstallMsg_->installProcess;
return true;
@@ -180,6 +190,21 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins
return true;
}
bool GtManagerService::GetUninstallState(const char *bundleName, UninstallState *uninstallState)
{
BundleInfo *uninstalledInfo = bundleMap_->Get(bundleName);
if (uninstalledInfo == nullptr) {
*uninstallState = BUNDLE_UNINSTALL_OK;
return true;
}
if (strcmp(bundleName, bundleUninstallMsg_->bundleName) == 0) {
*uninstallState = bundleUninstallMsg_->uninstallState;
return true;
}
*uninstallState = BUNDLE_UNINSTALL_DOING;
return true;
}
uint8_t GtManagerService::QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo)
{
if (want->element == nullptr) {
@@ -847,11 +872,26 @@ int32_t GtManagerService::ReportInstallCallback(uint8_t errCode, uint8_t install
bundleInstallMsg->bundleName = bundleInstallMsg_->bundleName;
bundleInstallMsg->smallIconPath = bundleInstallMsg_->smallIconPath;
bundleInstallMsg->bigIconPath = bundleInstallMsg_->bigIconPath;
(*installerCallback)(errCode, bundleInstallMsg);
return 0;
}
int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, char *bundleName,
uint8_t process, InstallerCallback installerCallback)
{
if (installerCallback == nullptr) {
return -1;
}
BundleInstallMsg *bundleUninstallMsg = reinterpret_cast<BundleInstallMsg *>(AdapterMalloc(sizeof(BundleInstallMsg)));
if (bundleUninstallMsg == nullptr) {
return -1;
}
bundleUninstallMsg->bundleName = bundleName;
bundleUninstallMsg->installProcess = process;
(*installerCallback)(errCode, bundleUninstallMsg);
return 0;
}
AppInfoList *GtManagerService::APP_InitAllAppInfo()
{
AppInfoList *list = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList));