!5266 增加DeleteAbc功能

Merge pull request !5266 from dujingcheng/deleteabc
This commit is contained in:
openharmony_ci 2024-01-13 08:09:18 +00:00 committed by Gitee
commit 7b4e3f6125
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 207 additions and 2 deletions

View File

@ -394,6 +394,9 @@ enum {
ERR_BUNDLE_MANAGER_VERIFY_PERMISSION_DENIED = 8521708,
ERR_BUNDLE_MANAGER_VERIFY_CREATE_TARGET_DIR_FAILED = 8521709,
ERR_BUNDLE_MANAGER_VERIFY_VERIFY_ABC_FAILED = 8521710,
ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR = 8521711,
ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED = 8521712,
ERR_BUNDLE_MANAGER_DELETE_ABC_SEND_REQUEST_FAILED = 8521713,
// code signature
ERR_BUNDLE_MANAGER_CODE_SIGNATURE_DELIVERY_FILE_FAILED = 8521800,

View File

@ -283,6 +283,7 @@ enum class BundleResourceInterfaceCode : uint32_t {
enum class VerifyManagerInterfaceCode : uint32_t {
VERIFY = 0,
CREATE_FD = 1,
DELETE_ABC = 2,
};
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -33,6 +33,7 @@ private:
ErrCode HandleVerify(MessageParcel& data, MessageParcel& reply);
ErrCode HandleCopyFiles(MessageParcel& data, MessageParcel& reply);
ErrCode HandleCreateFd(MessageParcel& data, MessageParcel& reply);
ErrCode HandleDeleteAbc(MessageParcel& data, MessageParcel& reply);
DISALLOW_COPY_AND_MOVE(VerifyManagerHost);
};

View File

@ -48,6 +48,11 @@ public:
{
return ERR_BUNDLEMANAGER_QUICK_FIX_INTERNAL_ERROR;
}
virtual ErrCode DeleteAbc(const std::string &path)
{
return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
}
};
} // AppExecFwk
} // OHOS

View File

@ -31,6 +31,7 @@ public:
const std::vector<std::string> &abcNames, bool flag) override;
virtual ErrCode RemoveFiles(const std::vector<std::string> &abcPaths) override;
virtual ErrCode DeleteAbc(const std::string &path) override;
private:
virtual ErrCode CopyFiles(

View File

@ -54,6 +54,8 @@ int VerifyManagerHost::OnRemoteRequest(uint32_t code, MessageParcel& data,
return HandleVerify(data, reply);
case static_cast<uint32_t>(VerifyManagerInterfaceCode::CREATE_FD):
return HandleCreateFd(data, reply);
case static_cast<uint32_t>(VerifyManagerInterfaceCode::DELETE_ABC):
return HandleDeleteAbc(data, reply);
default:
APP_LOGW("VerifyManagerHost receive unknown code, code = %{public}d", code);
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@ -113,5 +115,18 @@ ErrCode VerifyManagerHost::HandleCreateFd(MessageParcel& data, MessageParcel& re
close(fd);
return ERR_OK;
}
ErrCode VerifyManagerHost::HandleDeleteAbc(MessageParcel& data, MessageParcel& reply)
{
APP_LOGD("begin to HandleDeleteAbc.");
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
std::string path = data.ReadString();
auto ret = DeleteAbc(path);
if (!reply.WriteInt32(ret)) {
APP_LOGE("write ret failed.");
return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
}
return ERR_OK;
}
} // AppExecFwk
} // namespace OHOS

View File

