add caller uid to OPEN_TIME event

Signed-off-by: zhengzhuolan <zhengzhuolan@huawei-partners.com>
This commit is contained in:
zhengzhuolan
2026-03-03 14:54:01 +08:00
parent 1b340308aa
commit f8f53d05cb
4 changed files with 35 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Copyright (c) 2024-2026 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
@@ -34,6 +34,7 @@ struct GrantUriPermissionInfo {
uint32_t flag = 0;
int32_t appIndex = 0;
int32_t userId = -1;
int32_t callerUid = -1;
int32_t collaboratorType = 0;
bool isSandboxApp = false;
bool isNotifyCollaborator = false;
@@ -2743,6 +2743,7 @@ void AbilityRecord::GrantUriPermission(Want &want, std::string targetBundleName,
grantInfo.userId = GetOwnerMissionUserId();
grantInfo.flag = want.GetFlags();
grantInfo.isNotifyCollaborator = isNotifyCollaborator;
grantInfo.callerUid = want.GetIntParam(Want::PARAM_RESV_CALLER_UID, IPCSkeleton::GetCallingUid());
if (!isNotifyCollaborator) {
grantInfo.targetAbilityName = abilityInfo_.name;
}
+2 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Copyright (c) 2024-2026 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
@@ -496,6 +496,7 @@ void UriUtils::PublishFileOpenEvent(const Want &want, const GrantUriPermissionIn
std::chrono::system_clock::now().time_since_epoch()).count();
std::string currentTime = std::to_string(timeNow);
msgWant.SetParam("viewTime", currentTime);
msgWant.SetParam("uid", grantInfo.callerUid);
EventFwk::CommonEventData commonData{msgWant};
EventFwk::CommonEventPublishInfo commonEventPublishInfo;
std::vector<std::string> subscriberPermissions = {"ohos.permission.MANAGE_LOCAL_ACCOUNTS"};
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Copyright (c) 2025-2026 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
@@ -136,6 +136,35 @@ HWTEST_F(UriUtilsSecondTest, IsDmsCall_004, TestSize.Level1)
EXPECT_FALSE(ret);
}
/*
* Feature: UriUtils
* Function: PublishFileOpenEvent
* SubFunction: NA
* FunctionPoints: UriUtils PublishFileOpenEvent with callerUid
*/
HWTEST_F(UriUtilsSecondTest, PublishFileOpenEvent_003, TestSize.Level1)
{
Want want;
auto wangUri = want.GetUri();
std::string uriStr = wangUri.ToString();
std::string schemeStr = wangUri.GetScheme();
EXPECT_EQ(uriStr, "");
EXPECT_EQ(schemeStr, "");
WantParams params;
sptr<AAFwk::IArray> ao = new (std::nothrow) AAFwk::Array(1, AAFwk::g_IID_IString);
if (ao != nullptr) {
ao->Set(0, String::Box("file"));
params.SetParam("ability.params.stream", ao);
}
want.SetParams(params);
want.SetUri("file://data/storage/el2/distributedfiles/test.txt");
GrantUriPermissionInfo grantInfo;
grantInfo.callerUid = 20010080;
UriUtils::GetInstance().PublishFileOpenEvent(want, grantInfo);
wangUri = want.GetUri();
EXPECT_NE(wangUri.ToString(), "");
}
/*
* Feature: UriUtils
* Function: IsSandboxApp