mirror of
https://gitee.com/openharmony/appexecfwk_standard
synced 2024-11-23 13:09:48 +00:00
Merge branch 'master_0308_2' of https://gitee.com/for_master_code/appexecfwk_standard into master_0308_2
This commit is contained in:
commit
6427ce60af
@ -118,6 +118,8 @@ const std::map<std::string, std::string> ABI_MAP = {
|
||||
{X86, "x86"},
|
||||
{X86_64, "x86_64"},
|
||||
};
|
||||
const std::string SO_SUFFIX = ".so";
|
||||
constexpr unsigned int SO_SUFFIX_LEN = 3;
|
||||
|
||||
// uid and gid
|
||||
constexpr int32_t INVALID_UID = -1;
|
||||
@ -195,9 +197,10 @@ const int32_t MAX_LIMIT_SIZE = 4;
|
||||
const std::string DATA_ABILITY_URI_PREFIX = "dataability://";
|
||||
const char DATA_ABILITY_URI_SEPARATOR = '/';
|
||||
|
||||
const std::string EXTENSION_URI_PARAM_SEPARATOR = "///";
|
||||
const uint32_t EXTENSION_URI_PARAM_SEPARATOR_LEN = 3;
|
||||
const std::string EXTENSION_URI_MODULE_JSON_SEPARATOR = "//";
|
||||
const std::string EXTENSION_SCHEME_SEPARATOR = ":///";
|
||||
const uint32_t EXTENSION_SCHEME_SEPARATOR_LEN = 4;
|
||||
const std::string EXTENSION_URI_MODULE_JSON_SEPARATOR = "://";
|
||||
const std::string SEPARATOR = "/";
|
||||
|
||||
const int MAX_DIMENSION_SIZE = 10;
|
||||
const int MAX_DEVICETYPE_SIZE = 50;
|
||||
|
@ -187,6 +187,7 @@ private:
|
||||
/**
|
||||
* @brief Extract the code to temporilay directory and rename it.
|
||||
* @param info Indicates the InnerBundleInfo object of a bundle.
|
||||
* @param modulePath normal files decompression path.
|
||||
* @return Returns ERR_OK if the bundle extract and renamed successfully; returns error code otherwise.
|
||||
*/
|
||||
ErrCode ExtractModule(InnerBundleInfo &info, const std::string &modulePath);
|
||||
@ -222,9 +223,13 @@ private:
|
||||
/**
|
||||
* @brief Extract files of the current installing module package.
|
||||
* @param info Indicates the InnerBundleInfo object of a bundle under installing.
|
||||
* @param modulePath normal files decompression path.
|
||||
* @param targetSoPath so files decompression path.
|
||||
* @param cpuAbi cpuAbi.
|
||||
* @return Returns ERR_OK if the module files extraced successfully; returns error code otherwise.
|
||||
*/
|
||||
ErrCode ExtractModuleFiles(const InnerBundleInfo &info, const std::string &modulePath);
|
||||
ErrCode ExtractModuleFiles(const InnerBundleInfo &info, const std::string &modulePath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi);
|
||||
/**
|
||||
* @brief Create the data directories of current installing module package.
|
||||
* @param info Indicates the InnerBundleInfo object of a bundle under installing.
|
||||
@ -413,7 +418,6 @@ private:
|
||||
ErrCode GrantRequestPermissions(const InnerBundleInfo &info, const uint32_t tokenId);
|
||||
ErrCode UpdateDefineAndRequestPermissions(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo);
|
||||
ErrCode SetDirApl(const InnerBundleInfo &info);
|
||||
ErrCode CopyNativeSo(const InnerBundleInfo &info, const std::string &moduleDir);
|
||||
|
||||
InstallerState state_ = InstallerState::INSTALL_START;
|
||||
std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; // this pointer will get when public functions called
|
||||
|
@ -555,8 +555,11 @@ public:
|
||||
{
|
||||
APP_LOGD("uri : %{public}s", uri.c_str());
|
||||
for (const auto &item : baseExtensionInfos_) {
|
||||
if (uri.find(item.second.uri) == 0) {
|
||||
if (uri == item.second.uri) {
|
||||
extensionAbilityInfo = item.second;
|
||||
APP_LOGD("find target extension, bundleName : %{public}s, moduleName : %{public}s, name : %{public}s",
|
||||
extensionAbilityInfo.bundleName.c_str(), extensionAbilityInfo.moduleName.c_str(),
|
||||
extensionAbilityInfo.name.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,13 @@ public:
|
||||
/**
|
||||
* @brief Extract the files of a HAP module to the code directory.
|
||||
* @param srcModulePath Indicates the HAP file path.
|
||||
* @param targetPath Indicates the code directory path that the HAP to be extracted to.
|
||||
* @param targetPath normal files decompression path.
|
||||
* @param targetSoPath so files decompression path.
|
||||
* @param cpuAbi cpuAbi.
|
||||
* @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
|
||||
*/
|
||||
virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath) override;
|
||||
virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi) override;
|
||||
/**
|
||||
* @brief Rename the module directory from temporaily path to the real path.
|
||||
* @param oldPath Indicates the old path name.
|
||||
@ -112,7 +115,6 @@ public:
|
||||
*/
|
||||
virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl) override;
|
||||
|
||||
virtual ErrCode CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath) override;
|
||||
private:
|
||||
std::string GetBundleDataDir(const std::string &el, const int userid) const;
|
||||
ErrCode CreateNewBundleDataDir(const std::string &bundleName, const int userid, const int uid, const int gid,
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_extractor.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -55,10 +56,19 @@ public:
|
||||
/**
|
||||
* @brief Extract the files of a compressed package to a specific directory.
|
||||
* @param srcModulePath Indicates the package file path.
|
||||
* @param targetPath Indicates the destination directory path that to be extracted to.
|
||||
* @param targetPath normal files decompression path.
|
||||
* @param targetSoPath so files decompression path.
|
||||
* @param cpuAbi cpuAbi.
|
||||
* @return Returns true if the package extracted successfully; returns false otherwise.
|
||||
*/
|
||||
static bool ExtractFiles(const std::string &sourcePath, const std::string &targetPath);
|
||||
static bool ExtractFiles(const std::string &sourcePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi);
|
||||
|
||||
static bool isNativeSo(const std::string &entryName, const std::string &targetSoPath, const std::string &cpuAbi);
|
||||
|
||||
static void ExtractSo(const BundleExtractor &extractor, const std::string &entryName,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi);
|
||||
|
||||
/**
|
||||
* @brief Rename a directory from old path to new path.
|
||||
* @param oldPath Indicates the old path name.
|
||||
@ -144,8 +154,6 @@ public:
|
||||
* @return Returns disk size.
|
||||
*/
|
||||
static int64_t GetDiskUsageFromPath(const std::vector<std::string> &path);
|
||||
|
||||
static bool CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -39,10 +39,13 @@ public:
|
||||
/**
|
||||
* @brief Extract the files of a HAP module to the code directory.
|
||||
* @param srcModulePath Indicates the HAP file path.
|
||||
* @param targetPath Indicates the code directory path that the HAP to be extracted to.
|
||||
* @param targetPath normal files decompression path.
|
||||
* @param targetSoPath so files decompression path.
|
||||
* @param cpuAbi cpuAbi.
|
||||
* @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
|
||||
*/
|
||||
ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath);
|
||||
ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi);
|
||||
/**
|
||||
* @brief Rename the module directory from temporaily path to the real path.
|
||||
* @param oldPath Indicates the old path name.
|
||||
@ -124,7 +127,6 @@ public:
|
||||
*/
|
||||
ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl);
|
||||
|
||||
ErrCode CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath);
|
||||
private:
|
||||
/**
|
||||
* @brief Get the installd proxy object.
|
||||
|
@ -116,8 +116,6 @@ private:
|
||||
*/
|
||||
bool HandleSetDirApl(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
bool HandleCopyNativeSo(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
using InstalldFunc = bool (InstalldHost::*)(MessageParcel &, MessageParcel &);
|
||||
std::unordered_map<uint32_t, InstalldFunc> funcMap_;
|
||||
};
|
||||
|
@ -37,10 +37,13 @@ public:
|
||||
/**
|
||||
* @brief Extract the files of a HAP module to the code directory.
|
||||
* @param srcModulePath Indicates the HAP file path.
|
||||
* @param targetPath Indicates the code directory path that the HAP to be extracted to.
|
||||
* @param targetPath normal files decompression path.
|
||||
* @param targetSoPath so files decompression path.
|
||||
* @param cpuAbi cpuAbi.
|
||||
* @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
|
||||
*/
|
||||
virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &destPath) = 0;
|
||||
virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi) = 0;
|
||||
/**
|
||||
* @brief Rename the module directory from temporaily path to the real path.
|
||||
* @param oldPath Indicates the old path name.
|
||||
@ -113,8 +116,6 @@ public:
|
||||
* @return Returns ERR_OK if set apl successfully; returns error code otherwise.
|
||||
*/
|
||||
virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl) = 0;
|
||||
|
||||
virtual ErrCode CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath) = 0;
|
||||
protected:
|
||||
enum Message : uint32_t {
|
||||
CREATE_BUNDLE_DIR = 1,
|
||||
@ -127,8 +128,7 @@ protected:
|
||||
REMOVE_MODULE_DATA_DIR,
|
||||
REMOVE_DIR,
|
||||
GET_BUNDLE_STATS,
|
||||
SET_DIR_APL,
|
||||
COPY_NATIVE_SO
|
||||
SET_DIR_APL
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -37,10 +37,13 @@ public:
|
||||
/**
|
||||
* @brief Extract the files of a HAP module to the code directory through a proxy object.
|
||||
* @param srcModulePath Indicates the HAP file path.
|
||||
* @param targetPath Indicates the code directory path that the HAP to be extracted to.
|
||||
* @param targetPath normal files decompression path.
|
||||
* @param targetSoPath so files decompression path.
|
||||
* @param cpuAbi cpuAbi.
|
||||
* @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
|
||||
*/
|
||||
virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath) override;
|
||||
virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi) override;
|
||||
/**
|
||||
* @brief Rename the module directory from temporaily path to the real path through a proxy object.
|
||||
* @param oldPath Indicates the old path name.
|
||||
@ -113,8 +116,6 @@ public:
|
||||
* @return Returns ERR_OK if set apl successfully; returns error code otherwise.
|
||||
*/
|
||||
virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl) override;
|
||||
|
||||
virtual ErrCode CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath) override;
|
||||
private:
|
||||
ErrCode TransactInstalldCmd(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
|
@ -820,11 +820,6 @@ ErrCode BaseBundleInstaller::ProcessBundleInstallStatus(InnerBundleInfo &info, i
|
||||
APP_LOGE("extract module failed");
|
||||
return result;
|
||||
}
|
||||
result = CopyNativeSo(info, modulePath);
|
||||
if (result != ERR_OK) {
|
||||
APP_LOGE("copy native so failed, error : %{public}d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = CreateModuleDataDir(info);
|
||||
if (result != ERR_OK) {
|
||||
@ -926,11 +921,6 @@ ErrCode BaseBundleInstaller::ProcessNewModuleInstall(InnerBundleInfo &newInfo, I
|
||||
APP_LOGE("extract module and rename failed");
|
||||
return result;
|
||||
}
|
||||
result = CopyNativeSo(newInfo, modulePath);
|
||||
if (result != ERR_OK) {
|
||||
APP_LOGE("copy native so failed, error : %{public}d", result);
|
||||
return result;
|
||||
}
|
||||
ScopeGuard moduleGuard([&] { RemoveModuleDir(modulePath); });
|
||||
result = CreateModuleDataDir(newInfo);
|
||||
if (result != ERR_OK) {
|
||||
@ -1023,11 +1013,6 @@ ErrCode BaseBundleInstaller::ProcessModuleUpdate(InnerBundleInfo &newInfo,
|
||||
APP_LOGE("extract module and rename failed");
|
||||
return result;
|
||||
}
|
||||
result = CopyNativeSo(newInfo, moduleTmpDir_);
|
||||
if (result != ERR_OK) {
|
||||
APP_LOGE("copy native so failed, error : %{public}d", result);
|
||||
return result;
|
||||
}
|
||||
if (!dataMgr_->UpdateBundleInstallState(bundleName_, InstallState::UPDATING_SUCCESS)) {
|
||||
APP_LOGE("old module update state failed");
|
||||
return ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR;
|
||||
@ -1155,7 +1140,17 @@ ErrCode BaseBundleInstaller::CreateBundleDataDir(InnerBundleInfo &info, bool onl
|
||||
|
||||
ErrCode BaseBundleInstaller::ExtractModule(InnerBundleInfo &info, const std::string &modulePath)
|
||||
{
|
||||
auto result = ExtractModuleFiles(info, modulePath);
|
||||
std::string targetSoPath;
|
||||
std::string nativeLibraryPath = info.GetBaseApplicationInfo().nativeLibraryPath;
|
||||
if (!nativeLibraryPath.empty()) {
|
||||
targetSoPath.append(Constants::BUNDLE_CODE_DIR).append(Constants::PATH_SEPARATOR)
|
||||
.append(info.GetBundleName()).append(Constants::PATH_SEPARATOR)
|
||||
.append(nativeLibraryPath).append(Constants::PATH_SEPARATOR);
|
||||
}
|
||||
std::string cpuAbi = info.GetBaseApplicationInfo().cpuAbi;
|
||||
APP_LOGD("begin to extract module files, modulePath : %{public}s, targetSoPath : %{public}s, cpuAbi : %{public}s",
|
||||
modulePath.c_str(), targetSoPath.c_str(), cpuAbi.c_str());
|
||||
auto result = ExtractModuleFiles(info, modulePath, targetSoPath, cpuAbi);
|
||||
if (result != ERR_OK) {
|
||||
APP_LOGE("fail to extrace module dir, error is %{public}d", result);
|
||||
return result;
|
||||
@ -1166,38 +1161,6 @@ ErrCode BaseBundleInstaller::ExtractModule(InnerBundleInfo &info, const std::str
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BaseBundleInstaller::CopyNativeSo(const InnerBundleInfo &info, const std::string &moduleDir)
|
||||
{
|
||||
APP_LOGD("begin to copy native so, bundleName : %{public}s, moduleName : %{public}s",
|
||||
info.GetBundleName().c_str(), info.GetCurrentModulePackage().c_str());
|
||||
|
||||
std::string nativeLibraryPath = info.GetBaseApplicationInfo().nativeLibraryPath;
|
||||
std::string cpuAbi = info.GetBaseApplicationInfo().cpuAbi;
|
||||
APP_LOGD("nativeLibraryPath : %{public}s, cpuAbi : %{public}s", nativeLibraryPath.c_str(), cpuAbi.c_str());
|
||||
if (nativeLibraryPath.empty()) {
|
||||
APP_LOGD("native so not exist, skip");
|
||||
return ERR_OK;
|
||||
}
|
||||
if (cpuAbi.empty()) {
|
||||
APP_LOGE("cpuAbi invalid");
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
std::string srcLibPath;
|
||||
srcLibPath.append(moduleDir).append(Constants::PATH_SEPARATOR)
|
||||
.append(Constants::LIB_FOLDER_NAME).append(Constants::PATH_SEPARATOR)
|
||||
.append(cpuAbi).append(Constants::PATH_SEPARATOR);
|
||||
APP_LOGD("srcLibPath : %{public}s", srcLibPath.c_str());
|
||||
|
||||
std::string targetLibPath;
|
||||
targetLibPath.append(Constants::BUNDLE_CODE_DIR).append(Constants::PATH_SEPARATOR)
|
||||
.append(info.GetBundleName()).append(Constants::PATH_SEPARATOR)
|
||||
.append(nativeLibraryPath).append(Constants::PATH_SEPARATOR);
|
||||
APP_LOGD("targetLibPath : %{public}s", targetLibPath.c_str());
|
||||
|
||||
return InstalldClient::GetInstance()->CopyNativeSo(srcLibPath, targetLibPath);
|
||||
}
|
||||
|
||||
ErrCode BaseBundleInstaller::RemoveBundleAndDataDir(const InnerBundleInfo &info, bool isUninstall) const
|
||||
{
|
||||
// remove bundle dir
|
||||
@ -1321,10 +1284,11 @@ ErrCode BaseBundleInstaller::ParseBundleInfo(const std::string &bundleFilePath,
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BaseBundleInstaller::ExtractModuleFiles(const InnerBundleInfo &info, const std::string &modulePath)
|
||||
ErrCode BaseBundleInstaller::ExtractModuleFiles(const InnerBundleInfo &info, const std::string &modulePath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
APP_LOGD("extract module to %{public}s", modulePath.c_str());
|
||||
auto result = InstalldClient::GetInstance()->ExtractModuleFiles(modulePath_, modulePath);
|
||||
auto result = InstalldClient::GetInstance()->ExtractModuleFiles(modulePath_, modulePath, targetSoPath, cpuAbi);
|
||||
if (result != ERR_OK) {
|
||||
APP_LOGE("extract module files failed, error is %{public}d", result);
|
||||
return result;
|
||||
|
@ -2900,15 +2900,25 @@ bool BundleDataMgr::QueryExtensionAbilityInfoByUri(const std::string &uri, int32
|
||||
APP_LOGE("uri empty");
|
||||
return false;
|
||||
}
|
||||
if (uri.find(Constants::EXTENSION_URI_PARAM_SEPARATOR) == std::string::npos) {
|
||||
APP_LOGE("uri not include ///, invalid");
|
||||
// example of valid param uri : fileShare:///com.example.FileShare/person/10
|
||||
// example of convertUri : fileShare://com.example.FileShare
|
||||
size_t schemePos = uri.find(Constants::EXTENSION_SCHEME_SEPARATOR);
|
||||
if (schemePos == uri.npos) {
|
||||
APP_LOGE("uri not include :///, invalid");
|
||||
return false;
|
||||
}
|
||||
std::string convertUri = uri;
|
||||
convertUri.replace(uri.find(Constants::EXTENSION_URI_PARAM_SEPARATOR),
|
||||
Constants::EXTENSION_URI_PARAM_SEPARATOR_LEN, Constants::EXTENSION_URI_MODULE_JSON_SEPARATOR);
|
||||
size_t cutPos = uri.find(Constants::SEPARATOR, schemePos + Constants::EXTENSION_SCHEME_SEPARATOR_LEN);
|
||||
if (cutPos == uri.npos) {
|
||||
APP_LOGE("uri not include /, invalid");
|
||||
return false;
|
||||
}
|
||||
// 1. cut string
|
||||
std::string convertUri = uri.substr(0, cutPos);
|
||||
// 2. replace :/// with ://
|
||||
convertUri.replace(schemePos, Constants::EXTENSION_SCHEME_SEPARATOR_LEN,
|
||||
Constants::EXTENSION_URI_MODULE_JSON_SEPARATOR);
|
||||
APP_LOGD("convertUri : %{public}s", convertUri.c_str());
|
||||
|
||||
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
if (bundleInfos_.empty()) {
|
||||
APP_LOGE("bundleInfos_ data is empty");
|
||||
|
@ -40,6 +40,8 @@ bool BundleMgrHostImpl::GetApplicationInfo(
|
||||
bool BundleMgrHostImpl::GetApplicationInfo(
|
||||
const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo)
|
||||
{
|
||||
APP_LOGD("start GetApplicationInfo, bundleName : %{public}s, flags : %{public}d, userId : %{public}d",
|
||||
appName.c_str(), flags, userId);
|
||||
if (!VerifyQueryPermission(appName)) {
|
||||
APP_LOGE("verify permission failed");
|
||||
return false;
|
||||
@ -62,6 +64,7 @@ bool BundleMgrHostImpl::GetApplicationInfos(
|
||||
bool BundleMgrHostImpl::GetApplicationInfos(
|
||||
int32_t flags, int32_t userId, std::vector<ApplicationInfo> &appInfos)
|
||||
{
|
||||
APP_LOGD("start GetApplicationInfos, flags : %{public}d, userId : %{public}d", flags, userId);
|
||||
if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) {
|
||||
APP_LOGE("verify permission failed");
|
||||
return false;
|
||||
@ -84,6 +87,8 @@ bool BundleMgrHostImpl::GetBundleInfo(
|
||||
bool BundleMgrHostImpl::GetBundleInfo(
|
||||
const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId)
|
||||
{
|
||||
APP_LOGD("start GetBundleInfo, bundleName : %{public}s, flags : %{public}d, userId : %{public}d",
|
||||
bundleName.c_str(), flags, userId);
|
||||
if (!VerifyQueryPermission(bundleName)) {
|
||||
APP_LOGE("verify permission failed");
|
||||
return false;
|
||||
@ -126,6 +131,7 @@ bool BundleMgrHostImpl::GetBundleInfos(const BundleFlag flag, std::vector<Bundle
|
||||
|
||||
bool BundleMgrHostImpl::GetBundleInfos(int32_t flags, std::vector<BundleInfo> &bundleInfos, int32_t userId)
|
||||
{
|
||||
APP_LOGD("start GetBundleInfos, flags : %{public}d, userId : %{public}d", flags, userId);
|
||||
if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) {
|
||||
APP_LOGE("verify permission failed");
|
||||
return false;
|
||||
|
@ -64,7 +64,8 @@ ErrCode InstalldHostImpl::CreateBundleDir(const std::string &bundleDir)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode InstalldHostImpl::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath)
|
||||
ErrCode InstalldHostImpl::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
APP_LOGD("ExtractModuleFiles extract original src %{public}s and target src %{public}s",
|
||||
srcModulePath.c_str(), targetPath.c_str());
|
||||
@ -76,7 +77,7 @@ ErrCode InstalldHostImpl::ExtractModuleFiles(const std::string &srcModulePath, c
|
||||
APP_LOGE("create target dir %{public}s failed", targetPath.c_str());
|
||||
return ERR_APPEXECFWK_INSTALLD_CREATE_DIR_FAILED;
|
||||
}
|
||||
if (!InstalldOperator::ExtractFiles(srcModulePath, targetPath)) {
|
||||
if (!InstalldOperator::ExtractFiles(srcModulePath, targetPath, targetSoPath, cpuAbi)) {
|
||||
APP_LOGE("extract %{public}s to %{public}s failed", srcModulePath.c_str(), targetPath.c_str());
|
||||
InstalldOperator::DeleteDir(targetPath);
|
||||
return ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT;
|
||||
@ -393,31 +394,5 @@ ErrCode InstalldHostImpl::SetDirApl(const std::string &dir, const std::string &b
|
||||
return ERR_OK;
|
||||
#endif // WITH_SELINUX
|
||||
}
|
||||
|
||||
ErrCode InstalldHostImpl::CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath)
|
||||
{
|
||||
APP_LOGD("srcLibPath : %{public}s, targetLibPath : %{public}s", srcLibPath.c_str(), targetLibPath.c_str());
|
||||
if (srcLibPath.empty() || targetLibPath.empty()) {
|
||||
APP_LOGE("Calling the function CopyNativeSo with invalid param");
|
||||
return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
|
||||
}
|
||||
if (!InstalldOperator::IsExistDir(srcLibPath)) {
|
||||
APP_LOGW("srcLibPath : %{public}s not exist", srcLibPath.c_str());
|
||||
return ERR_OK;
|
||||
}
|
||||
// create dir if not exist
|
||||
if (!InstalldOperator::IsExistDir(targetLibPath)) {
|
||||
if (!InstalldOperator::MkRecursiveDir(targetLibPath, true)) {
|
||||
APP_LOGE("create targetLibPath %{public}s failed", targetLibPath.c_str());
|
||||
return ERR_APPEXECFWK_INSTALLD_CREATE_DIR_FAILED;
|
||||
}
|
||||
}
|
||||
// copy so to targetLibPath, modify so DAC
|
||||
if (!InstalldOperator::CopyNativeSo(srcLibPath, targetLibPath)) {
|
||||
APP_LOGE("copy native so failed");
|
||||
return ERR_APPEXECFWK_INSTALLD_EXTRACT_FILES_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -27,9 +27,7 @@
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "bundle_extractor.h"
|
||||
#include "directory_ex.h"
|
||||
#include "file_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -81,7 +79,8 @@ bool InstalldOperator::DeleteDir(const std::string &path)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InstalldOperator::ExtractFiles(const std::string &sourcePath, const std::string &targetPath)
|
||||
bool InstalldOperator::ExtractFiles(const std::string &sourcePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
BundleExtractor extractor(sourcePath);
|
||||
if (!extractor.Init()) {
|
||||
@ -106,6 +105,11 @@ bool InstalldOperator::ExtractFiles(const std::string &sourcePath, const std::st
|
||||
if (entryName.back() == Constants::PATH_SEPARATOR[0]) {
|
||||
continue;
|
||||
}
|
||||
// handle native so
|
||||
if (isNativeSo(entryName, targetSoPath, cpuAbi)) {
|
||||
ExtractSo(extractor, entryName, targetSoPath, cpuAbi);
|
||||
continue;
|
||||
}
|
||||
const std::string dir = GetPathDir(entryName);
|
||||
std::string filePath = targetDir + dir;
|
||||
if (!dir.empty()) {
|
||||
@ -126,6 +130,59 @@ bool InstalldOperator::ExtractFiles(const std::string &sourcePath, const std::st
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InstalldOperator::isNativeSo(const std::string &entryName,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
APP_LOGD("isNativeSo, entryName : %{public}s", entryName.c_str());
|
||||
if (targetSoPath.empty()) {
|
||||
APP_LOGD("current hap not include so");
|
||||
return false;
|
||||
}
|
||||
std::string prefix = Constants::LIBS + cpuAbi + Constants::PATH_SEPARATOR;
|
||||
if (entryName.find(prefix) == std::string::npos) {
|
||||
APP_LOGD("entryName not start with %{public}s", prefix.c_str());
|
||||
return false;
|
||||
}
|
||||
size_t len = entryName.length();
|
||||
if (len <= Constants::SO_SUFFIX_LEN) {
|
||||
APP_LOGD("entryName length invalid");
|
||||
return false;
|
||||
}
|
||||
std::string suffix = entryName.substr(len - Constants::SO_SUFFIX_LEN, len);
|
||||
if (suffix != Constants::SO_SUFFIX) {
|
||||
APP_LOGD("entryName suffix not .so");
|
||||
return false;
|
||||
}
|
||||
APP_LOGD("find native so, entryName : %{public}s", entryName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void InstalldOperator::ExtractSo(const BundleExtractor &extractor, const std::string &entryName,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
// create dir if not exist
|
||||
if (!IsExistDir(targetSoPath)) {
|
||||
if (!MkRecursiveDir(targetSoPath, true)) {
|
||||
APP_LOGE("create targetSoPath %{public}s failed", targetSoPath.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::string prefix = Constants::LIBS + cpuAbi + Constants::PATH_SEPARATOR;
|
||||
std::string targetSoName = entryName.substr(prefix.length());
|
||||
std::string targetSo = targetSoPath + targetSoName;
|
||||
bool ret = extractor.ExtractFile(entryName, targetSo);
|
||||
if (!ret) {
|
||||
APP_LOGE("extract so failed, entryName : %{public}s", entryName.c_str());
|
||||
return;
|
||||
}
|
||||
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
if (!OHOS::ChangeModeFile(targetSo, mode)) {
|
||||
APP_LOGE("change mode failed, targetSo : %{public}s", targetSo.c_str());
|
||||
return;
|
||||
}
|
||||
APP_LOGD("extract so success, targetSo : %{public}s", targetSo.c_str());
|
||||
}
|
||||
|
||||
bool InstalldOperator::RenameDir(const std::string &oldPath, const std::string &newPath)
|
||||
{
|
||||
if (oldPath.empty() || oldPath.size() > PATH_MAX) {
|
||||
@ -340,36 +397,5 @@ int64_t InstalldOperator::GetDiskUsageFromPath(const std::vector<std::string> &p
|
||||
}
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
bool InstalldOperator::CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath)
|
||||
{
|
||||
APP_LOGD("begin to copy native so");
|
||||
std::vector<std::string> nativeSoList;
|
||||
GetDirFiles(srcLibPath, nativeSoList);
|
||||
|
||||
size_t pos = srcLibPath.size();
|
||||
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
std::vector<char> content;
|
||||
|
||||
for (const std::string &fileName : nativeSoList) {
|
||||
if (!OHOS::LoadBufferFromFile(fileName, content)) {
|
||||
APP_LOGE("LoadBufferFromFile failed, fileName : %{public}s", fileName.c_str());
|
||||
continue;
|
||||
}
|
||||
std::string targetFileName = targetLibPath + fileName.substr(pos);
|
||||
if (!OHOS::SaveBufferToFile(targetFileName, content, true)) {
|
||||
APP_LOGE("SaveBufferToFile failed, targetFileName : %{public}s", targetFileName.c_str());
|
||||
continue;
|
||||
}
|
||||
if (!OHOS::ChangeModeFile(targetFileName, mode)) {
|
||||
APP_LOGE("change mode failed, targetFileName : %{public}s", targetFileName.c_str());
|
||||
continue;
|
||||
}
|
||||
APP_LOGD("copy native so success, targetFileName : %{public}s", targetFileName.c_str());
|
||||
}
|
||||
|
||||
APP_LOGD("copy native so finish");
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -33,14 +33,15 @@ ErrCode InstalldClient::CreateBundleDir(const std::string &bundleDir)
|
||||
return CallService(&IInstalld::CreateBundleDir, bundleDir);
|
||||
}
|
||||
|
||||
ErrCode InstalldClient::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath)
|
||||
ErrCode InstalldClient::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
if (srcModulePath.empty() || targetPath.empty()) {
|
||||
APP_LOGE("src module path or target path is empty");
|
||||
return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
|
||||
}
|
||||
|
||||
return CallService(&IInstalld::ExtractModuleFiles, srcModulePath, targetPath);
|
||||
return CallService(&IInstalld::ExtractModuleFiles, srcModulePath, targetPath, targetSoPath, cpuAbi);
|
||||
}
|
||||
|
||||
ErrCode InstalldClient::RenameModuleDir(const std::string &oldPath, const std::string &newPath)
|
||||
@ -137,16 +138,6 @@ ErrCode InstalldClient::SetDirApl(const std::string &dir, const std::string &bun
|
||||
return CallService(&IInstalld::SetDirApl, dir, bundleName, apl);
|
||||
}
|
||||
|
||||
ErrCode InstalldClient::CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath)
|
||||
{
|
||||
if (srcLibPath.empty() || targetLibPath.empty()) {
|
||||
APP_LOGE("param invalid");
|
||||
return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR;
|
||||
}
|
||||
|
||||
return CallService(&IInstalld::CopyNativeSo, srcLibPath, targetLibPath);
|
||||
}
|
||||
|
||||
void InstalldClient::ResetInstalldProxy()
|
||||
{
|
||||
if ((installdProxy_ != nullptr) && (installdProxy_->AsObject() != nullptr)) {
|
||||
|
@ -47,7 +47,6 @@ void InstalldHost::init()
|
||||
funcMap_.emplace(IInstalld::Message::SET_DIR_APL, &InstalldHost::HandleSetDirApl);
|
||||
funcMap_.emplace(IInstalld::Message::REMOVE_DIR, &InstalldHost::HandleRemoveDir);
|
||||
funcMap_.emplace(IInstalld::Message::GET_BUNDLE_STATS, &InstalldHost::HandleGetBundleStats);
|
||||
funcMap_.emplace(IInstalld::Message::COPY_NATIVE_SO, &InstalldHost::HandleCopyNativeSo);
|
||||
}
|
||||
|
||||
int InstalldHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
@ -85,8 +84,10 @@ bool InstalldHost::HandleExtractModuleFiles(MessageParcel &data, MessageParcel &
|
||||
{
|
||||
std::string srcModulePath = Str16ToStr8(data.ReadString16());
|
||||
std::string targetPath = Str16ToStr8(data.ReadString16());
|
||||
std::string targetSoPath = Str16ToStr8(data.ReadString16());
|
||||
std::string cpuAbi = Str16ToStr8(data.ReadString16());
|
||||
APP_LOGI("extract module %{public}s", targetPath.c_str());
|
||||
ErrCode result = ExtractModuleFiles(srcModulePath, targetPath);
|
||||
ErrCode result = ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi);
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
|
||||
return true;
|
||||
}
|
||||
@ -185,14 +186,5 @@ bool InstalldHost::HandleSetDirApl(MessageParcel &data, MessageParcel &reply)
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InstalldHost::HandleCopyNativeSo(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string srcLibPath = Str16ToStr8(data.ReadString16());
|
||||
std::string targetLibPath = Str16ToStr8(data.ReadString16());
|
||||
ErrCode result = CopyNativeSo(srcLibPath, targetLibPath);
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -49,12 +49,15 @@ ErrCode InstalldProxy::CreateBundleDir(const std::string &bundleDir)
|
||||
return TransactInstalldCmd(IInstalld::Message::CREATE_BUNDLE_DIR, data, reply, option);
|
||||
}
|
||||
|
||||
ErrCode InstalldProxy::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath)
|
||||
ErrCode InstalldProxy::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi)
|
||||
{
|
||||
MessageParcel data;
|
||||
INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
|
||||
INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcModulePath));
|
||||
INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetPath));
|
||||
INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetSoPath));
|
||||
INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(cpuAbi));
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
@ -184,18 +187,6 @@ ErrCode InstalldProxy::SetDirApl(const std::string &dir, const std::string &bund
|
||||
return TransactInstalldCmd(IInstalld::Message::SET_DIR_APL, data, reply, option);
|
||||
}
|
||||
|
||||
ErrCode InstalldProxy::CopyNativeSo(const std::string &srcLibPath, const std::string &targetLibPath)
|
||||
{
|
||||
MessageParcel data;
|
||||
INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor()));
|
||||
INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(srcLibPath));
|
||||
INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(targetLibPath));
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
return TransactInstalldCmd(IInstalld::Message::COPY_NATIVE_SO, data, reply, option);
|
||||
}
|
||||
|
||||
ErrCode InstalldProxy::TransactInstalldCmd(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ config("bundlemgr_test_config") {
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content/",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/uri/include",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/include",
|
||||
"//foundation/aafwk/standard/services/common/include",
|
||||
"//base/notification/ces_standard/interfaces/innerkits/native/include",
|
||||
|
@ -63,7 +63,8 @@ public:
|
||||
int RemoveBundleDir(const std::string &bundleDir) const;
|
||||
int RemoveBundleDataDir(const std::string &bundleDataDir) const;
|
||||
int CleanBundleDataDir(const std::string &bundleDataDir) const;
|
||||
int ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath) const;
|
||||
int ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi) const;
|
||||
int RenameModuleDir(const std::string &oldPath, const std::string &newPath) const;
|
||||
bool CheckBundleDirExist() const;
|
||||
bool CheckBundleDataDirExist() const;
|
||||
@ -152,12 +153,13 @@ int BmsInstallDaemonTest::CleanBundleDataDir(const std::string &bundleDataDir) c
|
||||
return InstalldClient::GetInstance()->CleanBundleDataDir(bundleDataDir);
|
||||
}
|
||||
|
||||
int BmsInstallDaemonTest::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath) const
|
||||
int BmsInstallDaemonTest::ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
|
||||
const std::string &targetSoPath, const std::string &cpuAbi) const
|
||||
{
|
||||
if (!service_->IsServiceReady()) {
|
||||
service_->Start();
|
||||
}
|
||||
return InstalldClient::GetInstance()->ExtractModuleFiles(srcModulePath, targetPath);
|
||||
return InstalldClient::GetInstance()->ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi);
|
||||
}
|
||||
|
||||
int BmsInstallDaemonTest::RenameModuleDir(const std::string &oldPath, const std::string &newPath) const
|
||||
@ -498,7 +500,7 @@ HWTEST_F(BmsInstallDaemonTest, ExtractBundleFile_0100, Function | SmallTest | Le
|
||||
bool dirExist = CheckBundleDirExist();
|
||||
EXPECT_TRUE(dirExist);
|
||||
auto bundleFile = BUNDLE_FILE;
|
||||
int result = ExtractModuleFiles(bundleFile, TEMP_DIR);
|
||||
int result = ExtractModuleFiles(bundleFile, TEMP_DIR, "", "");
|
||||
EXPECT_EQ(result, 0);
|
||||
int result1 = RenameModuleDir(TEMP_DIR, MODULE_DIR);
|
||||
EXPECT_EQ(result1, 0);
|
||||
@ -516,7 +518,7 @@ HWTEST_F(BmsInstallDaemonTest, ExtractBundleFile_0200, Function | SmallTest | Le
|
||||
CreateBundleDir(BUNDLE_CODE_DIR);
|
||||
bool dirExist = CheckBundleDirExist();
|
||||
EXPECT_TRUE(dirExist);
|
||||
int result = ExtractModuleFiles("", TEMP_DIR);
|
||||
int result = ExtractModuleFiles("", TEMP_DIR, "", "");
|
||||
EXPECT_EQ(result, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
|
||||
}
|
||||
|
||||
@ -533,7 +535,7 @@ HWTEST_F(BmsInstallDaemonTest, ExtractBundleFile_0300, Function | SmallTest | Le
|
||||
bool dirExist = CheckBundleDirExist();
|
||||
EXPECT_TRUE(dirExist);
|
||||
auto bundleFile = BUNDLE_FILE;
|
||||
int result = ExtractModuleFiles(bundleFile, "");
|
||||
int result = ExtractModuleFiles(bundleFile, "", "", "");
|
||||
EXPECT_EQ(result, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
|
||||
}
|
||||
|
||||
@ -550,7 +552,7 @@ HWTEST_F(BmsInstallDaemonTest, ExtractBundleFile_0400, Function | SmallTest | Le
|
||||
bool dirExist = CheckBundleDirExist();
|
||||
EXPECT_TRUE(dirExist);
|
||||
auto bundleFile = BUNDLE_FILE;
|
||||
int result = ExtractModuleFiles(bundleFile, TEMP_DIR);
|
||||
int result = ExtractModuleFiles(bundleFile, TEMP_DIR, "", "");
|
||||
EXPECT_EQ(result, 0);
|
||||
int result1 = RenameModuleDir("", MODULE_DIR);
|
||||
EXPECT_EQ(result1, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
|
||||
@ -569,7 +571,7 @@ HWTEST_F(BmsInstallDaemonTest, ExtractBundleFile_0500, Function | SmallTest | Le
|
||||
bool dirExist = CheckBundleDirExist();
|
||||
EXPECT_TRUE(dirExist);
|
||||
auto bundleFile = BUNDLE_FILE;
|
||||
int result = ExtractModuleFiles(bundleFile, TEMP_DIR);
|
||||
int result = ExtractModuleFiles(bundleFile, TEMP_DIR, "", "");
|
||||
EXPECT_EQ(result, 0);
|
||||
int result1 = RenameModuleDir(TEMP_DIR, "");
|
||||
EXPECT_EQ(result1, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
|
||||
|
@ -35,11 +35,13 @@ namespace {
|
||||
constexpr int32_t COLOR_CHANNEL_GREEN = 1;
|
||||
constexpr int32_t COLOR_CHANNEL_BLUE = 2;
|
||||
constexpr int32_t COLOR_CHANNEL_ALPHA = 3;
|
||||
constexpr int32_t NUMBER_ONE = 1;
|
||||
constexpr int32_t QUALITY = 30;
|
||||
constexpr double EPSILON = 1e-5;
|
||||
const std::string JPG = "jpg";
|
||||
const std::string PNG = "png";
|
||||
const std::string JPEG = "jpeg";
|
||||
const std::string BUNDLE_PATH = "/data/app/el1/bundle";
|
||||
struct EncodeMemo {
|
||||
ImageRow buffer;
|
||||
uint32_t size;
|
||||
@ -56,7 +58,11 @@ void ImageCompress::ReleasePngPointer(png_bytep* rowPointers, uint32_t h)
|
||||
|
||||
bool ImageCompress::IsPathValid(std::string& fileName)
|
||||
{
|
||||
return access(fileName.c_str(), F_OK) == 0;
|
||||
if (fileName.find(BUNDLE_PATH) != std::string::npos) {
|
||||
return access(fileName.c_str(), F_OK) == 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
double ImageCompress::CalRatio(std::string fileName)
|
||||
@ -154,6 +160,7 @@ bool ImageCompress::InitPngFile(std::shared_ptr<ImageBuffer>& imageBuffer,
|
||||
}
|
||||
png_read_update_info(png, info);
|
||||
if (imageBuffer->GetImageDataPointer()) {
|
||||
png_destroy_read_struct(&png, &info, NULL);
|
||||
return false;
|
||||
}
|
||||
imageBuffer->MallocImageMap(RGBA_COMPONENTS);
|
||||
@ -168,6 +175,7 @@ bool ImageCompress::InitPngFile(std::shared_ptr<ImageBuffer>& imageBuffer,
|
||||
for (uint32_t h = 0; h < imageBuffer->GetHeight(); ++h) {
|
||||
if (memcpy_s(imageRow, strides, rowPointers[h], strides) != EOK) {
|
||||
ReleasePngPointer(rowPointers, imageBuffer->GetHeight());
|
||||
png_destroy_read_struct(&png, &info, NULL);
|
||||
return false;
|
||||
}
|
||||
imageRow += strides;
|
||||
@ -321,8 +329,8 @@ int32_t ImageCompress::ResizeRGBAImage(std::shared_ptr<ImageBuffer>& imageBuffer
|
||||
uint32_t components = imageBufferIn->GetComponents();
|
||||
for (uint32_t h = 0; h < imageBufferOut->GetHeight(); ++h) {
|
||||
for (uint32_t w = 0; w < imageBufferOut->GetWidth(); ++w) {
|
||||
uint32_t heightIndex = std::round(h / ratio);
|
||||
uint32_t widthIndex = std::round(w / ratio);
|
||||
uint64_t heightIndex = std::round(h / ratio);
|
||||
uint64_t widthIndex = std::round(w / ratio);
|
||||
if (heightIndex > imageBufferIn->GetHeight()) {
|
||||
heightIndex = imageBufferIn->GetHeight() - 1;
|
||||
}
|
||||
@ -379,11 +387,12 @@ int32_t ImageCompress::DecodeJPGFile(std::string fileName, std::shared_ptr<Image
|
||||
|
||||
ImageRow imageRow = imageBuffer->GetImageDataPointer().get();
|
||||
uint32_t row_stride = cinfo.output_width * cinfo.output_components;
|
||||
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 1);
|
||||
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, NUMBER_ONE);
|
||||
while (cinfo.output_scanline < cinfo.image_height) {
|
||||
jpeg_read_scanlines(&cinfo, buffer, 1);
|
||||
jpeg_read_scanlines(&cinfo, buffer, NUMBER_ONE);
|
||||
if (memcpy_s(imageRow, row_stride, *buffer, row_stride) != EOK) {
|
||||
APP_LOGE("ImageCompress: memcpy_s buffer failed");
|
||||
fclose(inFile);
|
||||
return -1;
|
||||
}
|
||||
imageRow += row_stride;
|
||||
@ -457,8 +466,8 @@ int32_t ImageCompress::ResizeRGBImage(std::shared_ptr<ImageBuffer>& imageBufferI
|
||||
uint32_t components = imageBufferIn->GetComponents();
|
||||
for (uint32_t h = 0; h < imageBufferOut->GetHeight(); ++h) {
|
||||
for (uint32_t w = 0; w < imageBufferOut->GetWidth(); ++w) {
|
||||
uint32_t heightIndex = std::round(h / ratio);
|
||||
uint32_t widthIndex = std::round(w / ratio);
|
||||
uint64_t heightIndex = std::round(h / ratio);
|
||||
uint64_t widthIndex = std::round(w / ratio);
|
||||
if (heightIndex > imageBufferIn->GetHeight()) {
|
||||
heightIndex = imageBufferIn->GetHeight() - 1;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ config("bms_module_test_config") {
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content/",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/include",
|
||||
"//foundation/aafwk/standard/services/common/include",
|
||||
]
|
||||
|
@ -23,7 +23,6 @@ config("bundlemgr_fuzztest_config") {
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content/",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/include",
|
||||
"//foundation/aafwk/standard/services/common/include",
|
||||
"//base/notification/ces_standard/interfaces/innerkits/native/include",
|
||||
|
@ -25,7 +25,6 @@ config("third_page_demo1_config") {
|
||||
"${services_path}/bundlemgr/include",
|
||||
"${aafwk_path}/services/abilitymgr/include",
|
||||
"${common_path}/log/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"${SUBST_TOOLS_DIR}/include",
|
||||
"//third_party/jsoncpp/include",
|
||||
]
|
||||
@ -47,7 +46,6 @@ ohos_shared_library("page_ability_native1") {
|
||||
"${innerkits_path}/appexecfwk_base:appexecfwk_base",
|
||||
"${innerkits_path}/appexecfwk_core:appexecfwk_core",
|
||||
"${services_path}/bundlemgr:libbms",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//utils/native/base:utilsbase",
|
||||
]
|
||||
|
@ -25,7 +25,6 @@ config("third_page_demo2_config") {
|
||||
"${services_path}/bundlemgr/include",
|
||||
"${aafwk_path}/services/abilitymgr/include",
|
||||
"${common_path}/log/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"${SUBST_TOOLS_DIR}/include",
|
||||
"//third_party/jsoncpp/include",
|
||||
]
|
||||
@ -47,7 +46,6 @@ ohos_shared_library("page_ability_native2") {
|
||||
"${innerkits_path}/appexecfwk_base:appexecfwk_base",
|
||||
"${innerkits_path}/appexecfwk_core:appexecfwk_core",
|
||||
"${services_path}/bundlemgr:libbms",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//utils/native/base:utilsbase",
|
||||
]
|
||||
|
@ -25,7 +25,6 @@ config("third_page_demo3_config") {
|
||||
"${services_path}/bundlemgr/include",
|
||||
"${aafwk_path}/services/abilitymgr/include",
|
||||
"${common_path}/log/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"${SUBST_TOOLS_DIR}/include",
|
||||
"//third_party/jsoncpp/include",
|
||||
]
|
||||
@ -47,7 +46,6 @@ ohos_shared_library("page_ability_native3") {
|
||||
"${innerkits_path}/appexecfwk_base:appexecfwk_base",
|
||||
"${innerkits_path}/appexecfwk_core:appexecfwk_core",
|
||||
"${services_path}/bundlemgr:libbms",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//utils/native/base:utilsbase",
|
||||
]
|
||||
|
@ -25,7 +25,6 @@ config("third_page_demo4_config") {
|
||||
"${services_path}/bundlemgr/include",
|
||||
"${aafwk_path}/services/abilitymgr/include",
|
||||
"${common_path}/log/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"${SUBST_TOOLS_DIR}/include",
|
||||
"//third_party/jsoncpp/include",
|
||||
]
|
||||
@ -47,7 +46,6 @@ ohos_shared_library("page_ability_native4") {
|
||||
"${innerkits_path}/appexecfwk_base:appexecfwk_base",
|
||||
"${innerkits_path}/appexecfwk_core:appexecfwk_core",
|
||||
"${services_path}/bundlemgr:libbms",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//utils/native/base:utilsbase",
|
||||
]
|
||||
|
@ -20,6 +20,7 @@ config("tools_bm_config_mock") {
|
||||
include_dirs = [
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_base/include",
|
||||
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"${aafwk_path}/interfaces/innerkits/uri/include",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include",
|
||||
"${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content",
|
||||
"${appexecfwk_path}/interfaces/innerkits/libeventhandler/include",
|
||||
@ -27,7 +28,6 @@ config("tools_bm_config_mock") {
|
||||
"${appexecfwk_path}/tools/test/mock",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
|
||||
"//base/security/appverify/interfaces/innerkits/appverify/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//third_party/googletest/googlemock/include",
|
||||
"//third_party/json/single_include",
|
||||
]
|
||||
|
@ -57,12 +57,10 @@ ohos_shared_library("zlib") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:task_dispatcher",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"hilog_native:libhilog_base",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user