@ -32,7 +32,8 @@ const std::string SEPARATOR = "/";
const int32_t DEFAULT_BUFFER_SIZE = 65536;
}
VerifyManagerProxy::VerifyManagerProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IVerifyManager>(object)
VerifyManagerProxy::VerifyManagerProxy(const sptr<IRemoteObject> &object)
: IRemoteProxy<IVerifyManager>(object)
{
APP_LOGI("create VerifyManagerProxy.");
}
@ -190,7 +191,36 @@ ErrCode VerifyManagerProxy::CopyFiles(
return ERR_OK;
}
bool VerifyManagerProxy::SendRequest(VerifyManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply)
ErrCode VerifyManagerProxy::DeleteAbc(const std::string &path)
{
APP_LOGI("begin to call DeleteAbc.");
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (path.empty()) {
APP_LOGE("DeleteAbc failed due to params error.");
return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
APP_LOGE("WriteInterfaceToken failed.");
return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
}
if (!data.WriteString(path)) {
APP_LOGE("write path failed.");
return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
}
MessageParcel reply;
if (!SendRequest(VerifyManagerInterfaceCode::DELETE_ABC, data, reply)) {
APP_LOGE("SendRequest failed.");
return ERR_BUNDLE_MANAGER_DELETE_ABC_SEND_REQUEST_FAILED;
}
return reply.ReadInt32();
}
bool VerifyManagerProxy::SendRequest(
VerifyManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply)
{
MessageOption option(MessageOption::TF_SYNC);
sptr<IRemoteObject> remote = Remote();

View File

@ -51,6 +51,7 @@ constexpr const char* PROFILE_TYPE = "profileType";
constexpr const char* STRING_TYPE = "napi_string";
constexpr const char* GET_LAUNCH_WANT_FOR_BUNDLE = "GetLaunchWantForBundle";
constexpr const char* VERIFY_ABC = "VerifyAbc";
constexpr const char* DELETE_ABC = "DeleteAbc";
constexpr const char* ERR_MSG_BUNDLE_SERVICE_EXCEPTION = "Bundle manager service is excepted.";
constexpr const char* ADDITIONAL_INFO = "additionalInfo";
const std::string GET_BUNDLE_ARCHIVE_INFO = "GetBundleArchiveInfo";
@ -1730,6 +1731,84 @@ napi_value VerifyAbc(napi_env env, napi_callback_info info)
return promise;
}
ErrCode InnerDeleteAbc(const std::string &path)
{
auto verifyManager = CommonFunc::GetVerifyManager();
if (verifyManager == nullptr) {
APP_LOGE("iBundleMgr is null");
return ERROR_BUNDLE_SERVICE_EXCEPTION;
}
ErrCode ret = verifyManager->DeleteAbc(path);
if (ret != ERR_OK) {
APP_LOGE("DeleteAbc failed");
}
return CommonFunc::ConvertErrCode(ret);
}
void DeleteAbcExec(napi_env env, void *data)
{
VerifyCallbackInfo* asyncCallbackInfo = reinterpret_cast<VerifyCallbackInfo*>(data);
if (asyncCallbackInfo == nullptr) {
APP_LOGE("error VerifyCallbackInfo is nullptr");
return;
}
asyncCallbackInfo->err = InnerDeleteAbc(asyncCallbackInfo->deletePath);
}
void DeleteAbcComplete(napi_env env, napi_status status, void *data)
{
VerifyCallbackInfo *asyncCallbackInfo = reinterpret_cast<VerifyCallbackInfo *>(data);
if (asyncCallbackInfo == nullptr) {
APP_LOGE("asyncCallbackInfo is null");
return;
}
std::unique_ptr<VerifyCallbackInfo> callbackPtr {asyncCallbackInfo};
napi_value result[ARGS_POS_TWO] = {0};
if (asyncCallbackInfo->err == NO_ERROR) {
NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0]));
} else {
result[0] = BusinessError::CreateCommonError(
env, asyncCallbackInfo->err, DELETE_ABC, Constants::PERMISSION_RUN_DYN_CODE);
}
CommonFunc::NapiReturnDeferred<VerifyCallbackInfo>(
env, asyncCallbackInfo, result, ARGS_SIZE_ONE);
}
napi_value DeleteAbc(napi_env env, napi_callback_info info)
{
APP_LOGD("napi call DeleteAbc called");
NapiArg args(env, info);
VerifyCallbackInfo *asyncCallbackInfo = new (std::nothrow) VerifyCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
APP_LOGE("VerifyCallbackInfo asyncCallbackInfo is null.");
return nullptr;
}
std::unique_ptr<VerifyCallbackInfo> callbackPtr {asyncCallbackInfo};
if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_ONE)) {
APP_LOGE("VerifyCallbackInfo napi func init failed");
BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
return nullptr;
}
if (!CommonFunc::ParseString(env, args[ARGS_POS_ZERO], asyncCallbackInfo->deletePath)) {
APP_LOGE("CleanBundleCacheFiles deletePath is not a string!");
BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, DELETE_ABC, TYPE_STRING);
return nullptr;
}
auto promise = CommonFunc::AsyncCallNativeMethod<VerifyCallbackInfo>(
env, asyncCallbackInfo, "DeleteAbc", DeleteAbcExec, DeleteAbcComplete);
callbackPtr.release();
APP_LOGD("napi call DeleteAbc done");
return promise;
}
static ErrCode InnerGetLaunchWantForBundleExec(
const std::string& bundleName, Want &want, int32_t userId)
{

View File

@ -119,6 +119,7 @@ struct VerifyCallbackInfo : public BaseCallbackInfo {
explicit VerifyCallbackInfo(napi_env napiEnv) : BaseCallbackInfo(napiEnv) {}
std::vector<std::string> abcPaths;
bool flag = false;
std::string deletePath;
};
enum AbilityProfileType : uint32_t {
@ -259,6 +260,7 @@ napi_value GetSpecifiedDistributionType(napi_env env, napi_callback_info info);
napi_value GetAdditionalInfo(napi_env env, napi_callback_info info);
napi_value GetBundleInfoForSelfSync(napi_env env, napi_callback_info info);
napi_value VerifyAbc(napi_env env, napi_callback_info info);
napi_value DeleteAbc(napi_env env, napi_callback_info info);
napi_value GetJsonProfile(napi_env env, napi_callback_info info);
napi_value GetRecoverableApplicationInfo(napi_env env, napi_callback_info info);
napi_value SetAdditionalInfo(napi_env env, napi_callback_info info);

View File

@ -140,6 +140,7 @@ static napi_value BundleManagerExport(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getBundleInfoForSelfSync", GetBundleInfoForSelfSync),
DECLARE_NAPI_FUNCTION("getJsonProfile", GetJsonProfile),
DECLARE_NAPI_FUNCTION("verifyAbc", VerifyAbc),
DECLARE_NAPI_FUNCTION("deleteAbc", DeleteAbc),
DECLARE_NAPI_PROPERTY("ProfileType", nProfileType),
DECLARE_NAPI_FUNCTION("getRecoverableApplicationInfo", GetRecoverableApplicationInfo),
DECLARE_NAPI_FUNCTION("setAdditionalInfo", SetAdditionalInfo),

View File

@ -78,6 +78,7 @@ constexpr ErrCode ERROR_BUNDLE_SERVICE_EXCEPTION = 17700101;
// verify abc
constexpr ErrCode ERROR_VERIFY_ABC = 17700201;
constexpr ErrCode ERROR_DELETE_ABC = 17700202;
// zlib errCode
constexpr ErrCode ERR_ZLIB_SRC_FILE_INVALID = 900001;

View File

@ -110,6 +110,7 @@ constexpr const char* ERR_MSG_ENTERPRISE_BUNDLE_NOT_ALLOWED =
constexpr const char* ERR_MSG_DEBUG_BUNDLE_NOT_ALLOWED =
"Failed to install the HAP because debug bundle cannot be installed under non-developer mode.";
constexpr const char* ERR_MSG_ERROR_VERIFY_ABC = "Failed to verify abc.";
constexpr const char* ERR_MSG_ERROR_DELETE_ABC = "Failed to delete abc.";
constexpr const char* ERROR_MSG_NOT_APP_GALLERY_CALL = "Not app gallery call.";
static std::unordered_map<int32_t, const char*> ERR_MSG_MAP = {
@ -168,6 +169,7 @@ static std::unordered_map<int32_t, const char*> ERR_MSG_MAP = {
{ ERROR_INSTALL_DEBUG_BUNDLE_NOT_ALLOWED, ERR_MSG_DEBUG_BUNDLE_NOT_ALLOWED},
{ ERROR_VERIFY_ABC, ERR_MSG_ERROR_VERIFY_ABC},
{ ERROR_NOT_APP_GALLERY_CALL, ERROR_MSG_NOT_APP_GALLERY_CALL},
{ ERROR_DELETE_ABC, ERR_MSG_ERROR_DELETE_ABC},
};
} // namespace

View File

@ -113,6 +113,9 @@ static std::unordered_map<int32_t, int32_t> ERR_MAP = {
{ ERR_BUNDLE_MANAGER_VERIFY_CREATE_TARGET_DIR_FAILED, ERROR_VERIFY_ABC },
{ ERR_BUNDLE_MANAGER_VERIFY_VERIFY_ABC_FAILED, ERROR_VERIFY_ABC },
{ ERR_BUNDLE_MANAGER_VERIFY_PERMISSION_DENIED, ERROR_PERMISSION_DENIED_ERROR },
{ ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR, ERROR_DELETE_ABC },
{ ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED, ERROR_DELETE_ABC },
{ ERR_BUNDLE_MANAGER_DELETE_ABC_SEND_REQUEST_FAILED, ERROR_DELETE_ABC },
};
}
using Want = OHOS::AAFwk::Want;

View File

@ -29,6 +29,7 @@ public:
const std::vector<std::string> &abcNames, bool flag) override;
ErrCode CreateFd(const std::string &fileName, int32_t &fd, std::string &path) override;
ErrCode DeleteAbc(const std::string &path) override;
private:
ErrCode InnerVerify(const std::vector<std::string> &abcPaths,

View File

@ -43,6 +43,17 @@ bool IsFileNameValid(const std::string &fileName)
}
return true;
}
bool IsValidPath(const std::string &path)
{
if (path.empty()) {
return false;
}
if (path.find("..") != std::string::npos) {
return false;
}
return true;
}
}
VerifyManagerHostImpl::VerifyManagerHostImpl()
{
@ -253,5 +264,54 @@ ErrCode VerifyManagerHostImpl::CreateFd(const std::string &fileName, int32_t &fd
}
return ERR_OK;
}
ErrCode VerifyManagerHostImpl::DeleteAbc(const std::string &path)
{
if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_RUN_DYN_CODE)) {
APP_LOGE("DeleteAbc failed due to permission denied.");
return ERR_BUNDLE_MANAGER_VERIFY_PERMISSION_DENIED;
}
if (!IsValidPath(path)) {
APP_LOGE("DeleteAbc failed due to invalid path");
return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
}
if (!BundleUtil::CheckFileType(path, Constants::ABC_FILE_SUFFIX)) {
APP_LOGE("DeleteAbc failed due to not abc file.");
return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
}
auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
if (dataMgr == nullptr) {
APP_LOGE("DeleteAbc failed due to dataMgr is null");
return ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
}
int32_t callingUid = IPCSkeleton::GetCallingUid();
InnerBundleInfo innerBundleInfo;
if (dataMgr->GetInnerBundleInfoByUid(callingUid, innerBundleInfo) != ERR_OK) {
APP_LOGE("DeleteAbc failed due to get callingUid failed");
return ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
}
std::string realPath;
realPath.append(Constants::BUNDLE_CODE_DIR).append(Constants::PATH_SEPARATOR)
.append(innerBundleInfo.GetBundleName()).append(Constants::PATH_SEPARATOR)
.append(ABCS_DIR).append(Constants::PATH_SEPARATOR).append(path);
bool isExist = false;
auto result = InstalldClient::GetInstance()->IsExistFile(realPath, isExist);
if (result != ERR_OK) {
APP_LOGE("DeleteAbc %{public}s failed due to call IsExistFile failed %{public}d",
realPath.c_str(), result);
return ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
}
if (!isExist) {
APP_LOGE("DeleteAbc failed due to path %{public}s is not exist", realPath.c_str());
return ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
}
result = InstalldClient::GetInstance()->RemoveDir(realPath);
if (result != ERR_OK) {
APP_LOGE("DeleteAbc failed due to remove path %{public}s failed %{public}d",
realPath.c_str(), result);
return ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
}
return ERR_OK;
}
} // AppExecFwk
} // namespace OHOS