Signed-off-by: shilei <shilei91@huawei.com>
Change-Id: I2f896b5e234c7151d4efe09364c410b2f093ef1f
This commit is contained in:
shilei
2022-11-08 16:56:42 +08:00
parent 0b5b2e37dc
commit 241d1ed518
21 changed files with 385 additions and 201 deletions
+2 -1
View File
@@ -32,7 +32,8 @@
"third_party": [
"zlib",
"bounds_checking_function",
"cjson"
"cjson",
"jerryscript"
]
},
"build": {
+6
View File
@@ -54,6 +54,12 @@ public:
uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) const;
PreAppList *InitPreAppInfo(void) const;
void InsertPreAppInfo(const char *filePath, PreAppList *list) const;
void SetPreAppInfo(PreAppList *list) const;
private:
BundleMsClient() = default;
+15
View File
@@ -43,4 +43,19 @@ uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, i
{
return OHOS::BundleMsClient::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len);
}
PreAppList *InitPreAppInfo(void)
{
return OHOS::BundleMsClient::GetInstance().InitPreAppInfo();
}
void InsertPreAppInfo(const char *filePath, PreAppList *list)
{
OHOS::BundleMsClient::GetInstance().InsertPreAppInfo(filePath, list);
}
void SetPreAppInfo(PreAppList *list)
{
OHOS::BundleMsClient::GetInstance().SetPreAppInfo(list);
}
}
+49 -5
View File
@@ -152,8 +152,11 @@ bool BundleMsClient::RegisterInstallerCallback (InstallerCallback installerCallb
uint8_t BundleMsClient::QueryAbilityInfo (const Want *want, AbilityInfo *abilityInfo) const
{
if ((want == nullptr) || (abilityInfo == nullptr)) {
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
}
if (!Initialize()) {
return -1;
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
return bmsProxy_->QueryAbilityInfo(want, abilityInfo);
}
@@ -164,7 +167,8 @@ uint8_t BundleMsClient::GetBundleInfo (const char *bundleName, int32_t flags, Bu
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
}
if (!Initialize()) {
return -1;
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Initialize is failed");
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
return bmsProxy_->GetBundleInfo(bundleName, flags, bundleInfo);
}
@@ -178,13 +182,17 @@ uint8_t BundleMsClient::GetBundleInfos (int32_t flags, BundleInfo **bundleInfos,
return ERR_APPEXECFWK_QUERY_NO_INFOS;
}
if (!Initialize()) {
return -1;
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Initialize is failed");
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
return bmsProxy_->GetBundleInfos(flags, bundleInfos, len);
}
bool BundleMsClient::GetInstallState (const char *bundleName, InstallState *installState, uint8_t *installProcess) const
{
if ((bundleName == nullptr) || (installState == nullptr) || (installProcess == nullptr)) {
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
}
if (!Initialize()) {
return false;
}
@@ -193,8 +201,11 @@ bool BundleMsClient::GetInstallState (const char *bundleName, InstallState *inst
uint32_t BundleMsClient::GetBundleSize (const char *bundleName) const
{
if (bundleName == nullptr) {
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
}
if (!Initialize()) {
return -1;
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
return bmsProxy_->GetBundleSize(bundleName);
}
@@ -209,9 +220,42 @@ void BundleMsClient::UpdateBundleInfoList () const
uint8_t BundleMsClient::GetBundleInfosNoReplication (const int flags, BundleInfo **bundleInfos, int32_t *len) const
{
if ((bundleInfos == nullptr) || (len == nullptr)) {
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
}
if (!Initialize()) {
return -1;
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
return bmsProxy_->GetBundleInfosNoReplication(flags, bundleInfos, len);
}
PreAppList *BundleMsClient::InitPreAppInfo () const
{
if (!Initialize()) {
return nullptr;
}
return bmsProxy_->InitPreAppInfo();
}
void BundleMsClient::InsertPreAppInfo (const char *filePath, PreAppList *list) const
{
if ((filePath == nullptr) || (list == nullptr)) {
return;
}
if (!Initialize()) {
return;
}
bmsProxy_->InsertPreAppInfo(filePath, list);
}
void BundleMsClient::SetPreAppInfo(PreAppList *list) const
{
if (list == nullptr) {
return;
}
if (!Initialize()) {
return;
}
bmsProxy_->SetPreAppInfo(list);
}
} // namespace OHOS
+3
View File
@@ -58,6 +58,9 @@ struct BmsSliteInterface {
bool (*RegisterInstallerCallback)(InstallerCallback installerCallback);
void (*UpdateBundleInfoList)();
uint8_t (*GetBundleInfosNoReplication)(const int flags, BundleInfo **bundleInfos, int32_t *len);
PreAppList *(*InitPreAppInfo)(void);
void (*InsertPreAppInfo)(const char *filePath, PreAppList *list);
void (*SetPreAppInfo)(PreAppList *list);
};
#ifdef __cplusplus
#if __cplusplus
@@ -19,6 +19,7 @@
#include <stdint.h>
#include "bundle_manager.h"
#include "los_list.h"
#ifdef __cplusplus
#if __cplusplus
@@ -26,6 +27,7 @@ extern "C" {
#endif
#endif /* __cplusplus */
#define MAX_APP_FILE_PATH_LEN 100
typedef enum {
BUNDLE_INSTALL_DOING = 0,
BUNDLE_INSTALL_OK = 1,
@@ -44,6 +46,11 @@ typedef struct {
uint8_t installProcess;
} BundleInstallMsg;
typedef struct {
LOS_DL_LIST appDoubleList;
char filePath[MAX_APP_FILE_PATH_LEN];
} PreAppList;
/**
* @brief Get the install state and install process of the bundle.
*
@@ -95,6 +102,31 @@ void UpdateBundleInfoList(void);
*/
uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len);
/**
* @brief Initializing preset application information.
*
* @return Returns an empty PreAppList.
*
*/
PreAppList *InitPreAppInfo(void);
/**
* @brief Insert preset application information to the list.
*
* @param filePath Indicates the file path of the preconfigured application.
* @param list Indicates the inserted list.
*
*/
void InsertPreAppInfo(const char *filePath, PreAppList *list);
/**
* @brief Setting the preset application list.
*
* @param list Indicates the preset application list.
*
*/
void SetPreAppInfo(PreAppList *list);
#ifdef __cplusplus
#if __cplusplus
}
+11
View File
@@ -30,11 +30,17 @@ if (ohos_kernel_type == "liteos_m") {
"src/gt_bundle_parser.cpp",
"src/gt_extractor_util.cpp",
]
defines = [ "JERRY_FOR_IAR_CONFIG" ]
deps = [
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
"//base/global/resource_management_lite/frameworks/resmgr_lite:global_resmgr",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
"//build/lite/config/component/cJSON:cjson_static",
"//foundation/arkui/ace_engine_lite/frameworks:ace_lite",
"//foundation/systemabilitymgr/samgr_lite/samgr:samgr",
"//third_party/jerryscript/jerry-core:jerry-core_static",
]
include_dirs = [
@@ -56,8 +62,13 @@ if (ohos_kernel_type == "liteos_m") {
"//foundation/systemabilitymgr/samgr_lite/interfaces/kits/registry",
"//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr",
"//foundation/communication/ipc/interfaces/innerkits/c/ipc/include",
"//third_party/jerryscript/jerry-core",
"//third_party/jerryscript/jerry-core/api",
"//third_party/jerryscript/jerry-core/ecma/base",
"//third_party/jerryscript/jerry-core/include",
"//third_party/jerryscript/jerry-core/jrt",
"//third_party/jerryscript/jerry-core/jmem",
"//third_party/jerryscript/jerry-core/lit",
"//third_party/cJSON",
"//third_party/zlib",
"//third_party/zlib/contrib/minizip",
+11 -11
View File
@@ -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[] = "/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";
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";
// store bundle permissions for IAM
const char PERMISSIONS_PATH[] = "/data/user/ace/etc/permissions";
const char PERMISSIONS_PATH[] = "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[] = "/data/user/ace/run/tmpResource";
const char TMP_RESOURCE_DIR[] = "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 = 50;
const uint8_t MAX_THIRD_BUNDLE_NUMBER = 45;
struct SignatureInfo {
char *bundleName;
+3
View File
@@ -40,6 +40,9 @@ public:
static bool RegisterInstallerCallback(InstallerCallback installerCallback);
static void UpdateBundleInfoList();
static uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len);
static PreAppList *InitPreAppInfo();
static void InsertPreAppInfo(const char *filePath, PreAppList *list);
static void SetPreAppInfo(PreAppList *list);
static void Init();
static BundleMgrSliteFeature *GetInstance()
@@ -17,6 +17,7 @@
#define OHOS_GT_BUNDLE_EXTRACTOR_H
#include "bundle_common.h"
#include "stdint.h"
namespace OHOS {
class GtBundleExtractor {
+2 -1
View File
@@ -19,6 +19,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "generate-bytecode.h"
#ifdef __cplusplus
}
#endif
@@ -42,7 +43,7 @@ private:
uint8_t PreCheckBundle(const char *path, int32_t &fp, SignatureInfo &signatureInfo, uint32_t &fileSize,
uint8_t bundleStyle);
uint8_t ProcessBundleInstall(const char *path, const char *randStr, InstallRecord &installRecord,
uint8_t bundleStyle, InstallerCallback installerCallback);
uint8_t bundleStyle, InstallerCallback installerCallback, bool &isUpdate);
uint8_t HandleFileAndBackUpRecord(const InstallRecord &record, const char *tmpPath, const char *randStr,
const char *dataPath, bool isUpdate);
uint8_t UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelId, uint32_t iconId, BundleInfo *bundleInfo,
+8 -12
View File
@@ -26,11 +26,9 @@
#include "install_param.h"
#include "bundle_install_msg.h"
#include "bundle_manager.h"
#include "los_list.h"
#include "ohos_types.h"
namespace OHOS {
#define MAX_APP_FILE_PATH_LEN 100
struct ToBeInstalledApp {
bool isSystemApp;
bool isUpdated;
@@ -38,10 +36,6 @@ struct ToBeInstalledApp {
char *installedPath;
char *appId;
};
struct AppInfoList {
LOS_DL_LIST appDoubleList;
char filePath[MAX_APP_FILE_PATH_LEN];
};
typedef enum {
BUNDLE_INSTALL,
@@ -81,6 +75,9 @@ public:
bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
uint32_t GetBundleSize(const char *bundleName);
bool RegisterInstallerCallback(InstallerCallback installerCallback);
PreAppList *InitPreAppInfo(void);
void InsertPreAppInfo(const char *filePath, PreAppList *list);
void SetPreAppInfo(PreAppList *list);
private:
GtManagerService();
@@ -97,16 +94,12 @@ private:
bool isSystemApp, bool isUpdated, const char *appId);
void RemoveSystemAppPathList(List<ToBeInstalledApp *> *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<ToBeInstalledApp *> *systemPathList);
AppInfoList *APP_InitAllAppInfo(void);
void APP_QueryAppInfo(const char *appDir, AppInfoList *list);
void APP_InsertAppInfo(char *filePath, AppInfoList *list);
void APP_FreeAllAppInfo(AppInfoList *list);
void InstallPreBundle(List<ToBeInstalledApp *> systemPathList, InstallerCallback installerCallback);
void QueryPreAppInfo(const char *appDir, PreAppList *list);
void FreePreAppInfo(const PreAppList *list);
GtBundleInstaller *installer_;
BundleMap *bundleMap_;
@@ -115,6 +108,9 @@ private:
char *jsEngineVer_;
uint32_t installedThirdBundleNum_;
List<ToBeInstalledApp *> systemPathList_;
PreAppList *preAppList_;
bool updateFlag_;
int32_t oldVersionCode_;
};
}
@@ -32,7 +32,7 @@ public:
private:
static uint32_t ReadInt(int32_t fp);
static uint64_t ReadLong(int32_t fp);
static char *ReadString(int32_t fp, uint32_t len);
static unsigned char *ReadString(int32_t fp, uint32_t len);
static bool HasCopiedData(const char *filePath, int32_t fp, uint64_t size);
};
} // namespace OHOS
+5 -4
View File
@@ -15,6 +15,7 @@
#include "bundle_mgr_service.h"
#include "adapter.h"
#include "bundle_service_interface.h"
#include "bundlems_log.h"
#include "bundle_mgr_slite_feature.h"
@@ -62,7 +63,11 @@ BOOL BundleMgrService::ServiceInitialize(Service *service, Identity identity)
BundleMgrService *bundleManagerService = static_cast<BundleMgrService *>(service);
bundleManagerService->identity_ = identity;
Request request = {
#ifndef __LITEOS_M__
.msgId = BMS_SCAN_PACKAGE_MSG,
#else
.msgId = BMS_REGISTER_CALLBACK_MSG,
#endif
.len = 0,
.data = nullptr,
.msgValue = 0,
@@ -99,11 +104,7 @@ 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
+18 -1
View File
@@ -22,7 +22,6 @@
#include "utils.h"
#include "want_utils.h"
namespace OHOS {
BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
DEFAULT_IUNKNOWN_ENTRY_BEGIN,
@@ -36,6 +35,9 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
.RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback,
.UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList,
.GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication,
.InitPreAppInfo = BundleMgrSliteFeature::InitPreAppInfo,
.InsertPreAppInfo = BundleMgrSliteFeature::InsertPreAppInfo,
.SetPreAppInfo = BundleMgrSliteFeature::SetPreAppInfo,
DEFAULT_IUNKNOWN_ENTRY_END
};
@@ -145,4 +147,19 @@ uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, Bund
{
return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len);
}
PreAppList *BundleMgrSliteFeature::InitPreAppInfo()
{
return OHOS::GtManagerService::GetInstance().InitPreAppInfo();
}
void BundleMgrSliteFeature::InsertPreAppInfo(const char *filePath, PreAppList *list)
{
OHOS::GtManagerService::GetInstance().InsertPreAppInfo(filePath, list);
}
void BundleMgrSliteFeature::SetPreAppInfo(PreAppList *list)
{
OHOS::GtManagerService::GetInstance().SetPreAppInfo(list);
}
} // namespace OHOS
+46 -3
View File
@@ -49,6 +49,27 @@ const int32_t MAX_JSON_SIZE = 1024 * 64;
const uint32_t MAX_JSON_SIZE = 1024 * 64;
#endif
#ifdef __LITEOS_M__
#ifndef CONFIG_FT_MODE
static void *CJsonBmsMalloc(size_t size)
{
return OhosMalloc(MEM_TYPE_CJSON_LSRAM, size);
}
static void CJsonBmsFree(void *pointer)
{
OhosFree(pointer);
}
static void OhosBmsCjsonHooksInit(void)
{
cJSON_Hooks hooks;
hooks.malloc_fn = CJsonBmsMalloc;
hooks.free_fn = CJsonBmsFree;
cJSON_InitHooks(&hooks);
}
#endif // CONFIG_FT_MODE
#endif // __LITEOS_M__
/*
* path should not include ".." or "./" or ".\0"
*/
@@ -93,7 +114,11 @@ bool BundleUtil::IsFile(const char *path)
if (ret != 0) {
return false;
}
#ifdef __LITEOS_M__
#ifndef CONFIG_FT_MODE
OhosBmsCjsonHooksInit();
#endif
#endif
int32_t fp = open(path, O_RDONLY, S_IREAD | S_IWRITE);
if (fp >= 0) {
close(fp);
@@ -113,7 +138,11 @@ bool BundleUtil::IsDir(const char *path)
if (ret != 0) {
return false;
}
#ifdef __LITEOS_M__
#ifndef CONFIG_FT_MODE
OhosBmsCjsonHooksInit();
#endif
#endif
if ((buf.st_mode & S_IFDIR) == S_IFDIR) {
return true;
}
@@ -183,6 +212,11 @@ uint32_t BundleUtil::GetFileSize(const char *filePath)
if (ret != 0) {
return 0;
}
#ifdef __LITEOS_M__
#ifndef CONFIG_FT_MODE
OhosBmsCjsonHooksInit();
#endif
#endif
return fileInfo.st_size;
}
@@ -256,6 +290,11 @@ uint32_t BundleUtil::GetCurrentFolderSize(const char *dirPath, List<char *>* lis
list->PushBack(Utils::Strdup(filePath));
}
}
#ifdef __LITEOS_M__
#ifndef CONFIG_FT_MODE
OhosBmsCjsonHooksInit();
#endif
#endif
closedir(dir);
return fileSize;
}
@@ -351,7 +390,11 @@ cJSON *BundleUtil::GetJsonStream(const char *path)
#endif
return nullptr;
}
#ifdef __LITEOS_M__
#ifndef CONFIG_FT_MODE
OhosBmsCjsonHooksInit();
#endif
#endif
if (size > MAX_JSON_SIZE) {
#ifdef APP_PLATFORM_WATCHGT
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] GetJsonStream size fail:%d", size);
+12 -10
View File
@@ -76,7 +76,7 @@ uint8_t GtBundleExtractor::ExtractHap(const char *codePath, const char *bundleNa
if (errorCode != ERR_OK) {
UI_Free(relativeFilePath);
UI_Free(fileName);
return errorCode;
break;
}
index = index + INT_LENGTH + strlen(fileName) + INT_LENGTH + strlen(relativeFilePath) + LONG_LENGTH + fileSize;
UI_Free(relativeFilePath);
@@ -84,7 +84,7 @@ uint8_t GtBundleExtractor::ExtractHap(const char *codePath, const char *bundleNa
relativeFilePath = nullptr;
fileName = nullptr;
}
return errorCode;
return ERR_OK;
}
char *GtBundleExtractor::ExtractHapProfile(int32_t fp, uint32_t totalFileSize)
@@ -142,6 +142,7 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32
uint8_t errorCode = ExtractFileDataPos(fp, index);
if (errorCode != ERR_OK) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] extract file data pos failed!");
return false;
}
@@ -150,7 +151,7 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] get file attr failed!");
UI_Free(fileName);
UI_Free(relativeFilePath);
return false;
break;
}
int32_t fileNameLen = strlen(fileName);
@@ -185,13 +186,14 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName
if (!BundleUtil::CheckRealPath(path)) {
return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR;
}
#ifndef __LITEOS_M__
#ifdef __LITEOS_M__
int32_t totalFileSize = BundleUtil::GetFileSize(path);
#else
int32_t totalFileSize = APPVERI_GetUnsignedFileLength(path);
if (totalFileSize == V_ERR) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] get unsigned file length failed!");
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
#else
int32_t totalFileSize = 0;
#endif
char *emptyJsPathComp[] = {const_cast<char *>(TMP_RESOURCE_DIR), const_cast<char *>(ASSET_JS_PATH)};
char *emptyJsPath = BundleUtil::Strscat(emptyJsPathComp, sizeof(emptyJsPathComp) / sizeof(char *));
@@ -205,12 +207,13 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName
}
AdapterFree(emptyJsPath);
int32_t fp = open(path, O_RDONLY, S_IREAD | S_IWRITE);
int32_t fp = open(path, O_RDONLY, S_IREAD);
if (fp < 0) {
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS;
}
// extractor config.json、 resources dir and resources.index in TMP_RESOURCE_DIR
if (!ExtractResourceFile(TMP_RESOURCE_DIR, fp, static_cast<uint32_t>(totalFileSize))) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] extract resource file failed!");
close(fp);
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR;
}
@@ -219,6 +222,7 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName
BundleRes bundleRes = { 0 };
BundleInfo *bundleInfo = GtBundleParser::ParseHapProfile(TMP_RESOURCE_DIR, &bundleRes);
if (bundleInfo == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] parse hap profile get bundle info failed!");
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR;
}
if (bundleRes.abilityRes != nullptr) {
@@ -252,9 +256,7 @@ 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;
}
+19 -24
View File
@@ -55,8 +55,8 @@ uint8_t GtBundleInstaller::PreCheckBundle(const char *path, int32_t &fp, Signatu
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS;
}
uint32_t size = BundleUtil::GetFileSize(path);
if (size == 0) {
fileSize = BundleUtil::GetFileSize(path);
if (fileSize == 0) {
return ERR_APPEXECFWK_INSTALL_FAILED_BAD_FILE;
}
@@ -92,8 +92,10 @@ uint8_t GtBundleInstaller::PreCheckBundle(const char *path, int32_t &fp, Signatu
// check number of current installed third bundles whether is to MAX_THIRD_BUNDLE_NUMBER
if (bundleStyle == THIRD_APP_FLAG) {
uint32_t numOfBundles = GtManagerService::GetInstance().GetNumOfThirdBundles();
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] bundle num is %d", numOfBundles);
if (GtManagerService::GetInstance().QueryBundleInfo(bundleName) == nullptr &&
numOfBundles >= MAX_THIRD_BUNDLE_NUMBER) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] bundle quantity exceeds the limit!");
UI_Free(bundleName);
return ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_BUNDLE_NUMBER;
}
@@ -196,12 +198,13 @@ uint8_t GtBundleInstaller::Install(const char *path, InstallerCallback installer
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
uint8_t errorCode = ProcessBundleInstall(path, randStr, installRecord, bundleStyle, installerCallback);
bool isUpdate = false;
uint8_t errorCode = ProcessBundleInstall(path, randStr, installRecord, bundleStyle, installerCallback, isUpdate);
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)) {
@@ -214,7 +217,7 @@ uint8_t GtBundleInstaller::Install(const char *path, InstallerCallback installer
RecordThirdSystemBundle(installRecord.bundleName, THIRD_SYSTEM_BUNDLE_JSON);
}
if (bundleStyle == THIRD_APP_FLAG) {
if (bundleStyle == THIRD_APP_FLAG && !isUpdate) {
GtManagerService::GetInstance().AddNumOfThirdBundles();
}
// record app info event when install app
@@ -222,7 +225,7 @@ uint8_t GtBundleInstaller::Install(const char *path, InstallerCallback installer
}
uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *randStr, InstallRecord &installRecord,
uint8_t bundleStyle, InstallerCallback installerCallback)
uint8_t bundleStyle, InstallerCallback installerCallback, bool &isUpdate)
{
SignatureInfo signatureInfo;
signatureInfo = {.bundleName = nullptr, .appId = nullptr, .restricPermission = nullptr, .restricNum = 0};
@@ -240,14 +243,6 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra
CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo);
(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);
@@ -257,13 +252,16 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra
uint32_t iconId = (bundleRes.abilityRes != nullptr) ? bundleRes.abilityRes->iconId : 0;
AdapterFree(bundleRes.abilityRes);
// check signatureInfo
#ifndef __LITEOS_M__
errorCode = CheckProvisionInfoIsValid(signatureInfo, permissions, bundleInfo->bundleName);
CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo);
#endif
installRecord.codePath = bundleInfo->codePath;
installRecord.bundleName = bundleInfo->bundleName;
installRecord.appId = signatureInfo.appId;
char innerAppId[] = "appId";
installRecord.appId = innerAppId;
installRecord.versionCode = bundleInfo->versionCode;
bundleInfo->appId = Utils::Strdup(signatureInfo.appId);
bundleInfo->appId = Utils::Strdup(innerAppId);
// check version when in update status
errorCode = CheckVersionAndSignature(installRecord.bundleName, installRecord.appId, bundleInfo);
CHECK_PRO_RESULT(errorCode, fp, permissions, bundleInfo, signatureInfo);
@@ -290,7 +288,7 @@ uint8_t GtBundleInstaller::ProcessBundleInstall(const char *path, const char *ra
(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;
isUpdate = GtManagerService::GetInstance().QueryBundleInfo(installRecord.bundleName) != nullptr;
errorCode = HandleFileAndBackUpRecord(installRecord, tmpCodePath, randStr, bundleInfo->dataPath, isUpdate);
AdapterFree(tmpCodePath);
CHECK_PRO_ROLLBACK(errorCode, permissions, bundleInfo, signatureInfo, randStr);
@@ -588,11 +586,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<char *>(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);
@@ -745,12 +743,10 @@ 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;
}
@@ -761,12 +757,11 @@ uint8_t GtBundleInstaller::StorePermissions(const char *bundleName, PermissionTr
if (!BundleUtil::IsDir(PERMISSIONS_PATH)) {
BundleUtil::MkDirs(PERMISSIONS_PATH);
}
#ifndef __LITEOS_M__
if (SaveOrUpdatePermissions(const_cast<char *>(bundleName), permissions, permNum,
static_cast<IsUpdate>(isUpdate)) != 0) {
return ERR_APPEXECFWK_INSTALL_FAILED_STORE_PERMISSIONS_ERROR;
}
#endif
return ERR_OK;
}
+127 -108
View File
@@ -31,6 +31,7 @@
#include "gt_bundle_parser.h"
#include "gt_extractor_util.h"
#include "jerryscript_adapter.h"
#include "los_tick.h"
#include "sys/stat.h"
#include "unistd.h"
#include "utils.h"
@@ -40,13 +41,10 @@ using namespace OHOS::ACELite;
namespace OHOS {
const uint8_t OPERATION_DOING = 200;
const uint8_t BMS_INSTALLATION_START = 101;
const uint8_t BMS_UNINSTALLATION_START = 104;
const uint8_t BMS_INSTALLATION_COMPLETED = 100;
#ifndef __LITEOS_M__
const uint8_t BMS_INSTALLATION_START = 101;
#endif
GtManagerService::GtManagerService()
{
installer_ = new GtBundleInstaller();
@@ -55,6 +53,9 @@ GtManagerService::GtManagerService()
bundleInstallMsg_ = nullptr;
jsEngineVer_ = nullptr;
installedThirdBundleNum_ = 0;
preAppList_ = nullptr;
updateFlag_ = false;
oldVersionCode_ = -1;
}
GtManagerService::~GtManagerService()
@@ -68,18 +69,15 @@ 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<char *>(AdapterMalloc(strlen(hapPath) + 1));
if (path == nullptr) {
return false;
@@ -89,7 +87,6 @@ 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
@@ -108,7 +105,8 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
&(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath),
&(bundleInstallMsg_->bigIconPath));
if (ret != 0) {
char *name = strchr(path, '/');
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Install extract install msg failed, ret is %{public}d", ret);
char *name = strrchr(path, '/');
bundleInstallMsg_->bundleName = Utils::Strdup(name + 1);
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback);
ClearSystemBundleInstallMsg();
@@ -117,11 +115,21 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
return false;
}
updateFlag_ = false;
oldVersionCode_ = -1;
BundleInfo *installedInfo = bundleMap_->Get(bundleInstallMsg_->bundleName);
if (installedInfo != nullptr) {
updateFlag_ = true;
oldVersionCode_ = installedInfo->versionCode;
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] App is in the updated state");
}
SetCurrentBundle(bundleInstallMsg_->bundleName);
(void) ReportInstallCallback(OPERATION_DOING, 0, BMS_INSTALLATION_START, installerCallback);
DisableServiceWdg();
ret = installer_->Install(path, installerCallback);
EnableServiceWdg();
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] Install ret is %d", ret);
if (ret == 0) {
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback);
} else {
@@ -129,10 +137,6 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
}
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;
@@ -148,11 +152,9 @@ 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<char *>(AdapterMalloc(strlen(bundleName) + 1));
if (innerBundleName == nullptr) {
return false;
@@ -165,8 +167,10 @@ bool GtManagerService::Uninstall(const char *bundleName, const InstallParam *ins
(void) ReportUninstallCallback(OPERATION_DOING, BUNDLE_UNINSTALL_DOING, innerBundleName,
BMS_UNINSTALLATION_START, installerCallback);
DisableServiceWdg();
uint8_t ret = installer_->Uninstall(innerBundleName);
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] uninstall ret is %d", ret);
EnableServiceWdg();
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);
@@ -187,9 +191,12 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins
}
BundleInfo *installedInfo = bundleMap_->Get(bundleName);
if (installedInfo != nullptr) {
*installState = BUNDLE_INSTALL_OK;
*installProcess = BMS_INSTALLATION_COMPLETED;
return true;
bool isUpdateSuccess = updateFlag_ && oldVersionCode_ < installedInfo->versionCode;
if (!updateFlag_ || isUpdateSuccess) {
*installState = BUNDLE_INSTALL_OK;
*installProcess = BMS_INSTALLATION_COMPLETED;
return true;
}
}
if (bundleInstallMsg_ == nullptr || bundleInstallMsg_->bundleName == nullptr) {
*installState = BUNDLE_INSTALL_FAIL;
@@ -272,35 +279,49 @@ uint8_t GtManagerService::GetBundleInfosNoReplication(const int flags, BundleInf
bool GtManagerService::RegisterInstallerCallback(InstallerCallback installerCallback)
{
#ifndef __LITEOS_M__
if (installerCallback == nullptr) {
return false;
}
#endif
InstallPreBundle(systemPathList_, installerCallback);
return true;
}
void GtManagerService::InstallPreBundle(List<ToBeInstalledApp *> 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
// get third system bundle uninstall record
cJSON *uninstallRecord = BundleUtil::GetJsonStream(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON);
if (uninstallRecord == nullptr) {
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] InstallPreBundle uninstallRecord is nullptr!");
(void) unlink(UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON);
}
// scan system apps and third system apps
DisableServiceWdg();
ScanSystemApp(uninstallRecord, &systemPathList_);
if (uninstallRecord != nullptr) {
cJSON_Delete(uninstallRecord);
}
// scan third apps
ScanThirdApp(INSTALL_PATH, &systemPathList_);
EnableServiceWdg();
for (auto node = systemPathList.Begin(); node != systemPathList.End(); node = node->next_) {
ToBeInstalledApp *toBeInstalledApp = node->value_;
if (!BundleUtil::IsFile(toBeInstalledApp->path) ||
!BundleUtil::EndWith(toBeInstalledApp->path, INSTALL_FILE_SUFFIX)) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Pre install file path is invalid");
continue;
}
if (toBeInstalledApp->isUpdated) {
(void) ReloadBundleInfo(toBeInstalledApp->installedPath, toBeInstalledApp->appId,
toBeInstalledApp->isSystemApp);
}
if (!BundleUtil::IsFile(toBeInstalledApp->path) ||
!BundleUtil::EndWith(toBeInstalledApp->path, INSTALL_FILE_SUFFIX)) {
return;
}
(void) Install(toBeInstalledApp->path, nullptr, installerCallback);
}
RemoveSystemAppPathList(&systemPathList);
@@ -308,31 +329,28 @@ void GtManagerService::InstallPreBundle(List<ToBeInstalledApp *> systemPathList,
void GtManagerService::InstallAllSystemBundle(InstallerCallback installerCallback)
{
AppInfoList *list = GtManagerService::APP_InitAllAppInfo();
PreAppList *list = preAppList_;
if (list == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] InstallAllSystemBundle InitAllAppInfo fail, list is nullptr");
return;
}
AppInfoList *currentNode = nullptr;
AppInfoList *nextNode = nullptr;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) {
if (currentNode == nullptr) {
return;
}
if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) ||
(strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) {
PreAppList *currentNode = nullptr;
PreAppList *nextNode = nullptr;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, PreAppList, appDoubleList) {
if ((strcmp(((PreAppList *)currentNode)->filePath, ".") == 0) ||
(strcmp(((PreAppList *)currentNode)->filePath, "..") == 0)) {
continue;
}
if (!BundleUtil::IsFile(((AppInfoList *)currentNode)->filePath) ||
!BundleUtil::EndWith(((AppInfoList *)currentNode)->filePath, INSTALL_FILE_SUFFIX)) {
GtManagerService::APP_FreeAllAppInfo(list);
if (!BundleUtil::IsFile(((PreAppList *)currentNode)->filePath) ||
!BundleUtil::EndWith(((PreAppList *)currentNode)->filePath, INSTALL_FILE_SUFFIX)) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Install all system bundle file path is invalid");
return;
}
(void) Install(((AppInfoList *)currentNode)->filePath, nullptr, installerCallback);
(void) Install(((PreAppList *)currentNode)->filePath, nullptr, installerCallback);
}
GtManagerService::APP_FreeAllAppInfo(list);
GtManagerService::FreePreAppInfo(list);
}
void GtManagerService::ClearSystemBundleInstallMsg()
@@ -375,35 +393,7 @@ void GtManagerService::ScanPackages()
HILOG_WARN(HILOG_MODULE_AAFWK, "[BMS] get jsEngine version fail when restart!");
}
#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);
}
// scan system apps and third system apps
ScanSystemApp(uninstallRecord, &systemPathList_);
if (uninstallRecord != nullptr) {
cJSON_Delete(uninstallRecord);
}
// scan third apps
ScanThirdApp(INSTALL_PATH, &systemPathList_);
#ifdef __LITEOS_M__
InstallerCallback installerCallback = nullptr;
RegisterInstallerCallback(installerCallback);
#endif
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] get jsEngine version success!");
}
void GtManagerService::RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemPathList)
@@ -425,7 +415,7 @@ void GtManagerService::RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemP
void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInstalledApp *> *systemPathList)
{
AppInfoList *list = GtManagerService::APP_InitAllAppInfo();
PreAppList *list = preAppList_;
if (list == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ScanSystemApp InitAllAppInfo fail, list is nullptr");
return;
@@ -434,29 +424,30 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInst
uint8_t scanFlag = 0;
char *bundleName = nullptr;
int32_t versionCode = -1;
AppInfoList *currentNode = nullptr;
AppInfoList *nextNode = nullptr;
PreAppList *currentNode = nullptr;
PreAppList *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, PreAppList, appDoubleList) {
if (currentNode == nullptr) {
return;
}
if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) ||
(strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) {
if ((strcmp(((PreAppList *)currentNode)->filePath, ".") == 0) ||
(strcmp(((PreAppList *)currentNode)->filePath, "..") == 0)) {
continue;
}
if (BundleUtil::StartWith(((AppInfoList *)currentNode)->filePath, SYSTEM_BUNDLE_PATH)) {
if (BundleUtil::StartWith(((PreAppList *)currentNode)->filePath, SYSTEM_BUNDLE_PATH)) {
scanFlag = SYSTEM_APP_FLAG;
} else if (BundleUtil::StartWith(((AppInfoList *)currentNode)->filePath, THIRD_SYSTEM_BUNDLE_PATH)) {
} else if (BundleUtil::StartWith(((PreAppList *)currentNode)->filePath, THIRD_SYSTEM_BUNDLE_PATH)) {
scanFlag = THIRD_SYSTEM_APP_FLAG;
} else {
continue; // skip third app
}
// scan system app
bool res = CheckSystemBundleIsValid(((AppInfoList *)currentNode)->filePath, &bundleName, versionCode);
bool res = CheckSystemBundleIsValid(((PreAppList *)currentNode)->filePath, &bundleName, versionCode);
if (!res) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ScanSystemApp CheckSystemBundleIsValid failed!");
APP_ERRCODE_EXTRA(EXCE_ACE_APP_SCAN, EXCE_ACE_APP_SCAN_INVALID_SYSTEM_APP);
AdapterFree(bundleName);
continue;
@@ -469,11 +460,11 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInst
continue;
}
ReloadEntireBundleInfo(((AppInfoList *)currentNode)->filePath, bundleName,
ReloadEntireBundleInfo(((PreAppList *)currentNode)->filePath, bundleName,
systemPathList, versionCode, scanFlag);
AdapterFree(bundleName);
}
GtManagerService::APP_FreeAllAppInfo(list);
GtManagerService::FreePreAppInfo(list);
}
void GtManagerService::ScanThirdApp(const char *appDir, const List<ToBeInstalledApp *> *systemPathList)
@@ -488,19 +479,33 @@ void GtManagerService::ScanThirdApp(const char *appDir, const List<ToBeInstalled
if (dir == nullptr) {
return;
}
char *bundleName = reinterpret_cast<char *>(AdapterMalloc(MAX_BUNDLE_NAME_LEN + 1));
int32_t entLen = 0;
while ((ent = readdir(dir)) != nullptr) {
if ((strcmp(ent->d_name, ".") == 0) || (strcmp(ent->d_name, "..")) == 0) {
++entLen;
if (memset_s(bundleName, MAX_BUNDLE_NAME_LEN + 1, 0, MAX_BUNDLE_NAME_LEN + 1) != EOK) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] memset fail when initialize bundle name!");
break;
}
if (strcpy_s(bundleName, MAX_BUNDLE_NAME_LEN + 1, ent->d_name) != 0) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] failed to copy bundle name!");
break;
}
if ((strcmp(bundleName, ".") == 0) || (strcmp(bundleName, "..")) == 0) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] strcmp fail when reload third app!");
continue;
}
int32_t len = strlen(appDir) + 1 + strlen(ent->d_name) + 1;
int32_t len = strlen(appDir) + 1 + strlen(bundleName) + 1;
char *appPath = reinterpret_cast<char *>(UI_Malloc(len));
if (appPath == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] malloc fail when reload third app!");
break;
}
if (sprintf_s(appPath, len, "%s/%s", appDir, ent->d_name) < 0) {
if (sprintf_s(appPath, len, "%s/%s", appDir, bundleName) < 0) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] strcat fail when reload third app!");
UI_Free(appPath);
break;
@@ -513,20 +518,24 @@ void GtManagerService::ScanThirdApp(const char *appDir, const List<ToBeInstalled
}
if (IsSystemBundleInstalledPath(appPath, systemPathList)) {
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] app path is not third bundle path!");
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] app path is not third bundle path!");
UI_Free(appPath);
continue;
}
if (installedThirdBundleNum_ >= MAX_THIRD_BUNDLE_NUMBER) {
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] third bundle reload number is to MAX_THIRD_BUNDLE_NUMBER!");
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] third bundle reload number is %d!",
installedThirdBundleNum_);
UI_Free(appPath);
continue;
}
ReloadEntireBundleInfo(appPath, ent->d_name, nullptr, -1, THIRD_APP_FLAG);
ReloadEntireBundleInfo(appPath, bundleName, nullptr, -1, THIRD_APP_FLAG);
UI_Free(appPath);
}
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] third app number is %{public}d", entLen);
AdapterFree(bundleName);
closedir(dir);
}
@@ -575,6 +584,7 @@ void GtManagerService::ReloadEntireBundleInfo(const char *appPath, const char *b
int32_t oldVersionCode = -1;
if (appPath == nullptr || bundleName == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ReloadEntireBundleInfo app path or bundle name is nullptr!");
APP_ERRCODE_EXTRA(EXCE_ACE_APP_SCAN, EXCE_ACE_APP_SCAN_UNKNOWN_BUNDLE_INFO);
return;
}
@@ -601,6 +611,7 @@ void GtManagerService::ReloadEntireBundleInfo(const char *appPath, const char *b
}
} else {
if (!res && !BundleUtil::CheckBundleJsonIsValid(bundleName, &codePath, &appId, oldVersionCode)) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] ReloadEntireBundleInfo CheckBundleJsonIsValid failed!");
RecordAbiityInfoEvt(bundleName);
APP_ERRCODE_EXTRA(EXCE_ACE_APP_SCAN, EXCE_ACE_APP_SCAN_PARSE_JSON_FALIED);
AdapterFree(appId);
@@ -677,7 +688,6 @@ bool GtManagerService::ReloadBundleInfo(const char *profileDir, const char *appI
AdapterFree(bundleRes);
APP_ERRCODE_EXTRA(EXCE_ACE_APP_SCAN, EXCE_ACE_APP_SCAN_PARSE_PROFILE_FALIED);
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] reload bundle info fail!, isSystemApp is %d", isSystemApp);
BundleUtil::RemoveDir(profileDir);
return false;
}
@@ -756,7 +766,6 @@ void GtManagerService::UpdateBundleInfoList()
}
}
#ifdef BC_TRANS_ENABLE
void GtManagerService::TransformJsToBcWhenRestart(const char *codePath, const char *bundleName)
{
if (codePath == nullptr) {
@@ -778,6 +787,13 @@ void GtManagerService::TransformJsToBcWhenRestart(const char *codePath, const ch
return;
}
if (jsEngineVer_ == nullptr) {
cJSON_Delete(installRecordJson);
AdapterFree(bundleJsonPath);
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] TransformJsToBcWhenRestart jsEngineVer_ is nullptr!");
return;
}
cJSON *jsEngineVerObj = cJSON_CreateString(jsEngineVer_);
if (jsEngineVerObj == nullptr) {
cJSON_Delete(installRecordJson);
@@ -830,9 +846,7 @@ 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);
@@ -862,7 +876,6 @@ void GtManagerService::TransformJsToBc(const char *codePath, const char *bundleJ
}
(void)BundleUtil::StoreJsonContentToFile(bundleJsonPath, installRecordObj);
}
#endif
bool GtManagerService::CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object)
{
@@ -977,26 +990,23 @@ int32_t GtManagerService::ReportUninstallCallback(uint8_t errCode, uint8_t insta
return 0;
}
AppInfoList *GtManagerService::APP_InitAllAppInfo()
PreAppList *GtManagerService::InitPreAppInfo()
{
AppInfoList *list = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList));
PreAppList *list = (PreAppList *)AdapterMalloc(sizeof(PreAppList));
if (list == nullptr) {
return nullptr;
}
if (memset_s(list, sizeof(AppInfoList), 0, sizeof(AppInfoList)) != EOK) {
if (memset_s(list, sizeof(PreAppList), 0, sizeof(PreAppList)) != EOK) {
AdapterFree(list);
return nullptr;
}
LOS_ListInit(&list->appDoubleList);
APP_QueryAppInfo(SYSTEM_BUNDLE_PATH, list);
APP_QueryAppInfo(THIRD_SYSTEM_BUNDLE_PATH, list);
return list;
}
void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list)
void GtManagerService::QueryPreAppInfo(const char *appDir, PreAppList *list)
{
struct dirent *ent = nullptr;
if (appDir == nullptr) {
@@ -1041,25 +1051,25 @@ void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list)
continue;
}
APP_InsertAppInfo(appPath, (AppInfoList *)&list->appDoubleList);
InsertPreAppInfo(appPath, (PreAppList *)&list->appDoubleList);
AdapterFree(appPath);
}
closedir(dir);
AdapterFree(fileName);
closedir(dir);
}
void GtManagerService::APP_InsertAppInfo(char *filePath, AppInfoList *list)
void GtManagerService::InsertPreAppInfo(const char *filePath, PreAppList *list)
{
if ((filePath == nullptr) || (list == nullptr)) {
return;
}
AppInfoList *app = (AppInfoList *)AdapterMalloc(sizeof(AppInfoList));
PreAppList *app = (PreAppList *)AdapterMalloc(sizeof(PreAppList));
if (app == nullptr) {
return;
}
if (memset_s(app, sizeof(AppInfoList), 0, sizeof(AppInfoList)) != 0) {
if (memset_s(app, sizeof(PreAppList), 0, sizeof(PreAppList)) != 0) {
AdapterFree(app);
return;
}
@@ -1073,15 +1083,24 @@ void GtManagerService::APP_InsertAppInfo(char *filePath, AppInfoList *list)
return;
}
void GtManagerService::APP_FreeAllAppInfo(AppInfoList *list)
void GtManagerService::SetPreAppInfo(PreAppList *list)
{
if (list == nullptr) {
return;
}
preAppList_ = list;
return;
}
void GtManagerService::FreePreAppInfo(const PreAppList *list)
{
if (list == nullptr) {
return;
}
AppInfoList *currentNode = nullptr;
AppInfoList *nextNode = nullptr;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) {
PreAppList *currentNode = nullptr;
PreAppList *nextNode = nullptr;
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, PreAppList, appDoubleList) {
if (currentNode != nullptr) {
LOS_ListDelete(&(currentNode->appDoubleList));
AdapterFree(currentNode);
+4 -10
View File
@@ -402,6 +402,7 @@ BundleInfo *GtBundleParser::CreateBundleInfo(const char *path, const BundleProfi
uint8_t errorCode = ConvertResInfoToBundleInfo(path, bundleRes.abilityRes->labelId, bundleRes.abilityRes->iconId,
bundleInfo);
if (errorCode != ERR_OK) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] convert res to bundle info failed!");
BundleInfoUtils::FreeBundleInfo(bundleInfo);
return nullptr;
}
@@ -419,11 +420,7 @@ 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);
@@ -454,6 +451,7 @@ uint8_t GtBundleParser::ConvertResInfoToBundleInfo(const char *path, uint32_t la
if (labelId != 0) {
char *label = nullptr;
if (GLOBAL_GetValueById(labelId, resPath, &label) != 0) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] global get label failed!");
Free(label);
AdapterFree(resPath);
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_LABEL_RES_ERROR;
@@ -483,6 +481,7 @@ bool GtBundleParser::ConvertIconResToBundleInfo(const char *resPath, uint32_t ic
char *relativeIconPath = nullptr;
if (GLOBAL_GetValueById(iconId, const_cast<char *>(resPath), &relativeIconPath) != 0) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] global get icon failed!");
return false;
}
// set relativeIconDir
@@ -490,8 +489,7 @@ 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<char *>(ASSETS), relativeIconPath, const_cast<char *>(ICON_NAME)
@@ -607,11 +605,7 @@ 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);
+10 -10
View File
@@ -33,8 +33,8 @@ const uint8_t SHIFT_NUM = 8;
uint32_t GtExtractorUtil::ReadInt(int32_t fp)
{
char buf[INT_LENGTH] = {0};
if (read(fp, buf, INT_LENGTH) != INT_LENGTH) {
unsigned char buf[INT_LENGTH] = {0};
if (read(fp, buf, INT_LENGTH) != INT_LENGTH) {
return UINT_MAX;
}
@@ -50,7 +50,7 @@ uint32_t GtExtractorUtil::ReadInt(int32_t fp)
bool GtExtractorUtil::CheckMagicNumber(int32_t fp)
{
char buf[MAGIC_NUMBER_LEN] = {0};
unsigned char buf[MAGIC_NUMBER_LEN] = {0};
if (read(fp, buf, MAGIC_NUMBER_LEN) != MAGIC_NUMBER_LEN) {
return false;
}
@@ -62,7 +62,7 @@ bool GtExtractorUtil::CheckMagicNumber(int32_t fp)
uint64_t GtExtractorUtil::ReadLong(int32_t fp)
{
char buf[LONG_LENGTH] = {0};
unsigned char buf[LONG_LENGTH] = {0};
if (read(fp, buf, LONG_LENGTH) != LONG_LENGTH) {
return 0;
}
@@ -77,9 +77,9 @@ uint64_t GtExtractorUtil::ReadLong(int32_t fp)
return result;
}
char *GtExtractorUtil::ReadString(int32_t fp, uint32_t len)
unsigned char *GtExtractorUtil::ReadString(int32_t fp, uint32_t len)
{
char *buf = reinterpret_cast<char *>(UI_Malloc((len + 1) * sizeof(char)));
unsigned char *buf = reinterpret_cast<unsigned char *>(UI_Malloc((len + 1) * sizeof(unsigned char)));
if (buf == nullptr) {
return nullptr;
}
@@ -108,7 +108,7 @@ uint8_t GtExtractorUtil::ExtractFileHeaderInfo(int32_t fp, char **bundleName)
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}
if ((*bundleName = ReadString(fp, bundleNameLen)) == nullptr) {
if ((*bundleName = (char *)ReadString(fp, bundleNameLen)) == nullptr) {
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}
return ERR_OK;
@@ -136,7 +136,7 @@ uint8_t GtExtractorUtil::ExtractFileAttr(int32_t fp, char **fileName, char **rel
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}
if ((*fileName = ReadString(fp, nameLen)) == nullptr) {
if ((*fileName = (char *)ReadString(fp, nameLen)) == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Read fileName fail");
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}
@@ -146,7 +146,7 @@ uint8_t GtExtractorUtil::ExtractFileAttr(int32_t fp, char **fileName, char **rel
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Read path Int fail");
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
} else {
if ((*relativeFilePath = ReadString(fp, pathLen)) == nullptr) {
if ((*relativeFilePath = (char *)ReadString(fp, pathLen)) == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Read relativeFilePath fail");
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}
@@ -168,7 +168,7 @@ uint8_t GtExtractorUtil::ExtractFileAttr(int32_t fp, char **fileName, uint32_t &
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}
if ((*fileName = ReadString(fp, nameLen)) == nullptr) {
if ((*fileName = (char *)ReadString(fp, nameLen)) == nullptr) {
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] Read fileName fail");
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID;
}