From 1335d514200fa8530b6338a8ee07528a9940f694 Mon Sep 17 00:00:00 2001 From: edwardcaoyue Date: Sat, 4 Nov 2023 15:10:25 +0800 Subject: [PATCH] uid auth to pid auth Signed-off-by: edwardcaoyue --- .../include/concurrent_task_type.h | 1 + services/include/concurrent_task_controller.h | 13 +- services/include/qos_interface.h | 16 +- services/src/concurrent_task_controller.cpp | 197 +++++++----------- services/src/qos_interface.cpp | 36 ++-- .../phone/concurrent_task_client_test.cpp | 1 + .../phone/concurrent_task_controller_test.cpp | 50 ++--- test/unittest/phone/qos_interface_test.cpp | 59 +++--- 8 files changed, 166 insertions(+), 207 deletions(-) diff --git a/frameworks/concurrent_task_client/include/concurrent_task_type.h b/frameworks/concurrent_task_client/include/concurrent_task_type.h index ada4b13..b8171eb 100644 --- a/frameworks/concurrent_task_client/include/concurrent_task_type.h +++ b/frameworks/concurrent_task_client/include/concurrent_task_type.h @@ -27,6 +27,7 @@ enum MsgType { MSG_CONTINUOUS_TASK_START, MSG_CONTINUOUS_TASK_END, MSG_FOCUS, + MSG_AUTH_REQUEST, MSG_SYSTEM_MAX, MSG_APP_START_TYPE = 100, MSG_REG_RENDER = MSG_APP_START_TYPE, diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 8f12f15..b8bdc81 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -45,7 +45,6 @@ private: bool CheckUid(pid_t uid); void TypeMapInit(); void QosApplyInit(); - void SetSystemAuth(int uid, bool status); void TryCreateRsGroup(); void QueryUi(pid_t uid, IntervalReply& queryRs); void QueryRender(pid_t uid, IntervalReply& queryRs); @@ -53,19 +52,19 @@ private: void QueryHwc(pid_t uid, IntervalReply& queryRs); int GetRequestType(std::string strRequstType); void DealSystemRequest(int requestType, const Json::Value& payload); - void DealAppRequest(int requestType, const Json::Value& payload, pid_t uid); void NewForeground(int uid, int pid); void NewBackground(int uid, int pid); void NewAppStart(int uid, int pid); void AppKilled(int uid, int pid); void ContinuousTaskProcess(int uid, int pid, int status); + void AuthRequestProcess(int uid, int pid); bool ModifySystemRate(const Json::Value& payload); void SetAppRate(const Json::Value& payload); int FindRateFromInfo(int uiTid, const Json::Value& payload); void SetRenderServiceRate(const Json::Value& payload); bool CheckJsonValid(const Json::Value& payload); void SetFrameRate(int rtgId, int rate); - std::list::iterator GetRecordOfUid(int uid); + std::list::iterator GetRecordOfPid(int pid); void PrintInfo(); bool ParsePayload(const Json::Value& payload, int& uid, int& pid); @@ -73,7 +72,7 @@ private: std::list foregroundApp_ = {}; std::unordered_map msgType_ = {}; QosPolicy qosPolicy_; - std::map> authApps_; + std::vector authApps_; int renderServiceGrpId_ = -1; int rsTid_ = -1; int systemRate_ = 0; @@ -82,13 +81,13 @@ private: class ForegroundAppRecord { public: - explicit ForegroundAppRecord(int uid, int uiTid); + explicit ForegroundAppRecord(int pid, int uiTid); ~ForegroundAppRecord(); void AddKeyThread(int tid, int prio = PRIO_NORMAL); bool BeginScene(); bool EndScene(); - int GetUid() const; + int GetPid() const; int GetGrpId() const; int GetRate() const; void SetRate(int appRate); @@ -98,7 +97,7 @@ public: void PrintKeyThreads(); private: - int uid_ = 0; + int pid_ = 0; int grpId_ = 0; int rate_ = 0; int uiTid_ = 0; diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index ece62eb..c0cf0ae 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -35,13 +35,13 @@ constexpr unsigned int RTG_SCHED_IPC_MAGIC = 0xAB; * auth_ctrl */ struct AuthCtrlData { - unsigned int uid; + unsigned int pid; unsigned int type; unsigned int rtgUaFlag; unsigned int qosUaFlag; unsigned int status; #ifdef QOS_EXT_ENABLE - bool enhance_status; + bool enhanceStatus; #endif }; @@ -169,12 +169,12 @@ struct RtgEnableData { * interface */ int EnableRtg(bool flag); -int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status); -int AuthPause(unsigned int uid); -int AuthDelete(unsigned int uid); -int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status); -int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status); -int AuthEnhance(unsigned int uid, bool enhance_status); +int AuthEnable(unsigned int pid, unsigned int uaFlag, unsigned int status); +int AuthPause(unsigned int pid); +int AuthDelete(unsigned int pid); +int AuthGet(unsigned int pid, unsigned int *uaFlag, unsigned int *status); +int AuthSwitch(unsigned int pid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status); +int AuthEnhance(unsigned int pid, bool enhanceStatus); int QosApply(unsigned int level); int QosApplyForOther(unsigned int level, int tid); int QosLeave(void); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 410d29d..098c6d6 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -108,14 +108,14 @@ void TaskController::QueryUi(int uid, IntervalReply& queryRs) return; } pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - auto iter = GetRecordOfUid(uid); + auto iter = GetRecordOfPid(pid); if (iter == foregroundApp_.end()) { - CONCUR_LOGD("Query ui with uid %{public}d failed: pid %{public}d", uid, pid); + CONCUR_LOGD("Query ui with pid %{public}d failed", pid); return; } int grpId = iter->GetGrpId(); if (grpId <= 0) { - CONCUR_LOGI("%{public}d Query ui with none grpid", uid); + CONCUR_LOGI("%{public}d Query ui with none grpid", pid); queryRs.rtgId = -1; } else { queryRs.rtgId = grpId; @@ -128,14 +128,14 @@ void TaskController::QueryRender(int uid, IntervalReply& queryRs) return; } pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - auto iter = GetRecordOfUid(uid); + auto iter = GetRecordOfPid(pid); if (iter == foregroundApp_.end()) { - CONCUR_LOGD("Query render with uid %{public}d failed, pid %{public}d", uid, pid); + CONCUR_LOGD("Query render with pid %{public}d failed", pid); return; } int grpId = iter->GetGrpId(); if (grpId <= 0) { - CONCUR_LOGI("%{public}d Query render with none grpid", uid); + CONCUR_LOGI("%{public}d Query render with none grpid", pid); queryRs.rtgId = -1; } else { queryRs.rtgId = grpId; @@ -169,39 +169,22 @@ void TaskController::QueryHwc(int uid, IntervalReply& queryRs) return; } pid_t pid = IPCSkeleton::GetInstance().GetCallingPid(); - auto iter = GetRecordOfUid(uid); + auto iter = GetRecordOfPid(pid); if (iter == foregroundApp_.end()) { - CONCUR_LOGD("Query ipc thread with uid %{public}d failed, pid %{public}d", uid, pid); + CONCUR_LOGD("Query ipc thread with pid %{public}d failed", pid); return; } int grpId = iter->GetGrpId(); if (grpId <= 0) { - CONCUR_LOGI("%{public}d Query ipc thread with none grpid", uid); + CONCUR_LOGI("%{public}d Query ipc thread with none grpid", pid); queryRs.rtgId = -1; } else { queryRs.rtgId = grpId; } } -void TaskController::SetSystemAuth(int uid, bool status) -{ - int ret; - if (status) { - ret = AuthEnable(uid, AF_RTG_ALL, static_cast(AuthStatus::AUTH_STATUS_FOREGROUND)); - } else { - ret = AuthDelete(uid); - } - - if (ret == 0) { - CONCUR_LOGI("set auth status(%{public}d) for %{public}d success", status, uid); - } else { - CONCUR_LOGE("set auth status(%{public}d) for %{public}d fail with ret %{public}d ", status, uid, ret); - } -} - void TaskController::Init() { - SetSystemAuth(RS_UID, true); TypeMapInit(); qosPolicy_.Init(); TryCreateRsGroup(); @@ -209,7 +192,6 @@ void TaskController::Init() void TaskController::Release() { - SetSystemAuth(RS_UID, false); msgType_.clear(); if (renderServiceGrpId_ <= 0) { return; @@ -227,6 +209,7 @@ void TaskController::TypeMapInit() msgType_.insert(pair("appKilled", MSG_APP_KILLED)); msgType_.insert(pair("continuousStart", MSG_CONTINUOUS_TASK_START)); msgType_.insert(pair("continuousEnd", MSG_CONTINUOUS_TASK_END)); + msgType_.insert(pair("authRequest", MSG_AUTH_REQUEST)); } void TaskController::TryCreateRsGroup() @@ -248,7 +231,6 @@ void TaskController::TryCreateRsGroup() CONCUR_LOGI("CreateRsRtgGroup failed! rtGrp:%{public}d", renderServiceGrpId_); return; } - SetSystemAuth(RS_UID, true); } int TaskController::GetRequestType(std::string strRequstType) @@ -262,7 +244,7 @@ int TaskController::GetRequestType(std::string strRequstType) bool TaskController::CheckUid(pid_t uid) { - if ((uid != SYSTEM_UID) && (uid != 0)) { + if ((uid != SYSTEM_UID) && (uid != 0) && (uid != RS_UID)) { return false; } return true; @@ -307,42 +289,19 @@ void TaskController::DealSystemRequest(int requestType, const Json::Value& paylo case MSG_CONTINUOUS_TASK_END: ContinuousTaskProcess(uid, pid, requestType); break; + case MSG_AUTH_REQUEST: + AuthRequestProcess(uid, pid); + break; default: CONCUR_LOGE("Unknown system request"); break; } } -void TaskController::DealAppRequest(int requestType, const Json::Value& payload, pid_t uid) -{ - if (uid <= SYSTEM_UID) { - CONCUR_LOGE("Unexpected uid in app req"); - return; - } - int tid = 0; - try { - tid = stoi(payload["tid"].asString()); - } catch (...) { - CONCUR_LOGE("Unexpected tid format"); - return; - } - if ((requestType >= MSG_REG_RENDER) && (requestType <= MSG_REG_KEY_THERAD)) { - int prioType = PRIO_NORMAL; - auto record = GetRecordOfUid(uid); - if (record == foregroundApp_.end()) { - return; - } - if (requestType != MSG_REG_KEY_THERAD) { - prioType = PRIO_RT; - } - record->AddKeyThread(tid, prioType); - } -} - -std::list::iterator TaskController::GetRecordOfUid(int uid) +std::list::iterator TaskController::GetRecordOfPid(int pid) { for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetUid() == uid) { + if (iter->GetPid() == pid) { return iter; } } @@ -352,24 +311,24 @@ std::list::iterator TaskController::GetRecordOfUid(int uid) void TaskController::NewForeground(int uid, int pid) { int uiTid = pid; - auto it = authApps_.find(uid); + auto it = find(authApps_.begin(), authApps_.end(), pid); if (it == authApps_.end()) { - CONCUR_LOGI("un-authed uid %{public}d", uid); + CONCUR_LOGI("un-authed pid %{public}d", pid); return; } - unsigned int uidParam = static_cast(uid); + unsigned int pidParam = static_cast(pid); unsigned int uaFlag = AF_RTG_ALL; unsigned int status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); - int ret = AuthEnable(uidParam, uaFlag, status); + int ret = AuthEnable(pidParam, uaFlag, status); if (ret == 0) { - CONCUR_LOGI("auth_enable %{public}d success", uid); + CONCUR_LOGI("auth_enable %{public}d success", pid); } else { - CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", uid, ret); + CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", pid, ret); } bool found = false; bool ddlEnabled = OHOS::system::GetBoolParameter(INTERVAL_DDL, false); for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetUid() == uid) { + if (iter->GetPid() == pid) { found = true; if (ddlEnabled) { iter->AddKeyThread(uiTid, PRIO_RT); @@ -377,9 +336,9 @@ void TaskController::NewForeground(int uid, int pid) iter->BeginScene(); } } - CONCUR_LOGI("uid %{public}d change to foreground.", uid); + CONCUR_LOGI("pid %{public}d change to foreground.", pid); if (!found) { - ForegroundAppRecord *tempRecord = new ForegroundAppRecord(uid, uiTid); + ForegroundAppRecord *tempRecord = new ForegroundAppRecord(pid, uiTid); if (tempRecord->IsValid()) { foregroundApp_.push_back(*tempRecord); if (ddlEnabled) { @@ -394,22 +353,22 @@ void TaskController::NewForeground(int uid, int pid) void TaskController::NewBackground(int uid, int pid) { - auto it = authApps_.find(uid); + auto it = find(authApps_.begin(), authApps_.end(), pid); if (it == authApps_.end()) { - CONCUR_LOGI("un-authed uid %{public}d", uid); + CONCUR_LOGI("un-authed pid %{public}d", pid); return; } - CONCUR_LOGI("uid %{public}d change to background.", uid); - unsigned int uidParam = static_cast(uid); + CONCUR_LOGI("pid %{public}d change to background.", pid); + unsigned int pidParam = static_cast(pid); - int ret = AuthPause(uidParam); + int ret = AuthPause(pidParam); if (ret == 0) { - CONCUR_LOGI("auth_pause %{public}d success", uid); + CONCUR_LOGI("auth_pause %{public}d success", pid); } else { - CONCUR_LOGI("auth_pause %{public}d fail with %{public}d", uid, ret); + CONCUR_LOGI("auth_pause %{public}d fail with %{public}d", pid, ret); } for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetUid() == uid) { + if (iter->GetPid() == pid) { iter->EndScene(); return; } @@ -418,69 +377,71 @@ void TaskController::NewBackground(int uid, int pid) void TaskController::NewAppStart(int uid, int pid) { - CONCUR_LOGI("uid %{public}d start.", uid); - unsigned int uidParam = static_cast(uid); + CONCUR_LOGI("pid %{public}d start.", pid); + unsigned int pidParam = static_cast(pid); unsigned int uaFlag = AF_RTG_ALL; unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); - int ret = AuthEnable(uidParam, uaFlag, status); + int ret = AuthEnable(pidParam, uaFlag, status); if (ret == 0) { - CONCUR_LOGI("auth_enable %{public}d success", uid); + CONCUR_LOGI("auth_enable %{public}d success", pid); } else { - CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", uid, ret); + CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", pid, ret); return; } - auto it = authApps_.find(uid); - if (it == authApps_.end()) { - authApps_.insert(pair>(uid, {pid})); - CONCUR_LOGD("uid %{public}d create, insert pid %{public}d", uid, pid); - } else { - auto iter = it->second.find(pid); - if (iter == it->second.end()) { - it->second.insert(pid); - CONCUR_LOGD("pid %{public}d insert uid %{public}d, size = %{public}d", - pid, uid, static_cast(it->second.size())); - } - } + authApps_.push_back(pid); } void TaskController::AppKilled(int uid, int pid) { - CONCUR_LOGI("uid %{public}d killed.", uid); - auto it = authApps_.find(uid); - if (it != authApps_.end()) { - it->second.erase(pid); - if (it->second.size() != 0) { - CONCUR_LOGD("uid %{public}d is still has %{public}d pid", uid, static_cast(it->second.size())); - return; - } - authApps_.erase(it); - } - unsigned int uidParam = static_cast(uid); - int ret = AuthDelete(uidParam); + CONCUR_LOGI("pid %{public}d killed.", pid); + unsigned int pidParam = static_cast(pid); + int ret = AuthDelete(pidParam); if (ret == 0) { - CONCUR_LOGI("auth_delete %{public}d success", uid); + CONCUR_LOGI("auth_delete %{public}d success", pid); } else { - CONCUR_LOGE("auth_delete %{public}d fail with %{public}d", uid, ret); + CONCUR_LOGE("auth_delete %{public}d fail with %{public}d", pid, ret); } std::lock_guard lock(appInfoLock_); for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { - if (iter->GetUid() == uid) { + if (iter->GetPid() == pid) { foregroundApp_.erase(iter++); break; } } + for (auto iter = authApps_.begin(); iter != authApps_.end(); iter++) { + if (*iter == pid) { + authApps_.erase(iter); + break; + } + } +} + +void TaskController::AuthRequestProcess(int uid, int pid) +{ + if (uid != RS_UID) { + CONCUR_LOGE("uid %{public}d cannot request auth", uid); + return; + } + unsigned int uaFlag = AF_RTG_ALL; + unsigned int status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); + int ret = AuthEnable(pid, uaFlag, status); + if (ret == 0) { + CONCUR_LOGI("auth process %{public}d success", pid); + } else { + CONCUR_LOGI("auth process %{public}d failed, ret %{public}d", pid, ret); + } } void TaskController::ContinuousTaskProcess(int uid, int pid, int status) { int ret = -1; if (status == static_cast(MSG_CONTINUOUS_TASK_START)) { - ret = AuthEnhance(uid, true); - CONCUR_LOGI("auth_enhance uid %{public}d start, ret %{public}d", uid, ret); + ret = AuthEnhance(pid, true); + CONCUR_LOGI("auth_enhance pid %{public}d start, ret %{public}d", pid, ret); } else if (status == static_cast(MSG_CONTINUOUS_TASK_END)) { - ret = AuthEnhance(uid, false); - CONCUR_LOGI("auth_enhance uid %{public}d end, ret %{public}d", uid, ret); + ret = AuthEnhance(pid, false); + CONCUR_LOGI("auth_enhance pid %{public}d end, ret %{public}d", pid, ret); } else { CONCUR_LOGE("Invalid auth_enhance status %{public}d", status); } @@ -634,9 +595,9 @@ int TaskController::CreateNewRtgGrp(int prioType, int rtNum) return ret; } -ForegroundAppRecord::ForegroundAppRecord(int uid, int uiTid) +ForegroundAppRecord::ForegroundAppRecord(int pid, int uiTid) { - uid_ = uid; + pid_ = pid; uiTid_ = uiTid; if (OHOS::system::GetBoolParameter(INTERVAL_DDL, false)) { grpId_ = TaskController::GetInstance().CreateNewRtgGrp(PRIO_RT, MAX_KEY_THREADS); @@ -682,7 +643,7 @@ void ForegroundAppRecord::AddKeyThread(int tid, int prio) bool ForegroundAppRecord::BeginScene() { if (grpId_ <= 0) { - CONCUR_LOGI("Error begin scene in uid %{public}d", uid_); + CONCUR_LOGI("Error begin scene in pid %{public}d", pid_); return false; } OHOS::RME::BeginFrameFreq(grpId_, 0); @@ -694,16 +655,16 @@ bool ForegroundAppRecord::EndScene() { grpId_ = SearchRtgForTid(uiTid_); if (grpId_ <= 0) { - CONCUR_LOGI("Error end scene loss grpId_ in uid %{public}d", uid_); + CONCUR_LOGI("Error end scene loss grpId_ in pid %{public}d", pid_); return false; } OHOS::RME::EndScene(grpId_); return true; } -int ForegroundAppRecord::GetUid() const +int ForegroundAppRecord::GetPid() const { - return uid_; + return pid_; } int ForegroundAppRecord::GetGrpId() const @@ -733,7 +694,7 @@ int ForegroundAppRecord::GetUiTid() const bool ForegroundAppRecord::IsValid() { - if (uid_ > 0) { + if (pid_ > 0) { return true; } return false; @@ -742,7 +703,7 @@ bool ForegroundAppRecord::IsValid() void ForegroundAppRecord::PrintKeyThreads() { std::string strLog = "pid "; - strLog.append(std::to_string(uid_)); + strLog.append(std::to_string(pid_)); strLog.append(" has key threads: "); for (auto iter = keyThreads_.begin(); iter != keyThreads_.end(); iter++) { std::string temp = std::to_string(*iter); diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index 2d6f775..5ef20e8 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -87,7 +87,7 @@ int EnableRtg(bool flag) return 0; }; -int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status) +int AuthEnable(unsigned int pid, unsigned int uaFlag, unsigned int status) { struct AuthCtrlData data; int fd; @@ -98,7 +98,7 @@ int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status) return fd; } - data.uid = uid; + data.pid = pid; data.rtgUaFlag = uaFlag; data.qosUaFlag = AF_QOS_ALL; data.status = status; @@ -107,14 +107,14 @@ int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status) ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); #ifdef QOS_DEBUG if (ret < 0) { - printf("auth enable failed for uid %u with status %u\n", uid, status); + printf("auth enable failed for pid %u with status %u\n", pid, status); } #endif close(fd); return ret; } -int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status) +int AuthSwitch(unsigned int pid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status) { struct AuthCtrlData data; int fd; @@ -125,7 +125,7 @@ int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, uns return fd; } - data.uid = uid; + data.pid = pid; data.rtgUaFlag = rtgFlag; data.qosUaFlag = qosFlag; data.status = status; @@ -134,14 +134,14 @@ int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, uns ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); #ifdef QOS_DEBUG if (ret < 0) { - printf("auth switch failed for uid %u with status %u\n", uid, status); + printf("auth switch failed for pid %u with status %u\n", pid, status); } #endif close(fd); return ret; } -int AuthDelete(unsigned int uid) +int AuthDelete(unsigned int pid) { struct AuthCtrlData data; int fd; @@ -152,20 +152,20 @@ int AuthDelete(unsigned int uid) return fd; } - data.uid = uid; + data.pid = pid; data.type = static_cast(AuthManipulateType::AUTH_DELETE); ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); #ifdef QOS_DEBUG if (ret < 0) { - printf("auth delete failed for uid %u\n", uid); + printf("auth delete failed for pid %u\n", pid); } #endif close(fd); return ret; } -int AuthPause(unsigned int uid) +int AuthPause(unsigned int pid) { struct AuthCtrlData data; int fd; @@ -176,7 +176,7 @@ int AuthPause(unsigned int uid) return fd; } - data.uid = uid; + data.pid = pid; data.type = static_cast(AuthManipulateType::AUTH_SWITCH); data.rtgUaFlag = 0; data.qosUaFlag = AF_QOS_DELEGATED; @@ -185,14 +185,14 @@ int AuthPause(unsigned int uid) ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); #ifdef QOS_DEBUG if (ret < 0) { - printf("auth pause failed for uid %u\n", uid); + printf("auth pause failed for pid %u\n", pid); } #endif close(fd); return ret; } -int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status) +int AuthGet(unsigned int pid, unsigned int *uaFlag, unsigned int *status) { struct AuthCtrlData data; int fd; @@ -203,13 +203,13 @@ int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status) return fd; } - data.uid = uid; + data.pid = pid; data.type = static_cast(AuthManipulateType::AUTH_GET); ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); #ifdef QOS_DEBUG if (ret < 0) { - printf("auth get failed for uid %u\n", uid); + printf("auth get failed for pid %u\n", pid); } #endif close(fd); @@ -220,7 +220,7 @@ int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status) return ret; } -int AuthEnhance(unsigned int uid, bool enhance_status) +int AuthEnhance(unsigned int pid, bool enhanceStatus) { int ret = 0; #ifdef QOS_EXT_ENABLE @@ -230,8 +230,8 @@ int AuthEnhance(unsigned int uid, bool enhance_status) return fd; } - data.uid = uid; - data.enhance_status = enhance_status; + data.pid = pid; + data.enhanceStatus = enhanceStatus; ret = ioctl(fd, ENHANCE_AUTH_CTRL_OPERATION, &data); close(fd); #endif diff --git a/test/unittest/phone/concurrent_task_client_test.cpp b/test/unittest/phone/concurrent_task_client_test.cpp index 050ab80..6fb5453 100644 --- a/test/unittest/phone/concurrent_task_client_test.cpp +++ b/test/unittest/phone/concurrent_task_client_test.cpp @@ -58,6 +58,7 @@ HWTEST_F(ConcurrentTaskClientTest, ReportDataTest, TestSize.Level1) int64_t value = 3587; std::unordered_map payload; payload["uid"] = "3587"; + payload["pid"] = "12345"; payload["type"] = "appStart"; ConcurrentTaskClient::GetInstance().ReportData(resType, value, payload); } diff --git a/test/unittest/phone/concurrent_task_controller_test.cpp b/test/unittest/phone/concurrent_task_controller_test.cpp index fb4893b..ab64bf4 100644 --- a/test/unittest/phone/concurrent_task_controller_test.cpp +++ b/test/unittest/phone/concurrent_task_controller_test.cpp @@ -103,18 +103,6 @@ HWTEST_F(ConcurrentTaskControllerTest, InitTest, TestSize.Level1) TaskController::GetInstance().Init(); } -/** - * @tc.name: PushTaskTest - * @tc.desc: Test whether the PushTask interface are normal. - * @tc.type: FUNC - */ -HWTEST_F(ConcurrentTaskControllerTest, AuthSystemTest, TestSize.Level1) -{ - TaskController::GetInstance().SetSystemAuth(3039, true); - TaskController::GetInstance().SetSystemAuth(3039, false); - TaskController::GetInstance().SetSystemAuth(3039, true); -} - /** * @tc.name: PushTaskTest * @tc.desc: Test whether the PushTask interface are normal. @@ -210,12 +198,12 @@ HWTEST_F(ConcurrentTaskControllerTest, NewForegroundTest, TestSize.Level1) fore.NewBackground(uid, tid); fore.ContinuousTaskProcess(uid, tid, static_cast(MSG_CONTINUOUS_TASK_START)); fore.AppKilled(uid, tid); - uid = 574; - fore.foregroundApp_.push_back(ForegroundAppRecord(574, 0)); + tid = 574; + fore.foregroundApp_.push_back(ForegroundAppRecord(tid, 0)); fore.foregroundApp_.push_back(ForegroundAppRecord(1, 0)); fore.foregroundApp_.push_back(ForegroundAppRecord(3, 0)); auto iter = fore.foregroundApp_.begin(); - EXPECT_EQ(iter->GetUid(), uid); + EXPECT_EQ(iter->GetPid(), tid); fore.NewForeground(uid, tid); fore.NewBackground(uid, tid); fore.NewAppStart(uid, tid); @@ -255,7 +243,7 @@ HWTEST_F(ConcurrentTaskControllerTest, AddKeyThreadTest, TestSize.Level1) int tid4 = 48; int tid5 = 49; int prio = PRIO_NORMAL; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid, 0); + ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(tid, 0); foregroundapprecord.AddKeyThread(tid, prio); foregroundapprecord.keyThreads_.insert(tid); foregroundapprecord.AddKeyThread(tid, prio); @@ -284,8 +272,8 @@ HWTEST_F(ConcurrentTaskControllerTest, AddKeyThreadTest, TestSize.Level1) */ HWTEST_F(ConcurrentTaskControllerTest, BeginSceneTest, TestSize.Level1) { - int uid = 758; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid, 0); + int pid = 758; + ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0); foregroundapprecord.BeginScene(); foregroundapprecord.EndScene(); foregroundapprecord.grpId_ = -1; @@ -303,20 +291,20 @@ HWTEST_F(ConcurrentTaskControllerTest, BeginSceneTest, TestSize.Level1) */ HWTEST_F(ConcurrentTaskControllerTest, IsValidTest, TestSize.Level1) { - int uid = 758; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid, 0); - EXPECT_EQ(foregroundapprecord.GetUid(), foregroundapprecord.uid_); + int pid = 758; + ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0); + EXPECT_EQ(foregroundapprecord.GetPid(), foregroundapprecord.pid_); EXPECT_EQ(foregroundapprecord.GetGrpId(), foregroundapprecord.grpId_); - foregroundapprecord.uid_ = -1; + foregroundapprecord.pid_ = -1; foregroundapprecord.grpId_ = 1; EXPECT_EQ(foregroundapprecord.IsValid(), false); - foregroundapprecord.uid_ = -1; + foregroundapprecord.pid_ = -1; foregroundapprecord.grpId_ = -1; EXPECT_EQ(foregroundapprecord.IsValid(), false); - foregroundapprecord.uid_ = 1; + foregroundapprecord.pid_ = 1; foregroundapprecord.grpId_ = -1; EXPECT_EQ(foregroundapprecord.IsValid(), true); - foregroundapprecord.uid_ = 1; + foregroundapprecord.pid_ = 1; foregroundapprecord.grpId_ = 1; EXPECT_EQ(foregroundapprecord.IsValid(), true); } @@ -328,8 +316,8 @@ HWTEST_F(ConcurrentTaskControllerTest, IsValidTest, TestSize.Level1) */ HWTEST_F(ConcurrentTaskControllerTest, PrintKeyThreadsTest, TestSize.Level1) { - int uid = 758; - ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(uid, 0); + int pid = 758; + ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0); foregroundapprecord.keyThreads_.insert(1); foregroundapprecord.keyThreads_.insert(3); foregroundapprecord.keyThreads_.insert(5); @@ -431,14 +419,14 @@ HWTEST_F(ConcurrentTaskControllerTest, SetFrameRateTest, TestSize.Level1) } /** - * @tc.name: GetUid - * @tc.desc: Test whether the GetUid interface are normal. + * @tc.name: GetPid + * @tc.desc: Test whether the GetPid interface are normal. * @tc.type: FUNC */ -HWTEST_F(ConcurrentTaskControllerTest, GetUidTest, TestSize.Level1) +HWTEST_F(ConcurrentTaskControllerTest, GetPidTest, TestSize.Level1) { ForegroundAppRecord foreApp = ForegroundAppRecord(758, 0); - EXPECT_EQ(foreApp.GetUid(), 758); + EXPECT_EQ(foreApp.GetPid(), 758); } /** diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index b154419..2260232 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -23,7 +23,7 @@ using namespace testing; using namespace testing::ext; using namespace OHOS::FFRT_TEST; using namespace std; - +constexpr unsigned int AF_QOS_ALL = 0x0003; class QosInterfaceTest : public testing::Test { public: @@ -69,10 +69,10 @@ HWTEST_F(QosInterfaceTest, EnableRtgTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, AuthEnableTest, TestSize.Level1) { - unsigned int uid = 1; - unsigned int uaFlag = 1; - unsigned int status = 1; - int ret = AuthEnable(uid, uaFlag, status); + unsigned int pid = gettid(); + unsigned int uaFlag = AF_RTG_ALL; + unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); + int ret = AuthEnable(pid, uaFlag, status); EXPECT_EQ(ret, 0); } @@ -83,11 +83,13 @@ HWTEST_F(QosInterfaceTest, AuthEnableTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, AuthSwitchTest, TestSize.Level1) { - unsigned int uid = 1; - unsigned int rtgFlag = 1; - unsigned int qosFlag = 1; - unsigned int status = 1; - int ret = AuthSwitch(uid, rtgFlag, qosFlag, status); + unsigned int pid = gettid(); + unsigned int rtgFlag = AF_RTG_ALL; + unsigned int qosFlag = AF_QOS_ALL; + unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); + AuthEnable(pid, rtgFlag, status); + status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); + int ret = AuthSwitch(pid, rtgFlag, qosFlag, status); EXPECT_EQ(ret, 0); } @@ -98,9 +100,13 @@ HWTEST_F(QosInterfaceTest, AuthSwitchTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, AuthDeleteTest, TestSize.Level1) { - unsigned int uid = 1; - int ret = AuthDelete(uid); + unsigned int pid = gettid(); + unsigned int uaFlag = AF_RTG_ALL; + unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); + AuthEnable(pid, uaFlag, status); + int ret = AuthDelete(pid); EXPECT_EQ(ret, 0); + AuthEnable(pid, uaFlag, status); } /** @@ -110,10 +116,13 @@ HWTEST_F(QosInterfaceTest, AuthDeleteTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, AuthPauseTest, TestSize.Level1) { - unsigned int uid = 1; - int ret = -1; - ret = AuthPause(uid); - EXPECT_EQ(ret, -1); + unsigned int pid = gettid(); + unsigned int uaFlag = AF_RTG_ALL; + unsigned int status = static_cast(AuthStatus::AUTH_STATUS_BACKGROUND); + AuthEnable(pid, uaFlag, status); + int ret = AuthPause(pid); + EXPECT_EQ(ret, 0); + AuthEnable(pid, uaFlag, status); } /** @@ -140,15 +149,15 @@ HWTEST_F(QosInterfaceTest, QosApplyTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1) { - unsigned int uid = 1000; + unsigned int pid = gettid(); unsigned int uaFlag1 = 0; unsigned int *uaFlag = &uaFlag1; unsigned int status1 = 0; unsigned int *status = &status1; - int ret = AuthGet(uid, uaFlag, status); + int ret = AuthGet(pid, uaFlag, status); EXPECT_GE(ret, 0); - uid = -1; - ret = AuthGet(uid, uaFlag, status); + pid = -1; + ret = AuthGet(pid, uaFlag, status); EXPECT_EQ(ret, -1); } @@ -159,12 +168,12 @@ HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, AuthEnhanceTest, TestSize.Level1) { - unsigned int uid = 1000; - bool enhance_status = false; - int ret = AuthEnhance(uid, enhance_status); + unsigned int pid = gettid(); + bool enhanceStatus = false; + int ret = AuthEnhance(pid, enhanceStatus); EXPECT_EQ(ret, 0); - enhance_status = false; - ret = AuthEnhance(uid, enhance_status); + enhanceStatus = false; + ret = AuthEnhance(pid, enhanceStatus); EXPECT_EQ(ret, 0); } -- Gitee