mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
支持批量授权
Signed-off-by: duansizhao <duansizhao@huawei.com> Change-Id: Ia04fcc59665be2a266f83ca16cabe505ab5f2b0a
This commit is contained in:
@@ -40,6 +40,17 @@ public:
|
||||
int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0);
|
||||
|
||||
/**
|
||||
* @brief Authorize the uri permission of to targetBundleName.
|
||||
*
|
||||
* @param uriVec The file uri list.
|
||||
* @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
|
||||
* @param targetBundleName The user of uri.
|
||||
* @param autoremove the uri is temperarily or not
|
||||
*/
|
||||
int GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0);
|
||||
|
||||
/**
|
||||
* @brief Clear user's uri authorization record with auto remove flag.
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_INTERFACE_H
|
||||
#define OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_INTERFACE_H
|
||||
|
||||
#include <vector>
|
||||
#include "base/security/access_token/interfaces/innerkits/accesstoken/include/access_token.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "uri.h"
|
||||
@@ -38,6 +38,18 @@ public:
|
||||
virtual int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0) = 0;
|
||||
|
||||
/**
|
||||
* @brief Authorize the uri permission to targetBundleName.
|
||||
*
|
||||
* @param uriVec The file urilist.
|
||||
* @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
|
||||
* @param targetBundleName The user of uri.
|
||||
* @param autoremove the uri is temperarily or not
|
||||
* @return Returns true if the authorization is successful, otherwise returns false.
|
||||
*/
|
||||
virtual int GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0) = 0;
|
||||
|
||||
/**
|
||||
* @brief Clear user's uri authorization record with autoremove flag.
|
||||
*
|
||||
@@ -98,6 +110,9 @@ public:
|
||||
|
||||
// ipc id for VerifyUriPermission
|
||||
ON_VERIFY_URI_PERMISSION,
|
||||
|
||||
// ipc id for BatchGrantUriPermission
|
||||
ON_BATCH_GRANT_URI_PERMISSION,
|
||||
};
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_PROXY_H
|
||||
#define OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_PROXY_H
|
||||
|
||||
#include<vector>
|
||||
#include "iremote_proxy.h"
|
||||
#include "uri_permission_manager_interface.h"
|
||||
|
||||
@@ -29,6 +30,9 @@ public:
|
||||
virtual int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0) override;
|
||||
|
||||
virtual int GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0) override;
|
||||
|
||||
virtual void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
virtual int RevokeAllUriPermissions(const Security::AccessToken::AccessTokenID tokenId) override;
|
||||
virtual int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override;
|
||||
|
||||
@@ -38,6 +38,7 @@ private:
|
||||
int HandleRevokeUriPermission(MessageParcel &data, MessageParcel &reply);
|
||||
int HandleRevokeAllUriPermission(MessageParcel &data, MessageParcel &reply);
|
||||
int HandleGrantUriPermission(MessageParcel &data, MessageParcel &reply);
|
||||
int HandleBatchGrantUriPermission(MessageParcel &data, MessageParcel &reply);
|
||||
int HandleRevokeUriPermissionManually(MessageParcel &data, MessageParcel &reply);
|
||||
int HandleCheckPerSiSTableUriPermissionProxy(MessageParcel &data, MessageParcel &reply);
|
||||
int HandleVerifyUriPermission(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
const int LOAD_SA_TIMEOUT_MS = 4 * 1000;
|
||||
const int MAX_URI_COUNT = 500;
|
||||
} // namespace
|
||||
UriPermissionManagerClient& UriPermissionManagerClient::GetInstance()
|
||||
{
|
||||
@@ -41,7 +42,21 @@ int UriPermissionManagerClient::GrantUriPermission(const Uri &uri, unsigned int
|
||||
if (uriPermMgr) {
|
||||
return uriPermMgr->GrantUriPermission(uri, flag, targetBundleName, autoremove, appIndex);
|
||||
}
|
||||
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
int UriPermissionManagerClient::GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex)
|
||||
{
|
||||
HILOG_DEBUG("targetBundleName: %{public}s, uriVec size: %{public}zu", targetBundleName.c_str(), uriVec.size());
|
||||
if (uriVec.size() == 0 || uriVec.size() > MAX_URI_COUNT) {
|
||||
HILOG_ERROR("The size of uriVec should be between 1 and %{public}i.", MAX_URI_COUNT);
|
||||
return INNER_ERR;
|
||||
}
|
||||
auto uriPermMgr = ConnectUriPermService();
|
||||
if (uriPermMgr) {
|
||||
return uriPermMgr->GrantUriPermission(uriVec, flag, targetBundleName, autoremove, appIndex);
|
||||
}
|
||||
return INNER_ERR;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,51 @@ int UriPermissionManagerProxy::GrantUriPermission(const Uri &uri, unsigned int f
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int UriPermissionManagerProxy::GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::GrantUriPermission is called.");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(IUriPermissionManager::GetDescriptor())) {
|
||||
HILOG_ERROR("Write interface token failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteUint32(uriVec.size())) {
|
||||
HILOG_ERROR("Write size of uriVec failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
for (const auto &uri : uriVec) {
|
||||
if (!data.WriteParcelable(&uri)) {
|
||||
HILOG_ERROR("Write uri failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
}
|
||||
if (!data.WriteInt32(flag)) {
|
||||
HILOG_ERROR("Write flag failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteString(targetBundleName)) {
|
||||
HILOG_ERROR("Write targetBundleName failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteInt32(autoremove)) {
|
||||
HILOG_ERROR("Write autoremove failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (!data.WriteInt32(appIndex)) {
|
||||
HILOG_ERROR("Write appIndex failed.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int error = Remote()->SendRequest(UriPermMgrCmd::ON_BATCH_GRANT_URI_PERMISSION, data, reply, option);
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("SendRequest fial, error: %{public}d", error);
|
||||
return INNER_ERR;
|
||||
}
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
void UriPermissionManagerProxy::RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId)
|
||||
{
|
||||
HILOG_DEBUG("UriPermissionManagerProxy::RevokeUriPermission is called.");
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
namespace {
|
||||
const int MAX_URI_COUNT = 500;
|
||||
}
|
||||
int UriPermissionManagerStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
@@ -31,6 +34,9 @@ int UriPermissionManagerStub::OnRemoteRequest(
|
||||
case UriPermMgrCmd::ON_GRANT_URI_PERMISSION : {
|
||||
return HandleGrantUriPermission(data, reply);
|
||||
}
|
||||
case UriPermMgrCmd::ON_BATCH_GRANT_URI_PERMISSION : {
|
||||
return HandleBatchGrantUriPermission(data, reply);
|
||||
}
|
||||
case UriPermMgrCmd::ON_REVOKE_URI_PERMISSION : {
|
||||
return HandleRevokeUriPermission(data, reply);
|
||||
}
|
||||
@@ -83,6 +89,31 @@ int UriPermissionManagerStub::HandleGrantUriPermission(MessageParcel &data, Mess
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int UriPermissionManagerStub::HandleBatchGrantUriPermission(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
auto size = data.ReadUint32();
|
||||
if (size <= 0 || size > MAX_URI_COUNT) {
|
||||
HILOG_ERROR("size is invalid.");
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
std::vector<Uri> uriVec;
|
||||
for (auto i = 0; i < size; i++) {
|
||||
std::unique_ptr<Uri> uri(data.ReadParcelable<Uri>());
|
||||
if (!uri) {
|
||||
HILOG_ERROR("To read uri failed.");
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
uriVec.emplace_back(*uri);
|
||||
}
|
||||
auto flag = data.ReadInt32();
|
||||
auto targetBundleName = data.ReadString();
|
||||
auto autoremove = data.ReadInt32();
|
||||
auto appIndex = data.ReadInt32();
|
||||
int result = GrantUriPermission(uriVec, flag, targetBundleName, autoremove, appIndex);
|
||||
reply.WriteInt32(result);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int UriPermissionManagerStub::HandleRevokeUriPermissionManually(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::unique_ptr<Uri> uri(data.ReadParcelable<Uri>());
|
||||
|
||||
@@ -1286,6 +1286,7 @@ void AbilityConnectManager::TerminateDone(const std::shared_ptr<AbilityRecord> &
|
||||
"Transition life state error. expect %{public}s, actual %{public}s", expect.c_str(), actual.c_str());
|
||||
return;
|
||||
}
|
||||
IN_PROCESS_CALL_WITHOUT_RET(abilityRecord->RevokeUriPermission());
|
||||
abilityRecord->RemoveAbilityDeathRecipient();
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->TerminateAbility(abilityRecord->GetToken(), false);
|
||||
RemoveServiceAbility(abilityRecord);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <singleton.h>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "constants.h"
|
||||
#include "ability_event_handler.h"
|
||||
@@ -84,6 +85,7 @@ const int VECTOR_SIZE = 2;
|
||||
const int LOAD_TIMEOUT_ASANENABLED = 150;
|
||||
const int TERMINATE_TIMEOUT_ASANENABLED = 150;
|
||||
const int HALF_TIMEOUT = 2;
|
||||
const int MAX_URI_COUNT = 500;
|
||||
#ifdef SUPPORT_ASAN
|
||||
const int COLDSTART_TIMEOUT_MULTIPLE = 15000;
|
||||
const int LOAD_TIMEOUT_MULTIPLE = 15000;
|
||||
@@ -379,6 +381,8 @@ void AbilityRecord::ForegroundAbility(const Closure &task, uint32_t sceneFlag)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
HILOG_INFO("name:%{public}s.", abilityInfo_.name.c_str());
|
||||
CHECK_POINTER(lifecycleDeal_);
|
||||
// grant uri permission
|
||||
GrantUriPermission(want_, applicationInfo_.bundleName, false, 0);
|
||||
|
||||
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
|
||||
if (handler && task) {
|
||||
@@ -2600,8 +2604,17 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName,
|
||||
std::vector<std::string> uriVec;
|
||||
std::string uriStr = want.GetUri().ToString();
|
||||
uriVec = want.GetStringArrayParam(AbilityConfig::PARAMS_STREAM);
|
||||
uriVec.emplace_back(uriStr);
|
||||
if (!uriStr.empty()) {
|
||||
uriVec.emplace_back(uriStr);
|
||||
}
|
||||
HILOG_DEBUG("GrantUriPermission uriVec size: %{public}zu", uriVec.size());
|
||||
if (uriVec.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if (uriVec.size() > MAX_URI_COUNT) {
|
||||
HILOG_ERROR("size of uriVec is more than %{public}i", MAX_URI_COUNT);
|
||||
return;
|
||||
}
|
||||
auto bundleFlag = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO;
|
||||
uint32_t fromTokenId = 0;
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
@@ -2615,6 +2628,7 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName,
|
||||
PermissionVerification::GetInstance()->VerifyPermissionByTokenId(tokenId, PERMISSION_PROXY_AUTHORIZATION_URI);
|
||||
auto userId = GetCurrentAccountId();
|
||||
auto callerTokenId = static_cast<uint32_t>(want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, -1));
|
||||
std::unordered_map<uint32_t, std::vector<Uri>> uriVecMap; // flag, vector
|
||||
for (auto&& str : uriVec) {
|
||||
Uri uri(str);
|
||||
auto&& scheme = uri.GetScheme();
|
||||
@@ -2660,11 +2674,18 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName,
|
||||
}
|
||||
flag &= (~Want::FLAG_AUTH_PERSISTABLE_URI_PERMISSION);
|
||||
}
|
||||
int autoremove = 1;
|
||||
if (uriVecMap.find(flag) == uriVecMap.end()) {
|
||||
std::vector<Uri> uriVec;
|
||||
uriVecMap.emplace(flag, uriVec);
|
||||
}
|
||||
uriVecMap[flag].emplace_back(uri);
|
||||
}
|
||||
int autoremove = 1;
|
||||
for (const auto &item : uriVecMap) {
|
||||
auto ret = IN_PROCESS_CALL(
|
||||
AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission(uri, flag,
|
||||
AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission(item.second, item.first,
|
||||
targetBundleName, autoremove, appIndex_));
|
||||
if (ret == 0) {
|
||||
if (ret == ERR_OK) {
|
||||
isGrantedUriPermission_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "app_mgr_interface.h"
|
||||
#include "bundlemgr/bundle_mgr_interface.h"
|
||||
@@ -47,6 +48,8 @@ public:
|
||||
|
||||
int GrantUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0) override;
|
||||
int GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex = 0) override;
|
||||
void RevokeUriPermission(const TokenId tokenId) override;
|
||||
int RevokeAllUriPermissions(uint32_t tokenId) override;
|
||||
int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override;
|
||||
@@ -69,6 +72,17 @@ private:
|
||||
int DeletTempUriPermission(const std::string &uri, uint32_t flag, uint32_t targetTokenId);
|
||||
int DeletTempUriPermissionAndShareFile(const std::string &uri, uint32_t targetTokenId);
|
||||
|
||||
void GetUriPermissionBatchFlag(const std::vector<Uri> &uriVec,
|
||||
unsigned int flag, uint32_t targetTokenId,
|
||||
std::unordered_map<uint32_t, std::vector<std::string>> &uriVecMap,
|
||||
std::unordered_map<uint32_t, std::vector<uint32_t>> &fromTokenIdVecMap);
|
||||
|
||||
int GrantBatchUriPermissionImpl(const std::vector<std::string> &uriVec, unsigned int flag,
|
||||
std::vector<uint32_t> &fromTokenIdVec, TokenId targetTokenId, int autoremove);
|
||||
|
||||
int GrantSingleUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string &targetBundleName, int autoremove, int32_t appIndex);
|
||||
|
||||
void InitPersistableUriPermissionConfig();
|
||||
|
||||
class ProxyDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "uri_permission_manager_stub_impl.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "hilog_wrapper.h"
|
||||
@@ -89,6 +91,14 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned in
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex)
|
||||
{
|
||||
HILOG_DEBUG("CALL: appIndex is %{public}d.", appIndex);
|
||||
std::vector<Uri> uriVec = { uri };
|
||||
return GrantUriPermission(uriVec, flag, targetBundleName, autoremove, appIndex);
|
||||
}
|
||||
|
||||
int UriPermissionManagerStubImpl::GrantUriPermission(const std::vector<Uri> &uriVec, unsigned int flag,
|
||||
const std::string targetBundleName, int autoremove, int32_t appIndex)
|
||||
{
|
||||
HILOG_DEBUG("CALL: appIndex is %{public}d, uriVec size is %{public}zu", appIndex, uriVec.size());
|
||||
// reject sandbox to grant uri permission
|
||||
ConnectManager(appMgr_, APP_MGR_SERVICE_ID);
|
||||
if (appMgr_ == nullptr) {
|
||||
@@ -111,29 +121,35 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned in
|
||||
HILOG_WARN("UriPermissionManagerStubImpl::GrantUriPermission: The param flag is invalid.");
|
||||
return ERR_CODE_INVALID_URI_FLAG;
|
||||
}
|
||||
Uri uri_inner = uri;
|
||||
auto&& scheme = uri_inner.GetScheme();
|
||||
if (scheme != "file") {
|
||||
HILOG_WARN("only support file uri.");
|
||||
return ERR_CODE_INVALID_URI_TYPE;
|
||||
}
|
||||
auto&& authority = uri_inner.GetAuthority();
|
||||
auto fromTokenId = GetTokenIdByBundleName(authority, 0);
|
||||
auto targetTokenId = GetTokenIdByBundleName(targetBundleName, appIndex);
|
||||
auto callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
unsigned int tmpFlag = 0;
|
||||
ret = GetUriPermissionFlag(uri, flag, fromTokenId, targetTokenId, tmpFlag);
|
||||
if (ret != ERR_OK || tmpFlag == 0) {
|
||||
return ret;
|
||||
}
|
||||
// auto remove URI permission for clipboard
|
||||
auto targetTokenId = GetTokenIdByBundleName(targetBundleName, appIndex);
|
||||
Security::AccessToken::NativeTokenInfo nativeInfo;
|
||||
Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerTokenId, nativeInfo);
|
||||
// autoremove will be set to 1 if the process name is foundation.
|
||||
HILOG_DEBUG("callerprocessName : %{public}s", nativeInfo.processName.c_str());
|
||||
if (nativeInfo.processName == "pasteboard_serv") {
|
||||
if (nativeInfo.processName == "foundation") {
|
||||
autoremove = 1;
|
||||
}
|
||||
return GrantUriPermissionImpl(uri, tmpFlag, fromTokenId, targetTokenId, autoremove);
|
||||
// reserve origin process
|
||||
if (uriVec.size() == 1) {
|
||||
return GrantSingleUriPermission(uriVec[0], flag, targetBundleName, autoremove, appIndex);
|
||||
}
|
||||
std::unordered_map<uint32_t, std::vector<std::string>> uriVecMap;
|
||||
std::unordered_map<uint32_t, std::vector<uint32_t>> fromTokenIdVecMap;
|
||||
GetUriPermissionBatchFlag(uriVec, flag, targetTokenId, uriVecMap, fromTokenIdVecMap);
|
||||
if (uriVecMap.empty()) {
|
||||
HILOG_DEBUG("uriVecMap is empty");
|
||||
return INNER_ERR;
|
||||
}
|
||||
ret = INNER_ERR;
|
||||
for (const auto &item : uriVecMap) {
|
||||
auto tempRet = GrantBatchUriPermissionImpl(item.second, item.first, fromTokenIdVecMap[item.first],
|
||||
targetTokenId, autoremove);
|
||||
if (tempRet == ERR_OK) {
|
||||
ret = ERR_OK;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int UriPermissionManagerStubImpl::GetUriPermissionFlag(const Uri &uri, unsigned int flag,
|
||||
@@ -156,7 +172,7 @@ int UriPermissionManagerStubImpl::GetUriPermissionFlag(const Uri &uri, unsigned
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
if (!authorityFlag) {
|
||||
// ignore persistable uri permission flag.
|
||||
// application uri: ignore persistable uri permission flag.
|
||||
newFlag &= (~Want::FLAG_AUTH_PERSISTABLE_URI_PERMISSION);
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -166,6 +182,7 @@ int UriPermissionManagerStubImpl::GetUriPermissionFlag(const Uri &uri, unsigned
|
||||
HILOG_WARN("Do not have persistable uri permission proxy.");
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
// the device do not support persistable uri permission flag.
|
||||
newFlag &= (~Want::FLAG_AUTH_PERSISTABLE_URI_PERMISSION);
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -252,7 +269,13 @@ int UriPermissionManagerStubImpl::GrantUriPermissionImpl(const Uri &uri, unsigne
|
||||
return INNER_ERR;
|
||||
}
|
||||
auto uriStr = uri.ToString();
|
||||
auto ret = storageManager_->CreateShareFile(uriStr, targetTokenId, flag);
|
||||
std::vector<std::string> uriVec = { uriStr };
|
||||
auto resVec = storageManager_->CreateShareFile(uriVec, targetTokenId, flag);
|
||||
if (resVec.size() == 0) {
|
||||
HILOG_ERROR("storageManager resVec is empty.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
auto ret = resVec[0];
|
||||
if (ret != 0 && ret != -EEXIST) {
|
||||
HILOG_ERROR("failed to CreateShareFile.");
|
||||
return INNER_ERR;
|
||||
@@ -271,6 +294,106 @@ int UriPermissionManagerStubImpl::GrantUriPermissionImpl(const Uri &uri, unsigne
|
||||
return ret;
|
||||
}
|
||||
|
||||
int UriPermissionManagerStubImpl::GrantSingleUriPermission(const Uri &uri, unsigned int flag,
|
||||
const std::string &targetBundleName, int autoremove, int32_t appIndex)
|
||||
{
|
||||
Uri uri_inner = uri;
|
||||
auto&& scheme = uri_inner.GetScheme();
|
||||
if (scheme != "file") {
|
||||
HILOG_WARN("only support file uri.");
|
||||
return ERR_CODE_INVALID_URI_TYPE;
|
||||
}
|
||||
auto&& authority = uri_inner.GetAuthority();
|
||||
auto fromTokenId = GetTokenIdByBundleName(authority, 0);
|
||||
auto targetTokenId = GetTokenIdByBundleName(targetBundleName, appIndex);
|
||||
unsigned int tmpFlag = 0;
|
||||
auto ret = GetUriPermissionFlag(uri, flag, fromTokenId, targetTokenId, tmpFlag);
|
||||
if (ret != ERR_OK || tmpFlag == 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = GrantUriPermissionImpl(uri, tmpFlag, fromTokenId, targetTokenId, autoremove);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UriPermissionManagerStubImpl::GetUriPermissionBatchFlag(const std::vector<Uri> &uriVec,
|
||||
unsigned int flag, uint32_t targetTokenId,
|
||||
std::unordered_map<uint32_t, std::vector<std::string>> &uriVecMap,
|
||||
std::unordered_map<uint32_t, std::vector<uint32_t>> &fromTokenIdVecMap)
|
||||
{
|
||||
HILOG_DEBUG("GetUriPermissionBatchFlag Call, flag is %{public}i", flag);
|
||||
for (const auto &uri : uriVec) {
|
||||
Uri uri_inner = uri;
|
||||
auto&& scheme = uri_inner.GetScheme();
|
||||
if (scheme != "file") {
|
||||
HILOG_WARN("only support file uri.");
|
||||
continue;
|
||||
}
|
||||
auto&& authority = uri_inner.GetAuthority();
|
||||
auto fromTokenId = GetTokenIdByBundleName(authority, 0);
|
||||
unsigned int tmpFlag = 0;
|
||||
auto ret = GetUriPermissionFlag(uri, flag, fromTokenId, targetTokenId, tmpFlag);
|
||||
if (ret != ERR_OK || tmpFlag == 0) {
|
||||
continue;
|
||||
}
|
||||
if (uriVecMap.find(tmpFlag) == uriVecMap.end()) {
|
||||
HILOG_DEBUG("find tempFlag = %{public}i", tmpFlag);
|
||||
std::vector<std::string> uriVec;
|
||||
uriVecMap.emplace(tmpFlag, uriVec);
|
||||
std::vector<uint32_t> tokenIdVec;
|
||||
fromTokenIdVecMap.emplace(tmpFlag, tokenIdVec);
|
||||
}
|
||||
uriVecMap[tmpFlag].emplace_back(uri.ToString());
|
||||
fromTokenIdVecMap[tmpFlag].emplace_back(fromTokenId);
|
||||
}
|
||||
}
|
||||
|
||||
int UriPermissionManagerStubImpl::GrantBatchUriPermissionImpl(const std::vector<std::string> &uriVec,
|
||||
unsigned int flag, std::vector<uint32_t> &fromTokenIdVec, TokenId targetTokenId, int autoremove)
|
||||
{
|
||||
HILOG_DEBUG("CALL: targetTokenId is %{public}d, flag is %{public}i, uriVec size is %{public}zu",
|
||||
targetTokenId, flag, uriVec.size());
|
||||
ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID);
|
||||
if (storageManager_ == nullptr) {
|
||||
HILOG_ERROR("ConnectManager failed");
|
||||
return INNER_ERR;
|
||||
}
|
||||
auto resVec = storageManager_->CreateShareFile(uriVec, targetTokenId, flag);
|
||||
if (resVec.size() == 0) {
|
||||
HILOG_ERROR("storageManager resVec is empty.");
|
||||
return INNER_ERR;
|
||||
}
|
||||
if (resVec.size() > 0 && resVec.size() != uriVec.size()) {
|
||||
HILOG_ERROR("Failed to createShareFile.");
|
||||
return resVec[0];
|
||||
}
|
||||
int successCount = 0;
|
||||
for (size_t i = 0; i < uriVec.size(); i++) {
|
||||
auto ret = resVec[i];
|
||||
if (ret != 0 && ret != -EEXIST) {
|
||||
HILOG_ERROR("failed to CreateShareFile.");
|
||||
continue;
|
||||
}
|
||||
auto uriStr = uriVec[i];
|
||||
auto fromTokenId = fromTokenIdVec[i];
|
||||
if ((flag & Want::FLAG_AUTH_PERSISTABLE_URI_PERMISSION) == 0) {
|
||||
ret = AddTempUriPermission(uriStr, flag, fromTokenId, targetTokenId, autoremove);
|
||||
successCount += (ret == ERR_OK ? 1 : 0);
|
||||
continue;
|
||||
}
|
||||
// grant persistable uri permission
|
||||
ret = uriPermissionRdb_->AddGrantInfo(uriStr, flag, fromTokenId, targetTokenId);
|
||||
if (ret == ERR_OK) {
|
||||
successCount++;
|
||||
DeletTempUriPermission(uriStr, flag, targetTokenId);
|
||||
}
|
||||
}
|
||||
HILOG_DEBUG("total %{public}i uri permissions added.", successCount);
|
||||
if (successCount == 0) {
|
||||
return INNER_ERR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId)
|
||||
{
|
||||
HILOG_INFO("Start to remove uri permission.");
|
||||
@@ -375,8 +498,6 @@ int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, co
|
||||
auto uriTokenId = GetTokenIdByBundleName(authority, 0);
|
||||
auto tokenId = GetTokenIdByBundleName(bundleName, 0);
|
||||
auto callerTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
VerifyUriPermission(uri, Want::FLAG_AUTH_READ_URI_PERMISSION, tokenId);
|
||||
VerifyUriPermission(uri, Want::FLAG_AUTH_WRITE_URI_PERMISSION, tokenId);
|
||||
auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission(
|
||||
AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI);
|
||||
bool authorityFlag = authority == "media" || authority == "docs";
|
||||
|
||||
@@ -212,15 +212,22 @@ public:
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t CreateShareFile(std::string uri, uint32_t tokenId, uint32_t flag) override
|
||||
virtual std::vector<int32_t> CreateShareFile(const std::vector<std::string> &uriList,
|
||||
uint32_t tokenId, uint32_t flag) override
|
||||
{
|
||||
if (isZero) {
|
||||
return E_OK;
|
||||
int size = uriList.size();
|
||||
if (size <= 0) {
|
||||
return { -1 };
|
||||
}
|
||||
return -1;
|
||||
if (isZero) {
|
||||
std::vector<int32_t> retVec(size, ERR_OK);
|
||||
return retVec;
|
||||
}
|
||||
std::vector<int32_t> retVec(size, -1);
|
||||
return retVec;
|
||||
}
|
||||
|
||||
virtual int32_t DeleteShareFile(uint32_t tokenId, std::vector<std::string>sharePathList) override
|
||||
|
||||
virtual int32_t DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &sharePathList) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
+13
-6
@@ -212,15 +212,22 @@ public:
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t CreateShareFile(std::string uri, uint32_t tokenId, uint32_t flag) override
|
||||
virtual std::vector<int32_t> CreateShareFile(const std::vector<std::string> &uriList, uint32_t tokenId,
|
||||
uint32_t flag) override
|
||||
{
|
||||
if (isZero) {
|
||||
return E_OK;
|
||||
int size = uriList.size();
|
||||
if (size <= 0) {
|
||||
return { -1 };
|
||||
}
|
||||
return -1;
|
||||
if (isZero) {
|
||||
std::vector<int32_t> retVec(size, ERR_OK);
|
||||
return retVec;
|
||||
}
|
||||
std::vector<int32_t> retVec(size, -1);
|
||||
return retVec;
|
||||
}
|
||||
|
||||
virtual int32_t DeleteShareFile(uint32_t tokenId, std::vector<std::string>sharePathList) override
|
||||
|
||||
virtual int32_t DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &sharePathList) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user