mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
对接udmf
Signed-off-by: duansizhao <duansizhao@huawei.com> Change-Id: I45152f83912d12be4ef885d20fa1896a6c94a532
This commit is contained in:
@@ -107,6 +107,7 @@
|
||||
"selinux_adapter",
|
||||
"storage_service",
|
||||
"toolchain",
|
||||
"udmf",
|
||||
"webview",
|
||||
"window_manager",
|
||||
"zlib"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -31,9 +31,13 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t ERR_OK = 0;
|
||||
constexpr int32_t argCountFour = 4;
|
||||
constexpr int32_t argCountThree = 3;
|
||||
constexpr int32_t argCountTwo = 2;
|
||||
constexpr int32_t ARG_COUNT_TWO = 2;
|
||||
constexpr int32_t ARG_COUNT_THREE = 3;
|
||||
constexpr int32_t ARG_COUNT_FOUR = 4;
|
||||
constexpr int32_t ARG_INDEX_ZERO = 0;
|
||||
constexpr int32_t ARG_INDEX_ONE = 1;
|
||||
constexpr int32_t ARG_INDEX_TWO = 2;
|
||||
constexpr int32_t ARG_INDEX_THREE = 3;
|
||||
|
||||
struct UriPermissionParam {
|
||||
std::string uriStr;
|
||||
@@ -41,6 +45,9 @@ struct UriPermissionParam {
|
||||
std::string bundleName;
|
||||
int32_t appIndex = 0;
|
||||
bool hasAppIndex = false;
|
||||
std::string key;
|
||||
int32_t callerTokenId = 0;
|
||||
int32_t targetTokenId = 0;
|
||||
};
|
||||
|
||||
static void ResolveGrantUriPermissionTask(napi_env env, NapiAsyncTask &task, int32_t errCode)
|
||||
@@ -107,11 +114,22 @@ static void ResolveRevokeUriPermissionWithAppIndexTask(napi_env env, NapiAsyncTa
|
||||
return;
|
||||
}
|
||||
|
||||
static bool ParseGrantUriPermissionParams(napi_env env, NapiCallbackInfo &info, UriPermissionParam ¶m)
|
||||
static void ResolveGrantUriPermissionByKeyAsCallerTask(napi_env env, NapiAsyncTask &task, int32_t errCode)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "ResolveGrantUriPermissionByKeyAsCallerTask");
|
||||
if (errCode == ERR_OK) {
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
return;
|
||||
}
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, errCode, "ohos.permission.GRANT_URI_PERMISSION_AS_CALLER"));
|
||||
return;
|
||||
}
|
||||
|
||||
static bool ParseGrantUriPermissionParams(napi_env env, const NapiCallbackInfo &info, UriPermissionParam ¶m)
|
||||
{
|
||||
// only support 3 or 4 params
|
||||
if (info.argc < argCountThree) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "param number invalid");
|
||||
if (info.argc < ARG_COUNT_THREE) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "too few parameters");
|
||||
ThrowTooFewParametersError(env);
|
||||
return false;
|
||||
}
|
||||
@@ -125,18 +143,18 @@ static bool ParseGrantUriPermissionParams(napi_env env, NapiCallbackInfo &info,
|
||||
ThrowInvalidParamError(env, "Parse param flag failed, flag must be number.");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(env, info.argv[argCountTwo], param.bundleName)) {
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(env, info.argv[ARG_COUNT_TWO], param.bundleName)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "targetBundleName invalid");
|
||||
ThrowInvalidParamError(env, "Parse param targetBundleName failed, targetBundleName must be string.");
|
||||
return false;
|
||||
}
|
||||
if (info.argc >= argCountFour) {
|
||||
if (info.argc >= ARG_COUNT_FOUR) {
|
||||
// process param index or callback
|
||||
if (CheckTypeForNapiValue(env, info.argv[argCountThree], napi_function)) {
|
||||
if (CheckTypeForNapiValue(env, info.argv[ARG_COUNT_THREE], napi_function)) {
|
||||
return true;
|
||||
}
|
||||
if (!CheckTypeForNapiValue(env, info.argv[argCountThree], napi_number) ||
|
||||
!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[argCountThree], param.appIndex)) {
|
||||
if (!CheckTypeForNapiValue(env, info.argv[ARG_COUNT_THREE], napi_number) ||
|
||||
!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[ARG_COUNT_THREE], param.appIndex)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "appIndex invalid");
|
||||
ThrowInvalidParamError(env, "Parse param appCloneIndex failed, appCloneIndex must be number.");
|
||||
return false;
|
||||
@@ -150,10 +168,10 @@ static bool ParseGrantUriPermissionParams(napi_env env, NapiCallbackInfo &info,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ParseRevokeUriPermissionParams(napi_env env, NapiCallbackInfo &info, UriPermissionParam ¶m)
|
||||
static bool ParseRevokeUriPermissionParams(napi_env env, const NapiCallbackInfo &info, UriPermissionParam ¶m)
|
||||
{
|
||||
// only support 2 or 3 params
|
||||
if (info.argc < argCountTwo) {
|
||||
if (info.argc < ARG_COUNT_TWO) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "Invalid args");
|
||||
ThrowTooFewParametersError(env);
|
||||
return false;
|
||||
@@ -168,13 +186,13 @@ static bool ParseRevokeUriPermissionParams(napi_env env, NapiCallbackInfo &info,
|
||||
ThrowInvalidParamError(env, "Parse param bundleName failed, bundleName must be string.");
|
||||
return false;
|
||||
}
|
||||
if (info.argc >= argCountThree) {
|
||||
if (info.argc >= ARG_COUNT_THREE) {
|
||||
// process param index or callback
|
||||
if (CheckTypeForNapiValue(env, info.argv[argCountTwo], napi_function)) {
|
||||
if (CheckTypeForNapiValue(env, info.argv[ARG_COUNT_TWO], napi_function)) {
|
||||
return true;
|
||||
}
|
||||
if (!CheckTypeForNapiValue(env, info.argv[argCountTwo], napi_number) ||
|
||||
!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[argCountTwo], param.appIndex)) {
|
||||
if (!CheckTypeForNapiValue(env, info.argv[ARG_COUNT_TWO], napi_number) ||
|
||||
!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[ARG_COUNT_TWO], param.appIndex)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "appCloneIndex invalid");
|
||||
ThrowInvalidParamError(env, "Parse param appCloneIndex failed, appCloneIndex must be number.");
|
||||
return false;
|
||||
@@ -187,6 +205,38 @@ static bool ParseRevokeUriPermissionParams(napi_env env, NapiCallbackInfo &info,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ParseGrantUriPermissionByKeyAsCallerParams(napi_env env, const NapiCallbackInfo &info,
|
||||
UriPermissionParam ¶m)
|
||||
{
|
||||
// key, flag, callerTokenId, targetTokenId
|
||||
if (info.argc < ARG_COUNT_FOUR) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "Too few args");
|
||||
ThrowTooFewParametersError(env);
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::AppExecFwk::UnwrapStringFromJS2(env, info.argv[ARG_INDEX_ZERO], param.key)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "invalid key");
|
||||
ThrowInvalidParamError(env, "Failed to parse param key, key must be string.");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[ARG_INDEX_ONE], param.flag)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "invalid flag");
|
||||
ThrowInvalidParamError(env, "Failed to parse param flag, flag must be number.");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[ARG_INDEX_TWO], param.callerTokenId)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "invalid callerTokenId");
|
||||
ThrowInvalidParamError(env, "Failed to parse param callerTokenId, callerTokenId must be number.");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[ARG_INDEX_THREE], param.targetTokenId)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "invalid targetTokenId");
|
||||
ThrowInvalidParamError(env, "Failed to Parse param targetTokenId, targetTokenId must be number.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class JsUriPermMgr {
|
||||
public:
|
||||
@@ -209,6 +259,11 @@ public:
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsUriPermMgr, OnRevokeUriPermission);
|
||||
}
|
||||
|
||||
static napi_value GrantUriPermissionByKeyAsCaller(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsUriPermMgr, OnGrantUriPermissionByKeyAsCaller);
|
||||
}
|
||||
|
||||
private:
|
||||
napi_value OnGrantUriPermission(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
@@ -234,13 +289,46 @@ private:
|
||||
}
|
||||
return ResolveGrantUriPermissionTask(env, task, errCode);
|
||||
};
|
||||
napi_value lastParam = (info.argc >= argCountFour && !param.hasAppIndex) ? info.argv[argCountThree] : nullptr;
|
||||
napi_value lastParam = (info.argc >= ARG_COUNT_FOUR && !param.hasAppIndex) ?
|
||||
info.argv[ARG_COUNT_THREE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsUriPermMgr::OnGrantUriPermission",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value OnGrantUriPermissionByKeyAsCaller(napi_env env, const NapiCallbackInfo& info)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "OnGrantUriPermissionByKeyAsCaller start");
|
||||
UriPermissionParam param;
|
||||
if (!ParseGrantUriPermissionByKeyAsCallerParams(env, info, param)) {
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
auto selfToken = IPCSkeleton::GetSelfTokenID();
|
||||
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "app not system-app");
|
||||
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
auto innerErrCode = std::make_shared<ErrCode>(ERR_OK);
|
||||
NapiAsyncTask::ExecuteCallback execute =
|
||||
[param, innerErrCode]() {
|
||||
*innerErrCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermissionByKeyAsCaller(
|
||||
param.key, param.flag, param.callerTokenId, param.targetTokenId);
|
||||
};
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (*innerErrCode != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "GrantUriPermissionByKeyAsCaller fail:%{public}d", *innerErrCode);
|
||||
}
|
||||
ResolveGrantUriPermissionByKeyAsCallerTask(env, task, *innerErrCode);
|
||||
};
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsUriPermMgr::OnGrantUriPermissionByKeyAsCaller",
|
||||
env, CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value OnRevokeUriPermission(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "start");
|
||||
@@ -265,7 +353,8 @@ private:
|
||||
}
|
||||
return ResolveRevokeUriPermissionTask(env, task, errCode);
|
||||
};
|
||||
napi_value lastParam = (info.argc >= argCountThree && !param.hasAppIndex) ? info.argv[argCountTwo] : nullptr;
|
||||
napi_value lastParam = (info.argc >= ARG_COUNT_THREE && !param.hasAppIndex) ?
|
||||
info.argv[ARG_COUNT_TWO] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsUriPermMgr::OnRevokeUriPermission",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -287,6 +376,8 @@ napi_value CreateJsUriPermMgr(napi_env env, napi_value exportObj)
|
||||
const char *moduleName = "JsUriPermMgr";
|
||||
BindNativeFunction(env, exportObj, "grantUriPermission", moduleName, JsUriPermMgr::GrantUriPermission);
|
||||
BindNativeFunction(env, exportObj, "revokeUriPermission", moduleName, JsUriPermMgr::RevokeUriPermission);
|
||||
BindNativeFunction(env, exportObj, "grantUriPermissionByKeyAsCaller", moduleName,
|
||||
JsUriPermMgr::GrantUriPermissionByKeyAsCaller);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -111,6 +111,10 @@ constexpr const char* ERROR_MSG_CALLER_NOT_ATOMIC_SERVICE =
|
||||
"The caller is not atomic service.";
|
||||
constexpr const char* ERROR_MSG_NOT_UI_ABILITY_CONTEXT =
|
||||
"The context is not UIAbilityContext.";
|
||||
constexpr const char* ERR_MSG_GET_FILE_URIS_BY_KEY_FAILED = "Failed to get file uri from key.";
|
||||
constexpr const char* ERR_MSG_NO_PERMISSION_GRANT_URI = "No permission to grant uri permission.";
|
||||
constexpr const char* ERR_MSG_INVALID_CALLER_TOKENID = "Caller token id is invalid.";
|
||||
constexpr const char* ERR_MSG_INVALID_TARGET_TOKENID = "Target token id is invalid.";
|
||||
|
||||
// follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework
|
||||
constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220;
|
||||
@@ -191,6 +195,10 @@ static std::unordered_map<AbilityErrorCode, const char*> ERR_CODE_MAP = {
|
||||
{ AbilityErrorCode::ERROR_CODE_TARGET_NOT_STARTED, ERROR_TARGET_NOT_STARTED},
|
||||
{ AbilityErrorCode::ERROR_CODE_CALLER_NOT_ATOMIC_SERVICE, ERROR_MSG_CALLER_NOT_ATOMIC_SERVICE},
|
||||
{ AbilityErrorCode::ERROR_CODE_NOT_UI_ABILITY_CONTEXT, ERROR_MSG_NOT_UI_ABILITY_CONTEXT},
|
||||
{ AbilityErrorCode::ERR_CODE_GET_FILE_URIS_BY_KEY_FAILED, ERR_MSG_GET_FILE_URIS_BY_KEY_FAILED},
|
||||
{ AbilityErrorCode::ERR_CODE_NO_PERMISSION_GRANT_URI, ERR_MSG_NO_PERMISSION_GRANT_URI},
|
||||
{ AbilityErrorCode::ERR_CODE_INVALID_CALLER_TOKENID, ERR_MSG_INVALID_CALLER_TOKENID},
|
||||
{ AbilityErrorCode::ERR_CODE_INVALID_TARGET_TOKENID, ERR_MSG_INVALID_TARGET_TOKENID},
|
||||
};
|
||||
|
||||
static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP {
|
||||
@@ -273,6 +281,10 @@ static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP
|
||||
{ERR_TARGET_NOT_IN_APP_IDENTIFIER_ALLOW_LIST, AbilityErrorCode::ERROR_CODE_TARGET_NOT_IN_APP_IDENTIFIER_ALLOW_LIST},
|
||||
{ERR_TARGET_NOT_STARTED, AbilityErrorCode::ERROR_CODE_TARGET_NOT_STARTED},
|
||||
{ERR_CALLER_NOT_ATOMIC_SERVICE, AbilityErrorCode::ERROR_CODE_CALLER_NOT_ATOMIC_SERVICE},
|
||||
{ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED, AbilityErrorCode::ERR_CODE_GET_FILE_URIS_BY_KEY_FAILED},
|
||||
{ERR_UPMS_NO_PERMISSION_GRANT_URI, AbilityErrorCode::ERR_CODE_NO_PERMISSION_GRANT_URI},
|
||||
{ERR_UPMS_INVALID_CALLER_TOKENID, AbilityErrorCode::ERR_CODE_INVALID_CALLER_TOKENID},
|
||||
{ERR_UPMS_INVALID_TARGET_TOKENID, AbilityErrorCode::ERR_CODE_INVALID_TARGET_TOKENID},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -802,6 +802,25 @@ enum {
|
||||
* Result (2097334) for app selector not exists.
|
||||
*/
|
||||
ERR_APP_SELECTOR_NOT_EXISTS = 2097334,
|
||||
|
||||
/**
|
||||
* Result (2097340-2097350) for uri permission error result.
|
||||
*/
|
||||
ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED = 2097340,
|
||||
|
||||
ERR_UPMS_NO_PERMISSION_GRANT_URI = 2097341,
|
||||
|
||||
ERR_UPMS_INVALID_CALLER_TOKENID = 2097342,
|
||||
|
||||
ERR_UPMS_INVALID_TARGET_TOKENID = 2097343,
|
||||
|
||||
ERR_UPMS_ADD_PRIVILEGED_FAILED = 2097344,
|
||||
|
||||
ERR_UPMS_GET_ORI_URI_FAILED = 2097345,
|
||||
|
||||
ERR_UPMS_NOT_FILE_URI = 2097346,
|
||||
|
||||
ERR_UPMS_GRANT_URI_PERMISSION_FAILED = 2097347,
|
||||
|
||||
/**
|
||||
* Native error(3000000) for target bundle not exist.
|
||||
|
||||
@@ -28,6 +28,9 @@ interface OHOS.AAFwk.IUriPermissionManager {
|
||||
int GrantUriPermissionPrivileged([in] UriPermissionRawData rawData, [in] unsigned int flag,
|
||||
[in] String targetBundleName, [in] int appIndex, [in] unsigned int initiatorTokenId,
|
||||
[in] int hideSensitiveType);
|
||||
int GrantUriPermissionByKey([in] String key, [in] unsigned int flag, [in] unsigned int targetTokenId);
|
||||
int GrantUriPermissionByKeyAsCaller([in] String key, [in] unsigned int flag,
|
||||
[in] unsigned int callerTokenId, [in] unsigned int targetTokenId);
|
||||
int RevokeAllUriPermissions([in] unsigned int tokenId);
|
||||
int RevokeUriPermissionManually([in] Uri uri, [in] String bundleName, [in] int appIndex);
|
||||
boolean VerifyUriPermission([in] Uri uri, [in] unsigned int flag, [in] unsigned int tokenId);
|
||||
|
||||
@@ -104,6 +104,11 @@ public:
|
||||
|
||||
int32_t ClearPermissionTokenByMap(const uint32_t tokenId);
|
||||
|
||||
int32_t GrantUriPermissionByKey(const std::string &key, uint32_t flag, uint32_t targetTokenId);
|
||||
|
||||
int32_t GrantUriPermissionByKeyAsCaller(const std::string &key, uint32_t flag, uint32_t callerTokenId,
|
||||
uint32_t targetTokenId);
|
||||
|
||||
#ifdef ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER
|
||||
int32_t Active(const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result);
|
||||
#endif // ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER
|
||||
|
||||
@@ -165,6 +165,40 @@ int32_t UriPermissionManagerClient::GrantUriPermissionPrivileged(const std::vect
|
||||
return funcResult;
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerClient::GrantUriPermissionByKey(const std::string &key, uint32_t flag,
|
||||
uint32_t targetTokenId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "GrantUriPermissionByKey call");
|
||||
auto uriPermMgr = ConnectUriPermService();
|
||||
if (uriPermMgr) {
|
||||
int32_t funcResult = INNER_ERR;
|
||||
auto ret = uriPermMgr->GrantUriPermissionByKey(key, flag, targetTokenId, funcResult);
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "IPC failed, error:%{public}d", ret);
|
||||
return INNER_ERR;
|
||||
}
|
||||
return funcResult;
|
||||
}
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerClient::GrantUriPermissionByKeyAsCaller(const std::string &key, uint32_t flag,
|
||||
uint32_t callerTokenId, uint32_t targetTokenId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "GrantUriPermissionByKeyAsCaller call");
|
||||
auto uriPermMgr = ConnectUriPermService();
|
||||
if (uriPermMgr) {
|
||||
int32_t funcResult = INNER_ERR;
|
||||
auto ret = uriPermMgr->GrantUriPermissionByKeyAsCaller(key, flag, callerTokenId, targetTokenId, funcResult);
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "IPC failed, error:%{public}d", ret);
|
||||
return INNER_ERR;
|
||||
}
|
||||
return funcResult;
|
||||
}
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
int UriPermissionManagerClient::RevokeAllUriPermissions(const uint32_t tokenId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "call");
|
||||
|
||||
+9
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -192,6 +192,14 @@ enum class AbilityErrorCode {
|
||||
// The interaction process between Ability and the Window encountered an error.
|
||||
ERROR_CODE_FROM_WINDOW = 16000085,
|
||||
|
||||
ERR_CODE_GET_FILE_URIS_BY_KEY_FAILED = 16000091,
|
||||
|
||||
ERR_CODE_NO_PERMISSION_GRANT_URI = 16000092,
|
||||
|
||||
ERR_CODE_INVALID_CALLER_TOKENID = 16000093,
|
||||
|
||||
ERR_CODE_INVALID_TARGET_TOKENID = 16000094,
|
||||
|
||||
// the target not in app identifier allow list.
|
||||
ERROR_CODE_TARGET_NOT_IN_APP_IDENTIFIER_ALLOW_LIST = 16000200,
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -87,6 +87,8 @@ private:
|
||||
|
||||
bool CheckIsInAncoAppIdentifier(const std::string &identifier, const std::string &bundleName);
|
||||
|
||||
void ProcessUDMFKey(Want &want);
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(UriUtils);
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -42,6 +42,7 @@ const std::string PARAMS_URI = "ability.verify.uri";
|
||||
const std::string DISTRIBUTED_FILES_PATH = "/data/storage/el2/distributedfiles/";
|
||||
const std::string HIDE_SENSITIVE_TYPE = "ohos.media.params.hideSensitiveType";
|
||||
const std::string DMS_PROCESS_NAME = "distributedsched";
|
||||
const std::string UDMF_DATA_KEY = "ohos.param.ability.udmfKey";
|
||||
const int32_t MAX_URI_COUNT = 500;
|
||||
constexpr int32_t API14 = 14;
|
||||
constexpr int32_t API_VERSION_MOD = 100;
|
||||
@@ -425,6 +426,7 @@ void UriUtils::GrantUriPermission(Want &want, std::string targetBundleName, int3
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "sandbox can not grant UriPermission");
|
||||
return;
|
||||
}
|
||||
ProcessUDMFKey(want);
|
||||
|
||||
if (IsDmsCall(callerTokenId)) {
|
||||
GrantDmsUriPermission(want, callerTokenId, targetBundleName, appIndex);
|
||||
@@ -451,6 +453,14 @@ void UriUtils::GrantUriPermission(Want &want, std::string targetBundleName, int3
|
||||
PublishFileOpenEvent(want);
|
||||
}
|
||||
|
||||
void UriUtils::ProcessUDMFKey(Want &want)
|
||||
{
|
||||
// PARAMS_STREAM and UDMF_DATA_KEY is conflict
|
||||
if (!want.GetStringArrayParam(AbilityConfig::PARAMS_STREAM).empty()) {
|
||||
want.RemoveParam(UDMF_DATA_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
bool UriUtils::GrantUriPermissionInner(std::vector<std::string> uriVec, uint32_t callerTokenId,
|
||||
const std::string &targetBundleName, int32_t appIndex, Want &want)
|
||||
{
|
||||
|
||||
@@ -125,6 +125,13 @@ public:
|
||||
*/
|
||||
bool IsGrantPersistUriPermission();
|
||||
|
||||
/**
|
||||
* IsSupportGrantUriPermission, check whether to grant temp uri permission, default true.
|
||||
*
|
||||
* @return Whether to grant temp uri permission.
|
||||
*/
|
||||
bool IsSupportGrantUriPermission();
|
||||
|
||||
/**
|
||||
* IsStartOptionsWithAnimation, check whether the start options have animation.
|
||||
*
|
||||
@@ -408,6 +415,7 @@ private:
|
||||
std::mutex isConnectSupportCrossUserMutex_;
|
||||
volatile DeviceConfiguration<bool> isConnectSupportCrossUser_ = {false, false};
|
||||
volatile DeviceConfiguration<bool> isSupportAppServiceExtension_ = {false, false};
|
||||
volatile DeviceConfiguration<bool> isGrantTempUriPermission_ = {false, true};
|
||||
DeviceConfiguration<std::vector<std::pair<std::string, std::string>>>
|
||||
residentProcessInExtremeMemory_ = {false, {}};
|
||||
std::mutex residentProcessInExtremeMemoryMutex_;
|
||||
|
||||
@@ -43,6 +43,7 @@ constexpr const char* PERMISSION_READ_IMAGEVIDEO = "ohos.permission.READ_IMAGEVI
|
||||
constexpr const char* PERMISSION_WRITE_AUDIO = "ohos.permission.WRITE_AUDIO";
|
||||
constexpr const char* PERMISSION_READ_AUDIO = "ohos.permission.READ_AUDIO";
|
||||
constexpr const char* PERMISSION_GRANT_URI_PERMISSION_PRIVILEGED = "ohos.permission.GRANT_URI_PERMISSION_PRIVILEGED";
|
||||
constexpr const char* PERMISSION_GRANT_URI_PERMISSION_AS_CALLER = "ohos.permission.GRANT_URI_PERMISSION_AS_CALLER";
|
||||
constexpr const char* PERMISSION_READ_WRITE_DOWNLOAD = "ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY";
|
||||
constexpr const char* PERMISSION_READ_WRITE_DESKTON = "ohos.permission.READ_WRITE_DESKTOP_DIRECTORY";
|
||||
constexpr const char* PERMISSION_READ_WRITE_DOCUMENTS = "ohos.permission.READ_WRITE_DOCUMENTS_DIRECTORY";
|
||||
|
||||
@@ -40,6 +40,7 @@ constexpr const char* START_SPECIFIED_PROCESS = "persist.sys.abilityms.start_spe
|
||||
constexpr const char* USE_MULTI_RENDER_PROCESS = "persist.sys.abilityms.use_multi_render_process";
|
||||
constexpr const char* LIMIT_MAXIMUM_OF_RENDER_PROCESS = "persist.sys.abilityms.limit_maximum_of_render_process";
|
||||
constexpr const char* GRANT_PERSIST_URI_PERMISSION = "persist.sys.abilityms.grant_persist_uri_permission";
|
||||
constexpr const char* GRANT_TEMPORARY_URI_PERMISSION = "persist.sys.abilityms.grant_temporary_uri_permission";
|
||||
constexpr const char* START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation";
|
||||
constexpr const char* MULTI_PROCESS_MODEL = "persist.sys.abilityms.multi_process_model";
|
||||
constexpr const char* PARAM_ANCO_APP_IDENTIFIER = "persist.hmos_fusion_mgr.anco_identifier";
|
||||
@@ -204,6 +205,16 @@ bool AppUtils::IsGrantPersistUriPermission()
|
||||
return isGrantPersistUriPermission_.value;
|
||||
}
|
||||
|
||||
bool AppUtils::IsSupportGrantUriPermission()
|
||||
{
|
||||
if (!isGrantTempUriPermission_.isLoaded) {
|
||||
isGrantTempUriPermission_.value = system::GetBoolParameter(GRANT_TEMPORARY_URI_PERMISSION, true);
|
||||
isGrantTempUriPermission_.isLoaded = true;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isGrantTempUriPermission_.value);
|
||||
return isGrantTempUriPermission_.value;
|
||||
}
|
||||
|
||||
bool AppUtils::IsStartOptionsWithAnimation()
|
||||
{
|
||||
if (!isStartOptionsWithAnimation_.isLoaded) {
|
||||
@@ -472,7 +483,7 @@ std::string AppUtils::GetCacheExtensionTypeList()
|
||||
|
||||
std::string AppUtils::GetAncoAppIdentifiers()
|
||||
{
|
||||
std::string identifiers = system::GetParameter(PARAM_ANCO_APP_IDENTIFIER, "");\
|
||||
std::string identifiers = system::GetParameter(PARAM_ANCO_APP_IDENTIFIER, "");
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ libupms_sources = [
|
||||
"src/uri_permission_manager_service.cpp",
|
||||
"src/uri_permission_manager_stub_impl.cpp",
|
||||
"src/uri_permission_utils.cpp",
|
||||
"src/upms_udmf_utils.cpp",
|
||||
]
|
||||
|
||||
#build so
|
||||
@@ -93,6 +94,7 @@ ohos_shared_library("libupms") {
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"storage_service:storage_manager_sa_proxy",
|
||||
"udmf:udmf_client",
|
||||
]
|
||||
|
||||
defines = []
|
||||
@@ -161,6 +163,7 @@ ohos_static_library("libupms_static") {
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"storage_service:storage_manager_sa_proxy",
|
||||
"udmf:udmf_client",
|
||||
]
|
||||
if (ability_runtime_upms) {
|
||||
deps += [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -39,9 +39,9 @@ class BatchUri {
|
||||
public:
|
||||
BatchUri() {}
|
||||
|
||||
int32_t Init(const std::vector<Uri> &uriVec, uint32_t mode = 0, const std::string &callerBundleName = "",
|
||||
const std::string &targetBundleName = "");
|
||||
|
||||
int32_t Init(const std::vector<std::string> &uriVec, uint32_t mode = 0,
|
||||
const std::string &callerAlterBundleName = "", const std::string &targetAlterBundleName = "");
|
||||
|
||||
void InitFileUriInfo(Uri &uriInner, uint32_t index, const uint32_t mode = 0,
|
||||
const std::string &callerBundleName = "", const std::string &targetBundleName = "");
|
||||
|
||||
@@ -56,35 +56,41 @@ public:
|
||||
void SetCheckProxyByPolicyResult(std::vector<bool> &proxyResultByPolicy);
|
||||
|
||||
int32_t GetUriToGrantByMap(std::vector<std::string> &uriVec);
|
||||
|
||||
|
||||
void SelectPermissionedUri(std::vector<Uri> &uris, std::vector<int32_t> &indexs, std::vector<std::string> &uriVec);
|
||||
|
||||
int32_t GetUriToGrantByPolicy(std::vector<PolicyInfo> &docsPolicyInfoVec,
|
||||
std::vector<PolicyInfo> &bundlePolicyInfoVec);
|
||||
|
||||
bool GetUriToGrantByPolicy(std::vector<PolicyInfo> &policyVec);
|
||||
|
||||
int32_t GetPermissionedUriCount();
|
||||
|
||||
|
||||
// media
|
||||
int32_t GetMediaUriToGrant(std::vector<std::string> &uriVec);
|
||||
|
||||
bool IsAllUriValid();
|
||||
|
||||
bool IsAllUriPermissioned();
|
||||
|
||||
// media uri
|
||||
std::vector<Uri> mediaUris;
|
||||
std::vector<int32_t> mediaIndexs;
|
||||
|
||||
std::vector<std::string> mediaUris;
|
||||
std::vector<int32_t> mediaIndexes;
|
||||
|
||||
// docs and bundle uri
|
||||
std::vector<Uri> otherUris;
|
||||
std::vector<int32_t> otherIndexs;
|
||||
std::vector<int32_t> otherIndexes;
|
||||
std::vector<PolicyInfo> otherPolicyInfos;
|
||||
|
||||
// caller's uri
|
||||
std::vector<PolicyInfo> selfBundlePolicyInfos;
|
||||
|
||||
// for check proxy uri permission
|
||||
std::vector<int32_t> proxyIndexsByMap;
|
||||
std::vector<int32_t> proxyIndexsByPolicy;
|
||||
|
||||
std::vector<int32_t> proxyIndexesByMap;
|
||||
std::vector<int32_t> proxyIndexesByPolicy;
|
||||
|
||||
// result of CheckUriPermission
|
||||
std::vector<bool> result;
|
||||
std::vector<bool> checkResult;
|
||||
std::vector<bool> isDocsUriVec;
|
||||
|
||||
// target's uri
|
||||
@@ -99,7 +105,7 @@ struct BatchStringUri {
|
||||
std::vector<std::string> uriStrVec;
|
||||
std::vector<std::string> contentUris;
|
||||
std::vector<std::string> mediaUriVec;
|
||||
std::vector<PolicyInfo> policys;
|
||||
std::vector<PolicyInfo> policyVec;
|
||||
};
|
||||
} // OHOS
|
||||
} // AAFwk
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -27,7 +27,7 @@ namespace AAFwk {
|
||||
class MediaPermissionManager {
|
||||
public:
|
||||
static MediaPermissionManager &GetInstance();
|
||||
std::vector<bool> CheckUriPermission(const std::vector<Uri> &uriVec, uint32_t callerTokenId, uint32_t flag);
|
||||
std::vector<bool> CheckUriPermission(const std::vector<std::string> &uriVec, uint32_t callerTokenId, uint32_t flag);
|
||||
int32_t GrantUriPermission(const std::vector<std::string> &uris, uint32_t flag, uint32_t callerTokenId,
|
||||
uint32_t targetTokenId, int32_t hideSensitiveType);
|
||||
int32_t RevokeUriPermission(uint32_t callerTokenId, uint32_t targetTokenId, const std::string &uri);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_UPMS_UDMF_UTILS_H
|
||||
#define OHOS_ABILITY_RUNTIME_UPMS_UDMF_UTILS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
class UDMFUtils {
|
||||
public:
|
||||
static int32_t ProcessUdmfKey(const std::string &key, uint32_t callerTokenId, uint32_t targetTokenId,
|
||||
std::vector<std::string> &uris);
|
||||
private:
|
||||
static int32_t GetBatchData(const std::string &key, std::vector<std::string> &uris);
|
||||
static int32_t AddPrivilege(const std::string &key, uint32_t tokenId, const std::string &readPermission);
|
||||
};
|
||||
} // OHOS
|
||||
} // AAFwk
|
||||
#endif // OHOS_ABILITY_RUNTIME_UPMS_UDMF_UTILS_H
|
||||
@@ -109,6 +109,12 @@ public:
|
||||
const std::string& targetBundleName, int32_t appIndex, uint32_t initiatorTokenId,
|
||||
int32_t hideSensitiveType, int32_t& funcResult) override;
|
||||
|
||||
ErrCode GrantUriPermissionByKeyAsCaller(const std::string &key, uint32_t flag, uint32_t callerTokenId,
|
||||
uint32_t targetTokenId, int32_t &funcResult) override;
|
||||
|
||||
ErrCode GrantUriPermissionByKey(const std::string &key, uint32_t flag,
|
||||
uint32_t targetTokenId, int32_t &funcResult) override;
|
||||
|
||||
/*
|
||||
* only support local file uri, not support distribute docs and content uri.
|
||||
*/
|
||||
@@ -136,7 +142,7 @@ private:
|
||||
|
||||
int32_t AddTempUriPermission(const std::string &uri, uint32_t flag, TokenId fromTokenId, TokenId targetTokenId);
|
||||
|
||||
int32_t GrantUriPermissionInner(const std::vector<Uri> &uriVec, uint32_t flag,
|
||||
int32_t GrantUriPermissionInner(const std::vector<std::string> &uriVec, uint32_t flag,
|
||||
uint32_t callerTokenId, uint32_t targetTokenId, const std::string &targetBundleName);
|
||||
|
||||
int32_t GrantUriPermissionPrivilegedInner(const std::vector<Uri> &uriVec, uint32_t flag, uint32_t callerTokenId,
|
||||
@@ -162,11 +168,11 @@ private:
|
||||
int32_t GrantBatchUriPermissionImpl(const std::vector<std::string> &uriVec,
|
||||
uint32_t flag, TokenId callerTokenId, TokenId targetTokenId);
|
||||
|
||||
std::vector<bool> CheckUriPermission(TokenIdPermission &tokenIdPermission, const std::vector<Uri> &uriVec,
|
||||
std::vector<bool> CheckUriPermission(TokenIdPermission &tokenIdPermission, const std::vector<std::string> &uriVec,
|
||||
uint32_t flag);
|
||||
|
||||
void CheckProxyUriPermission(TokenIdPermission &tokenIdPermission, const std::vector<Uri> &uriVec, uint32_t flag,
|
||||
std::vector<bool> &result);
|
||||
void CheckProxyUriPermission(TokenIdPermission &tokenIdPermission, const std::vector<std::string> &uriVec,
|
||||
uint32_t flag, std::vector<bool> &result);
|
||||
|
||||
void RevokeMapUriPermission(uint32_t tokenId);
|
||||
|
||||
@@ -197,6 +203,18 @@ private:
|
||||
|
||||
ErrCode CheckGrantUriPermissionPrivileged(uint32_t callerTokenId, uint32_t flag, int32_t& funcResult);
|
||||
|
||||
int32_t GrantUriPermissionByKeyInner(const std::string &key, uint32_t flag,
|
||||
uint32_t callerTokenId, uint32_t targetTokenId);
|
||||
|
||||
int32_t CheckGrantUriPermissionByKeyAsCaller();
|
||||
|
||||
int32_t CheckGrantUriPermissionByKey();
|
||||
|
||||
int32_t CheckGrantUriPermissionByKeyParams(const std::string &key, uint32_t flag,
|
||||
UPMSAppInfo &callerAppInfo, UPMSAppInfo &targetAppInfo, std::vector<std::string> &uris);
|
||||
|
||||
inline int32_t WrapErrorCode(int32_t errorCode, int32_t &funcRet);
|
||||
|
||||
#ifdef ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER
|
||||
ErrCode Active(const UriPermissionRawData& policyRawData, std::vector<uint32_t>& res, int32_t& funcResult) override;
|
||||
bool RawDataToPolicyInfo(const UriPermissionRawData& policyRawData, std::vector<PolicyInfo>& policy);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -27,7 +27,7 @@ class UPMSUtils {
|
||||
public:
|
||||
static bool SendShareUnPrivilegeUriEvent(uint32_t callTokenId, uint32_t targetTokenId);
|
||||
static bool SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId,
|
||||
const std::vector<Uri> &uriVec, const std::vector<bool> &resVec);
|
||||
const std::vector<std::string> &uriVec, const std::vector<bool> &resVec);
|
||||
static int32_t GetCurrentAccountId();
|
||||
static bool IsFoundationCall();
|
||||
static bool IsSAOrSystemAppCall();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -22,8 +22,8 @@
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
|
||||
int32_t BatchUri::Init(const std::vector<Uri> &uriVec, uint32_t mode, const std::string &callerBundleName,
|
||||
const std::string &targetBundleName)
|
||||
int32_t BatchUri::Init(const std::vector<std::string> &uriVec, uint32_t mode,
|
||||
const std::string &callerAlterBundleName, const std::string &targetAlterBundleName)
|
||||
{
|
||||
if (uriVec.empty()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "uriVec is empty.");
|
||||
@@ -31,12 +31,12 @@ int32_t BatchUri::Init(const std::vector<Uri> &uriVec, uint32_t mode, const std:
|
||||
}
|
||||
totalUriCount = static_cast<int32_t>(uriVec.size());
|
||||
validUriCount = 0;
|
||||
result = std::vector<bool>(totalUriCount, false);
|
||||
checkResult = std::vector<bool>(totalUriCount, false);
|
||||
isDocsUriVec = std::vector<bool>(totalUriCount, false);
|
||||
isTargetBundleUri = std::vector<bool>(totalUriCount, false);
|
||||
bool isPrintAuthority = true;
|
||||
for (size_t index = 0; index < uriVec.size(); index++) {
|
||||
auto uriInner = uriVec[index];
|
||||
Uri uriInner = Uri(uriVec[index]);
|
||||
auto &&scheme = uriInner.GetScheme();
|
||||
if (isPrintAuthority) {
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "uri type: %{public}s.", uriInner.GetAuthority().c_str());
|
||||
@@ -47,7 +47,7 @@ int32_t BatchUri::Init(const std::vector<Uri> &uriVec, uint32_t mode, const std:
|
||||
continue;
|
||||
}
|
||||
validUriCount++;
|
||||
InitFileUriInfo(uriInner, index, mode, callerBundleName, targetBundleName);
|
||||
InitFileUriInfo(uriInner, index, mode, callerAlterBundleName, targetAlterBundleName);
|
||||
}
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "count of uri is %{public}d, count of valid uri is %{public}d.",
|
||||
totalUriCount, validUriCount);
|
||||
@@ -55,20 +55,20 @@ int32_t BatchUri::Init(const std::vector<Uri> &uriVec, uint32_t mode, const std:
|
||||
}
|
||||
|
||||
void BatchUri::InitFileUriInfo(Uri &uriInner, uint32_t index, const uint32_t mode,
|
||||
const std::string &callerBundleName, const std::string &targetBundleName)
|
||||
const std::string &callerAlterBundleName, const std::string &targetAlterBundleName)
|
||||
{
|
||||
auto &&authority = uriInner.GetAuthority();
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "Authority of uri is %{public}s.", authority.c_str());
|
||||
// media uri
|
||||
if (authority == "media") {
|
||||
mediaUris.emplace_back(uriInner);
|
||||
mediaIndexs.emplace_back(index);
|
||||
mediaUris.emplace_back(uriInner.ToString());
|
||||
mediaIndexes.emplace_back(index);
|
||||
return;
|
||||
}
|
||||
// bundle uri
|
||||
isTargetBundleUri[index] = (!targetBundleName.empty() && authority == targetBundleName);
|
||||
if (!callerBundleName.empty() && authority == callerBundleName) {
|
||||
result[index] = true;
|
||||
isTargetBundleUri[index] = (!targetAlterBundleName.empty() && authority == targetAlterBundleName);
|
||||
if (!callerAlterBundleName.empty() && authority == callerAlterBundleName) {
|
||||
checkResult[index] = true;
|
||||
if (isTargetBundleUri[index]) {
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "uri belong to targetBundle.");
|
||||
targetBundleUriCount++;
|
||||
@@ -86,23 +86,23 @@ void BatchUri::InitFileUriInfo(Uri &uriInner, uint32_t index, const uint32_t mod
|
||||
}
|
||||
// docs and bundle uri, need to check uri pemission
|
||||
otherUris.emplace_back(uriInner);
|
||||
otherIndexs.emplace_back(index);
|
||||
otherIndexes.emplace_back(index);
|
||||
}
|
||||
|
||||
void BatchUri::SetMediaUriCheckResult(const std::vector<bool> &mediaUriResult)
|
||||
{
|
||||
for (size_t i = 0; i < mediaUriResult.size(); i++) {
|
||||
auto index = mediaIndexs[i];
|
||||
result[index] = mediaUriResult[i];
|
||||
auto index = mediaIndexes[i];
|
||||
checkResult[index] = mediaUriResult[i];
|
||||
}
|
||||
}
|
||||
|
||||
void BatchUri::SetOtherUriCheckResult(const std::vector<bool> &otherUriResult)
|
||||
{
|
||||
for (size_t i = 0; i < otherUriResult.size(); i++) {
|
||||
auto index = otherIndexs[i];
|
||||
result[index] = otherUriResult[i];
|
||||
if (result[index] && isTargetBundleUri[index]) {
|
||||
auto index = otherIndexes[i];
|
||||
checkResult[index] = otherUriResult[i];
|
||||
if (checkResult[index] && isTargetBundleUri[index]) {
|
||||
targetBundleUriCount++;
|
||||
}
|
||||
}
|
||||
@@ -110,9 +110,9 @@ void BatchUri::SetOtherUriCheckResult(const std::vector<bool> &otherUriResult)
|
||||
|
||||
int32_t BatchUri::GetMediaUriToGrant(std::vector<std::string> &uriVec)
|
||||
{
|
||||
for (size_t i = 0; i < mediaIndexs.size(); i++) {
|
||||
if (result[mediaIndexs[i]]) {
|
||||
uriVec.emplace_back(mediaUris[i].ToString());
|
||||
for (size_t i = 0; i < mediaIndexes.size(); i++) {
|
||||
if (checkResult[mediaIndexes[i]]) {
|
||||
uriVec.emplace_back(mediaUris[i]);
|
||||
}
|
||||
}
|
||||
return uriVec.size();
|
||||
@@ -122,10 +122,10 @@ void BatchUri::GetNeedCheckProxyPermissionURI(std::vector<PolicyInfo> &proxyUris
|
||||
std::vector<Uri> &proxyUrisByMap)
|
||||
{
|
||||
// docs uri and bundle uri
|
||||
for (size_t i = 0; i < otherIndexs.size(); i++) {
|
||||
auto index = otherIndexs[i];
|
||||
if (!result[index]) {
|
||||
proxyIndexsByPolicy.emplace_back(index);
|
||||
for (size_t i = 0; i < otherIndexes.size(); i++) {
|
||||
auto index = otherIndexes[i];
|
||||
if (!checkResult[index]) {
|
||||
proxyIndexesByPolicy.emplace_back(index);
|
||||
proxyUrisByPolicy.emplace_back(otherPolicyInfos[i]);
|
||||
}
|
||||
}
|
||||
@@ -134,19 +134,19 @@ void BatchUri::GetNeedCheckProxyPermissionURI(std::vector<PolicyInfo> &proxyUris
|
||||
void BatchUri::SetCheckProxyByMapResult(std::vector<bool> &proxyResultByMap)
|
||||
{
|
||||
for (size_t i = 0; i < proxyResultByMap.size(); i++) {
|
||||
auto index = proxyIndexsByMap[i];
|
||||
result[index] = proxyResultByMap[i];
|
||||
auto index = proxyIndexesByMap[i];
|
||||
checkResult[index] = proxyResultByMap[i];
|
||||
}
|
||||
proxyIndexsByMap.clear();
|
||||
proxyIndexesByMap.clear();
|
||||
}
|
||||
|
||||
void BatchUri::SetCheckProxyByPolicyResult(std::vector<bool> &proxyResultByPolicy)
|
||||
{
|
||||
for (size_t i = 0; i < proxyResultByPolicy.size(); i++) {
|
||||
auto index = proxyIndexsByPolicy[i];
|
||||
result[index] = proxyResultByPolicy[i];
|
||||
auto index = proxyIndexesByPolicy[i];
|
||||
checkResult[index] = proxyResultByPolicy[i];
|
||||
}
|
||||
proxyIndexsByPolicy.clear();
|
||||
proxyIndexesByPolicy.clear();
|
||||
}
|
||||
|
||||
int32_t BatchUri::GetUriToGrantByMap(std::vector<std::string> &uriVec)
|
||||
@@ -158,7 +158,7 @@ void BatchUri::SelectPermissionedUri(std::vector<Uri> &uris, std::vector<int32_t
|
||||
std::vector<std::string> &uriVec)
|
||||
{
|
||||
for (size_t i = 0; i < indexs.size(); i++) {
|
||||
if (result[indexs[i]]) {
|
||||
if (checkResult[indexs[i]]) {
|
||||
auto uriStr = uris[i].ToString();
|
||||
uriVec.emplace_back(uriStr);
|
||||
}
|
||||
@@ -175,8 +175,8 @@ int32_t BatchUri::GetUriToGrantByPolicy(std::vector<PolicyInfo> &docsPolicyInfoV
|
||||
count++;
|
||||
}
|
||||
for (size_t i = 0; i < otherPolicyInfos.size(); i++) {
|
||||
auto index = otherIndexs[i];
|
||||
if (!result[index]) {
|
||||
auto index = otherIndexes[i];
|
||||
if (!checkResult[index]) {
|
||||
continue;
|
||||
}
|
||||
// the uri belong to target app.
|
||||
@@ -195,15 +195,50 @@ int32_t BatchUri::GetUriToGrantByPolicy(std::vector<PolicyInfo> &docsPolicyInfoV
|
||||
return count;
|
||||
}
|
||||
|
||||
bool BatchUri::GetUriToGrantByPolicy(std::vector<PolicyInfo> &policyVec)
|
||||
{
|
||||
// self bundle uris
|
||||
for (const auto &selfBundleUriPolicy : selfBundlePolicyInfos) {
|
||||
policyVec.emplace_back(selfBundleUriPolicy);
|
||||
}
|
||||
for (size_t i = 0; i < otherPolicyInfos.size(); i++) {
|
||||
auto index = otherIndexes[i];
|
||||
if (!checkResult[index]) {
|
||||
return false;
|
||||
}
|
||||
// the uri belong to target app.
|
||||
if (isTargetBundleUri[index]) {
|
||||
continue;
|
||||
}
|
||||
policyVec.emplace_back(otherPolicyInfos[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t BatchUri::GetPermissionedUriCount()
|
||||
{
|
||||
int32_t permissionedUriCount = 0;
|
||||
for (auto checkRes: result) {
|
||||
for (auto checkRes: checkResult) {
|
||||
if (checkRes) {
|
||||
permissionedUriCount++;
|
||||
}
|
||||
}
|
||||
return permissionedUriCount;
|
||||
}
|
||||
|
||||
bool BatchUri::IsAllUriValid()
|
||||
{
|
||||
return validUriCount == totalUriCount;
|
||||
}
|
||||
|
||||
bool BatchUri::IsAllUriPermissioned()
|
||||
{
|
||||
for (auto checkRes : checkResult) {
|
||||
if (!checkRes) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // OHOS
|
||||
} // AAFwk
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -51,34 +51,30 @@ Media::MediaLibraryExtendManager *MediaPermissionManager::GetMediaLibraryManager
|
||||
return mediaLibraryManager;
|
||||
}
|
||||
|
||||
std::vector<bool> MediaPermissionManager::CheckUriPermission(const std::vector<Uri> &uriVec,
|
||||
std::vector<bool> MediaPermissionManager::CheckUriPermission(const std::vector<std::string> &uriVec,
|
||||
uint32_t callerTokenId, uint32_t flag)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "uris:%{public}zu, callerTokenId:%{public}u, flag:%{public}u",
|
||||
uriVec.size(), callerTokenId, flag);
|
||||
std::vector<std::string> uriStrVec;
|
||||
std::vector<bool> results = std::vector<bool>(uriVec.size(), false);
|
||||
for (auto &uri: uriVec) {
|
||||
uriStrVec.emplace_back(uri.ToString());
|
||||
}
|
||||
flag &= (Want::FLAG_AUTH_READ_URI_PERMISSION | Want::FLAG_AUTH_WRITE_URI_PERMISSION);
|
||||
auto mediaLibraryManager = GetMediaLibraryManager();
|
||||
if (mediaLibraryManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "GetMediaLibraryManager failed.");
|
||||
return results;
|
||||
}
|
||||
std::vector<uint32_t> flags(uriStrVec.size(), flag);
|
||||
auto ret = IN_PROCESS_CALL(mediaLibraryManager->CheckPhotoUriPermission(callerTokenId, uriStrVec, results, flags));
|
||||
std::vector<uint32_t> flags(uriVec.size(), flag);
|
||||
auto ret = IN_PROCESS_CALL(mediaLibraryManager->CheckPhotoUriPermission(callerTokenId, uriVec, results, flags));
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "CheckPhotoUriPermission finished.");
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "Check photo uri permission failed, ret is %{public}d", ret);
|
||||
results = std::vector<bool>(uriStrVec.size(), false);
|
||||
results = std::vector<bool>(uriVec.size(), false);
|
||||
return results;
|
||||
}
|
||||
if (results.size() != uriStrVec.size()) {
|
||||
if (results.size() != uriVec.size()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "size of results is unexpected: %{public}zu", results.size());
|
||||
results = std::vector<bool>(uriStrVec.size(), false);
|
||||
results = std::vector<bool>(uriVec.size(), false);
|
||||
return results;
|
||||
}
|
||||
return results;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "upms_udmf_utils.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
#include "udmf_client.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
constexpr const char *UDMF_FILE_URI_ENTRY = "general.file-uri";
|
||||
constexpr const char *UDMF_ORI_URI = "oriUri";
|
||||
constexpr const char *FILE_SCHEME = "file";
|
||||
}
|
||||
|
||||
int32_t UDMFUtils::GetBatchData(const std::string &key, std::vector<std::string> &uris)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "GetBatchData call");
|
||||
uris.clear();
|
||||
UDMF::QueryOption query = { .key = key };
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
auto ret = IN_PROCESS_CALL(UDMF::UdmfClient::GetInstance().GetBatchData(query, unifiedDataset));
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "GetBatchData failed:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
for (size_t i = 0; i < unifiedDataset.size(); i++) {
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> records = unifiedDataset[i].GetRecords();
|
||||
for (const auto &record : records) {
|
||||
auto fileEntry = record->GetEntry(UDMF_FILE_URI_ENTRY);
|
||||
std::shared_ptr<UDMF::Object> fileEntryObj = std::get<std::shared_ptr<UDMF::Object>>(fileEntry);
|
||||
if (fileEntryObj == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "file entry obj null");
|
||||
return ERR_UPMS_GET_ORI_URI_FAILED;
|
||||
}
|
||||
std::string oriUri;
|
||||
fileEntryObj->GetValue(UDMF_ORI_URI, oriUri);
|
||||
if (oriUri.empty()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "get oriUri failed");
|
||||
return ERR_UPMS_GET_ORI_URI_FAILED;
|
||||
}
|
||||
Uri uri(oriUri);
|
||||
if (uri.GetScheme() != FILE_SCHEME) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "not file uri:%{public}s", uri.GetScheme().c_str());
|
||||
return ERR_UPMS_NOT_FILE_URI;
|
||||
}
|
||||
uris.emplace_back(oriUri);
|
||||
}
|
||||
}
|
||||
if (uris.empty()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "uris empty");
|
||||
return ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t UDMFUtils::AddPrivilege(const std::string &key, uint32_t tokenId, const std::string &readPermission)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "AddPrivilege call");
|
||||
UDMF::QueryOption query = { .key = key };
|
||||
UDMF::Privilege privilege = { .tokenId = tokenId, .readPermission = readPermission };
|
||||
auto ret = IN_PROCESS_CALL(UDMF::UdmfClient::GetInstance().AddPrivilege(query, privilege));
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "AddPrivilege failed:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UDMFUtils::ProcessUdmfKey(const std::string &key, uint32_t callerTokenId, uint32_t targetTokenId,
|
||||
std::vector<std::string> &uris)
|
||||
{
|
||||
// To check if the key belong to callerTokenId
|
||||
auto ret = AddPrivilege(key, targetTokenId, "");
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "AddPrivilege failed:%{public}d", ret);
|
||||
return ERR_UPMS_ADD_PRIVILEGED_FAILED;
|
||||
}
|
||||
uint32_t selfToken = IPCSkeleton::GetSelfTokenID();
|
||||
ret = AddPrivilege(key, selfToken, "readAndKeep");
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "AddPrivilege self failed:%{public}d", ret);
|
||||
return ERR_UPMS_ADD_PRIVILEGED_FAILED;
|
||||
}
|
||||
ret = GetBatchData(key, uris);
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "GetBatchData failed:%{public}d", ret);
|
||||
return ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // OHOS
|
||||
} // AAFwk
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "system_ability_definition.h"
|
||||
#include "tokenid_kit.h"
|
||||
#include "uri_permission_utils.h"
|
||||
#include "upms_udmf_utils.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -56,6 +57,12 @@ constexpr int32_t CAPABILITY_NOT_SUPPORT = 801;
|
||||
constexpr int32_t SANDBOX_MANAGER_PERMISSION_DENIED = 1;
|
||||
}
|
||||
|
||||
inline int32_t UriPermissionManagerStubImpl::WrapErrorCode(int32_t errorCode, int32_t &funcRet)
|
||||
{
|
||||
funcRet = errorCode;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode UriPermissionManagerStubImpl::VerifyUriPermission(const Uri& uri, uint32_t flag, uint32_t tokenId,
|
||||
bool& funcResult)
|
||||
{
|
||||
@@ -191,10 +198,6 @@ ErrCode UriPermissionManagerStubImpl::GrantUriPermission(const std::vector<std::
|
||||
const std::string& targetBundleName, int32_t appIndex, uint32_t initiatorTokenId, int32_t& funcResult)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (uriVec.empty() || uriVec.size() > MAX_URI_COUNT) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "uriVec empty or exceed maxSize %{public}d", MAX_URI_COUNT);
|
||||
return ERR_URI_LIST_OUT_OF_RANGE;
|
||||
}
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "BundleName:%{public}s, appIndex:%{public}d, flag:%{public}u, uris:%{public}zu",
|
||||
targetBundleName.c_str(), appIndex, flag, uriVec.size());
|
||||
if (!UPMSUtils::IsSAOrSystemAppCall()) {
|
||||
@@ -207,7 +210,7 @@ ErrCode UriPermissionManagerStubImpl::GrantUriPermission(const std::vector<std::
|
||||
funcResult = checkResult;
|
||||
return ERR_OK;
|
||||
}
|
||||
if (uriVec.size() == 0 || uriVec.size() > MAX_URI_COUNT) {
|
||||
if (uriVec.empty() || uriVec.size() > MAX_URI_COUNT) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "out of range: %{public}zu", uriVec.size());
|
||||
funcResult = ERR_URI_LIST_OUT_OF_RANGE;
|
||||
return ERR_OK;
|
||||
@@ -228,11 +231,7 @@ ErrCode UriPermissionManagerStubImpl::GrantUriPermission(const std::vector<std::
|
||||
if (!UPMSUtils::IsFoundationCall()) {
|
||||
callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
}
|
||||
std::vector<Uri> uriVecInner;
|
||||
for (const auto& str : uriVec) {
|
||||
uriVecInner.emplace_back(str);
|
||||
}
|
||||
funcResult = GrantUriPermissionInner(uriVecInner, flag, callerTokenId, targetTokenId, targetBundleName);
|
||||
funcResult = GrantUriPermissionInner(uriVec, flag, callerTokenId, targetTokenId, targetBundleName);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -255,7 +254,7 @@ ErrCode UriPermissionManagerStubImpl::GrantUriPermission(const UriPermissionRawD
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerStubImpl::GrantUriPermissionInner(const std::vector<Uri> &uriVec, uint32_t flag,
|
||||
int32_t UriPermissionManagerStubImpl::GrantUriPermissionInner(const std::vector<std::string> &uriVec, uint32_t flag,
|
||||
uint32_t callerTokenId, uint32_t targetTokenId, const std::string &targetBundleName)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "call");
|
||||
@@ -270,15 +269,15 @@ int32_t UriPermissionManagerStubImpl::GrantUriPermissionInner(const std::vector<
|
||||
size_t permissionedUriCount = 0;
|
||||
for (size_t i = 0; i < checkResult.size(); i++) {
|
||||
if (!checkResult[i]) {
|
||||
TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri:%{private}s", uriVec[i].ToString().c_str());
|
||||
TAG_LOGW(AAFwkTag::URIPERMMGR, "No permission, uri:%{private}s", uriVec[i].c_str());
|
||||
continue;
|
||||
}
|
||||
permissionedUriCount++;
|
||||
auto uriInner = uriVec[i];
|
||||
auto uriInner = Uri(uriVec[i]);
|
||||
if (uriInner.GetScheme() == "media") {
|
||||
permissionedMediaUris.emplace_back(uriVec[i].ToString());
|
||||
permissionedMediaUris.emplace_back(uriVec[i]);
|
||||
} else {
|
||||
permissionedOtherUris.emplace_back(uriVec[i].ToString());
|
||||
permissionedOtherUris.emplace_back(uriVec[i]);
|
||||
}
|
||||
}
|
||||
// some uri is no permission
|
||||
@@ -608,6 +607,148 @@ int32_t UriPermissionManagerStubImpl::GrantUriPermissionPrivilegedImpl(BatchStri
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrCode UriPermissionManagerStubImpl::GrantUriPermissionByKeyAsCaller(const std::string &key, uint32_t flag,
|
||||
uint32_t callerTokenId, uint32_t targetTokenId, int32_t &funcResult)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
auto ret = CheckGrantUriPermissionByKeyAsCaller();
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "check fail:%{public}d", ret);
|
||||
return WrapErrorCode(ret, funcResult);
|
||||
}
|
||||
|
||||
ret = GrantUriPermissionByKeyInner(key, flag, callerTokenId, targetTokenId);
|
||||
return WrapErrorCode(ret, funcResult);
|
||||
}
|
||||
|
||||
ErrCode UriPermissionManagerStubImpl::GrantUriPermissionByKey(const std::string &key, uint32_t flag,
|
||||
uint32_t targetTokenId, int32_t &funcResult)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
auto ret = CheckGrantUriPermissionByKey();
|
||||
if (ret != ERR_OK) {
|
||||
return WrapErrorCode(ret, funcResult);
|
||||
}
|
||||
uint32_t callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
ret = GrantUriPermissionByKeyInner(key, flag, callerTokenId, targetTokenId);
|
||||
if (ret == ERR_UPMS_INVALID_CALLER_TOKENID) {
|
||||
return WrapErrorCode(INNER_ERR, funcResult);
|
||||
}
|
||||
return WrapErrorCode(ret, funcResult);
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerStubImpl::GrantUriPermissionByKeyInner(const std::string &key, uint32_t flag,
|
||||
uint32_t callerTokenId, uint32_t targetTokenId)
|
||||
{
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "key:%{public}s, flag:%{public}u, caller:%{public}u, target:%{public}u",
|
||||
key.c_str(), flag, callerTokenId, targetTokenId);
|
||||
UPMSAppInfo callerAppInfo = { .tokenId = callerTokenId };
|
||||
UPMSAppInfo targetAppInfo = { .tokenId = targetTokenId };
|
||||
std::vector<std::string> uris;
|
||||
auto ret = CheckGrantUriPermissionByKeyParams(key, flag, callerAppInfo, targetAppInfo, uris);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
// check uri permission
|
||||
TokenIdPermission tokenIdPermission(callerTokenId);
|
||||
auto checkResult = CheckUriPermission(tokenIdPermission, uris, flag);
|
||||
// grant uri permission
|
||||
std::vector<std::string> permissionedMediaUris;
|
||||
std::vector<std::string> permissionedOtherUris;
|
||||
for (size_t i = 0; i < checkResult.size(); i++) {
|
||||
if (!checkResult[i]) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "No permission, uri:%{private}s", uris[i].c_str());
|
||||
return ERR_UPMS_NO_PERMISSION_GRANT_URI;
|
||||
}
|
||||
auto uriInner = Uri(uris[i]);
|
||||
if (uriInner.GetScheme() == "media") {
|
||||
permissionedMediaUris.emplace_back(uris[i]);
|
||||
} else {
|
||||
permissionedOtherUris.emplace_back(uris[i]);
|
||||
}
|
||||
}
|
||||
if (!permissionedOtherUris.empty() &&
|
||||
GrantBatchUriPermissionImpl(permissionedOtherUris, flag, callerTokenId, targetTokenId) != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "grant batch uri permission failed");
|
||||
return ERR_UPMS_GRANT_URI_PERMISSION_FAILED;
|
||||
}
|
||||
if (!permissionedMediaUris.empty() &&
|
||||
GrantBatchMediaUriPermissionImpl(permissionedMediaUris, flag, callerTokenId, targetTokenId, 0) != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "grant media uri permission failed");
|
||||
return ERR_UPMS_GRANT_URI_PERMISSION_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerStubImpl::CheckGrantUriPermissionByKeyAsCaller()
|
||||
{
|
||||
if (!AppUtils::GetInstance().IsSupportGrantUriPermission()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "not support grant uri permission");
|
||||
return ERR_CAPABILITY_NOT_SUPPORT;
|
||||
}
|
||||
if (!UPMSUtils::IsSystemAppCall()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "caller not system");
|
||||
return ERR_NOT_SYSTEM_APP;
|
||||
}
|
||||
uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto permissionName = PermissionConstants::PERMISSION_GRANT_URI_PERMISSION_AS_CALLER;
|
||||
if (!PermissionVerification::GetInstance()->VerifyPermissionByTokenId(callingTokenId, permissionName)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "No permission to call");
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
auto ret = CheckCalledBySandBox();
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "sandbox not support grant uripermission");
|
||||
return ret;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerStubImpl::CheckGrantUriPermissionByKey()
|
||||
{
|
||||
if (!AppUtils::GetInstance().IsSupportGrantUriPermission()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "not support grant uri permission");
|
||||
return ERR_CAPABILITY_NOT_SUPPORT;
|
||||
}
|
||||
if (!UPMSUtils::IsSystemAppCall()) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "caller not system");
|
||||
return ERR_NOT_SYSTEM_APP;
|
||||
}
|
||||
auto ret = CheckCalledBySandBox();
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "sandbox not support grant uripermission");
|
||||
return ret;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t UriPermissionManagerStubImpl::CheckGrantUriPermissionByKeyParams(const std::string &key, uint32_t flag,
|
||||
UPMSAppInfo &callerAppInfo, UPMSAppInfo &targetAppInfo, std::vector<std::string> &uris)
|
||||
{
|
||||
if ((flag & FLAG_READ_WRITE_URI) == 0) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "Flag invalid");
|
||||
return ERR_CODE_INVALID_URI_FLAG;
|
||||
}
|
||||
if (callerAppInfo.tokenId == targetAppInfo.tokenId) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "caller equal to target");
|
||||
return ERR_UPMS_INVALID_TARGET_TOKENID;
|
||||
}
|
||||
if (!UPMSUtils::GetAlterableBundleNameByTokenId(callerAppInfo.tokenId, callerAppInfo.alterBundleName)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "callerTokenId invalid");
|
||||
return ERR_UPMS_INVALID_CALLER_TOKENID;
|
||||
}
|
||||
if (!UPMSUtils::GetAlterableBundleNameByTokenId(targetAppInfo.tokenId, targetAppInfo.alterBundleName)) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "targetTokenId invalid");
|
||||
return ERR_UPMS_INVALID_TARGET_TOKENID;
|
||||
}
|
||||
auto ret = UDMFUtils::ProcessUdmfKey(key, callerAppInfo.tokenId, targetAppInfo.tokenId, uris);
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "ProcessUdmfKey failed:%{public}d", ret);
|
||||
return ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode UriPermissionManagerStubImpl::CheckUriAuthorization(const std::vector<std::string>& uriStrVec,
|
||||
uint32_t flag, uint32_t tokenId, std::vector<bool>& funcResult)
|
||||
{
|
||||
@@ -627,12 +768,8 @@ ErrCode UriPermissionManagerStubImpl::CheckUriAuthorization(const std::vector<st
|
||||
TAG_LOGE(AAFwkTag::URIPERMMGR, "Flag invalid");
|
||||
return ERR_OK;
|
||||
}
|
||||
std::vector<Uri> uriVec;
|
||||
for (auto& uriStr: uriStrVec) {
|
||||
uriVec.emplace_back(uriStr);
|
||||
}
|
||||
TokenIdPermission tokenIdPermission(tokenId);
|
||||
funcResult = CheckUriPermission(tokenIdPermission, uriVec, flag);
|
||||
funcResult = CheckUriPermission(tokenIdPermission, uriStrVec, flag);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -665,18 +802,18 @@ ErrCode UriPermissionManagerStubImpl::CheckUriAuthorization(const UriPermissionR
|
||||
}
|
||||
|
||||
std::vector<bool> UriPermissionManagerStubImpl::CheckUriPermission(TokenIdPermission& tokenIdPermission,
|
||||
const std::vector<Uri>& uriVec, uint32_t flag)
|
||||
const std::vector<std::string>& uriVec, uint32_t flag)
|
||||
{
|
||||
// only reserve read and write file flag
|
||||
flag &= FLAG_READ_WRITE_URI;
|
||||
auto tokenId = tokenIdPermission.GetTokenId();
|
||||
std::vector<bool> result(uriVec.size(), false);
|
||||
std::vector<Uri> mediaUris;
|
||||
std::vector<std::string> mediaUris;
|
||||
std::vector<int32_t> mediaUriIndexs;
|
||||
std::string callerAlterableBundleName;
|
||||
UPMSUtils::GetAlterableBundleNameByTokenId(tokenId, callerAlterableBundleName);
|
||||
for (size_t i = 0; i < uriVec.size(); i++) {
|
||||
auto uri = uriVec[i];
|
||||
auto uri = Uri(uriVec[i]);
|
||||
auto &&scheme = uri.GetScheme();
|
||||
// checkUriPermission not support content uri
|
||||
if (scheme != "file") {
|
||||
@@ -691,7 +828,7 @@ std::vector<bool> UriPermissionManagerStubImpl::CheckUriPermission(TokenIdPermis
|
||||
continue;
|
||||
}
|
||||
if (authority == "media") {
|
||||
mediaUris.emplace_back(uri);
|
||||
mediaUris.emplace_back(uriVec[i]);
|
||||
mediaUriIndexs.emplace_back(i);
|
||||
continue;
|
||||
}
|
||||
@@ -711,7 +848,7 @@ std::vector<bool> UriPermissionManagerStubImpl::CheckUriPermission(TokenIdPermis
|
||||
}
|
||||
|
||||
void UriPermissionManagerStubImpl::CheckProxyUriPermission(TokenIdPermission &tokenIdPermission,
|
||||
const std::vector<Uri> &uriVec, uint32_t flag, std::vector<bool> &result)
|
||||
const std::vector<std::string> &uriVec, uint32_t flag, std::vector<bool> &result)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::URIPERMMGR, "Call");
|
||||
if (uriVec.size() != result.size()) {
|
||||
@@ -728,7 +865,7 @@ void UriPermissionManagerStubImpl::CheckProxyUriPermission(TokenIdPermission &to
|
||||
continue;
|
||||
}
|
||||
// media no need to check proxy permission, has checked by medialibrary
|
||||
auto uriInner = uriVec[i];
|
||||
auto uriInner = Uri(uriVec[i]);
|
||||
if (uriInner.GetAuthority() != "media") {
|
||||
bool funcResult = false;
|
||||
VerifyUriPermission(uriInner, flag, tokenId, funcResult);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -62,7 +62,7 @@ bool UPMSUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t ta
|
||||
}
|
||||
|
||||
bool UPMSUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId,
|
||||
const std::vector<Uri> &uriVec, const std::vector<bool> &resVec)
|
||||
const std::vector<std::string> &uriVec, const std::vector<bool> &resVec)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::URIPERMMGR, "send grant uri permission event start.");
|
||||
EventInfo eventInfo;
|
||||
@@ -71,7 +71,7 @@ bool UPMSUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uin
|
||||
}
|
||||
for (size_t i = 0; i < resVec.size(); i++) {
|
||||
if (resVec[i]) {
|
||||
eventInfo.uri = uriVec[i].ToString();
|
||||
eventInfo.uri = uriVec[i];
|
||||
EventReport::SendGrantUriPermissionEvent(EventName::GRANT_URI_PERMISSION, eventInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,5 +398,31 @@ HWTEST_F(AppUtilsTest, AppUtilsTest_1900, TestSize.Level2)
|
||||
}
|
||||
EXPECT_FALSE(isExist);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AppUtilsTest_2000
|
||||
* @tc.desc: Test IsSupportGrantUriPermission works
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppUtilsTest, AppUtilsTest_2000, TestSize.Level2)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2000 called.");
|
||||
auto isSupport = AAFwk::AppUtils::GetInstance().IsSupportGrantUriPermission();
|
||||
EXPECT_TRUE(isSupport);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AppUtilsTest_2100
|
||||
* @tc.desc: Test IsSupportGrantUriPermission works
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppUtilsTest, AppUtilsTest_2100, TestSize.Level2)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_2100 called.");
|
||||
auto &appUtils = AAFwk::AppUtils::GetInstance();
|
||||
appUtils.isGrantTempUriPermission_.isLoaded = true;
|
||||
auto isSupport = appUtils.IsSupportGrantUriPermission();
|
||||
EXPECT_TRUE(isSupport);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -36,12 +36,16 @@ ohos_unittest("uri_permission_impl_test") {
|
||||
"${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp",
|
||||
"mock/src/mock_ability_manager_client.cpp",
|
||||
"mock/src/mock_accesstoken_kit.cpp",
|
||||
"mock/src/mock_app_utils.cpp",
|
||||
"mock/src/mock_bundle_mgr_helper.cpp",
|
||||
"mock/src/mock_iability_manager_collaborator.cpp",
|
||||
"mock/src/mock_ipc_skeleton.cpp",
|
||||
"mock/src/mock_my_flag.cpp",
|
||||
"mock/src/mock_permission_verification.cpp",
|
||||
"mock/src/mock_sandbox_manager.cpp",
|
||||
"mock/src/mock_udmf_utils.cpp",
|
||||
"mock/src/mock_uri_permission_utils.cpp",
|
||||
"batch_uri_test.cpp",
|
||||
"uri_permission_impl_test.cpp",
|
||||
]
|
||||
|
||||
@@ -173,11 +177,55 @@ ohos_unittest("uri_permission_manager_stub_impl_test") {
|
||||
}
|
||||
}
|
||||
|
||||
ohos_unittest("upms_udmf_utils_test") {
|
||||
module_out_path = module_output_path
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
blocklist = "../../cfi_blocklist.txt"
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
include_dirs = [
|
||||
"mock/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_services_path}/uripermmgr/src/upms_udmf_utils.cpp",
|
||||
"mock/src/mock_my_flag.cpp",
|
||||
"mock/src/udmf_client.cpp",
|
||||
"udmf_utils_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"${ability_runtime_services_path}/common:common_config",
|
||||
"${ability_runtime_services_path}/uripermmgr:upms_config",
|
||||
]
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"googletest:gmock_main",
|
||||
"googletest:gtest_main",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
cflags_cc = []
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
":uri_permission_impl_test",
|
||||
":uri_permission_manager_stub_impl_test",
|
||||
":upms_udmf_utils_test",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "batch_uri.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class BatchUriTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void BatchUriTest::SetUpTestCase()
|
||||
{}
|
||||
|
||||
void BatchUriTest::TearDownTestCase()
|
||||
{}
|
||||
|
||||
void BatchUriTest::SetUp()
|
||||
{}
|
||||
|
||||
void BatchUriTest::TearDown()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @tc.number: Init_0100
|
||||
* @tc.name: Init
|
||||
* @tc.desc: Test Init.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, Init_0100, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
std::vector<std::string> uriVec;
|
||||
uint32_t mode = 0;
|
||||
std::string callerAlterBundleName = "callerBundleName";
|
||||
std::string targetAlterBundleName = "targetBundleName";
|
||||
auto ret = batchUri->Init(uriVec, mode, callerAlterBundleName, targetAlterBundleName);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: Init_0200
|
||||
* @tc.name: Init
|
||||
* @tc.desc: Test Init.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, Init_0200, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
std::vector<std::string> uriVec;
|
||||
uriVec.push_back("file://com.example.insertdata/data/storage/el2/base/haps/entry/files/temp1.txt");
|
||||
uriVec.push_back("testUri");
|
||||
uint32_t mode = 0;
|
||||
std::string callerAlterBundleName = "callerBundleName";
|
||||
std::string targetAlterBundleName = "targetBundleName";
|
||||
auto ret = batchUri->Init(uriVec, mode, callerAlterBundleName, targetAlterBundleName);
|
||||
EXPECT_EQ(ret, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetUriToGrantByPolicy_0100
|
||||
* @tc.name: GetUriToGrantByPolicy
|
||||
* @tc.desc: Test GetUriToGrantByPolicy.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, GetUriToGrantByPolicy_0100, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
PolicyInfo policyInfo;
|
||||
policyInfo.path = "testPath";
|
||||
policyInfo.mode = 0;
|
||||
batchUri->selfBundlePolicyInfos.push_back(policyInfo);
|
||||
batchUri->otherPolicyInfos.push_back(policyInfo);
|
||||
batchUri->otherIndexes.push_back(0);
|
||||
batchUri->checkResult.push_back(false);
|
||||
std::vector<PolicyInfo> policys;
|
||||
auto ret = batchUri->GetUriToGrantByPolicy(policys);
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetUriToGrantByPolicy_0200
|
||||
* @tc.name: GetUriToGrantByPolicy
|
||||
* @tc.desc: Test GetUriToGrantByPolicy.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, GetUriToGrantByPolicy_0200, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
PolicyInfo policyInfo;
|
||||
policyInfo.path = "testPath";
|
||||
policyInfo.mode = 0;
|
||||
batchUri->selfBundlePolicyInfos.push_back(policyInfo);
|
||||
batchUri->otherPolicyInfos.push_back(policyInfo);
|
||||
batchUri->otherIndexes.push_back(0);
|
||||
batchUri->checkResult.push_back(true);
|
||||
batchUri->isTargetBundleUri.push_back(true);
|
||||
std::vector<PolicyInfo> policys;
|
||||
auto ret = batchUri->GetUriToGrantByPolicy(policys);
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetUriToGrantByPolicy_0300
|
||||
* @tc.name: GetUriToGrantByPolicy
|
||||
* @tc.desc: Test GetUriToGrantByPolicy.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, GetUriToGrantByPolicy_0300, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
PolicyInfo policyInfo;
|
||||
policyInfo.path = "testPath";
|
||||
policyInfo.mode = 0;
|
||||
batchUri->selfBundlePolicyInfos.push_back(policyInfo);
|
||||
batchUri->otherPolicyInfos.push_back(policyInfo);
|
||||
batchUri->otherIndexes.push_back(0);
|
||||
batchUri->checkResult.push_back(true);
|
||||
batchUri->isTargetBundleUri.push_back(false);
|
||||
std::vector<PolicyInfo> policys;
|
||||
auto ret = batchUri->GetUriToGrantByPolicy(policys);
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: IsAllUriValid_0100
|
||||
* @tc.name: IsAllUriValid
|
||||
* @tc.desc: Test IsAllUriValid.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, IsAllUriValid_0100, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
batchUri->validUriCount = 0;
|
||||
batchUri->totalUriCount = 0;
|
||||
auto ret = batchUri->IsAllUriValid();
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
batchUri->totalUriCount = 1;
|
||||
ret = batchUri->IsAllUriValid();
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: IsAllUriPermissioned_0100
|
||||
* @tc.name: IsAllUriPermissioned
|
||||
* @tc.desc: Test IsAllUriPermissioned.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, IsAllUriPermissioned_0100, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
batchUri->checkResult.push_back(false);
|
||||
auto ret = batchUri->IsAllUriPermissioned();
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: IsAllUriPermissioned_0200
|
||||
* @tc.name: IsAllUriPermissioned
|
||||
* @tc.desc: Test IsAllUriPermissioned.
|
||||
*/
|
||||
HWTEST_F(BatchUriTest, IsAllUriPermissioned_0200, TestSize.Level2)
|
||||
{
|
||||
auto batchUri = std::make_shared<BatchUri>();
|
||||
ASSERT_NE(batchUri, nullptr);
|
||||
auto ret = batchUri->IsAllUriPermissioned();
|
||||
EXPECT_TRUE(ret);
|
||||
batchUri->checkResult.push_back(true);
|
||||
ret = batchUri->IsAllUriPermissioned();
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_APP_UTILS_H
|
||||
#define OHOS_ABILITY_RUNTIME_APP_UTILS_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class AppUtils {
|
||||
public:
|
||||
static AppUtils &GetInstance();
|
||||
static bool isSupportGrantUriPermission_;
|
||||
|
||||
~AppUtils();
|
||||
bool IsSupportGrantUriPermission();
|
||||
static void Init();
|
||||
|
||||
private:
|
||||
AppUtils();
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(AppUtils);
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -69,6 +69,25 @@ public:
|
||||
permissionReadWriteDesktop_ = false;
|
||||
permissionReadWriteDocuments_ = false;
|
||||
IsSystempAppCall_ = false;
|
||||
getTokenIdByBundleNameStatus_ = 0;
|
||||
isSAOrSystemAppCall_ = false;
|
||||
isSystemAppCall_ = false;
|
||||
isUriTypeValid_ = false;
|
||||
isDocsCloudUri_ = false;
|
||||
permissionGrantUriPermissionAsCaller_ = false;
|
||||
processUdmfKeyRet_ = 0;
|
||||
udmfUtilsUris_ = {};
|
||||
upmsUtilsCheckIsSystemAppByBundleNameRet_ = true;
|
||||
upmsUtilsCheckIsSystemAppByTokenIdRet_ = false;
|
||||
upmsUtilsGetDirByBundleNameAndAppIndexRet_ = true;
|
||||
upmsUtilsAlterBundleName_ = "";
|
||||
upmsUtilsGetAlterBundleNameByTokenIdRet_ = true;
|
||||
upmsUtilsBundleName_ = "";
|
||||
upmsUtilsGetBundleNameByTokenIdRet_ = false;
|
||||
upmsUtilsAppId_ = "";
|
||||
upmsUtilsGetAppIdByBundleNameRet_ = 0;
|
||||
upmsUtilsTokenId_ = 0;
|
||||
upmsUtilsIsFoundationCallRet_ = false;
|
||||
tokenInfos = {};
|
||||
}
|
||||
|
||||
@@ -87,13 +106,25 @@ public:
|
||||
static bool permissionReadWriteDocuments_;
|
||||
static bool IsSystempAppCall_;
|
||||
static bool permissionFileAccessPersist_;
|
||||
static bool permissionGrantUriPermissionAsCaller_;
|
||||
static bool isSAOrSystemAppCall_;
|
||||
static bool isUriTypeValid_;
|
||||
static bool isSystemAppCall_;
|
||||
static bool isDocsCloudUri_;
|
||||
static std::string bundleName_;
|
||||
static int32_t getTokenIdByBundleNameStatus_;
|
||||
|
||||
static int32_t processUdmfKeyRet_;
|
||||
static std::vector<std::string> udmfUtilsUris_;
|
||||
static bool upmsUtilsCheckIsSystemAppByBundleNameRet_;
|
||||
static bool upmsUtilsCheckIsSystemAppByTokenIdRet_;
|
||||
static bool upmsUtilsGetDirByBundleNameAndAppIndexRet_;
|
||||
static std::string upmsUtilsAlterBundleName_ ;
|
||||
static bool upmsUtilsGetAlterBundleNameByTokenIdRet_;
|
||||
static std::string upmsUtilsBundleName_;
|
||||
static bool upmsUtilsGetBundleNameByTokenIdRet_;
|
||||
static std::string upmsUtilsAppId_;
|
||||
static int32_t upmsUtilsGetAppIdByBundleNameRet_;
|
||||
static uint32_t upmsUtilsTokenId_;
|
||||
static bool upmsUtilsIsFoundationCallRet_;
|
||||
static TokenInfoMap tokenInfos;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UDMF_CLIENT_H
|
||||
#define UDMF_CLIENT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
namespace {
|
||||
constexpr const char* EMPTY_ENTRY_URI = "null";
|
||||
}
|
||||
|
||||
struct QueryOption {
|
||||
std::string key;
|
||||
};
|
||||
|
||||
struct Object {
|
||||
Object() {}
|
||||
|
||||
Object(const std::string &uri)
|
||||
{
|
||||
value_ = uri;
|
||||
}
|
||||
|
||||
bool GetValue(const std::string &key, std::string &value)
|
||||
{
|
||||
value = value_;
|
||||
return true;
|
||||
}
|
||||
std::string value_;
|
||||
};
|
||||
|
||||
using ValueType = std::variant<std::shared_ptr<Object>>;
|
||||
|
||||
struct UnifiedRecord {
|
||||
UnifiedRecord(const std::string &uri)
|
||||
{
|
||||
if (uri != EMPTY_ENTRY_URI) {
|
||||
entry = std::make_shared<Object>(uri);
|
||||
return;
|
||||
}
|
||||
entry = nullptr;
|
||||
}
|
||||
|
||||
ValueType GetEntry(const std::string &utdId)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
|
||||
std::shared_ptr<Object> entry = nullptr;
|
||||
};
|
||||
|
||||
struct UnifiedData {
|
||||
UnifiedData(std::vector<std::shared_ptr<UnifiedRecord>> records)
|
||||
{
|
||||
unifiedRecords_ = records;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<UnifiedRecord>> GetRecords()
|
||||
{
|
||||
return unifiedRecords_;
|
||||
}
|
||||
std::vector<std::shared_ptr<UnifiedRecord>> unifiedRecords_;
|
||||
};
|
||||
|
||||
struct Privilege {
|
||||
uint32_t tokenId = 0;
|
||||
std::string readPermission = "";
|
||||
};
|
||||
|
||||
class UdmfClient {
|
||||
public:
|
||||
static UdmfClient &GetInstance();
|
||||
|
||||
~UdmfClient() {};
|
||||
|
||||
int32_t GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataset);
|
||||
int32_t AddPrivilege(const QueryOption &query, const Privilege &privilege);
|
||||
static void Init();
|
||||
static std::vector<UnifiedData> unifiedData_;
|
||||
static int32_t getBatchDataRet_;
|
||||
static int32_t addPrivilegeRet_;
|
||||
static int32_t privilegeTokenId_;
|
||||
|
||||
private:
|
||||
UdmfClient() {};
|
||||
};
|
||||
} // OHOS
|
||||
} // UDMF
|
||||
#endif // UDMF_CLIENT_H
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mock_app_utils.h"
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
bool AppUtils::isSupportGrantUriPermission_ = true;
|
||||
|
||||
AppUtils::~AppUtils() {}
|
||||
|
||||
AppUtils::AppUtils() {}
|
||||
|
||||
AppUtils &AppUtils::GetInstance()
|
||||
{
|
||||
static AppUtils utils;
|
||||
return utils;
|
||||
}
|
||||
|
||||
void AppUtils::Init()
|
||||
{
|
||||
isSupportGrantUriPermission_ = true;
|
||||
}
|
||||
|
||||
bool AppUtils::IsSupportGrantUriPermission()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportGrantUriPermission_);
|
||||
return isSupportGrantUriPermission_;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -32,12 +32,25 @@ bool MyFlag::permissionReadWriteDesktop_ = false;
|
||||
bool MyFlag::permissionReadWriteDocuments_ = false;
|
||||
bool MyFlag::IsSystempAppCall_ = false;
|
||||
bool MyFlag::permissionFileAccessPersist_ = false;
|
||||
bool MyFlag::permissionGrantUriPermissionAsCaller_ = false;
|
||||
bool MyFlag::isSAOrSystemAppCall_ = false;
|
||||
bool MyFlag::isSystemAppCall_ = false;
|
||||
bool MyFlag::isUriTypeValid_ = false;
|
||||
bool MyFlag::isDocsCloudUri_ = false;
|
||||
int32_t MyFlag::getTokenIdByBundleNameStatus_ = 0;
|
||||
std::string MyFlag::bundleName_ = "";
|
||||
int32_t MyFlag::processUdmfKeyRet_ = 0;
|
||||
std::vector<std::string> MyFlag::udmfUtilsUris_ = {};
|
||||
bool MyFlag::upmsUtilsCheckIsSystemAppByBundleNameRet_ = true;
|
||||
bool MyFlag::upmsUtilsCheckIsSystemAppByTokenIdRet_ = false;
|
||||
bool MyFlag::upmsUtilsGetDirByBundleNameAndAppIndexRet_ = true;
|
||||
std::string MyFlag::upmsUtilsAlterBundleName_ = "";
|
||||
bool MyFlag::upmsUtilsGetAlterBundleNameByTokenIdRet_ = true;
|
||||
std::string MyFlag::upmsUtilsBundleName_ = "";
|
||||
bool MyFlag::upmsUtilsGetBundleNameByTokenIdRet_ = false;
|
||||
std::string MyFlag::upmsUtilsAppId_ = "";
|
||||
int32_t MyFlag::upmsUtilsGetAppIdByBundleNameRet_ = 0;
|
||||
bool MyFlag::upmsUtilsIsFoundationCallRet_;
|
||||
uint32_t MyFlag::upmsUtilsTokenId_ = 0;
|
||||
TokenInfoMap MyFlag::tokenInfos = {};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -29,6 +29,7 @@ constexpr const char* PERMISSION_READ_WRITE_DOWNLOAD = "ohos.permission.READ_WRI
|
||||
constexpr const char* PERMISSION_READ_WRITE_DESKTON = "ohos.permission.READ_WRITE_DESKTOP_DIRECTORY";
|
||||
constexpr const char* PERMISSION_READ_WRITE_DOCUMENTS = "ohos.permission.READ_WRITE_DOCUMENTS_DIRECTORY";
|
||||
constexpr const char* PERMISSION_FILE_ACCESS_PERSIST = "ohos.permission.FILE_ACCESS_PERSIST";
|
||||
constexpr const char* PERMISSION_GRANT_URI_PERMISSION_AS_CALLER = "ohos.permission.GRANT_URI_PERMISSION_AS_CALLER";
|
||||
} // namespace
|
||||
|
||||
bool PermissionVerification::VerifyPermissionByTokenId(const int &tokenId, const std::string &permissionName) const
|
||||
@@ -69,6 +70,9 @@ bool PermissionVerification::VerifyPermissionByTokenId(const int &tokenId, const
|
||||
if (permissionName == PERMISSION_FILE_ACCESS_PERSIST) {
|
||||
return MyFlag::permissionFileAccessPersist_;
|
||||
}
|
||||
if (permissionName == PERMISSION_GRANT_URI_PERMISSION_AS_CALLER) {
|
||||
return MyFlag::permissionGrantUriPermissionAsCaller_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool PermissionVerification::VerifyCallingPermission(const std::string &permissionName) const
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "upms_udmf_utils.h"
|
||||
#include "mock_my_flag.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
using MyFlag = OHOS::AAFwk::MyFlag;
|
||||
|
||||
int32_t UDMFUtils::GetBatchData(const std::string &key, std::vector<std::string> &uris)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t UDMFUtils::AddPrivilege(const std::string &key, uint32_t tokenId, const std::string &readPermission)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t UDMFUtils::ProcessUdmfKey(const std::string &key, uint32_t callerTokenId, uint32_t targetTokenId,
|
||||
std::vector<std::string> &uris)
|
||||
{
|
||||
uris = MyFlag::udmfUtilsUris_;
|
||||
return MyFlag::processUdmfKeyRet_;
|
||||
}
|
||||
} // OHOS
|
||||
} // AAFwk
|
||||
@@ -16,15 +16,6 @@
|
||||
#include "uri_permission_utils.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "bundle_mgr_client.h"
|
||||
#include "global_constant.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "os_account_manager_wrapper.h"
|
||||
#include "permission_verification.h"
|
||||
#include "tokenid_kit.h"
|
||||
#include "mock_my_flag.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -42,7 +33,7 @@ bool UPMSUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t ta
|
||||
}
|
||||
|
||||
bool UPMSUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId,
|
||||
const std::vector<Uri> &uriVec, const std::vector<bool> &resVec)
|
||||
const std::vector<std::string> &uriVec, const std::vector<bool> &resVec)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -60,12 +51,12 @@ int32_t UPMSUtils::GetCurrentAccountId()
|
||||
|
||||
bool UPMSUtils::IsFoundationCall()
|
||||
{
|
||||
return true;
|
||||
return MyFlag::upmsUtilsIsFoundationCallRet_;
|
||||
}
|
||||
|
||||
bool UPMSUtils::IsSAOrSystemAppCall()
|
||||
{
|
||||
return MyFlag::isSAOrSystemAppCall_;
|
||||
return MyFlag::isSAOrSystemAppCall_ || (MyFlag::IS_SA_CALL & MyFlag::flag_) != 0;
|
||||
}
|
||||
|
||||
bool UPMSUtils::IsSystemAppCall()
|
||||
@@ -75,7 +66,7 @@ bool UPMSUtils::IsSystemAppCall()
|
||||
|
||||
bool UPMSUtils::CheckIsSystemAppByBundleName(std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
return MyFlag::upmsUtilsCheckIsSystemAppByBundleNameRet_;
|
||||
}
|
||||
|
||||
bool UPMSUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t &targetApiVersion)
|
||||
@@ -85,32 +76,36 @@ bool UPMSUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t
|
||||
|
||||
bool UPMSUtils::CheckIsSystemAppByTokenId(uint32_t tokenId)
|
||||
{
|
||||
return false;
|
||||
return MyFlag::upmsUtilsCheckIsSystemAppByTokenIdRet_;
|
||||
}
|
||||
|
||||
bool UPMSUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName)
|
||||
{
|
||||
return true;
|
||||
dirName = MyFlag::upmsUtilsAlterBundleName_;
|
||||
return MyFlag::upmsUtilsGetDirByBundleNameAndAppIndexRet_;
|
||||
}
|
||||
|
||||
bool UPMSUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName)
|
||||
{
|
||||
bundleName = MyFlag::bundleName_;
|
||||
return true;
|
||||
bundleName = MyFlag::upmsUtilsAlterBundleName_;
|
||||
return MyFlag::upmsUtilsGetAlterBundleNameByTokenIdRet_;
|
||||
}
|
||||
|
||||
bool UPMSUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName)
|
||||
{
|
||||
return false;
|
||||
bundleName = MyFlag::upmsUtilsBundleName_;
|
||||
return MyFlag::upmsUtilsGetBundleNameByTokenIdRet_;
|
||||
}
|
||||
|
||||
int32_t UPMSUtils::GetAppIdByBundleName(const std::string &bundleName, std::string &appId)
|
||||
{
|
||||
return ERR_OK;
|
||||
appId = MyFlag::upmsUtilsAppId_;
|
||||
return MyFlag::upmsUtilsGetAppIdByBundleNameRet_;
|
||||
}
|
||||
|
||||
int32_t UPMSUtils::GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId)
|
||||
{
|
||||
tokenId = MyFlag::upmsUtilsTokenId_;
|
||||
return MyFlag::getTokenIdByBundleNameStatus_;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "udmf_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
|
||||
UdmfClient &UdmfClient::GetInstance()
|
||||
{
|
||||
static UdmfClient utils;
|
||||
return utils;
|
||||
}
|
||||
|
||||
void UdmfClient::Init()
|
||||
{
|
||||
getBatchDataRet_ = 0;
|
||||
addPrivilegeRet_ = 0;
|
||||
UdmfClient::unifiedData_.clear();
|
||||
}
|
||||
|
||||
int32_t UdmfClient::GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataset)
|
||||
{
|
||||
unifiedDataset = unifiedData_;
|
||||
return getBatchDataRet_;
|
||||
}
|
||||
|
||||
int32_t UdmfClient::AddPrivilege(const QueryOption &query, const Privilege &privilege)
|
||||
{
|
||||
if (privilege.tokenId == privilegeTokenId_) {
|
||||
return 0;
|
||||
}
|
||||
return addPrivilegeRet_;
|
||||
}
|
||||
|
||||
int32_t UdmfClient::getBatchDataRet_ = 0;
|
||||
int32_t UdmfClient::addPrivilegeRet_ = 0;
|
||||
int32_t UdmfClient::privilegeTokenId_ = 10000;
|
||||
std::vector<UnifiedData> UdmfClient::unifiedData_ = {};
|
||||
} // OHOS
|
||||
} // UDMF
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "udmf_client.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#define private public
|
||||
#include "upms_udmf_utils.h"
|
||||
#undef private
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class UriPermissionImplUdmfUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
void UriPermissionImplUdmfUtilsTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void UriPermissionImplUdmfUtilsTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void UriPermissionImplUdmfUtilsTest::SetUp()
|
||||
{
|
||||
UDMF::UdmfClient::Init();
|
||||
}
|
||||
|
||||
void UriPermissionImplUdmfUtilsTest::TearDown()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @tc.number: AddPrivilege_0100
|
||||
* @tc.desc: Test AddPrivilege works
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, AddPrivilege_0100, TestSize.Level1)
|
||||
{
|
||||
std::string key = "udmfKey";
|
||||
uint32_t targetTokenId = 100001;
|
||||
std::string readPermission = "";
|
||||
auto ret = UDMFUtils::AddPrivilege(key, targetTokenId, readPermission);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AddPrivilege_0200
|
||||
* @tc.desc: Test AddPrivilege works
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, AddPrivilege_0200, TestSize.Level1)
|
||||
{
|
||||
std::string key = "udmfKey";
|
||||
uint32_t targetTokenId = 100001;
|
||||
std::string readPermission = "";
|
||||
UDMF::UdmfClient::addPrivilegeRet_ = INNER_ERR;
|
||||
auto ret = UDMFUtils::AddPrivilege(key, targetTokenId, readPermission);
|
||||
EXPECT_EQ(ret, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0100
|
||||
* @tc.desc: Test GetBatchData works
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0100, TestSize.Level1)
|
||||
{
|
||||
std::string key = "";
|
||||
std::vector<std::string> uris;
|
||||
UDMF::UdmfClient::getBatchDataRet_ = INNER_ERR;
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, INNER_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0200
|
||||
* @tc.desc: Test GetBatchData works
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0200, TestSize.Level1)
|
||||
{
|
||||
std::string key = "";
|
||||
std::vector<std::string> uris;
|
||||
UDMF::UdmfClient::getBatchDataRet_ = 0;
|
||||
UDMF::UdmfClient::unifiedData_= {};
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0300
|
||||
* @tc.desc: Test GetBatchData works, unified record GetEntry is nullptr.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0300, TestSize.Level1)
|
||||
{
|
||||
// null entry
|
||||
std::string uri = "null";
|
||||
std::string key = "udmfKey";
|
||||
// create dataset
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> unifiedRecords;
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri));
|
||||
unifiedDataset.emplace_back(UDMF::UnifiedData(unifiedRecords));
|
||||
UDMF::UdmfClient::unifiedData_ = unifiedDataset;
|
||||
// GetEntry is nullptr
|
||||
std::vector<std::string> uris;
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_GET_ORI_URI_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0400
|
||||
* @tc.desc: Test GetBatchData works, unified record GetValue is empty.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0400, TestSize.Level1)
|
||||
{
|
||||
std::string uri = "";
|
||||
std::string key = "udmfKey";
|
||||
// create dataset
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> unifiedRecords;
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri));
|
||||
unifiedDataset.emplace_back(UDMF::UnifiedData(unifiedRecords));
|
||||
UDMF::UdmfClient::unifiedData_ = unifiedDataset;
|
||||
// GetValue oriUri is empty
|
||||
std::vector<std::string> uris;
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_GET_ORI_URI_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0500
|
||||
* @tc.desc: Test GetBatchData works, unified record oriUri is not file uri.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0500, TestSize.Level1)
|
||||
{
|
||||
std::string uri = "http://temp.txt";
|
||||
std::string key = "udmfKey";
|
||||
// create dataset
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> unifiedRecords;
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri));
|
||||
unifiedDataset.emplace_back(UDMF::UnifiedData(unifiedRecords));
|
||||
UDMF::UdmfClient::unifiedData_ = unifiedDataset;
|
||||
// GetValue oriUri is not file uri
|
||||
std::vector<std::string> uris;
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_NOT_FILE_URI);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0600
|
||||
* @tc.desc: Test GetBatchData works, unified record GetValue is file.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0600, TestSize.Level1)
|
||||
{
|
||||
std::string uri = "file://com.example.test/temp.txt";
|
||||
std::string key = "udmfKey";
|
||||
// create dataset
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> unifiedRecords;
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri));
|
||||
unifiedDataset.emplace_back(UDMF::UnifiedData(unifiedRecords));
|
||||
UDMF::UdmfClient::unifiedData_ = unifiedDataset;
|
||||
// GetValue oriUri is file uri
|
||||
std::vector<std::string> uris;
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_EQ(uris.size(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetBatchData_0700
|
||||
* @tc.desc: Test GetBatchData works, some uri is invalid.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, GetBatchData_0700, TestSize.Level1)
|
||||
{
|
||||
std::string uri1 = "file://com.example.test/temp.txt";
|
||||
std::string uri2 = "http://com.example.test/temp.txt";
|
||||
std::string key = "udmfKey";
|
||||
// create dataset
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> unifiedRecords;
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri1));
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri2));
|
||||
unifiedDataset.emplace_back(UDMF::UnifiedData(unifiedRecords));
|
||||
UDMF::UdmfClient::unifiedData_ = unifiedDataset;
|
||||
// one uri is invalid
|
||||
std::vector<std::string> uris;
|
||||
auto ret = UDMFUtils::GetBatchData(key, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_NOT_FILE_URI);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ProcessUdmfKey_0100
|
||||
* @tc.desc: Test ProcessUdmfKey works, AddPrivilege failed.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, ProcessUdmfKey_0100, TestSize.Level1)
|
||||
{
|
||||
std::string key = "";
|
||||
uint32_t callerTokenId = 100001;
|
||||
uint32_t targetTokenId = 100002;
|
||||
std::vector<std::string> uris;
|
||||
UDMF::UdmfClient::addPrivilegeRet_ = INNER_ERR;
|
||||
auto ret = UDMFUtils::ProcessUdmfKey(key, callerTokenId, targetTokenId, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_ADD_PRIVILEGED_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ProcessUdmfKey_0200
|
||||
* @tc.desc: Test ProcessUdmfKey works, AddPrivilege first, success second failed.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, ProcessUdmfKey_0200, TestSize.Level1)
|
||||
{
|
||||
std::string key = "";
|
||||
uint32_t callerTokenId = 100001;
|
||||
// AddPrivileged success
|
||||
uint32_t targetTokenId = UDMF::UdmfClient::privilegeTokenId_;
|
||||
std::vector<std::string> uris;
|
||||
UDMF::UdmfClient::addPrivilegeRet_ = INNER_ERR;
|
||||
auto ret = UDMFUtils::ProcessUdmfKey(key, callerTokenId, targetTokenId, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_ADD_PRIVILEGED_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ProcessUdmfKey_0300
|
||||
* @tc.desc: Test ProcessUdmfKey works, GetBatchData failed.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, ProcessUdmfKey_0300, TestSize.Level1)
|
||||
{
|
||||
std::string key = "";
|
||||
uint32_t callerTokenId = 100001;
|
||||
uint32_t targetTokenId = 100002;
|
||||
std::vector<std::string> uris;
|
||||
UDMF::UdmfClient::addPrivilegeRet_ = ERR_OK;
|
||||
UDMF::UdmfClient::getBatchDataRet_ = INNER_ERR;
|
||||
auto ret = UDMFUtils::ProcessUdmfKey(key, callerTokenId, targetTokenId, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ProcessUdmfKey_0400
|
||||
* @tc.desc: Test ProcessUdmfKey works, ProcessUdmfKey success.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplUdmfUtilsTest, ProcessUdmfKey_0400, TestSize.Level1)
|
||||
{
|
||||
std::string uri = "file://com.example.test/temp.txt";
|
||||
std::string key = "udmfKey";
|
||||
uint32_t callerTokenId = 100001;
|
||||
uint32_t targetTokenId = 100002;
|
||||
std::vector<std::string> uris;
|
||||
// create dataset
|
||||
std::vector<UDMF::UnifiedData> unifiedDataset;
|
||||
std::vector<std::shared_ptr<UDMF::UnifiedRecord>> unifiedRecords;
|
||||
unifiedRecords.emplace_back(std::make_shared<UDMF::UnifiedRecord>(uri));
|
||||
unifiedDataset.emplace_back(UDMF::UnifiedData(unifiedRecords));
|
||||
UDMF::UdmfClient::unifiedData_ = unifiedDataset;
|
||||
// processUdmfKey
|
||||
auto ret = UDMFUtils::ProcessUdmfKey(key, callerTokenId, targetTokenId, uris);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "mock_media_permission_manager.h"
|
||||
#include "mock_ability_manager_client.h"
|
||||
#include "mock_accesstoken_kit.h"
|
||||
#include "mock_app_mgr_service.h"
|
||||
#include "mock_app_utils.h"
|
||||
#include "mock_bundle_mgr_helper.h"
|
||||
#include "mock_ipc_skeleton.h"
|
||||
#include "mock_my_flag.h"
|
||||
@@ -58,6 +60,8 @@ void UriPermissionImplTest::TearDownTestCase() {}
|
||||
void UriPermissionImplTest::SetUp() {
|
||||
AbilityManagerClient::collaborator_ = nullptr;
|
||||
AbilityManagerClient::isNullInstance = false;
|
||||
AppUtils::Init();
|
||||
MyFlag::Init();
|
||||
}
|
||||
|
||||
void UriPermissionImplTest::TearDown() {}
|
||||
@@ -584,10 +588,11 @@ HWTEST_F(UriPermissionImplTest, Upms_RevokeUriPermissionManually_001, TestSize.L
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_HAP, "", "com.example.app1001");
|
||||
int32_t funcResult1 = -1;
|
||||
bool funcResult2 = false;
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
MyFlag::getTokenIdByBundleNameStatus_ = 0;
|
||||
MyFlag::upmsUtilsTokenId_ = 1002;
|
||||
upms->RevokeUriPermissionManually(uri, targetBundleName, appIndex, funcResult1);
|
||||
upms->VerifyUriPermission(uri, flagRead, targetTokenId, funcResult2);
|
||||
IPCSkeleton::callerTokenId = 0;
|
||||
MyFlag::tokenInfos.clear();
|
||||
ASSERT_EQ(funcResult2, false);
|
||||
}
|
||||
|
||||
@@ -740,33 +745,6 @@ HWTEST_F(UriPermissionImplTest, Upms_VerifyUriPermission_001, TestSize.Level1)
|
||||
ASSERT_EQ(funcResult, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: URIPermissionManagerService
|
||||
* Function: ConnectManager
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: URIPermissionManagerService SendSystemAppGrantUriPermissionEvent
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upms_SendSystemAppGrantUriPermissionEvent_001, TestSize.Level1)
|
||||
{
|
||||
std::vector<Uri> uriVec = { Uri("file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt") };
|
||||
const std::vector<bool> resVec = { true };
|
||||
auto ret = UPMSUtils::SendSystemAppGrantUriPermissionEvent(1001, 1002, uriVec, resVec);
|
||||
ASSERT_EQ(ret, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: URIPermissionManagerService
|
||||
* Function: ConnectManager
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: URIPermissionManagerService SendShareUnPrivilegeUriEvent
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upms_SendShareUnPrivilegeUriEvent_001, TestSize.Level1)
|
||||
{
|
||||
MyFlag::flag_ |= MyFlag::IS_SA_CALL;
|
||||
auto ret = UPMSUtils::SendShareUnPrivilegeUriEvent(1001, 1002);
|
||||
ASSERT_EQ(ret, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckUriPermission
|
||||
@@ -777,12 +755,12 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_001, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
auto mediaPhotoUri = Uri("file://media/Photo/1/IMG_001/test_001.jpg");
|
||||
std::string mediaPhotoUri = "file://media/Photo/1/IMG_001/test_001.jpg";
|
||||
uint32_t callerTokenId = 1001;
|
||||
uint32_t flagRead = 1;
|
||||
|
||||
TokenIdPermission tokenIdPermission(callerTokenId);
|
||||
std::vector<Uri> mediaPhotoUris = { mediaPhotoUri };
|
||||
std::vector<std::string> mediaPhotoUris = { mediaPhotoUri };
|
||||
auto ret = upms->CheckUriPermission(tokenIdPermission, mediaPhotoUris, flagRead)[0];
|
||||
ASSERT_EQ(ret, false);
|
||||
}
|
||||
@@ -797,12 +775,12 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_002, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
auto mediaAudioUri = Uri("file://media/Audio/1/Record_001/test_001.mp3");
|
||||
std::string mediaAudioUri = "file://media/Audio/1/Record_001/test_001.mp3";
|
||||
uint32_t callerTokenId = 1001;
|
||||
uint32_t flagRead = 1;
|
||||
|
||||
TokenIdPermission tokenIdPermission(callerTokenId);
|
||||
std::vector<Uri> mediaAudioUris = { mediaAudioUri };
|
||||
std::vector<std::string> mediaAudioUris = { mediaAudioUri };
|
||||
auto ret = upms->CheckUriPermission(tokenIdPermission, mediaAudioUris, flagRead)[0];
|
||||
ASSERT_EQ(ret, false);
|
||||
}
|
||||
@@ -817,7 +795,9 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_003, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
std::vector<Uri> docsUri = { Uri("file://docs/DestTop/Text/test_001.txt") };
|
||||
MyFlag::flag_ |= MyFlag::IS_SA_CALL;
|
||||
MyFlag::isSAOrSystemAppCall_ = true;
|
||||
std::vector<std::string> docsUri = { "file://docs/DestTop/Text/test_001.txt" };
|
||||
uint32_t callerTokenId = 1001;
|
||||
uint32_t targetTokenId = 1002;
|
||||
uint32_t flagRead = 1;
|
||||
@@ -846,14 +826,14 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_003, TestSize.Level1)
|
||||
ASSERT_EQ(ret, false);
|
||||
|
||||
// read
|
||||
upms->AddTempUriPermission(docsUri[0].ToString(), flagRead, callerTokenId, targetTokenId);
|
||||
upms->AddTempUriPermission(docsUri[0], flagRead, callerTokenId, targetTokenId);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagRead)[0];
|
||||
ASSERT_EQ(ret, true);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagWrite)[0];
|
||||
ASSERT_EQ(ret, false);
|
||||
|
||||
// write
|
||||
upms->AddTempUriPermission(docsUri[0].ToString(), flagWrite, callerTokenId, targetTokenId);
|
||||
upms->AddTempUriPermission(docsUri[0], flagWrite, callerTokenId, targetTokenId);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, docsUri, flagWrite)[0];
|
||||
ASSERT_EQ(ret, true);
|
||||
MyFlag::permissionProxyAuthorization_ = false;
|
||||
@@ -869,8 +849,10 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_004, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
std::vector<Uri> uri1 = { Uri("file://com.example.app1001/data/storage/el2/base/haps/entry/files/test_001.txt") };
|
||||
std::vector<Uri> uri2 = { Uri("file://com.example.app1002/data/storage/el2/base/haps/entry/files/test_002.txt") };
|
||||
MyFlag::isSAOrSystemAppCall_ = true;
|
||||
MyFlag::upmsUtilsAlterBundleName_ = "com.example.app1001";
|
||||
std::vector<std::string> uri1 = { "file://com.example.app1001/data/storage/el2/base/haps/entry/files/test1.txt" };
|
||||
std::vector<std::string> uri2 = { "file://com.example.app1002/data/storage/el2/base/haps/entry/files/test2.txt" };
|
||||
uint32_t callerTokenId = 1001;
|
||||
uint32_t targetTokenId = 1002;
|
||||
uint32_t flagRead = 1;
|
||||
@@ -891,6 +873,7 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_004, TestSize.Level1)
|
||||
// proxy uri permision
|
||||
MyFlag::permissionProxyAuthorization_ = true;
|
||||
tokenIdPermission = TokenIdPermission(targetTokenId);
|
||||
MyFlag::upmsUtilsAlterBundleName_ = "";
|
||||
// no record
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0];
|
||||
ASSERT_EQ(ret, false);
|
||||
@@ -898,14 +881,14 @@ HWTEST_F(UriPermissionImplTest, Upms_CheckUriPermission_004, TestSize.Level1)
|
||||
ASSERT_EQ(ret, false);
|
||||
|
||||
// read
|
||||
upms->AddTempUriPermission(uri1[0].ToString(), flagRead, callerTokenId, targetTokenId);
|
||||
upms->AddTempUriPermission(uri1[0], flagRead, callerTokenId, targetTokenId);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0];
|
||||
ASSERT_EQ(ret, true);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagWrite)[0];
|
||||
ASSERT_EQ(ret, false);
|
||||
|
||||
// write
|
||||
upms->AddTempUriPermission(uri1[0].ToString(), flagWrite, callerTokenId, targetTokenId);
|
||||
upms->AddTempUriPermission(uri1[0], flagWrite, callerTokenId, targetTokenId);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagRead)[0];
|
||||
ASSERT_EQ(ret, true);
|
||||
ret = upms->CheckUriPermission(tokenIdPermission, uri1, flagWrite)[0];
|
||||
@@ -924,6 +907,7 @@ HWTEST_F(UriPermissionImplTest, RevokeAllUriPermission_001, TestSize.Level1)
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
// mock foundation call
|
||||
MyFlag::upmsUtilsIsFoundationCallRet_ = true;
|
||||
IPCSkeleton::callerUId = 5523;
|
||||
int32_t funcResult = -1;
|
||||
upms->RevokeAllUriPermissions(1002, funcResult);
|
||||
@@ -1097,7 +1081,8 @@ HWTEST_F(UriPermissionImplTest, GrantUriPermissionPrivileged_003, TestSize.Level
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
MyFlag::getTokenIdByBundleNameStatus_ = ERR_GET_TARGET_BUNDLE_INFO_FAILED;
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_NATIVE, "foundation");
|
||||
IPCSkeleton::callerTokenId = 1001;
|
||||
MyFlag::permissionPrivileged_ = true;
|
||||
@@ -1157,7 +1142,7 @@ HWTEST_F(UriPermissionImplTest, GrantUriPermissionPrivileged_005, TestSize.Level
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_NATIVE, "foundation");
|
||||
IPCSkeleton::callerTokenId = 1001;
|
||||
MyFlag::permissionPrivileged_ = true;
|
||||
@@ -1189,7 +1174,7 @@ HWTEST_F(UriPermissionImplTest, GrantUriPermissionPrivileged_006, TestSize.Level
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_NATIVE, "foundation");
|
||||
IPCSkeleton::callerTokenId = 1001;
|
||||
MyFlag::permissionPrivileged_ = true;
|
||||
@@ -1285,7 +1270,8 @@ HWTEST_F(UriPermissionImplTest, GrantUriPermissionPrivileged_009, TestSize.Level
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
auto& upmc = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
MyFlag::getTokenIdByBundleNameStatus_ = ERR_GET_TARGET_BUNDLE_INFO_FAILED;
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_NATIVE, "foundation");
|
||||
IPCSkeleton::callerTokenId = 1001;
|
||||
MyFlag::permissionPrivileged_ = true;
|
||||
@@ -1348,6 +1334,7 @@ HWTEST_F(UriPermissionImplTest, GrantUriPermissionPrivileged_011, TestSize.Level
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
auto& upmc = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_NATIVE, "foundation");
|
||||
@@ -1386,6 +1373,7 @@ HWTEST_F(UriPermissionImplTest, GrantUriPermissionPrivileged_012, TestSize.Level
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_NATIVE, "foundation");
|
||||
IPCSkeleton::callerTokenId = 1001;
|
||||
MyFlag::permissionPrivileged_ = true;
|
||||
MyFlag::isUriTypeValid_ = true;
|
||||
|
||||
auto uri1 = Uri("file://com.example.app1001/data/storage/el2/base/haps/entry/files/test_001.txt");
|
||||
std::string targetBundleName = "com.example.app1002";
|
||||
@@ -1559,6 +1547,8 @@ HWTEST_F(UriPermissionImplTest, CheckUriAuthorization_005, TestSize.Level1)
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_HAP, "", "com.example.app1001");
|
||||
std::vector<bool> expectRes(1, true);
|
||||
UriPermissionRawData funcResult;
|
||||
MyFlag::upmsUtilsAlterBundleName_ = "com.example.app1001";
|
||||
MyFlag::upmsUtilsGetAlterBundleNameByTokenIdRet_ = true;
|
||||
upms->CheckUriAuthorization(stubPolicyRawData, flag, tokenId, funcResult);
|
||||
|
||||
std::vector<bool> expectResVec(1, false);
|
||||
@@ -1671,6 +1661,8 @@ HWTEST_F(UriPermissionImplTest, CheckUriAuthorization_010, TestSize.Level1)
|
||||
uint32_t flag = 1;
|
||||
uint32_t tokenId = 1001;
|
||||
MyFlag::tokenInfos[1001] = TokenInfo(1001, MyATokenTypeEnum::TOKEN_HAP, "", "com.example.app1001");
|
||||
MyFlag::upmsUtilsAlterBundleName_ = "com.example.app1001";
|
||||
MyFlag::upmsUtilsGetAlterBundleNameByTokenIdRet_ = true;
|
||||
upms->CheckUriAuthorization(uris, flag, tokenId, funcResult);
|
||||
|
||||
std::vector<bool> expectRes(1, true);
|
||||
@@ -1860,5 +1852,280 @@ HWTEST_F(UriPermissionImplTest, RevokeContentUriPermission_001, TestSize.Level1)
|
||||
ret = upms->RevokeContentUriPermission(tokenId);
|
||||
EXPECT_EQ(ret, INNER_ERR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: UriPermissionImplTest
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: capacity not support
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyAsCaller_001, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
AppUtils::isSupportGrantUriPermission_ = false;
|
||||
auto result = upms->CheckGrantUriPermissionByKeyAsCaller();
|
||||
EXPECT_EQ(result, ERR_CAPABILITY_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyAsCaller
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: not system app call
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyAsCaller_002, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = false;
|
||||
auto result = upms->CheckGrantUriPermissionByKeyAsCaller();
|
||||
EXPECT_EQ(result, ERR_NOT_SYSTEM_APP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyAsCaller
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no grantUriPermissonByKeyAsCaller permission
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyAsCaller_003, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = true;
|
||||
MyFlag::permissionGrantUriPermissionAsCaller_ = false;
|
||||
auto result = upms->CheckGrantUriPermissionByKeyAsCaller();
|
||||
EXPECT_EQ(result, CHECK_PERMISSION_FAILED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyAsCaller
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: CheckCalledBySandBox failed
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyAsCaller_004, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = true;
|
||||
MyFlag::permissionGrantUriPermissionAsCaller_ = true;
|
||||
auto mockAppMgr = new AppExecFwk::MockAppMgrService();
|
||||
mockAppMgr->judgeSandboxByPidRet_ = 0;
|
||||
mockAppMgr->isSandbox_ = true;
|
||||
upms->appMgr_ = mockAppMgr;
|
||||
auto result = upms->CheckGrantUriPermissionByKeyAsCaller();
|
||||
EXPECT_EQ(result, ERR_CODE_GRANT_URI_PERMISSION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyAsCaller
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: success
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyAsCaller_005, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = true;
|
||||
MyFlag::permissionGrantUriPermissionAsCaller_ = true;
|
||||
auto mockAppMgr = new AppExecFwk::MockAppMgrService();
|
||||
mockAppMgr->judgeSandboxByPidRet_ = 0;
|
||||
mockAppMgr->isSandbox_ = false;
|
||||
upms->appMgr_ = mockAppMgr;
|
||||
auto result = upms->CheckGrantUriPermissionByKeyAsCaller();
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyParams
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerStubImpl CheckGrantUriPermissionByKeyParams
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyParams_001, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
const std::string key = "";
|
||||
uint32_t flag = 0;
|
||||
UPMSAppInfo calerAppInfo = { .tokenId = 1001 };
|
||||
UPMSAppInfo targetAppInfo = { .tokenId = 1002 };
|
||||
std::vector<std::string> uris;
|
||||
auto ret = upms->CheckGrantUriPermissionByKeyParams(key, flag, calerAppInfo, targetAppInfo, uris);
|
||||
EXPECT_EQ(ret, ERR_CODE_INVALID_URI_FLAG);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyParams
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerStubImpl CheckGrantUriPermissionByKeyParams
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyParams_002, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
const std::string key = "";
|
||||
uint32_t flag = 1;
|
||||
UPMSAppInfo calerAppInfo = { .tokenId = 1001 };
|
||||
UPMSAppInfo targetAppInfo = { .tokenId = 1001 };
|
||||
std::vector<std::string> uris;
|
||||
auto ret = upms->CheckGrantUriPermissionByKeyParams(key, flag, calerAppInfo, targetAppInfo, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_INVALID_TARGET_TOKENID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyParams
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerStubImpl CheckGrantUriPermissionByKeyParams
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyParams_003, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
const std::string key = "";
|
||||
uint32_t flag = 1;
|
||||
UPMSAppInfo calerAppInfo = { .tokenId = 1001 };
|
||||
UPMSAppInfo targetAppInfo = { .tokenId = 1002 };
|
||||
std::vector<std::string> uris;
|
||||
MyFlag::upmsUtilsGetAlterBundleNameByTokenIdRet_ = false;
|
||||
auto ret = upms->CheckGrantUriPermissionByKeyParams(key, flag, calerAppInfo, targetAppInfo, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_INVALID_CALLER_TOKENID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyParams
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerStubImpl CheckGrantUriPermissionByKeyParams
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyParams_004, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
const std::string key = "";
|
||||
uint32_t flag = 1;
|
||||
UPMSAppInfo calerAppInfo = { .tokenId = 1001 };
|
||||
UPMSAppInfo targetAppInfo = { .tokenId = 1002 };
|
||||
std::vector<std::string> uris;
|
||||
MyFlag::processUdmfKeyRet_ = INNER_ERR;
|
||||
auto ret = upms->CheckGrantUriPermissionByKeyParams(key, flag, calerAppInfo, targetAppInfo, uris);
|
||||
EXPECT_EQ(ret, ERR_UPMS_GET_FILE_URIS_BY_KEY_FAILED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerStubImpl
|
||||
* Function: CheckGrantUriPermissionByKeyParams
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerStubImpl CheckGrantUriPermissionByKeyParams
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, Upmsi_CheckGrantUriPermissionByKeyParams_005, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
const std::string key = "";
|
||||
uint32_t flag = 1;
|
||||
UPMSAppInfo calerAppInfo = { .tokenId = 1001 };
|
||||
UPMSAppInfo targetAppInfo = { .tokenId = 1002 };
|
||||
std::vector<std::string> uris;
|
||||
MyFlag::processUdmfKeyRet_ = ERR_OK;
|
||||
auto ret = upms->CheckGrantUriPermissionByKeyParams(key, flag, calerAppInfo, targetAppInfo, uris);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerService
|
||||
* Function: GrantUriPermissionByKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerService GrantUriPermissionByKey
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, GrantUriPermissionByKey_001, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
std::string key = "testKey";
|
||||
uint32_t flag = 1;
|
||||
uint32_t targetTokenId = 100002;
|
||||
int32_t funcResult = -1;
|
||||
auto ret = upms->GrantUriPermissionByKey(key, flag, targetTokenId, funcResult);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_EQ(funcResult, ERR_NOT_SYSTEM_APP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerService
|
||||
* Function: GrantUriPermissionByKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerService GrantUriPermissionByKey
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, GrantUriPermissionByKey_002, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = true;
|
||||
std::string key = "testKey";
|
||||
uint32_t flag = 1;
|
||||
uint32_t targetTokenId = 100002;
|
||||
int32_t funcResult = -1;
|
||||
auto ret = upms->GrantUriPermissionByKey(key, flag, targetTokenId, funcResult);
|
||||
MyFlag::isSystemAppCall_ = false;
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_EQ(funcResult, INNER_ERR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerService
|
||||
* Function: GrantUriPermissionByKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerService GrantUriPermissionByKey
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, GrantUriPermissionByKey_003, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = true;
|
||||
sptr<AppExecFwk::MockAppMgrService> mockAppMgr(new AppExecFwk::MockAppMgrService());
|
||||
ASSERT_NE(mockAppMgr, nullptr);
|
||||
mockAppMgr->judgeSandboxByPidRet_ = 0;
|
||||
mockAppMgr->isSandbox_ = true;
|
||||
upms->appMgr_ = iface_cast<AppExecFwk::IAppMgr>(mockAppMgr);
|
||||
std::string key = "testKey";
|
||||
uint32_t flag = 1;
|
||||
uint32_t targetTokenId = 100002;
|
||||
int32_t funcResult = -1;
|
||||
auto ret = upms->GrantUriPermissionByKey(key, flag, targetTokenId, funcResult);
|
||||
MyFlag::isSystemAppCall_ = false;
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_EQ(funcResult, ERR_CODE_GRANT_URI_PERMISSION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerService
|
||||
* Function: GrantUriPermissionByKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriPermissionManagerService GrantUriPermissionByKey
|
||||
*/
|
||||
HWTEST_F(UriPermissionImplTest, GrantUriPermissionByKey_004, TestSize.Level1)
|
||||
{
|
||||
auto upms = std::make_unique<UriPermissionManagerStubImpl>();
|
||||
ASSERT_NE(upms, nullptr);
|
||||
MyFlag::isSystemAppCall_ = true;
|
||||
sptr<AppExecFwk::MockAppMgrService> mockAppMgr(new AppExecFwk::MockAppMgrService());
|
||||
ASSERT_NE(mockAppMgr, nullptr);
|
||||
mockAppMgr->judgeSandboxByPidRet_ = 0;
|
||||
mockAppMgr->isSandbox_ = false;
|
||||
upms->appMgr_ = iface_cast<AppExecFwk::IAppMgr>(mockAppMgr);
|
||||
std::string key = "testKey";
|
||||
uint32_t flag = 1;
|
||||
uint32_t targetTokenId = 100002;
|
||||
int32_t funcResult = -1;
|
||||
auto ret = upms->GrantUriPermissionByKey(key, flag, targetTokenId, funcResult);
|
||||
MyFlag::isSystemAppCall_ = false;
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -42,7 +42,10 @@ void UriPermissionManagerStubImplTest::SetUpTestCase() {}
|
||||
|
||||
void UriPermissionManagerStubImplTest::TearDownTestCase() {}
|
||||
|
||||
void UriPermissionManagerStubImplTest::SetUp() {}
|
||||
void UriPermissionManagerStubImplTest::SetUp()
|
||||
{
|
||||
MyFlag::Init();
|
||||
}
|
||||
|
||||
void UriPermissionManagerStubImplTest::TearDown() {}
|
||||
|
||||
@@ -200,6 +203,7 @@ HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_GrantUriPermission_002, TestSiz
|
||||
HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_GrantUriPermission_003, TestSize.Level1)
|
||||
{
|
||||
auto upmsi = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
MyFlag::isSAOrSystemAppCall_ = true;
|
||||
std::vector<std::string> uriVec;
|
||||
unsigned int flag = 1;
|
||||
std::string targetBundleName = "targetBundleName";
|
||||
@@ -207,7 +211,8 @@ HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_GrantUriPermission_003, TestSiz
|
||||
uint32_t initiatorTokenId = 1;
|
||||
int32_t funcResult = 1;
|
||||
auto result = upmsi->GrantUriPermission(uriVec, flag, targetBundleName, appIndex, initiatorTokenId, funcResult);
|
||||
EXPECT_EQ(result, ERR_URI_LIST_OUT_OF_RANGE);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
EXPECT_EQ(funcResult, INNER_ERR);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -455,7 +460,7 @@ HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_CheckUriAuthorization_002, Test
|
||||
HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_RevokeAllMapUriPermissions_001, TestSize.Level1)
|
||||
{
|
||||
auto upmsi = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
MyFlag::bundleName_ = "callerAuthority";
|
||||
MyFlag::upmsUtilsBundleName_ = "callerAuthority";
|
||||
GrantInfo info = { 1, 1, 1 };
|
||||
upmsi->uriMap_.insert({ "uri://callerAuthority", { info } });
|
||||
uint32_t tokenId = 1;
|
||||
@@ -472,7 +477,7 @@ HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_RevokeAllMapUriPermissions_001,
|
||||
HWTEST_F(UriPermissionManagerStubImplTest, Upmsi_RevokeAllMapUriPermissions_002, TestSize.Level1)
|
||||
{
|
||||
auto upmsi = std::make_shared<UriPermissionManagerStubImpl>();
|
||||
MyFlag::bundleName_ = "bundleName";
|
||||
MyFlag::upmsUtilsBundleName_ = "bundleName";
|
||||
GrantInfo info = { 1, 1, 1 };
|
||||
upmsi->uriMap_.insert({ "uri://callerAuthority", { info } });
|
||||
uint32_t tokenId = 1;
|
||||
|
||||
@@ -57,6 +57,7 @@ HWTEST_F(UriPermissionManagerTest, ConnectUriPermService_001, TestSize.Level1)
|
||||
upmc.saLoadFinished_ = true;
|
||||
EXPECT_EQ(upmc.GetUriPermMgr(), nullptr);
|
||||
auto ret = upmc.ConnectUriPermService();
|
||||
EXPECT_EQ(ret, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -72,6 +73,7 @@ HWTEST_F(UriPermissionManagerTest, ConnectUriPermService_002, TestSize.Level1)
|
||||
upmc.SetUriPermMgr(remoteObject);
|
||||
EXPECT_EQ(upmc.GetUriPermMgr(), nullptr);
|
||||
auto ret = upmc.ConnectUriPermService();
|
||||
EXPECT_EQ(ret, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -87,6 +89,7 @@ HWTEST_F(UriPermissionManagerTest, ConnectUriPermService_003, TestSize.Level1)
|
||||
upmc.SetUriPermMgr(remoteObject);
|
||||
EXPECT_EQ(upmc.GetUriPermMgr(), nullptr);
|
||||
auto ret = upmc.ConnectUriPermService();
|
||||
EXPECT_EQ(ret, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -466,5 +469,40 @@ HWTEST_F(UriPermissionManagerTest, UriPermissionManager_GrantUriPermissionPrivil
|
||||
auto res = upmc.GrantUriPermissionPrivileged(uriVec, flag, bundleName, appIndex, 0, 0);
|
||||
EXPECT_EQ(res, INNER_ERR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerClient
|
||||
* Function: GrantUriPermissionByKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Grant permission failed
|
||||
* CaseDescription: Verify UriPermissionManagerClient GrantUriPermissionByKey
|
||||
*/
|
||||
HWTEST_F(UriPermissionManagerTest, UriPermissionManager_GrantUriPermissionByKey_001, TestSize.Level1)
|
||||
{
|
||||
auto &upmc = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
std::string key = "testKey";
|
||||
uint32_t flag = Want::FLAG_AUTH_READ_URI_PERMISSION;
|
||||
uint32_t targetTokenId = 100002;
|
||||
auto ret = upmc.GrantUriPermissionByKey(key, flag, targetTokenId);
|
||||
EXPECT_NE(ret, ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriPermissionManagerClient
|
||||
* Function: GrantUriPermissionByKeyAsCaller
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Grant permission failed
|
||||
* CaseDescription: Verify UriPermissionManagerClient GrantUriPermissionByKeyAsCaller
|
||||
*/
|
||||
HWTEST_F(UriPermissionManagerTest, UriPermissionManager_GrantUriPermissionByKeyAsCaller_001, TestSize.Level1)
|
||||
{
|
||||
auto &upmc = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
std::string key = "testKey";
|
||||
uint32_t flag = Want::FLAG_AUTH_READ_URI_PERMISSION;
|
||||
uint32_t callerTokenId = 100001;
|
||||
uint32_t targetTokenId = 100002;
|
||||
auto ret = upmc.GrantUriPermissionByKeyAsCaller(key, flag, callerTokenId, targetTokenId);
|
||||
EXPECT_NE(ret, ERR_OK);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -52,7 +52,7 @@ void UriPermissionUtilsTest::TearDown() {}
|
||||
*/
|
||||
HWTEST_F(UriPermissionUtilsTest, Upms_SendSystemAppGrantUriPermissionEvent_001, TestSize.Level1)
|
||||
{
|
||||
std::vector<Uri> uriVec = { Uri("file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt") };
|
||||
std::vector<std::string> uriVec = { "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt" };
|
||||
const std::vector<bool> resVec = { true };
|
||||
auto ret = UPMSUtils::SendSystemAppGrantUriPermissionEvent(1001, 1002, uriVec, resVec);
|
||||
ASSERT_EQ(ret, false);
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace AAFwk {
|
||||
namespace {
|
||||
const int32_t BEYOND_MAX_URI_COUNT = 501;
|
||||
const int32_t MAX_URI_COUNT = 500;
|
||||
constexpr const char* UDMF_DATA_KEY = "ohos.param.ability.udmfKey";
|
||||
constexpr const char* ABILIY_PARAM_STREAM = "ability.params.stream";
|
||||
}
|
||||
class UriUtilsTest : public testing::Test {
|
||||
public:
|
||||
@@ -793,5 +795,47 @@ HWTEST_F(UriUtilsTest, CheckIsInAncoAppIdentifier_001, TestSize.Level1)
|
||||
ret = UriUtils::GetInstance().CheckIsInAncoAppIdentifier(identifier, bundleName);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriUtils
|
||||
* Function: ProcessUDMFKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriUtils ProcessUDMFKey
|
||||
*/
|
||||
HWTEST_F(UriUtilsTest, ProcessUDMFKey_001, TestSize.Level1)
|
||||
{
|
||||
auto &uriUtils = UriUtils::GetInstance();
|
||||
Want want;
|
||||
std::string udKey = "udmf:tempKey";
|
||||
want.SetParam(UDMF_DATA_KEY, udKey);
|
||||
uriUtils.ProcessUDMFKey(want);
|
||||
EXPECT_EQ(want.GetStringParam(UDMF_DATA_KEY).empty(), false);
|
||||
|
||||
std::vector<std::string> uris = { "file://com.example.test/aaa.txt" };
|
||||
want.SetParam(ABILIY_PARAM_STREAM, uris);
|
||||
uriUtils.ProcessUDMFKey(want);
|
||||
EXPECT_EQ(want.GetStringParam(UDMF_DATA_KEY).empty(), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: UriUtils
|
||||
* Function: ProcessUDMFKey
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: UriUtils ProcessUDMFKey
|
||||
*/
|
||||
HWTEST_F(UriUtilsTest, ProcessUDMFKey_002, TestSize.Level1)
|
||||
{
|
||||
auto &uriUtils = UriUtils::GetInstance();
|
||||
Want want;
|
||||
std::string udKey;
|
||||
want.SetParam(UDMF_DATA_KEY, udKey);
|
||||
uriUtils.ProcessUDMFKey(want);
|
||||
EXPECT_EQ(want.GetStringParam(UDMF_DATA_KEY).empty(), true);
|
||||
|
||||
std::vector<std::string> uris = { "file://com.example.test/aaa.txt" };
|
||||
want.SetParam(ABILIY_PARAM_STREAM, uris);
|
||||
uriUtils.ProcessUDMFKey(want);
|
||||
EXPECT_EQ(want.GetStringParam(UDMF_DATA_KEY).empty(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user