多用户显示上次使用打印机异常 Signed-off-by:baozewei@huawei.com

Signed-off-by: b30052170 <baozewei@huawei.com>
This commit is contained in:
b30052170 2024-10-18 17:27:27 +08:00
parent 2b592e0514
commit a715db8a48
3 changed files with 9 additions and 6 deletions

View File

@ -55,7 +55,7 @@ public:
static std::string GetPrintJobId();
static std::string GetEventTypeWithToken(int32_t userId, int64_t pid, const std::string &type);
static std::string GetEventType(const std::string &type);
static int32_t GetUserIdInEventType(const std::string &type);
static bool CheckUserIdInEventType(const std::string &type, int32_t callerUserId);
template <typename T, typename ReadFunc>
static bool readListFromParcel(Parcel &parcel, std::vector<T> &supportedList, const ReadFunc &readFunc)
{

View File

@ -116,16 +116,19 @@ std::string PrintUtils::GetEventType(const std::string &type)
return eventType;
}
int32_t PrintUtils::GetUserIdInEventType(const std::string &type)
bool CheckUserIdInEventType(const std::string &type, int32_t callerUserId)
{
auto userIdPos = type.find(USER_ID_DELIMITER);
auto eventPos = type.find(TASK_EVENT_DELIMITER);
if (userIdPos == std::string::npos || eventPos == std::string::npos || userIdPos >= type.length()) {
return E_PRINT_INVALID_USERID;
}
int32_t userId = std::stoi(type.substr(0, userIdPos));
PRINT_HILOGD("userId: %{public}d", userId);
return userId;
std::string userIdStr = type.substr(0, userIdPos);
PRINT_HILOGD("userId: %{public}s", userIdStr.c_str());
if (userIdStr == std::to_string(callerUserId)) {
return true;
}
return false;
}
int32_t PrintUtils::OpenFile(const std::string &filePath)

View File

@ -3455,7 +3455,7 @@ bool PrintServiceAbility::CheckUserIdInEventType(const std::string &type)
{
int32_t callerUserId = GetCurrentUserId();
PRINT_HILOGD("callerUserId = %{public}d", callerUserId);
if (callerUserId == PrintUtils::GetUserIdInEventType(type)) {
if (PrintUtils::CheckUserIdInEventType(type, callerUserId)) {
PRINT_HILOGD("find current user");
return true;
}